How to pass target stemming to shell command in Makefile


dkn37

I'm writing a static pattern rule to generate a list of dependencies for targets matching the pattern. Dependencies are generated via shell commands (file contents provide information about dependencies). Here is an example of an explicit rule:

f1.o: $(shell gendep src/f1/f1.source)
    ... (some compilation command here) ...

While this works, I don't want to rewrite it for every new target since I want to keep the same file structure. I try to use static pattern rules like this:

%.o: $(shell gendep src/%/%.source)
    ...

I'm having trouble passing the stem (the matching pattern of %) to a shell command. Shell commands are interpreted literally and in src/%/%. source, which of course does not exist.

I suspect there is a way to pass the stem to a shell command, but I can't seem to find it. Are there any experts here who can help me? Sorry, this is a newbie question (I did have a question).

beta

What you're trying to do is difficult because normally Make expands instructions $(shell ...)before running any rules or even deciding which ones have to be run . We can stop it with a helper extension (a slightly extended Make trick) :

.SECONDEXPANSION:

%.o: $$(shell gendep src/$$*/$$*.source)
    ...

Other methods exist for automatically generating dependencies .

Related


How to pass target stemming to shell command in Makefile

dkn37 I'm writing a static pattern rule to generate a list of dependencies for targets matching the pattern. Dependencies are generated via shell commands (file contents provide information about dependencies). Here is an example of an explicit rule: f1.o: $(s

How to pass target stemming to shell command in Makefile

dkn37 I'm writing a static pattern rule to generate a list of dependencies for targets matching the pattern. Dependencies are generated via shell commands (file contents provide information about dependencies). Here is an example of an explicit rule: f1.o: $(s

Execute shell command inside target in makefile

Jim Moriarty I am new to makefiles. I am trying to perform some shell operations in a makefile under a target. I created a new_target without modifying working code. The code looks like this: all: new_target existing_target new_target: TEST_FILES:=$(

How to pass only parameter value to Makefile target?

Ivan Gabriele: I'm from NodeJS land, so I think of Makefiles as the "scripts" section in npm package.json, which might be wrong (or not?). So my idea is to automate repetitive actions when installing new dependencies by typing: make install github.com/stretchr

How to pass only parameter value to Makefile target?

Ivan Gabriele: I'm from NodeJS land, so I think of Makefiles as the "scripts" section in npm package.json, which might be wrong (or not?). So my idea is to automate repetitive actions when installing new dependencies by typing: make install github.com/stretchr

How to pass only parameter value to Makefile target?

Ivan Gabriele: I'm from NodeJS land, so I think of Makefiles as the "scripts" section in npm package.json, which might be wrong (or not?). So my idea is to automate repetitive actions when installing new dependencies by typing: make install github.com/stretchr

How to pass only parameter value to Makefile target?

Ivan Gabriele: I'm from NodeJS land, so I think of Makefiles as the "scripts" section in npm package.json, which might be wrong (or not?). So my idea is to automate repetitive actions when installing new dependencies by typing: make install github.com/stretchr

How to compare two shell command outputs in Makefile?

Kenorb Mine Makefileare: .PHONY: check check: ifneq $(shell echo 123), $(shell echo 123) $(error Not equal) endif When I run, I get the error: $ make Makefile:3: *** Not equal. Stop. However, this should only happen if they a

How to get variables in $(shell) command in Makefile?

red 888 ❯ make --version GNU Make 3.81 ❯ bash --version GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin18) How can I pass a variable to $(shell) from inside a for loop? I can access the var outside of $(shell), but I don't know how to pass it to A_L

How to compare two shell command outputs in Makefile?

Kenorb Mine Makefileare: .PHONY: check check: ifneq $(shell echo 123), $(shell echo 123) $(error Not equal) endif When I run, I get the error: $ make Makefile:3: *** Not equal. Stop. However, this should only happen if they a

How to compare two shell command outputs in Makefile?

