-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile_4_macro
55 lines (44 loc) · 919 Bytes
/
Makefile_4_macro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Makefile:
# build shared library with -fPIC, -shared
CFLAGS = # -g # -O3 # -fPIC # CXXFLAGS for .cpp
LDFLAGS = # -L../foo -Wl,-rpath,../foo # -shared
LDLIBS = # -lhello
CPPFLAGS = -MMD -MP # -I../hello
#CC = $(CXX) # link with CXX for .cpp
all: main
# turn off assert() with NDEBUG
ifdef NDEBUG
CPPFLAGS += -DNDEBUG
CFLAGS += -O3
else
CFLAGS += -g
endif
# target name is basename of one of the source files
main : $(patsubst %.c,%.o,$(wildcard *.c)) # .cpp
-include *.d
clean : ; -rm -fr *.o *.d
.PHONY : clean
----
//main.c
#include <stdio.h>
#include <assert.h>
#include "hello.h"
int main(){
#ifndef NDEBUG
printf("no def\n");
#else
printf("yes def\n");
#endif
int i = 0;
assert(i);
hello();
}
----
$ make NDEBUG=1
cc -O3 -DNDEBUG -MMD -MP -c -o main.o main.c
cc main.o hello.o -o main
$
$ make
cc -g -MMD -MP -c -o main.o main.c
cc main.o hello.o -o main
$