-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.mk
124 lines (114 loc) · 2.87 KB
/
common.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
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
#
# Compile options
#
CFLAGS += -g -O0
CXXFLAGS = $(CFLAGS)
CPPFLAGS = -Wall -Werror
OBJ_SUFFIX = .o
SO_SUFFIX = .so
EXE_SUFFIX =
COPTS = $(CPPFLAGS)
LDOPTS =
LIBGEN := ar
LIBGEN_OPTS := -cr
SHARED_LIBGEN := $(CC)
SHARED_LIBGEN_OPTS := -shared
EXEGEN := $(CC)
EXEGEN_OPTS := -mwindow
BUILD := i686-pc-linux-gnu
HOST := i686-pc-linux-gnu
hardware_platform = i386-linux-gnu
CC = gcc
CXX = g++
CD = cd
CP = cp
CPTREE = cp -r
CHMOD = chmod
ECHO = echo
MKDIR = mkdir -p
PERL = perl
RM = rm -f
RMTREE = rm -rf
SED = sed
TOUCH = touch
XARGS = xargs
#
# Compile C or CXX source file into an intermediate file
#
# $@ = The name of the object (.o) file to create
# $< = The name of the source (.c or .cpp) file (must be first prerequisite listed in rule)
# $1 = Additional compile options
#
define COMPILE
@$(ECHO) Compiling $< into $@
@$(MKDIR) $(dir $@)
@$(RM) $@
$(if $(filter .m,$(suffix $<)), gcc -c -ObjC $(CFLAGS) $1 $< -o $@,)
$(if $(filter .c,$(suffix $<)), $(CC) -c $(CFLAGS) $1 $< -o $@,)
$(if $(filter .cpp,$(suffix $<)), $(CXX) -c $(CXXFLAGS) $1 $< -o $@,)
endef
#
# Build a dependency file from a C or CXX source file
#
# $@ = The name of the dependency (.d) file to create
# $< = The name of the source (.c or .cpp) file (must be first prerequisite listed in rule)
# $1 = Additional compile options
#
define BUILD_DEPENDS
@$(ECHO) Building dependency file for $<
@$(MKDIR) $(dir $@)
@$(RM) $@
$(if $(filter .m,$(suffix $<)), $(CC) -M $1 $< > $@.tmp,)
$(if $(filter .c,$(suffix $<)), $(CC) -M $(CFLAGS) $1 $< > $@.tmp,)
$(if $(filter .cpp,$(suffix $<)), $(CXX) -M $(CXXFLAGS) $1 $< > $@.tmp,)
$(SED) 's,.*\.o[ :]*,$(@:.d=.o) $@ : ,g' < $@.tmp > $@
@$(RM) $@.tmp
endef
#
# Build a library from a list of object files
#
# $@ = The name of the library (.a) file to create
# $1 = The list of all object (.o) files to put into the library
#
define BUILD_LIBRARY
@$(ECHO) Building library $@
@$(MKDIR) $(dir $@)
@$(RM) $@
@$(MKDIR) $(dir $@)
$(LIBGEN) $(LIBGEN_OPTS) $@ $1
endef
#
# Build a shared library from a list of object files
#
# $@ = The name of the library (.so) file to create
# $1 = The list of all object (.o) files to put into the library
#
define BUILD_SHARED_LIBRARY
@$(ECHO) Building shared library $@
@$(MKDIR) $(dir $@)
@$(RM) $@
@$(MKDIR) $(dir $@)
$(SHARED_LIBGEN) $(SHARED_LIBGEN_OPTS) -o $@ $1
endef
#
# Build an executable from a list of object files
#
# $@ = The name of the executable file to create
# $1 = The list of all object (.o) files to put into the library
#
define BUILD_EXECUTABLE
@$(ECHO) Building executable $@
@$(MKDIR) $(dir $@)
@$(RM) $@
@$(MKDIR) $(dir $@)
$(EXEGEN) $(EXEGEN_OPTS) -o $@ $1
endef
#
# Remove a library
#
# $1 = The name of the library (.so) to remove
#
define RM_LIBRARY
@$(ECHO) Removing library $1
@$(RM) $1
endef