Kenorb Mine Makefileare: .PHONY: check check: ifneq $(shell echo 123), $(shell echo 123) $(error Not equal) endif When I run, I get the error: $ make Makefile:3: *** Not equal. Stop. However, this should only happen if they a

How to change PATH for Makefile $(shell...) command?

user 541686 when i run export PATH := mypath $(error $(shell echo "$${PATH}")) Nothing seems to PATHchange for my call shell. Why is this happening and how do I actually change the PATHfor shellcall? Florian Weimer Is this GNU make? There's a long-standing GN

How to get variables in $(shell) command in Makefile?

red 888 ❯ make --version GNU Make 3.81 ❯ bash --version GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin18) How can I pass a variable to $(shell) from inside a for loop? I can access the var outside of $(shell), but I don't know how to pass it to A_L

How to use echo in shell command in Makefile?

w I have a GNU makefile . It runs fine on Linux, Solaris and OS X. However, under Cygwin-32, Cygwin-64 and MinGW it produces: /bin/sh: -c: line 0: syntax error near unexpected token `(' /bin/sh: -c: line 0: `echo 2.0.4(0.287/5/3) | egrep -i -c "fc22.i686"' Th

How to get variables in $(shell) command in Makefile?

red 888 ❯ make --version GNU Make 3.81 ❯ bash --version GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin18) How can I pass a variable to $(shell) from inside a for loop? I can access the var outside of $(shell), but I don't know how to pass it to A_L

How to get variables in $(shell) command in Makefile?

red 888 ❯ make --version GNU Make 3.81 ❯ bash --version GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin18) How can I pass a variable to $(shell) from inside a for loop? I can access the var outside of $(shell), but I don't know how to pass it to A_L

How to get variables in $(shell) command in Makefile?

red 888 ❯ make --version GNU Make 3.81 ❯ bash --version GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin18) How can I pass a variable to $(shell) from inside a for loop? I can access the var outside of $(shell), but I don't know how to pass it to A_L

How to compare two shell command outputs in Makefile?

Kenorb Mine Makefileare: .PHONY: check check: ifneq $(shell echo 123), $(shell echo 123) $(error Not equal) endif When I run, I get the error: $ make Makefile:3: *** Not equal. Stop. However, this should only happen if they a

How to compare two shell command outputs in Makefile?

Kenorb Mine Makefileare: .PHONY: check check: ifneq $(shell echo 123), $(shell echo 123) $(error Not equal) endif When I run, I get the error: $ make Makefile:3: *** Not equal. Stop. However, this should only happen if they a

How to compare two shell command outputs in Makefile?

Kenorb Mine Makefileare: .PHONY: check check: ifneq $(shell echo 123), $(shell echo 123) $(error Not equal) endif When I run, I get the error: $ make Makefile:3: *** Not equal. Stop. However, this should only happen if they a

How to compare two shell command outputs in Makefile?

Kenorb Mine Makefileare: .PHONY: check check: ifneq $(shell echo 123), $(shell echo 123) $(error Not equal) endif When I run, I get the error: $ make Makefile:3: *** Not equal. Stop. However, this should only happen if they a

How to change PATH for Makefile $(shell...) command?

user 541686 when i run export PATH := mypath $(error $(shell echo "$${PATH}")) Nothing seems to PATHchange for my call shell. Why is this happening and how do I actually change the PATHfor shellcall? Florian Weimer Is this GNU make? There's a long-standing GN

How to get variables in $(shell) command in Makefile?

red 888 ❯ make --version GNU Make 3.81 ❯ bash --version GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin18) How can I pass a variable to $(shell) from inside a for loop? I can access the var outside of $(shell), but I don't know how to pass it to A_L

How to get variables in $(shell) command in Makefile?

red 888 ❯ make --version GNU Make 3.81 ❯ bash --version GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin18) How can I pass a variable to $(shell) from inside a for loop? I can access the var outside of $(shell), but I don't know how to pass it to A_L