I\'ve got the below simple Makefile which I use for compiling a C program:
all:
gcc -Wall -o myfile myfile.c lol_dht22/dht22.c lol_dht22/locking.c -lwiri
Here's an example makefile that has the two options you are looking for.
all:
gcc -Wall -o myfile myfile.c lol_dht22/dht22.c lol_dht22/locking.c -lwiringPi -lcurl -lm
debug:
gcc -DDEBUG -Wall -o myfile myfile.c lol_dht22/dht22.c lol_dht22/locking.c -lwiringPi -lcurl -lm
You just needed to add a debug option, which is done in similar fashion to the 'all' option you had already declared.
If you want to know how to do it well, here it is. You don't do make debug
, instead, you should call
>make
or
>make DEFS=DEBUG
or
>make DEFS='ANY DEFINES YOU WANT'
In addition to normal Make rebuild criteria, the following Makefile recognizes rebuilds based on DEFS
.
define DEPENDABLE_VAR
.PHONY: phony
$1: phony
@if [[ `cat $1 2>&1` != '$($1)' ]]; then \
echo -n $($1) > $1 ; \
fi
endef
$(eval $(call DEPENDABLE_VAR,DEFS))
.PHONY: all
all: myfile
SRCS := myfile.c lol_dht22/dht22.c lol_dht22/locking.c
myfile: $(SRCS) Makefile DEFS
gcc $(addprefix -D, $(DEFS)) -Wall -o $@ $(SRCS) -lwiringPi -lcurl -lm