-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake.mk
47 lines (34 loc) · 1.18 KB
/
make.mk
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
ifndef EJ_MK
EJ_MK :=
EJ_LIB_DIR ?= $(EJ_DIR)
EJ_OBJ_DIR ?= $(EJ_DIR)/src
EJ_SHARED_LIBRARY := $(EJ_LIB_DIR)/libelfjack.so
EJ_STATIC_LIBRARY := $(EJ_LIB_DIR)/libelfjack.a
EJ_SOURCE_FILES := $(wildcard $(EJ_DIR)/src/*.c)
EJ_OBJECT_FILES := $(patsubst $(EJ_DIR)/src/%.c,$(EJ_OBJ_DIR)/%.o,$(EJ_SOURCE_FILES))
EJ_HEADER_FILES := $(wildcard $(EJ_DIR)/include/elfjack/*.h)
EJ_INCLUDE_FLAGS := -I$(EJ_DIR)/include
EJ_DEPS_FILE := $(EJ_OBJ_DIR)/deps.mk
DEPS_FILES += $(EJ_DEPS_FILE)
BUILD_DEPS ?= $(if $(MAKECMDGOALS),$(subst clean,,$(MAKECMDGOALS)),yes)
ifneq ($(BUILD_DEPS),)
$(EJ_DEPS_FILE): $(EJ_SOURCE_FILES) $(EJ_HEADER_FILES)
@mkdir -p $(@D)
@rm -f $@
for file in $(EJ_SOURCE_FILES); do \
echo "$(EJ_OBJ_DIR)/`$(CC) $(EJ_INCLUDE_FLAGS) -MM $$file`" >> $@ && \
echo '\t$$(CC) $$(CFLAGS) -fpic -ffunction-sections $(EJ_INCLUDE_FLAGS) -c $$< -o $$@' >> $@; \
done
include $(EJ_DEPS_FILE)
endif
$(EJ_SHARED_LIBRARY): $(EJ_OBJECT_FILES)
@mkdir -p $(@D)
$(CC) $(LDFLAGS) -shared -o $@ $^
$(EJ_STATIC_LIBRARY): $(EJ_OBJECT_FILES)
@mkdir -p $(@D)
$(AR) rcs $@ $^
ej_clean:
@rm -f $(EJ_SHARED_LIBRARY) $(EJ_STATIC_LIBRARY) $(EJ_OBJECT_FILES)
.PHONY: ej_clean
CLEAN_TARGETS += ej_clean
endif