forked from vitamin-caig/zxtune
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile.mak
200 lines (149 loc) · 4.76 KB
/
makefile.mak
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
include $(dirs.root)/make/default.mak
.SUFFIXES:
#default suffixes
suffix.cpp := .cpp
suffix.cpp.all := $(suffix.cpp) .cxx .cc
suffix.c := .c
suffix.res := .rc
suffix.src = $(suffix.cpp.all) $(suffix.c)
#reset default rules
%$(suffix.cpp) :
%.cxx :
%.cc :
%$(suffix.c) :
%$(suffix.res) :
%.mak :
#setup modes
ifneq ($(or $(pic),$(dynamic_name)),)
pic := 1
endif
ifdef debug
mode = debug
undefine release
else
mode = release
release = 1
endif
ifneq ($(or $(libraries.qt),$(ui_files),$(moc_files),$(qrc_files)),)
use_qt := 1
endif
platform_pathname = $(platform)$(if $(arch),_$(arch),)
mode_pathname = $(mode)$(if $(profile),_profile,)
submode_pathname = $(if $(pic),_pic,)$(if $(static_runtime),_static,)
#set directories
includes.dirs += $(dirs.root)/include $(dirs.root)/src $(dirs.root)
objs_dir = $(dirs.root)/obj/$(platform_pathname)/$(mode_pathname)$(submode_pathname)
libraries.dir = $(dirs.root)/lib/$(platform_pathname)/$(mode_pathname)$(submode_pathname)
bins_dir = $(dirs.root)/bin/$(platform_pathname)/$(mode_pathname)
#set environment
include $(dirs.root)/make/environment.mak
#set platform-specific parameters
include $(dirs.root)/make/platforms/$(platform).mak
#set host-specific parameters
include $(dirs.root)/make/hosts/$(host).mak
#set features
include $(dirs.root)/make/features.mak
#tune output according to type
ifdef library_name
output_dir = $(libraries.dir)
objects_dir = $(objs_dir)/$(library_name)
target = $(output_dir)/$(call makelib_name,$(library_name))
else ifdef binary_name
output_dir = $(bins_dir)
objects_dir = $(objs_dir)/$(binary_name)
target = $(output_dir)/$(call makebin_name,$(binary_name))
else ifdef dynamic_name
output_dir = $(bins_dir)
objects_dir = $(objs_dir)/$(dynamic_name)
target = $(output_dir)/$(call makedyn_name,$(dynamic_name))
pic := 1
else
$(error Invalid target)
endif
#main target
all: $(target)
#set compiler-specific parameters
include $(dirs.root)/make/compilers/$(compiler).mak
#calculate input source files
source_files += $(source_files.$(platform))
source_dirs += $(source_dirs.$(platform))
ifdef source_dirs
source_files += $(foreach suffix,$(suffix.src),$(foreach dir,$(source_dirs),$(wildcard $(dir)/*$(suffix))))
endif
#process texts if required
ifdef text_files
include $(dirs.root)/make/textator.mak
endif
#process qt if required
ifdef use_qt
include $(dirs.root)/make/qt.mak
endif
#process boost
include $(dirs.root)/make/boost.mak
#process l10n files
include $(dirs.root)/make/l10n.mak
ifdef jumbo.name
include $(dirs.root)/make/jumbo.mak
endif
#calculate object files from sources
OBJECTS = $(foreach src,$(notdir $(source_files) $(generated_sources)), $(objects_dir)/$(call makeobj_name,$(src)))
OBJECTS.CPP = $(filter $(foreach ext,$(suffix.cpp.all),%$(call makeobj_name,$(ext))),$(OBJECTS))
OBJECTS.C = $(filter %$(call makeobj_name,$(suffix.c)),$(OBJECTS))
OBJECTS.RES = $(filter %$(call makeobj_name,$(suffix.res)),$(OBJECTS))
TRANSLATIONS = $(mo_files) $(qm_files)
#make objects and binaries dir
$(objects_dir):
$(call makedir_cmd,$@)
$(output_dir):
$(info Building $(if $(library_name),library $(library_name),\
$(if $(binary_name),executable $(binary_name),dynamic object $(dynamic_name))))
$(call makedir_cmd,$@)
#build target
ifdef library_name
#simple libraries
$(target): $(OBJECTS) | $(output_dir) $(TRANSLATIONS)
$(call build_lib_cmd,$^,$@)
.PHONY: deps
else
#libraries helpers
include $(dirs.root)/libraries.mak
#binary and dynamic libraries with dependencies
LIBS = $(foreach lib,$(libraries),$(libraries.dir)/$(call makelib_name,$(lib)))
$(target): $(OBJECTS) $(LIBS) $(embedded_files) | $(output_dir) $(TRANSLATIONS)
$(link_cmd)
$(postlink_cmd)
$(if $(embedded_files),$(embed_file_cmd),)
$(LIBS): deps
deps: $(depends) $($(platform)_depends)
$(depends) $($(platform)_depends):
$(MAKE) pic=$(pic) static_runtime=$(static_runtime) -C $(addprefix $(dirs.root)/,$@) $(MAKECMDGOALS)
endif
$(OBJECTS): $(generated_headers) $(generated_sources) | $(objects_dir)
VPATH = $(sort $(dir $(source_files) $(generated_sources)))
$(OBJECTS.CPP): $(objects_dir)/$(call makeobj_name,%): %
$(call build_obj_cmd,$(CURDIR)/$<,$@)
$(OBJECTS.C): $(objects_dir)/$(call makeobj_name,%): %
$(call build_obj_cmd_cc,$(CURDIR)/$<,$@)
$(OBJECTS.RES): $(objects_dir)/$(call makeobj_name,%): %
$(call makeres_cmd,$<,$@)
.PHONY: clean
clean: clean_self clean_deps
clean_self:
-$(call rmfiles_cmd,$(wildcard $(target)*))
-$(call rmdir_cmd,$(objects_dir))
clean_deps: $(depends)
install: install_$(platform)
include $(dirs.root)/make/codeblocks.mak
test: $(target)
ifdef binary_name
$^
endif
report:
$(info src=$(source_files))
$(info src.gen=$(generated_sources))
$(info hdr.gen=$(generated_headers))
$(info obj=$(OBJECTS))
$(info obj.cpp=$(OBJECTS.CPP))
$(info obj.c=$(OBJECTS.C))
$(info obj.res=$(OBJECTS.RES))
$(info vpath=$(VPATH))