-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
196 lines (159 loc) · 6.86 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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#################################
# Makefile for ION-Core
# Require: gmake
#################################
# bring in the build list
include ./build-list.mk
# test if inclusion is successful
ifndef BUILD_LIST_INCLUDED
$(error build-list.mk is not found or not included, cannot build.)
endif
$(info build-list.mk has been included, proceed to build.)
###########################
# Build Rules
###########################
# This is probably the only thing users would want to change:
INSTALL_PATH = /usr/local/
PWD := $(shell pwd)
export SRC = $(PWD)/src
export INC = $(PWD)/inc
export OUT_BIN = $(PWD)/bin
export MAN = $(PWD)/man
export SCR = $(PWD)/scripts
export TESTS = $(PWD)/tests
# Just locally:
MDIR = $(PWD)/mdir
LIB = $(PWD)/lib
###########################
# Compiler Flags
###########################
# OS_FLAGS is for different combination of OS and HW architecture
# BP_EXTENDED is required enables extension blocks required for QoS.
# EXT_FLAGS is a list of individual extension blocks for locally sourced bundles
export CFLAG = -g -Wall $(OS_FLAGS) -DBP_EXTENDED ${EXT_FLAGS}
export PLATFORM = -lm -pthread
export SHARED_FLAG = -fPIC
export GCC = $(shell command -v gcc || echo /usr/bin/gcc)
##########################
# List of Files
##########################
# Ensure the obj directories exist
_STATIC_OBJ_DIR := $(shell mkdir -p $(LIB)/obj/static)
_SHARED_OBJ_DIR := $(shell mkdir -p $(LIB)/obj/shared)
################################
# Define build targets
################################
.PHONY: all $(PROGRAMS) clean distclean install man uninstall static shared
# Default target to build selected programs
all: $(PROGRAMS)
# Construct .mk file paths
MK_FILES := $(addprefix $(MDIR)/,$(addsuffix .mk,$(PROGRAMS)))
# Include all .mk files
include $(MK_FILES)
# Object files for static libraries
STATIC_ICI_OBJ_FILES := $(patsubst $(SRC)/%.c,$(LIB)/obj/static/%.o,$(SRC_libici))
STATIC_BP_OBJ_FILES := $(patsubst $(SRC)/%.c,$(LIB)/obj/static/%.o,$(SRC_libbp))
STATIC_LTP_OBJ_FILES := $(patsubst $(SRC)/%.c,$(LIB)/obj/static/%.o,$(SRC_libltp))
STATIC_CFDP_OBJ_FILES := $(patsubst $(SRC)/%.c,$(LIB)/obj/static/%.o,$(SRC_libcfdp))
# Object files for dynamic libraries
SHARED_ICI_OBJ_FILES := $(patsubst $(SRC)/%.c,$(LIB)/obj/shared/%.o,$(SRC_libici))
SHARED_BP_OBJ_FILES := $(patsubst $(SRC)/%.c,$(LIB)/obj/shared/%.o,$(SRC_libbp))
SHARED_LTP_OBJ_FILES := $(patsubst $(SRC)/%.c,$(LIB)/obj/shared/%.o,$(SRC_libltp))
SHARED_CFDP_OBJ_FILES := $(patsubst $(SRC)/%.c,$(LIB)/obj/shared/%.o,$(SRC_libcfdp))
# static library targets
static: staticlibici staticlibbp staticlibltp staticlibcfdp
staticlibici: $(STATIC_ICI_OBJ_FILES)
ar rcs $(LIB)/libicicore.a $^
staticlibbp: $(STATIC_BP_OBJ_FILES)
ar rcs $(LIB)/libbpcore.a $^
staticlibltp: $(STATIC_LTP_OBJ_FILES)
ar rcs $(LIB)/libltpcore.a $^
staticlibcfdp: $(STATIC_CFDP_OBJ_FILES)
ar rcs $(LIB)/libcfdpcore.a $^
# Object files compile rule for static library #
$(LIB)/obj/static/%.o: $(SRC)/%.c
$(GCC) $(CFLAG) -I$(INC) -c $< -o $@
# dynamic/shared library targets
shared: $(LIB)/libicicore.so $(LIB)/libbpcore.so $(LIB)/libltpcore.so $(LIB)/libcfdpcore.so
$(LIB)/libicicore.so: $(SHARED_ICI_OBJ_FILES)
$(GCC) -shared -o $(LIB)/libicicore.so $(SHARED_ICI_OBJ_FILES)
$(LIB)/libbpcore.so: $(SHARED_BP_OBJ_FILES)
$(GCC) -shared -o $(LIB)/libbpcore.so $(SHARED_ICI_OBJ_FILES) -L$(LIB) -licicore
$(LIB)/libltpcore.so: $(SHARED_LTP_OBJ_FILES)
$(GCC) -shared -o $(LIB)/libltpcore.so $(SHARED_ICI_OBJ_FILES) -L$(LIB) -licicore -lbpcore
$(LIB)/libcfdpcore.so: $(SHARED_CFDP_OBJ_FILES)
$(GCC) -shared -o $(LIB)/libcfdpcore.so $(SHARED_ICI_OBJ_FILES) -L$(LIB) -licicore -lbpcore
# Object files compile rule for shared library #
$(LIB)/obj/shared/%.o: $(SRC)/%.c
$(GCC) $(CFLAG) -I$(INC) -c $< $(SHARED_FLAG) -o $@
install:
$(info Make "install" target...)
find $(OUT_BIN) -maxdepth 1 -type f -exec cp -v {} $(INSTALL_PATH)/bin \;
cp -v $(OUT_BIN)/ionstart $(INSTALL_PATH)/bin
cp -v $(OUT_BIN)/ionstart.awk $(INSTALL_PATH)/bin
cp -v $(OUT_BIN)/ionstop $(INSTALL_PATH)/bin
cp -v $(OUT_BIN)/killm $(INSTALL_PATH)/bin
install-lib:
$(info Make "install-lib" target...)
@find $(LIB) -maxdepth 1 -name "*.a" -exec cp -v {} $(INSTALL_PATH)/lib \; || true
@find $(LIB) -maxdepth 1 -name "*.so" -exec cp -v {} $(INSTALL_PATH)/lib \; || true
# sym links to original .pod files are in ion-core/src/man
# generated man page is in ion-core/man
man:
$(info Make "man" target...)
./scripts/make-man-pages.sh $(SRC)/man "$(PROGRAMS)"
find $(MAN) -maxdepth 1 -type f -exec cp -v {} $(INSTALL_PATH)/share/man/man1 \; || true
clean:
$(info Make "clean" target...)
@find $(OUT_BIN) -type f ! -name '.gitkeep' ! -name 'ionstart' ! -name 'ionstart.awk' ! -name 'ionstop' ! -name 'killm' -exec rm -f {} + > /dev/null
@find $(LIB) -type f ! -name '.gitkeep' -exec rm -f {} + > /dev/null
test:
$(info Make "test" target...)
@echo "Processing PROGRAMS list from $(BUILD_LIST)..."
@ALL_TESTS_TO_RUN=""; \
for combo in $(COMBINATION_TESTS); do \
COMB=$$(echo $$combo | cut -d':' -f1); \
TESTS_TO_RUN=$$(echo $$combo | cut -d':' -f2 | tr '+' ' '); \
COMB_FOUND=1; \
for prog in $$(echo $$COMB | tr '+' ' '); do \
if ! echo "$(PROGRAMS)" | grep -q "$$prog"; then \
COMB_FOUND=0; \
break; \
fi; \
done; \
if [ $$COMB_FOUND -eq 1 ]; then \
echo "Combination found: $$COMB. Adding tests: $$TESTS_TO_RUN"; \
ALL_TESTS_TO_RUN="$$ALL_TESTS_TO_RUN $$TESTS_TO_RUN"; \
else \
echo "Combination not found: $$COMB"; \
fi; \
done; \
if [ -n "$$ALL_TESTS_TO_RUN" ]; then \
echo "Running the following tests: $$ALL_TESTS_TO_RUN"; \
cd $(TESTS) && ./runtests $$ALL_TESTS_TO_RUN; \
else \
echo "No valid combinations found. No tests to run."; \
fi
uninstall:
$(info Make "uninstall" target...)
@for prog in $(PROGRAMS); do \
rm -f $(INSTALL_PATH)/bin/$$prog; \
rm -f $(INSTALL_PATH)/share/man/man1/$$prog*; \
done
uninstall-lib:
$(info Make "uninstall-lib" target...)
@rm -f $(INSTALL_PATH)/lib/*core.a
@rm -f $(INSTALL_PATH)/lib/*core.so
## Clean up all build artifacts + all source files extracted from ION open source code
distclean:
$(info Make "distclean" target...)
@find $(INC) -mindepth 1 ! -name '.gitkeep' -exec rm -rf {} + > /dev/null
@find $(SRC) -mindepth 1 ! -name '.gitkeep' -exec rm -rf {} + > /dev/null
@find $(LIB) -mindepth 1 ! -name '.gitkeep' -exec rm -rf {} + > /dev/null
@find $(OUT_BIN) -mindepth 1 ! -name '.gitkeep' -exec rm -rf {} + > /dev/null
@find $(MAN) -mindepth 1 ! -name '.gitkeep' -exec rm -rf {} + > /dev/null
@find $(TESTS) -mindepth 1 ! -name '.gitkeep' -exec rm -rf {} + > /dev/null
@rm -f system_up > /dev/null
@rm -f configs > /dev/null
@rm -f scripts/macOS/install_macos_sysctl.sh > /dev/null
@rm -f scripts/macOS/sysctl_script.sh > /dev/null