-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmakefile
69 lines (44 loc) · 1.35 KB
/
makefile
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
DIR_INC=./include
DIR_SRC=./src
DIR_BIN=.
DIR_OBJ=./obj
DIR_LIB=./lib
CCFILE=arm-linux-gnueabihf-gcc
TARGET=xiaoaimqtt
# 下面黑版编译
#DIR_LIB=./lib.black
#CCFILE=aarch64-linux-gnu-gcc
#TARGET=xiaoaimqtt.black
#sources_all := $(shell find . -name "*.c" -o -name "*.cpp" -o -name "*.h")
#sources_c := $(filter %.c, $(sources_all))
#sources_h := $(filter %.h, $(sources_all))
sources_c := $(wildcard ./src/*.c)
sources_h := $(wildcard ./include/*.h)
INC_HEADER := $(sort $(dir $(sources_h)))
DIR_INC := $(strip $(subst / ./,:./,$(INC_HEADER)))
DIR_INC += #add a NULL on trail
DIR_INC := $(strip $(subst / , ,$(DIR_INC)))
VPATH=$(DIR_INC)
VPATH_INC=$(patsubst %,-I%,$(subst :, ,${VPATH}))
SRC=$(sources_c)
CLRDIR=$(notdir ${SRC})
OBJ=$(patsubst %.c,${DIR_OBJ}/%.o,$(CLRDIR))
CC=${CCFILE}
LD=${CCFILE}
LDFLAGS = -v -lgcc -lm -lc -lgcc_s
LDFLAGS += -L${DIR_LIB} -Wl,-rpath,`pwd`/${DIR_LIB} -lssl -lcrypto
BIN_TARGET=${DIR_BIN}/${TARGET}
.PHONY : clean rebuild all
all: $(BIN_TARGET)
%.d:%.c
set -e; rm -f $@; \ $(CC) -MM $(VPATH_INC) $< > $@.$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
include $(SOURCES:c=.d)
$(BIN_TARGET):$(OBJ)
$(LD) $(LDFLAGS) -o $@ $^ -lpthread -lm
${DIR_OBJ}/%.o:${DIR_SRC}/%.c
$(CC) $(VPATH_INC) -c $< -o $@
clean:
rm -rf $(DIR_OBJ)/*.o $(BIN_TARGET)
rebuild: clean all