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  <20182019  2020  2021  2022  2023  2024  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  <20182019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: Re: Forcing make rule in IOC Makefile
From: Andrew Johnson <[email protected]>
To: <[email protected]>
Date: Wed, 17 Jan 2018 18:39:20 -0600
Hi Martin,

On 01/17/2018 03:59 PM, Konrad, Martin wrote:
> include $(TOP)/configure/RULES
> #----------------------------------------
> #  ADD RULES AFTER THIS LINE
> 
> .PHONY: checkasg
> checkasg: FORCE
> 	@if grep -Pzo
> '(?s)record\([^\)]+\)(?:(?!field\(ASG|record\([^\)]+\)).)*?}' $(DB) >
> /dev/null ; then echo 'WARNING: Found records without access-security
> group. Please explicitly specify ASG field.' ; fi
> FORCE:
> 
> I can run this rule fine by saying "make checkasg". However, I would
> prefer if it would run as part of "make all". I tried the force
> mechanism above but it doesn't work:

You're close...

> /tmp/testioc/testApp/Db$ make
> make -C O.linux-x86_64 -f ../Makefile TOP=../../.. \
>     T_A=linux-x86_64 install
> make[1]: Entering directory '/tmp/testioc/testApp/Db/O.linux-x86_64'
> make[1]: Nothing to be done for 'install'.
> make[1]: Leaving directory '/tmp/testioc/testApp/Db/O.linux-x86_64'

The default target that the build system is asking GNUmake to build
above is called install, not all. You could make your checkasg rule a
direct dependency on install with this:
  install: checkasg
However it would also run the same check again when it descends into
each of your O.* directories, since they also use their parent
directory's Makefile. Your check would fail there since the .db files
that are in the parent directory, but you can fix that by using
$(addprefix ../,$(DB)) instead of $(DB) in the rule action, but now it
fails when run in the parent directory.

However if you remove the above dependency and instead add checkasg to
the TARGETS variable (before the include of the configure/RULES file)
like this:
  TARGETS += checkasg
then the build system will run the checkasg rule for you when it
descends into an O.* directory. You may want to avoid running it more
than once if you have multiple target architectures configured, so you
can put a conditional around the assignment:
  ifeq ($(EPICS_HOST_ARCH),$(T_A))
    TARGETS += checkasg
  endif


However I can suggest another, possibly better solution: You probably
only really want the check to happen when the individual DB file has
been changed (or when it hasn't passed yet). If you add a rule that
creates a dummy .asg-checked file for every file in $(DB) then the rule
would only be run when the DB file is newer than its .asg-checked file,
which implies the user has modified it since it was last checked.

I recommend moving your check code into a script, either Perl or Bash
would be fine (I'm calling it check-asg.sh below) and modifying it a
bit. The script should check the .db file named as its argument. If the
check fails it should emit the desired warning message and exit with an
error status. Then putting something like this in your Makefile should
cause it to be run automatically:

CHECKED = $(addsuffix .asg-checked, $(DB))
TARGETS += $(CHECKED)

include $(TOP)/configure/RULES

$(CHECKED): %.asg-checked : %
	check-asg.sh $< && touch $@

Note that there is no need for the script to search the parent
directory, the path-name it is given should be correct, even for files
that get generated inside the O.* directory.

Note that I haven't actually tried the above and I've probably made some
typo in it, but I'm reasonably confident that it should work or can be
made to work with minor tweaking — ask if you get stuck.

HTH,

- Andrew

-- 
Arguing for surveillance because you have nothing to hide is no
different than making the claim, "I don't care about freedom of
speech because I have nothing to say." -- Edward Snowdon

References:
Forcing make rule in IOC Makefile Konrad, Martin

Navigate by Date:
Prev: Forcing make rule in IOC Makefile Konrad, Martin
Next: IOC crash Hinko Kocevar
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  <20182019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: Forcing make rule in IOC Makefile Konrad, Martin
Next: Re: Forcing make rule in IOC Makefile Konrad, Martin
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  <20182019  2020  2021  2022  2023  2024 
ANJ, 18 Jan 2018 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·