Reputation: 3543
I saw previous SO posts 1, 2 etc. I want to pass a preprocessor directive at compile time. With scons, I could do:
num_times = ARGUMENTS.get('c', 1)
env.Append(CCFLAGS = '-DNUM_TIMES=%d' % int(num_times))
I hope, it should also be possible using make. I want to issue
make c=4
or something like that. Can someone suggest a method. I am compiling a folder, which has subfolders with their own makefiles. Thanks in advance.
Upvotes: 1
Views: 1762
Reputation: 206851
One simple approach is to do:
CFLAGS += -DNUM_TIMES=$(c)
export CFLAGS
all:
$(MAKE) -C your_subfolder
call with make c=2
, and not to touch CFLAGS
in the sub-folder makefiles.
Another is to have a Makefile
part in your root folder with all the common settings that you include
in your subdirectory makefiles (with include
). ($(MAKE)
ensures that the command line arguments you gave to make
will also be passed to sub-makes.)
Upvotes: 1