-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile_3_outofsrc
37 lines (31 loc) · 994 Bytes
/
Makefile_3_outofsrc
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
# Makefile
# 1. Generating prerequisites automatically for header files
# 2. Compile source files automatically in current directory tree
# 3. Out of source tree build
# .
# ├── f1.c
# ├── f1.h
# ├── f2
# │ ├── f22
# │ │ ├── f22.c
# │ │ └── f22.h
# │ ├── f2.c
# │ └── f2.h
# ├── main.c
# ├── Makefile
# └── print_log.h
# build shared library with -fPIC, -shared
CFLAGS = -g # -O3 # -fPIC # CXXFLAGS for .cpp
LDFLAGS = # -L../bar -Wl,-rpath,/foo/bar # -shared
LDLIBS = # -lbar
CPPFLAGS = -MMD -MP # -I../bar
DIR = ./.build
SRC = $(shell find . -type f -name "*.c") # .cpp
$(DIR)/main : $(addprefix $(DIR)/,$(SRC:.c=.o)) # .cpp
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@ # CXX for .cpp
$(DIR)/%.o : %.c # .cpp
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< # CXX CXXFLAGS for .cpp
-include $(shell find . -type f -name "*.d")
clean : ; -rm -fr $(DIR)
.PHONY : clean