-
Notifications
You must be signed in to change notification settings - Fork 49
/
Makefile
237 lines (193 loc) · 10 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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# https://github.com/bioinfornatics/MakefileForD
export PROJECT_NAME = gl3n
export AUTHOR = David Herberth
export DESCRIPTION = OpenGL Maths for D (not glm for D but better).
export REPO_SRC_DIR =
export LOGO_SRC =
export MAJOR_VERSION = 1
export MINOR_VERSION = 0
export PATCH_VERSION = 0
export PROJECT_VERSION = $(MAJOR_VERSION).$(MINOR_VERSION).$(PATCH_VERSION)
export LICENSE = MIT
export ROOT_SOURCE_DIR = gl3n
DDOCFILES = modules.ddoc settings.ddoc bootDoc$(PATH_SEP)bootdoc.ddoc
# include some command
include command.make
SOURCES = $(getSource)
OBJECTS = $(patsubst %.d,$(BUILD_PATH)$(PATH_SEP)%.o, $(SOURCES))
PICOBJECTS = $(patsubst %.d,$(BUILD_PATH)$(PATH_SEP)%.pic.o,$(SOURCES))
HEADERS = $(patsubst %.d,$(IMPORT_PATH)$(PATH_SEP)%.di, $(SOURCES))
DOCUMENTATIONS = $(patsubst %.d,$(DOC_PATH)$(PATH_SEP)%.html, $(SOURCES))
DDOCUMENTATIONS = $(patsubst %.d,$(DDOC_PATH)$(PATH_SEP)%.html, $(SOURCES))
DDOC_FLAGS = $(foreach macro,$(DDOCFILES), $(DDOC_MACRO)$(macro))
space :=
space +=
stripBugfix = $(subst $(space),.,$(strip $(wordlist 1, 2, $(subst ., ,$(1)))))
define make-lib
$(MKDIR) $(DLIB_PATH)
$(AR) rcs $(DLIB_PATH)$(PATH_SEP)$@ $^
$(RANLIB) $(DLIB_PATH)$(PATH_SEP)$@
endef
############# BUILD #############
all: static-lib header doc pkgfile-static
@echo ------------------ Building $^ done
all-shared: shared-lib header doc pkgfile-shared
@echo ------------------ Building $^ done
.PHONY : pkgfile
.PHONY : doc
.PHONY : ddoc
.PHONY : clean
static-lib: $(STATIC_LIBNAME)
shared-lib: $(SHARED_LIBNAME)
header: $(HEADERS)
doc: $(DOCUMENTATIONS)
@echo ------------------ Building Doc done
ddoc: settings.ddoc $(DDOCUMENTATIONS)
$(DC) $(DDOC_FLAGS) index.d $(DF)$(DDOC_PATH)$(PATH_SEP)index.html
@echo ------------------ Building DDoc done
geany-tag:
@echo ------------------ Building geany tag
$(MKDIR) geany_config
geany -c geany_config -g $(PROJECT_NAME).d.tags $(SOURCES)
pkgfile-shared:
@echo ------------------ Building pkg-config file
@echo "# Package Information for pkg-config" > $(PKG_CONFIG_FILE)
@echo "# Author: $(AUTHOR)" >> $(PKG_CONFIG_FILE)
@echo "# Created: `date`" >> $(PKG_CONFIG_FILE)
@echo "# Licence: $(LICENSE)" >> $(PKG_CONFIG_FILE)
@echo >> $(PKG_CONFIG_FILE)
@echo prefix=$(PREFIX) >> $(PKG_CONFIG_FILE)
@echo exec_prefix=$(PREFIX) >> $(PKG_CONFIG_FILE)
@echo libdir=$(LIB_DIR) >> $(PKG_CONFIG_FILE)
@echo includedir=$(INCLUDE_DIR) >> $(PKG_CONFIG_FILE)
@echo >> $(PKG_CONFIG_FILE)
@echo Name: "$(PROJECT_NAME)" >> $(PKG_CONFIG_FILE)
@echo Description: "$(DESCRIPTION)" >> $(PKG_CONFIG_FILE)
@echo Version: "$(PROJECT_VERSION)" >> $(PKG_CONFIG_FILE)
@echo Libs: $(LINKERFLAG)-l$(PROJECT_NAME)-$(COMPILER) >> $(PKG_CONFIG_FILE)
@echo Cflags: -I$(INCLUDE_DIR)$(PATH_SEP)$(PROJECT_NAME) $(LDCFLAGS)>> $(PKG_CONFIG_FILE)
@echo >> $(PKG_CONFIG_FILE)
pkgfile-static:
@echo ------------------ Building pkg-config file
@echo "# Package Information for pkg-config" > $(PKG_CONFIG_FILE)
@echo "# Author: $(AUTHOR)" >> $(PKG_CONFIG_FILE)
@echo "# Created: `date`" >> $(PKG_CONFIG_FILE)
@echo "# Licence: $(LICENSE)" >> $(PKG_CONFIG_FILE)
@echo >> $(PKG_CONFIG_FILE)
@echo prefix=$(PREFIX) >> $(PKG_CONFIG_FILE)
@echo exec_prefix=$(PREFIX) >> $(PKG_CONFIG_FILE)
@echo libdir=$(LIB_DIR) >> $(PKG_CONFIG_FILE)
@echo includedir=$(INCLUDE_DIR) >> $(PKG_CONFIG_FILE)
@echo >> $(PKG_CONFIG_FILE)
@echo Name: "$(PROJECT_NAME)" >> $(PKG_CONFIG_FILE)
@echo Description: "$(DESCRIPTION)" >> $(PKG_CONFIG_FILE)
@echo Version: "$(PROJECT_VERSION)" >> $(PKG_CONFIG_FILE)
@echo Libs: $(LIB_DIR)$(PATH_SEP)$(STATIC_LIBNAME) >> $(PKG_CONFIG_FILE)
@echo Cflags: -I$(INCLUDE_DIR)$(PATH_SEP)$(PROJECT_NAME) $(LDCFLAGS)>> $(PKG_CONFIG_FILE)
@echo >> $(PKG_CONFIG_FILE)
settings.ddoc:
@echo "PROJECTNAME = $(PROJECT_NAME)" > settings.ddoc
@echo "LINKPREFIX = $(LINKERFLAG)" >> settings.ddoc
@echo "REPOSRCDIR = $(REPO_SRC_DIR)" >> settings.ddoc
@echo "ROOT = $(ROOT_SOURCE_DIR)" >> settings.ddoc
@echo "LOGOSRC = $(LOGO_SRC)" >> settings.ddoc
@echo "LOGOALT = $(PROJECT_NAME)" >> settings.ddoc
# For build lib need create object files and after run make-lib
$(STATIC_LIBNAME): $(OBJECTS)
@echo ------------------ Building static library
$(make-lib)
# For build shared lib need create shared object files
$(SHARED_LIBNAME): $(PICOBJECTS)
@echo ------------------ Building shared library
$(MKDIR) $(DLIB_PATH)
$(DC) -shared $(SONAME_FLAG) $@.$(MAJOR_VERSION) $(OUTPUT)$(DLIB_PATH)$(PATH_SEP)$@.$(PROJECT_VERSION) $^
#$(CC) -l$(PHOBOS) -l$(DRUNTIME) -shared -Wl,-soname,$@.$(MAJOR_VERSION) -o $(DLIB_PATH)$(PATH_SEP)$@.$(PROJECT_VERSION) $^
.PHONY: output_directories
output_directories:
mkdir -p $(dir $(OBJECTS))
# create object files
$(BUILD_PATH)$(PATH_SEP)%.o : %.d output_directories
$(DC) $(DCFLAGS) $(DCFLAGS_LINK) $(DCFLAGS_IMPORT) -c $< $(OUTPUT)$@
# create shared object files
$(BUILD_PATH)$(PATH_SEP)%.pic.o : %.d
$(DC) $(DCFLAGS) $(DCFLAGS_LINK) $(FPIC) $(DCFLAGS_IMPORT) -c $< $(OUTPUT)$@
# Generate Header files
$(IMPORT_PATH)$(PATH_SEP)%.di : %.d
$(DC) $(DCFLAGS) $(DCFLAGS_LINK) $(DCFLAGS_IMPORT) -c $(NO_OBJ) $< $(HF)$@
# Generate Documentation
$(DOC_PATH)$(PATH_SEP)%.html : %.d
$(DC) $(DCFLAGS) $(DCFLAGS_LINK) $(DCFLAGS_IMPORT) -c $(NO_OBJ) $< $(DF)$@
# Generate ddoc Documentation
$(DDOC_PATH)$(PATH_SEP)%.html : %.d
$(DC) $(DCFLAGS) $(DCFLAGS_LINK) $(DCFLAGS_IMPORT) -c $(NO_OBJ) $(DDOC_FLAGS) $< $(DF)$@
############# CLEAN #############
clean: clean-objects clean-static-lib clean-doc clean-header clean-pkgfile
@echo ------------------ Cleaning $^ done
clean-shared: clean-shared-objects clean-shared-lib
@echo ------------------ Cleaning $^ done
clean-objects:
$(RM) $(OBJECTS)
@echo ------------------ Cleaning objects done
clean-shared-objects:
$(RM) $(PICOBJECTS)
@echo ------------------ Cleaning shared-object done
clean-static-lib:
$(RM) $(DLIB_PATH)$(PATH_SEP)$(STATIC_LIBNAME)
@echo ------------------ Cleaning static-lib done
clean-shared-lib:
$(RM) $(DLIB_PATH)$(PATH_SEP)$(SHARED_LIBNAME).$(PROJECT_VERSION)
@echo ------------------ Cleaning shared-lib done
clean-header:
$(RM) $(HEADERS)
@echo ------------------ Cleaning header done
clean-doc:
$(RM) $(DOCUMENTATIONS)
$(RM) $(DOC_PATH)
@echo ------------------ Cleaning doc done
clean-ddoc:
$(RM) $(DDOC_PATH)$(PATH_SEP)index.html
$(RM) $(DDOCUMENTATIONS)
$(RM) $(DDOC_PATH)$(PATH_SEP)$(PROJECT_NAME)
$(RM) $(DDOC_PATH)
@echo ------------------ Cleaning ddoc done
clean-geany-tag:
$(RM) geany_config $(PROJECT_NAME).d.tags
@echo ------------------ Cleaning geany tag done
clean-pkgfile:
$(RM) $(PKG_CONFIG_FILE)
@echo ------------------ Cleaning pkgfile done
############# INSTALL #############
install: install-static-lib install-doc install-header install-pkgfile
@echo ------------------ Installing $^ done
install-shared: install-shared-lib install-doc install-header install-pkgfile
@echo ------------------ Installing $^ done
install-static-lib:
$(MKDIR) $(DESTDIR)$(LIB_DIR)
$(CP) $(DLIB_PATH)$(PATH_SEP)$(STATIC_LIBNAME) $(DESTDIR)$(LIB_DIR)
@echo ------------------ Installing static-lib done
install-shared-lib:
$(MKDIR) $(DESTDIR)$(LIB_DIR)
$(CP) $(DLIB_PATH)$(PATH_SEP)$(SHARED_LIBNAME).$(PROJECT_VERSION) $(DESTDIR)$(LIB_DIR)
cd $(DESTDIR)$(LIB_DIR)$(PATH_SEP) && $(LN) $(SHARED_LIBNAME).$(PROJECT_VERSION) $(SHARED_LIBNAME).$(MAJOR_VERSION)
cd $(DESTDIR)$(LIB_DIR)$(PATH_SEP) && $(LN) $(SHARED_LIBNAME).$(MAJOR_VERSION) $(SHARED_LIBNAME)
@echo ------------------ Installing shared-lib done
install-header:
$(MKDIR) $(DESTDIR)$(INCLUDE_DIR)
$(CP) $(IMPORT_PATH)$(PATH_SEP)$(PROJECT_NAME) $(DESTDIR)$(INCLUDE_DIR)
@echo ------------------ Installing header done
install-doc:
$(MKDIR) $(DESTDIR)$(DATA_DIR)$(PATH_SEP)doc$(PATH_SEP)$(PROJECT_NAME)$(PATH_SEP)normal_doc$(PATH_SEP)
$(CP) $(DOC_PATH)$(PATH_SEP)* $(DESTDIR)$(DATA_DIR)$(PATH_SEP)doc$(PATH_SEP)$(PROJECT_NAME)$(PATH_SEP)normal_doc$(PATH_SEP)
@echo ------------------ Installing doc done
install-ddoc:
$(MKDIR) $(DESTDIR)$(DATA_DIR)$(PATH_SEP)doc$(PATH_SEP)$(PROJECT_NAME)$(PATH_SEP)cute_doc$(PATH_SEP)
$(CP) $(DDOC_PATH)$(PATH_SEP)* $(DESTDIR)$(DATA_DIR)$(PATH_SEP)doc$(PATH_SEP)$(PROJECT_NAME)$(PATH_SEP)cute_doc$(PATH_SEP)
@echo ------------------ Installing ddoc done
install-geany-tag:
$(MKDIR) $(DESTDIR)$(DATA_DIR)$(PATH_SEP)geany$(PATH_SEP)tags$(PATH_SEP)
$(CP) $(PROJECT_NAME).d.tags $(DESTDIR)$(DATA_DIR)$(PATH_SEP)geany$(PATH_SEP)tags$(PATH_SEP)
@echo ------------------ Installing geany tag done
install-pkgfile:
$(MKDIR) $(DESTDIR)$(PKGCONFIG_DIR)
$(CP) $(PKG_CONFIG_FILE) $(DESTDIR)$(PKGCONFIG_DIR)$(PATH_SEP)$(PROJECT_NAME).pc
@echo ------------------ Installing pkgfile done