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. |