Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static Pattern Rules and Filter --- errors: are they intentional #40

Closed
tiborh opened this issue Nov 21, 2021 · 4 comments
Closed

Static Pattern Rules and Filter --- errors: are they intentional #40

tiborh opened this issue Nov 21, 2021 · 4 comments

Comments

@tiborh
Copy link

tiborh commented Nov 21, 2021

When trying this in a Makefile:

obj_files = foo.result bar.o lose.o
src_files = foo.raw bar.c lose.c

all: $(obj_files)

$(filter %.o,$(obj_files)): %.o: %.c
echo "target: $@ prereq: $<"
$(filter %.result,$(obj_files)): %.result: %.raw
echo "target: $@ prereq: $<"

%.c %.raw:
touch $@

clean:
rm -f $(src_files)`

I get the following output:

$ make
touch foo.raw
echo "target: foo.result prereq: foo.raw"
target: foo.result prereq: foo.raw
touch bar.c
echo "target: bar.o prereq: bar.c"
target: bar.o prereq: bar.c
touch lose.c
echo "target: lose.o prereq: lose.c"
target: lose.o prereq: lose.c
touch all.c
cc -c -o all.o all.c
cc all.o foo.result bar.o lose.o -o all
cc: error: foo.result: No such file or directory
cc: error: bar.o: No such file or directory
cc: error: lose.o: No such file or directory
make: *** [: all] Error 1
rm all.o all.c

Is this intended output?

@theicfire
Copy link
Owner

Oof! Try adding .PHONY: all above the all: line. Like this:

obj_files = foo.result bar.o lose.o
src_files = foo.raw bar.c lose.c

.PHONY: all
all: $(obj_files)

$(filter %.o,$(obj_files)): %.o: %.c
	echo "target: $@ prereq: $<"
$(filter %.result,$(obj_files)): %.result: %.raw
	echo "target: $@ prereq: $<"

%.c %.raw:
	touch $@

clean:
	rm -f $(src_files)

Does that fix it for you?

@theicfire
Copy link
Owner

Should be fixed by e457b8d unless you're also noticing a second issue here.

@tiborh
Copy link
Author

tiborh commented Nov 22, 2021

Thank you. Yes, that solves it.
Output:

$ make
touch foo.raw
echo "target: foo.result prereq: foo.raw" 
target: foo.result prereq: foo.raw
touch bar.c
echo "target: bar.o prereq: bar.c"
target: bar.o prereq: bar.c
touch lose.c
echo "target: lose.o prereq: lose.c"
target: lose.o prereq: lose.c

Files in directory:

$ ls
bar.c  foo.raw  lose.c  Makefile

(make clean successfully restores original state)

@theicfire
Copy link
Owner

Great, thanks for letting me know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants