EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024  <2025 Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024  <2025
<== Date ==> <== Thread ==>

Subject: Re: EPICS app, Db Makefile, rule for python-generated Db file
From: "Johnson, Andrew N. via Tech-talk" <tech-talk at aps.anl.gov>
To: "Wells, Alex (DLSLtd,RAL,LSCI)" <alex.wells at diamond.ac.uk>, "tech-talk at aps.anl.gov" <tech-talk at aps.anl.gov>, Andrea Celentano <andrea.celentano at ge.infn.it>
Date: Tue, 6 May 2025 16:58:14 +0000

Hi Andrea,

 

To expand on Alex’s description, here’s an example of a complete Makefile I created recently for a production IOC which uses some more advanced techniques:

 

TOP=../..

include $(TOP)/configure/CONFIG

## Set variables below here

 

# Install .db and .substitutions files

DB += $(patsubst ../%,%, $(wildcard ../*.db ../*.substitutions))

 

# Convert .pcas files to .db and install

PCAS = $(wildcard ../*.pcas)

PCAS_DB = $(PCAS:../%.pcas=%.db)

DB += $(PCAS_DB)

 

include $(TOP)/configure/RULES

## Add rules below here

 

PCAS2DB = ../pcas2db.py

 

$(PCAS_DB:%=$(COMMON_DIR)/%): $(COMMON_DIR)/%.db: ../%.pcas $(PCAS2DB)

     @$(RM) $@

     $(PCAS2DB) $< > $@

 

$(PCAS_DB:%.db=%.db.d):

     @$(RM) $@

     @echo "$(COMMON_DIR)/$(@:.d=): ../Makefile" > $@

 

I’m using the $(wildcard …) and $(patsubst …) functions to create a list of existing files to be installed directly, and a separate list PCAS_DB of source files named .pcas that need converting into .db files. The python script reads a .pcas file and prints the generated database to stdout, so the Make rule which runs it captures the output into the .db file instead of requiring the script to send the output to a named file. When using a capture like that though I always ensure the build rule deletes the output file before running the script because if the script can’t be run for some reason Make will notice that there’s no output file and will stop the build.

 

I’m using static pattern rules to run the script on the set of .pcas files, and also to generate a .db.d dependency file for each generated .db file. The .db.d files have been required by the EPICS build rules since Base 3.15, they’re a bit annoying but easily generated, the final recipe above creates a minimal one. Note that these rules are actually run from inside the O.<host> directory that the build generates and descends into, so from there the Python script is actually found in the parent directory ../

 

One final reminder of something that Alex said, all of the indents shown above must start with a real tab (“\t” or 0x09) character, they can’t be made up of just space characters.

 

HTH,

 

- Andrew

 

-- 

Complexity comes for free, Simplicity you have to work for.

 

 

On 5/6/25, 3:08AM, "Tech-talk" <tech-talk-bounces at aps.anl.gov> wrote:

 

Hi Andrea,

 

The Makefile modifications are reasonably straightforward. The way I normally do this is as follows:

 

·         Have the Database specified in the "DB" macro; i.e. "DB += myDb.db" (this probably already exists in your IOC's Db/Makefile file)

·         Have a file named "myDb.py". This is your epicsdbbuilder script.

o    Ensure this file outputs its results to "sys.argv[1]", for reasons explained below

·         Add this rule to the Makefile, below that line. Note the "python" line should be indented with a tab:

%.db: ../%.py

    python $< $@

 

After this, running "make" should work as expected and you should see "myDb.db" appear in the built top level "db" folder.

 

To explain the Makefile magic:

·         %.db expands to the name of the database file the EPICS build system is currently trying to build

·         ../%.py will cause EPICS to target the Python file of the same name as the database file

·         python $< $@ will execute "python", passing "$<" (the file path to the Python script) and "$@", the full file path to the database being created. This is why you need to output the database contents to "sys.argv[1]".

 

Hope that helps!

 

Alex Wells


From: Tech-talk <tech-talk-bounces at aps.anl.gov> on behalf of Andrea Celentano via Tech-talk <tech-talk at aps.anl.gov>
Sent: Friday, May 2, 2025 10:54 AM
To: tech-talk at aps.anl.gov <tech-talk at aps.anl.gov>
Subject: EPICS app, Db Makefile, rule for python-generated Db file

 

Dear colleagues,

when developing the EPICS apps that I need, typically I use python scripts to generate Db files, using “epicsdbbuilder” tool (https://github.com/DiamondLightSource/epicsdbbuilder).

 

At this moment, my development flow is as follows. I create the python file to build the database file inside the “Db” folder, then I manually execute it, and then I run make.

 

Indeed, in the default Makefile obtained from “makeBaseApp.pl -t ioc”, I see that the last lines read:

 

#----------------------------------------

#  ADD RULES AFTER THIS LINE

 

This means that I can, in principle, add a rule so that the python script is executed automatically. However, I am not familiar enough with EPICS compilation system (and in general with Makefile) to write this rule. May I ask you for suggestions?

 

Thanks,

Bests,

Andrea Celentano

 

This e-mail and any attachments may contain confidential, copyright and or privileged material, and are for the use of the intended addressee only. If you are not the intended addressee or an authorised recipient of the addressee please notify us of receipt by returning the e-mail and do not use, copy, retain, distribute or disclose the information in or attached to the e-mail. Any opinions expressed within this e-mail are those of the individual and not necessarily of Diamond Light Source Ltd.
Diamond Light Source Ltd. cannot guarantee that this e-mail or any attachments are free from viruses and we cannot accept liability for any damage which you may sustain as a result of software viruses which may be transmitted in or with the message.
Diamond Light Source Limited (company no. 4375679). Registered in England and Wales with its registered office at Diamond House, Harwell Science and Innovation Campus, Didcot, Oxfordshire, OX11 0DE, United Kingdom.


References:
EPICS app, Db Makefile, rule for python-generated Db file Andrea Celentano via Tech-talk
Re: EPICS app, Db Makefile, rule for python-generated Db file Wells, Alex (DLSLtd,RAL,LSCI) via Tech-talk

Navigate by Date:
Prev: Re: [EXTERNAL] Phoebus: How to populate table widget with waveform array Kasemir, Kay via Tech-talk
Next: Re: Would this motor record documentation be considered "current" Peterson, Kevin M. via Tech-talk
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024  <2025
Navigate by Thread:
Prev: Re: EPICS app, Db Makefile, rule for python-generated Db file Wells, Alex (DLSLtd,RAL,LSCI) via Tech-talk
Next: Modbus problem bit swap Wago PLC Jeffrey Gamsby via Tech-talk
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024  <2025
ANJ, 06 May 2025 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions ·
· Download · Search · IRMIS · Talk · Documents · Links · Licensing ·