Keyword '|' in Makefile Prerequisites [duplicate] - makefile

This question already has an answer here:
What does $$# and the pipe symbol in Makefile stand for?
(1 answer)
Closed 6 years ago.
The MakeFile below:
afl-fuzz: afl-fuzz.c | test_x86
gcc afl-fuzz.c -o afl-fuzz
What's the meaning of '|' before test_x86 ?
The MakeFile is from: https://github.com/loverszhaokai/AFL/blob/gcc_mode/Makefile

targets : normal-prerequisites | order-only-prerequisites
The targets will not be updated if the order-only-prerequisites is changed.
Reference: https://www.gnu.org/software/make/manual/html_node/Prerequisite-Types.html

Related

pipe after colon in makefile: /home/.ssh/config: | /home/.ssh [duplicate]

This question already has an answer here:
What does $$# and the pipe symbol in Makefile stand for?
(1 answer)
Closed 2 years ago.
what does | mean in the following piece of makefile?
/home/.ssh:
install -d -m 700 /home/.ssh
/home/.ssh/config: | /home/.ssh
echo "$$CONFIG" >> $#
/home/.ssh/credentials: | /home/.ssh
echo "$$CREDENTIALS" >> $#
thanks
The pipe character declares the relationship to the prerequisite rule to be of an order-only¹ type. Here, if /home/.ssh did not exist, it would be created in any case, but if its timestamp changes, none of the other things will happen just because of that.
¹: https://www.gnu.org/software/make/manual/html_node/Prerequisite-Types.html

Can bash be used to rename by pattern? [duplicate]

This question already has answers here:
Rename files using regular expression in linux
(10 answers)
Closed 2 years ago.
I have files:
alpha_123_abc_file.txt
beta_456_def_file.txt
gamma_789_ghi_file.txt
Is there a way to rename all to cut the parts after the first _ character? To become:
123_abc_file.txt
456_def_file.txt
789_ghi_file.txt
I've looked into the perl tool but I an unsure if it has the capability to search out a pattern like that.
for file in *_*; do echo mv -- "$file" "${file#*_}"; done
Remove the echo when you're done testing and ready to actually do the mv.

bash: finding file without keyword [duplicate]

This question already has answers here:
Grep : get all file that doesn't have a line that matches [closed]
(3 answers)
Closed 4 years ago.
I am looking for a command in bash that lists the files in which a keyword is not present. for listing files with the keyword I do
fgrep KEYWORD .
I was thinking I could feed vimdiff with two files with the lists, something like this
diff `fgrep KEYWORD .` `ls .` (THIS IS NOT CORRECT)
but I would not like to create two new files at hoc.
How about using simple grep option.
grep -L "foo" *
You could use --files-without-match option too with it.

What's the meaning of $#?

I came across the makefile when I read something about flex
fb3-1: fb3-1.l fb3-1.y fb3-1.h
bison -d fb3-1.y
flex -ofb3-1.lex.c fb3-1.l
cc -o $# fb3-1.tab.c fb3-1.lex.c fb3-1funcs.c
but what's the meaning of $#? Is it in the shell or some argument of gcc?
$# is just short-hand for the file name of the current target (fb3-1 in this case).
See the Automatic Variables section of the gnu make manual for full details on this and other useful automatic variables such as $<.

How to provide parameters to a submake when running in parallel?

I am trying to use make to handle some data processing.
Consider the following simple rule in a makefile makefile-month
output_$(YEAR)_$(MONTH): input_$(YEAR)_$(MONTH)
foo input_$(YEAR)_$(MONTH) output_$(YEAR)_$(MONTH)
This rule can be used to process any required month using, e.g.
make -f makefile-month YEAR=2006 MONTH=2
And this works fine.
What I am really interested now is to use make to process several months in parallel.
However, I cannot find a simple way of achieving this.
Notice that using a shell for loop does not work with parallel make.
Defining a global makefile,
all:
for year in 2006; do \
for month in 1 2 3 4 5 6 7 8 9 10 11 12; do \
$(MAKE) -f makefile-month YEAR=$$year MONTH=$$month; \
done; \
done
and running,
make -j 12
does not execute each month in parallel.
Each call to the sub-make is executed in serial.
Any ideas?
There are lots of different ways to handle the details, but the overall solution is to move away from for loops in a single recipe and switch to individual targets. So for example:
YEARS := 2006 2007
MONTHS := 1 2 3 4 5 6 7 8 9 10 11 12
TARGETS := $(foreach Y,$(YEARS),$(foreach M,$(MONTHS),month.$Y.$M))
.PHONY: all $(TARGETS)
all: $(TARGETS)
$(TARGETS):
$(MAKE) -f makefile-month YEAR=$(word 2,$(subst ., ,$#)) MONTH=$(word 3,$(subst ., ,$#))
(note I didn't test this but hopefully you get the idea).

Resources