Hi.
My understanding is that you want to run a command if any of the targets are out of date, but only once, not once for each target. If so, then this seems to work:
#!/usr/bin/env bash
# @(#) s1 Demonstrate PHONY makefile targets.
# Utility functions: print-as-echo, print-line-with-visual-space.
pe() { for i;do printf "%s" "$i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
pl " Makefile:"
cat Makefile
pl " Command to execute if anything out of date:"
cat s2
pl " Initial content of files" [a-z].txt
cat [a-d].txt
pl " Results for touching conf:"
touch abcd.conf
make
cat [a-d].txt
pl " Results for touching a.txt:"
touch a.txt
make
cat [a-d].txt
producing:
% ./s1
-----
Makefile:
# Sun Feb 6 15:37:15 CST 2011
.PHONY: all
all: a.txt b.txt c.txt d.txt abcd.conf
./s2 abcd.conf
-----
Command to execute if anything out of date:
#!/usr/bin/env bash
# @(#) s2 Add one to change content of files.
# Utility functions: print-as-echo, print-line-with-visual-space.
pe() { for i;do printf "%s" "$i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
for file in [abcd].txt
do
t1=$( cat $file )
(( t1++ ))
pe "$t1" > $file
done
-----
Initial content of files a.txt b.txt c.txt d.txt
0
0
0
0
-----
Results for touching conf:
./s2 abcd.conf
1
1
1
1
-----
Results for touching a.txt:
./s2 abcd.conf
2
2
2
2
The file abcd.conf here is a dummy file, yours presumably has something that is operated upon by your "myscript".
Best wishes ... cheers, drl
( Edit 1: minor typo )
---------- Post updated at 16:40 ---------- Previous update was at 16:00 ----------
Hi.
I see that I forgot to add a plain make without touching anything. That action will also run the ./s2 script, so this is probably not an appropriate solution -- one might as well just always run the script.
I'll continue to poke around ... cheers, drl
---------- Post updated at 18:21 ---------- Previous update was at 16:40 ----------
Hi.
Mod 2:
#!/usr/bin/env bash
# @(#) s1 Demonstrate PHONY makefile targets.
# Utility functions: print-as-echo, print-line-with-visual-space.
pe() { for i;do printf "%s" "$i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
M=m2
pl " Makefile, $M:"
cat $M
pl " Command to execute if anything out of date:"
cat s2
pl " Initial content of files" [a-z].txt
cat [a-d].txt
pl " Results for touching a.txt:"
touch a.txt
make -f $M
cat [a-d].txt
pl " Results for touching c.txt:"
sleep 1
touch c.txt
make -f $M
cat [a-d].txt
pl " Results for plain make, nothing out of date:"
sleep 1
make -f $M
cat [a-d].txt
pl " Results for touching abcd.conf, backdated 5 seconds:"
t1=$(date --date="now - 5 sec" +'%Y%m%d%H%M.%S')
touch -t "$t1" abcd.conf
make -f $M
cat [a-d].txt
producing:
% ./s1
-----
Makefile, m2:
# Sun Feb 6 15:37:15 CST 2011
abcd.conf: a.txt b.txt c.txt d.txt
./s2 abcd.conf
touch abcd.conf
-----
Command to execute if anything out of date:
#!/usr/bin/env bash
# @(#) s2 Add one to change content of files.
# Utility functions: print-as-echo, print-line-with-visual-space.
pe() { for i;do printf "%s" "$i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
for file in [abcd].txt
do
t1=$( cat $file )
(( t1++ ))
pe "$t1" > $file
done
-----
Initial content of files a.txt b.txt c.txt d.txt
0
0
0
0
-----
Results for touching a.txt:
./s2 abcd.conf
touch abcd.conf
1
1
1
1
-----
Results for touching c.txt:
./s2 abcd.conf
touch abcd.conf
2
2
2
2
-----
Results for plain make, nothing out of date:
make: `abcd.conf' is up to date.
2
2
2
2
-----
Results for touching abcd.conf, backdated 5 seconds:
./s2 abcd.conf
touch abcd.conf
3
3
3
3
cheers, drl