开发者

sed in makefile, usage

开发者 https://www.devze.com 2023-01-17 12:10 出处:网络
I am in the process of learning makefile creation. Current target is to scan the $(SOURCEDIR) for .c files and create (according to that lise of .c file paths in the format of /path/file.c) a nice $(

I am in the process of learning makefile creation.

Current target is to scan the $(SOURCEDIR) for .c files and create (according to that lise of .c file paths in the format of /path/file.c) a nice $(VPATH) so I do not need to use recursive makefiles (aka pain in the a..).

Atm I am stuck with this, where $(SOURCETREE) will be empty on $(ECHO)

SOURCES := $(shell find $(SOURCEDIR) -name '*.c')
SOURCETREE := $(dir $(SOURCES))
SOURCETREE := $(shell $(ECHO) $(SOURCETREE) | $(SED) -e "s/[[:space:]]/\n/g" | uniq | $(SED) -e "s/\n/[[:space:]]/g");

Maybe I just do not get the point (got late again :/ )

Thanks for any help.

Note: In a bash shell it开发者_如何学运维 works perfectly on my linux workbox (I replace thevariables accordingly) Note: I am no sed pro, so please explain if you do an voodoo with sed, thank you


Comments:

  1. Remove the backticks. They are unnecessary; the $(shell) function already captures the command's output.

  2. The echo/sed/uniq/sed chain can be replaced by ls/uniq. ls will print one file name per line so no need for the replace-and-undo song and dance.

  3. It looks like you're losing the result from $(dir) because you use $(SOURCES) rather than $(SOURCETREE) in the third assignment.

Result:

SOURCES := $(shell find $(SOURCEDIR) -name '*.c')
SOURCETREE := $(dir $(SOURCES))
SOURCETREE := $(shell ls $(SOURCETREE) | uniq);

Actually, even this shortened shell invocation is unnecessary. The $(sort) function will sort a list of names and remove duplicates. From make's documentation: "Incidentally, since sort removes duplicate words, you can use it for this purpose even if you don't care about the sort order."

SOURCES := $(shell find $(SOURCEDIR) -name '*.c')
SOURCETREE := $(sort $(dir $(SOURCES)))
0

精彩评论

暂无评论...
验证码 换一张
取 消