-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile.depreciated
128 lines (109 loc) · 3.18 KB
/
Makefile.depreciated
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#ulib makefile
# setup install directory
TARGET ?= target
MKDIR_P := mkdir -p
CC := gcc
CFLAGS := -O0 -g -Wall -DNDEBUG
# Configurations switches -D
CONFIGS_D += URLP_CONFIG_LINUX_EMU
CONFIGS_D += URLPX_CONFIG_LINUX_EMU
CONFIGS_D += "memset_s(W,WL,V,OL)=memset(W,V,OL)"
# external includes dependancies -I
DEPS += external/mbedtls/include
DEPS += external/secp256k1/include
# Collect lib objects *.o
MODULES += libup2p
MODULES += libucrypto
MODULES += liburlp
MODULES += libusys/async
MODULES += libusys/unix
# Build test applications
APPLICATIONS += liburlp/test
APPLICATIONS += libusys/test
APPLICATIONS += libucrypto/test
APPLICATIONS += libup2p/test/unit
APPLICATIONS += libup2p/test/integration
# Build vars
APP_SRCS += $(APPLICATIONS)
LIBS += $(addprefix $(TARGET)/lib/,$(addsuffix .a,$(foreach mod, $(MODULES),$(subst /,-,$(mod)))))
APPS += $(addprefix $(TARGET)/bin/,$(foreach bin, $(APPLICATIONS),$(subst /,-,$(bin))))
SRCS += $(shell find $(MODULES) -name '*.c')
SRCS += $(shell find $(APP_SRCS) -name '*.c')
HDRS += $(shell find $(MODULES) -name '*.h')
OBJS += $(addprefix $(TARGET)/obj/,$(SRCS:.c=.o))
INCS += $(addprefix -I./,$(MODULES))
INCS += $(addprefix -I./,$(TARGET)/include)
INCS += $(addprefix -I./,$(DEPS))
DEFS += $(addprefix -D,$(CONFIGS_D))
DIRS += $(sort $(dir $(OBJS)))
DIRS += $(TARGET)/bin
DIRS += $(TARGET)/include
DIRS += $(TARGET)/lib
CFLAGS += $(DEFS)
LDFLAGS += $(LIBS) $(addprefix $(TARGET)/lib/, libmbedcrypto.a libsecp256k1.a)
INSTALL += $(LIBS)
INSTALL += $(APPS)
all: $(DIRS) $(OBJS) $(INSTALL)
$(APPS): $(DIRS) $(LIBS)
@echo "LINK $(notdir $@)"
@$(CC) $(shell find $(subst $(TARGET)/bin,$(TARGET)/obj,$(subst -,/,$@)) -name '*.o') \
$(CFLAGS) $(LDFLAGS) $(INCS) -o $@
# The name convention allows collecting lib objects with find,
# IE: $(TARGET)/lib/libucrypto-mbedtls-uaes.a:=$(TARGET)/obj/libucrypto/mbedtls/uaes/**/*.o
$(TARGET)/lib/%.a:
@echo "LINK $(notdir $@)"
@ar rcs $@ $(shell find \
$(subst $(TARGET)/lib,$(TARGET)/obj,$(subst .a,,$(subst -,/,$@))) -name '*.o')
# .c->.o
$(TARGET)/obj/%.o: %.c
@echo " CC $(notdir $<)"
@${CC} -c ${CFLAGS} $(INCS) $< -o $@
# create some output directories
$(DIRS):
@echo "MKDR $@"
@${MKDIR_P} ${DIRS}
# All libraries must have an 'include' directory if they want headers installed
$(TARGET)/include/%.h:
@echo "COPY $(notdir $@)"
@cp $(shell find $(MODULE_INCS) -name $(notdir $@)) $@
.PHONY: clean test test-mem print cscope
# clean our mess
clean:
@echo "CLEAN"
@rm -rf $(INSTALL)
@rm -rf $(TARGET)/obj
test:
@$(foreach bin,$(APPS), \
echo TEST $(bin); \
./$(bin); \
)
test-mem:
@$(foreach bin,$(APPS), \
echo TEST $(bin); \
valgrind \
--track-origins=yes \
--tool=memcheck \
--leak-check=full \
--quiet \
./$(bin); \
)
cscope:
find . \
\( -name '*.c' -o -name '*.h' -o -name '*.hpp' -o -name '*.cpp' \) -print > cscope.files
cscope -b
# Makefile debug print
print:
@echo \
DIRS: $(DIRS) \
LIBS: $(LIBS) \
SRCS: $(SRCS) \
HDRS: $(HDRS) \
INCS: $(INCS) \
OBJS: $(OBJS) \
DEFS: $(DEFS) \
APPS: $(APPS) \
INST: $(INSTALL) \
| sed -e 's/\s\+/\n/g'
#
#
#