-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
113 lines (90 loc) · 2.57 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
#tool macros
CC := ${CC}
CC ?= clang
AR ?= llvm-ar
# compiler flags
LDFLAGS := -O3 -Wall -fsanitize=address
CFLAGS := -O3 -g -fPIC
ARFLAGS := -X 64 --thin
# path macros
BIN_PATH := bin
OBJ_PATH := obj
SRC_PATH := src
DBG_PATH := debug
ifeq ($(PREFIX),)
PREFIX := /usr/local
endif
# compile macros
TARGET_NAME_DYNAMIC := liblamada
TARGET_NAME_STATIC := liblamada
ifeq ($(OS),Windows_NT)
$(error This library was not intended to be working on Windows Platform.)
TARGET_NAME_DYNAMIC := $(addsuffix .dll,$(TARGET_NAME_DYNAMIC))
TARGET_NAME_STATIC := $(addsuffix .lib,$(TARGET_NAME_STATIC))
else
TARGET_NAME_DYNAMIC := $(addsuffix .so,$(TARGET_NAME_DYNAMIC))
TARGET_NAME_STATIC := $(addsuffix .a,$(TARGET_NAME_STATIC))
endif
TARGET_DYNAMIC := $(BIN_PATH)/$(TARGET_NAME_DYNAMIC)
TARGET_STATIC := $(BIN_PATH)/$(TARGET_NAME_STATIC)
# src files & obj files
SRC := $(foreach x, $(SRC_PATH), $(wildcard $(addprefix $(x)/*,.c*)))
OBJ := $(addprefix $(OBJ_PATH)/, $(addsuffix .o, $(notdir $(basename $(SRC)))))
HEADERS := $(foreach x, $(SRC_PATH), $(wildcard $(addprefix $(x)/*,.h*)))
# clean files list
DISTCLEAN_LIST := $(OBJ)
CLEAN_LIST := $(TARGET_DYNAMIC) \
$(TARGET_STATIC) \
$(DISTCLEAN_LIST)
# default rule
default: makedir all
# non-phony targets
$(TARGET_STATIC): $(OBJ)
$(info $(NULL) AR $(TARGET_STATIC))
@$(AR) r $(TARGET_STATIC) $(OBJ) > /dev/null 2>&1
$(TARGET_DYNAMIC): $(OBJ)
$(info $(NULL) ELF $(TARGET_DYNAMIC))
@$(CC) -o $@ $(OBJ) $(LDFLAGS) -shared
$(OBJ_PATH)/%.o: $(SRC_PATH)/%.c*
$(info $(NULL) CC $< $@)
@$(CC) $(CFLAGS) -shared -o $@ $<
# phony rules
.PHONY: envinfo
envinfo:
ifeq ($(OS),Windows_NT)
$(info Platform: Windows $())
else
$(info Platform: $(shell uname -a))
endif
$(info CC: $(CC))
$(info AR: $(AR))
$(info LDFlags: $(LDFLAGS))
$(info CCFlags: $(CFLAGS))
$(info ARFlags: $(ARFLAGS))
$(info Targets: $(TARGET_DYNAMIC) $(TARGET_STATIC))
.PHONY: makedir
makedir:
@mkdir -p $(BIN_PATH) $(OBJ_PATH)
.PHONY: all
all: envinfo $(TARGET_DYNAMIC) $(TARGET_STATIC)
.PHONY: clean
clean:
@echo " CLEAN $(CLEAN_LIST)"
@rm -rf $(CLEAN_LIST)
.PHONY: installbin
installbin:
$(info $(NULL) INSTALL $(TARGET_STATIC))
@install $(TARGET_STATIC) $(PREFIX)/lib
$(info $(NULL) INSTALL $(TARGET_DYNAMIC))
@install $(TARGET_DYNAMIC) $(PREFIX)/lib
.PHONY: insatllheaders $(HEADERS)
installheaders: $(HEADERS)
$(HEADERS):
$(info $(NULL) INSTALL $@)
@cp $@ $(PREFIX)/include/lamada
.PHONY: installclean
installclean:
@rm -r $(PREFIX)/include/lamada
@mkdir -p $(PREFIX)/include/lamada
.PHONY: install
install: installclean installbin installheaders