How to run some commands globally in a Gnu Make file

ⅰ亾dé卋堺 提交于 2019-12-07 20:21:20

问题


I have a gnu Makefile that collects version information through environment variables. Now, I want to do "something" globally before any target is built using the gnumake syntax. As pseudo code, this means:

  • when a specified file exists, delete it
  • run through an array of strings and put their value into a specified file

I tried this:

$(shell if exist $(subst /,\,$(products)filenames.h) del /F/Q $(subst /,\,$(products)filenames.h))
$(foreach Item, $(EnvFilenames), @echo $(Item) >> $(subst /,\,$(products)filenames.h))

this gives me an error:

C:\temp\Makefile.mak:72: *** missing separator.  Stop.

where Line 72 is the $(shell ... line. If I put this in a define section:

define foobar
$(shell if exist $(subst /,\,$(products)filenames.h) del /F/Q $(subst /,\,$(products)filenames.h))
$(foreach Item, $(EnvFilenames), @echo $(Item) >> $(subst /,\,$(products)filenames.h))
endef

and call this for a target, it runs fine:

$(products)$test.o : test.c $(commons)
$(call foobar)
$(cc) $(cflags_m) test.c -o$@ 

and does what it should... but as soon as I want to call it from inside of another define, it fails again with a missing seperator.

What does it mean and how can I fix it?

Compilation takes place on a Win32 platform and does not have to be multi-platform.


回答1:


If once per Make invocation is sufficient, you could put it in a global assignment.

# Ignore the value, calling for side effects
IGNORE := $(shell commands with side effects)

I would recommend against this hack, but I can imagine situations where it might come in handy.



来源:https://stackoverflow.com/questions/9064577/how-to-run-some-commands-globally-in-a-gnu-make-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!