how I can get a makefile to manage conditional compilation?

Viewed 82

I have a C file with macros, to compile it I use gcc file.c -D and the (macro of the portion of code I want to compile). I am writing to ask you how I can get a makefile to manage conditional compilation, in order to compile the makefile deciding whether to create the first file or the second (the two MACROs of the file c)

1 Answers

You can call a Makefile with a parameter:

make action argument=something

Then your Makefile can take and propagate this parameter:

CC = gcc
CFLAGS += -std=c11 -pedantic -Wall

action: $(argument)
    $(CC) $(CFLAGS) $(argument) -o demo

clean:
    rm -f demo

Say you have two files: file1.c and file2.c, you can call

make action argument=file1.c

or

make action argument=file2.c

to decide whether to create the first file or the second .

Related