Debian Codegraph @

build/main.mk

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 2 — not the installed (fully patched) source.
2 Debian patches touch this file
1 # openMSX Build System
2 # ====================
3 #
4 # This is the home made build system for openMSX, adapted for the openMSX
5 # debugger.
6 #
7 # Used a lot of ideas from Peter Miller's excellent paper
8 # "Recursive Make Considered Harmful".
9 # http://www.tip.net.au/~millerp/rmch/recu-make-cons-harm.html
10 #
11 # TODO: Rename OPENMSX_SUBSET to SUBSET?
12
13
14 # Python Interpreter
15 # ==================
16
17 # We need Python from the 2.x series, version 2.5 or higher.
18 # Usually this executable is available as just "python", but on some systems
19 # you might have to be more specific, for example "python2" or "python2.6".
20 # Or if the Python interpreter is not in the search path, you can specify its
21 # full path.
22 PYTHON?=python3
23
24
25 # Logical Targets
26 # ===============
27
28 # Logical targets which require dependency files.
29 #DEPEND_TARGETS:=all app default install run bindist
30 DEPEND_TARGETS:=all app default
31 # Logical targets which do not require dependency files.
32 #NODEPEND_TARGETS:=clean config probe dist
33 NODEPEND_TARGETS:=clean dist
34 # Mark all logical targets as such.
35 .PHONY: $(DEPEND_TARGETS) $(NODEPEND_TARGETS)
36
37 # Default target; make sure this is always the first target in this Makefile.
38 MAKECMDGOALS?=default
39 default: all
40
41
42 # Base Directories
43 # ================
44
45 # All created files will be inside this directory.
46 BUILD_BASE:=derived
47
48 # All global Makefiles are inside this directory.
49 MAKE_PATH:=build
50
51 # Platforms
52 # =========
53
54 ifeq ($(origin OPENMSX_TARGET_OS),environment)
55 # Do not perform autodetection if platform was specified by the user.
56 else # OPENMSX_TARGET_OS not from environment
57
58 DETECTSYS_PATH:=$(BUILD_BASE)/detectsys
59 DETECTSYS_MAKE:=$(DETECTSYS_PATH)/detectsys.mk
60 DETECTSYS_SCRIPT:=$(MAKE_PATH)/detectsys.py
61
62 -include $(DETECTSYS_MAKE)
63
64 $(DETECTSYS_MAKE): $(DETECTSYS_SCRIPT)
65 @echo "Autodetecting native system:"
66 @mkdir -p $(@D)
67 @$(PYTHON) $< > $@
68
69 endif # OPENMSX_TARGET_OS
70
71 PLATFORM:=
72 ifneq ($(origin OPENMSX_TARGET_OS),undefined)
73 PLATFORM:=$(OPENMSX_TARGET_OS)
74 endif
75
76 # Ignore rest of Makefile if autodetection was not performed yet.
77 # Note that the include above will force a reload of the Makefile.
78 ifneq ($(PLATFORM),)
79
80 # Load OS specific settings.
81 #$(call DEFCHECK,OPENMSX_TARGET_OS)
82 #include $(MAKE_PATH)/platform-$(OPENMSX_TARGET_OS).mk
83 # Check that all expected variables were defined by OS specific Makefile:
84 # - executable file name extension
85 #$(call DEFCHECK,EXEEXT)
86 # - platform supports symlinks?
87 #$(call BOOLCHECK,USE_SYMLINK)
88
89
90 # Paths
91 # =====
92
93 #BUILD_PATH:=$(BUILD_BASE)/$(PLATFORM)-$(OPENMSX_FLAVOUR)
94 BUILD_PATH:=$(BUILD_BASE)
95 GEN_SRC_PATH:=$(BUILD_PATH)/src
96
97 SOURCES_PATH:=src
98 RESOURCES_PATH:=resources
99
100 ifeq ($(OPENMSX_TARGET_OS),darwin)
101 # Note: Make cannot deal with spaces inside paths: it will even see BINARY_FULL
102 # as two files instead of one. Therefore, we use an underscore during
103 # development and we'll have to rename the app folder for the release
104 # versions.
105 APP_SUPPORT_PATH:=build/package-darwin
106 APP_PATH:=$(BUILD_PATH)/openMSX_Debugger.app
107 APP_PLIST:=$(APP_PATH)/Contents/Info.plist
108 APP_ICON:=$(APP_PATH)/Contents/Resources/debugger-logo.icns
109 APP_RESOURCES:=$(APP_ICON)
110 BINARY_PATH:=$(APP_PATH)/Contents/MacOS
111 PKGINFO_FULL:=$(APP_PATH)/Contents/PkgInfo
112 else
113 BINARY_PATH:=$(BUILD_PATH)/bin
114 endif
115 #BINARY_FILE:=openmsx-debugger$(EXEEXT)
116 BINARY_FILE:=openmsx-debugger
117 BINARY_FULL:=$(BINARY_PATH)/$(BINARY_FILE)
118
119 VERSION_SCRIPT:=build/version2code.py
120 VERSION_HEADER:=$(BUILD_PATH)/config/Version.ii
121 GENERATED_HEADERS:=$(VERSION_HEADER)
122 VERSION_LOG:=$(BUILD_BASE)/version.log
123 PACKAGE_DETAILED_VERSION:=$(shell PYTHONPATH=build $(PYTHON) -c \
124 "import version; print(version.getDetailedVersion())" \
125 )
126
127
128 # Filesets
129 # ========
130
131 # If there will be more resource files, introduce a new category in node.mk.
132 RESOURCES_FULL:=$(RESOURCES_PATH)/resources.qrc
133
134 # Force evaluation upon assignment.
135 SOURCES_FULL:=
136 HEADERS_FULL:=
137 MOC_HDR_FULL:=
138 UI_FULL:=
139 # Include root node.
140 CURDIR:=
141 include node.mk
142 # Remove "./" in front of file names.
143 # It can cause trouble because Make removes it automatically in rules.
144 SOURCES_FULL:=$(SOURCES_FULL:./%=%)
145 HEADERS_FULL:=$(HEADERS_FULL:./%=%)
146 MOC_HDR_FULL:=$(MOC_HDR_FULL:./%=%)
147 UI_FULL:=$(UI_FULL:./%=%)
148 # Apply subset to sources list.
149 SOURCES_FULL:=$(filter $(SOURCES_PATH)/$(OPENMSX_SUBSET)%,$(SOURCES_FULL))
150 ifeq ($(SOURCES_FULL),)
151 $(error Sources list empty $(if \
152 $(OPENMSX_SUBSET),after applying subset "$(OPENMSX_SUBSET)*"))
153 endif
154 # Sanity check: only .cpp files are allowed in sources list,
155 # because we don't have any way to build other sources.
156 NON_CPP_SOURCES:=$(filter-out %.cpp,$(SOURCES_FULL))
157 ifneq ($(NON_CPP_SOURCES),)
158 $(error The following sources files do not have a .cpp extension: \
159 $(NON_CPP_SOURCES))
160 endif
161
162 MOC_SRC_FULL:=$(patsubst \
163 $(SOURCES_PATH)/%.h,$(GEN_SRC_PATH)/moc_%.cpp,$(MOC_HDR_FULL) \
164 )
165 RES_SRC_FULL:=$(patsubst \
166 $(RESOURCES_PATH)/%.qrc,$(GEN_SRC_PATH)/qrc_%.cpp,$(RESOURCES_FULL) \
167 )
168 UI_HDR_FULL:=$(patsubst \
169 $(SOURCES_PATH)/%.ui,$(GEN_SRC_PATH)/ui_%.h,$(UI_FULL) \
170 )
171 GEN_SRC_FULL:=$(MOC_SRC_FULL) $(RES_SRC_FULL)
172
173 SOURCES:=$(SOURCES_FULL:$(SOURCES_PATH)/%.cpp=%)
174 GEN_SRC:=$(GEN_SRC_FULL:$(GEN_SRC_PATH)/%.cpp=%)
175 HEADERS:=$(HEADERS_FULL:$(SOURCES_PATH)/%=%)
176
177 DEPEND_PATH:=$(BUILD_PATH)/dep
178 DEPEND_FULL:=$(addsuffix .d,$(addprefix $(DEPEND_PATH)/,$(SOURCES)))
179 DEPEND_FULL+=$(addsuffix .d,$(addprefix $(DEPEND_PATH)/,$(GEN_SRC)))
180
181 OBJECTS_PATH:=$(BUILD_PATH)/obj
182 OBJECTS_FULL:=$(addsuffix .o,$(addprefix $(OBJECTS_PATH)/,$(SOURCES)))
183 GEN_OBJ_FULL:=$(addsuffix .o,$(addprefix $(OBJECTS_PATH)/,$(GEN_SRC)))
184
185 ifeq ($(OPENMSX_TARGET_OS),mingw32)
186 RESOURCE_SRC:=$(RESOURCES_PATH)/openmsx-debugger.rc
187 RESOURCE_OBJ:=$(OBJECTS_PATH)/resources.o
188 RESOURCE_SCRIPT:=build/win_resource.py
189 RESOURCE_HEADER:=$(BUILD_PATH)/config/resource-info.h
190 else
191 RESOURCE_OBJ:=
192 endif
193
194 # Build Rules
195 # ===========
196
197 # Include dependency files.
198 ifneq ($(filter $(DEPEND_TARGETS),$(MAKECMDGOALS)),)
199 -include $(DEPEND_FULL)
200 endif
201
202 # Clean up build tree of current flavour.
203 # We don't have flavours (yet?), so clean up everything except "detectsys".
204 clean:
205 @echo "Cleaning up..."
206 @rm -rf $(OBJECTS_PATH)
207 @rm -rf $(DEPEND_PATH)
208 @rm -rf $(GEN_SRC_PATH)
209 ifeq ($(OPENMSX_TARGET_OS),darwin)
210 @rm -rf $(APP_PATH)
211 else
212 @rm -rf $(BINARY_PATH)
213 endif
214
215 # Generate version header.
216 .PHONY: forceversionextraction
217 forceversionextraction:
218 $(VERSION_HEADER): forceversionextraction
219 @$(PYTHON) $(VERSION_SCRIPT) $@
220
221 # Default target.
222 ifeq ($(OPENMSX_TARGET_OS),darwin)
223 all: app
224 else
225 all: $(BINARY_FULL)
226 endif
227
228 ifeq ($(QMAKE),)
229 QMAKE:=qmake
230 QT_VERSION:=$(shell $(QMAKE) -query QT_VERSION 2> /dev/null)
231 ifeq ($(QT_VERSION),)
232 QMAKE:=/usr/local/opt/qt5/bin/qmake
233 QT_VERSION:=$(shell $(QMAKE) -query QT_VERSION)
234 endif
235 else
236 QT_VERSION:=$(shell $(QMAKE) -query QT_VERSION)
237 endif
238 ifeq ($(QT_VERSION),)
239 $(error qmake not found, please install and/or pass QMAKE)
240 else ifeq ($(filter 5.%,$(QT_VERSION)),)
241 $(error Qt version $(QT_VERSION) found; please pass QMAKE pointing to Qt 5.x instead)
242 endif
243
244 QT_INSTALL_HEADERS:=$(shell $(QMAKE) -query QT_INSTALL_HEADERS)
245 QT_INSTALL_LIBS:=$(shell $(QMAKE) -query QT_INSTALL_LIBS)
246 QT_INSTALL_BINS:=$(shell $(QMAKE) -query QT_INSTALL_BINS)
247 # On MingW32 you get backslashes from qmake -query, which we don't want:
248 ifeq ($(OPENMSX_TARGET_OS),mingw32)
249 QT_INSTALL_HEADERS:=$(subst \,/,$(QT_INSTALL_HEADERS))
250 QT_INSTALL_LIBS:=$(subst \,/,$(QT_INSTALL_LIBS))
251 QT_INSTALL_BINS:=$(subst \,/,$(QT_INSTALL_BINS))
252 endif
253 QT_COMPONENTS:=Core Widgets Gui Network Xml
254 QT_HEADER_DIRS:=$(addprefix $(QT_INSTALL_HEADERS)/Qt,$(QT_COMPONENTS))
255 QT_HEADER_DIRS+=$(QT_INSTALL_HEADERS)
256 ifeq ($(OPENMSX_TARGET_OS),darwin)
257 QT_HEADER_DIRS+=$(patsubst %,/Library/Frameworks/Qt%.framework/Headers,$(QT_COMPONENTS))
258 endif
259
260 CXX?=c++
261 WINDRES?=windres
262 CXXFLAGS:= -g -fPIC
263 INCLUDE_INTERNAL:=$(sort $(foreach header,$(HEADERS_FULL),$(patsubst %/,%,$(dir $(header)))))
264 INCLUDE_INTERNAL+=$(BUILD_PATH)/config
265 COMPILE_FLAGS:=$(addprefix -I,$(QT_HEADER_DIRS) $(INCLUDE_INTERNAL) $(GEN_SRC_PATH))
266 # Enable C++17
267 COMPILE_FLAGS+=-std=c++17
268 ifeq ($(OPENMSX_TARGET_OS),darwin)
269 LINK_FLAGS:=-F$(QT_INSTALL_LIBS) $(addprefix -framework Qt,$(QT_COMPONENTS))
270 OSX_VER:=10.13
271 COMPILE_FLAGS+=-mmacosx-version-min=$(OSX_VER) -stdlib=libc++
272 LINK_FLAGS+=-mmacosx-version-min=$(OSX_VER) -stdlib=libc++
273 else
274 COMPILE_ENV:=
275 LINK_ENV:=
276 ifeq ($(OPENMSX_TARGET_OS),mingw32)
277 COMPILE_FLAGS+=-static-libgcc -static-libstdc++
278 LINK_FLAGS:=-Wl,-rpath,$(QT_INSTALL_BINS) -L$(QT_INSTALL_BINS) $(addprefix -lQt5,$(QT_COMPONENTS)) -lws2_32 -lsecur32 -mwindows -static-libgcc -static-libstdc++
279 else
280 LINK_FLAGS:=-Wl,-rpath,$(QT_INSTALL_LIBS) -L$(QT_INSTALL_LIBS) $(addprefix -lQt5,$(QT_COMPONENTS))
281 endif
282 endif
283 DEPEND_FLAGS:=
284
285 # GCC flags:
286 # (these should be omitted if we ever want to support other compilers)
287 # Generic compilation flags.
288 CXXFLAGS+=-pipe
289 # Stricter warning and error reporting.
290 CXXFLAGS+=-Wall -Wextra -pedantic
291 # Empty definition of used headers, so header removal doesn't break things.
292 DEPEND_FLAGS+=-MP
293
294 # Generate Meta Object Compiler sources.
295 $(MOC_SRC_FULL): $(GEN_SRC_PATH)/moc_%.cpp: $(SOURCES_PATH)/%.h
296 @echo "Generating $(@F)..."
297 @mkdir -p $(@D)
298 @$(QT_INSTALL_BINS)/moc -o $@ $<
299
300 # Generate resource source.
301 $(RES_SRC_FULL): $(GEN_SRC_PATH)/qrc_%.cpp: $(RESOURCES_PATH)/%.qrc
302 @echo "Generating $(@F)..."
303 @mkdir -p $(@D)
304 @$(QT_INSTALL_BINS)/rcc -name $(<:$(RESOURCES_PATH)/%.qrc=%) $< -o $@
305
306 # Generate ui files.
307 $(UI_HDR_FULL): $(GEN_SRC_PATH)/ui_%.h: $(SOURCES_PATH)/%.ui
308 @echo "Generating $(@F)..."
309 @mkdir -p $(@D)
310 @$(QT_INSTALL_BINS)/uic -o $@ $<
311 # This is a workaround for the lack of order-only dependencies in GNU Make
312 # versions before than 3.80 (for example Mac OS X 10.3 still ships with 3.79).
313 # It creates a dummy file, which is never modified after its initial creation.
314 # If a rule that produces a file does not modify that file, Make considers the
315 # target to be up-to-date. That way, the targets "ui-dummy-file" depends on
316 # will always be checked before compilation, but they will not cause all object
317 # files to be considered outdated.
318 GEN_DUMMY_FILE:=$(GEN_SRC_PATH)/dummy-file
319 $(GEN_DUMMY_FILE): $(UI_HDR_FULL) $(GENERATED_HEADERS)
320 @test -e $@ || touch $@
321
322 # Compile and generate dependency files in one go.
323 SRC_DEPEND_SUBST=$(patsubst $(SOURCES_PATH)/%.cpp,$(DEPEND_PATH)/%.d,$<)
324 GEN_DEPEND_SUBST=$(patsubst $(GEN_SRC_PATH)/%.cpp,$(DEPEND_PATH)/%.d,$<)
325 $(OBJECTS_FULL): $(GEN_DUMMY_FILE)
326 $(OBJECTS_FULL): $(OBJECTS_PATH)/%.o: $(SOURCES_PATH)/%.cpp $(DEPEND_PATH)/%.d
327 @echo "Compiling $(patsubst $(SOURCES_PATH)/%,%,$<)..."
328 @mkdir -p $(@D)
329 @mkdir -p $(patsubst $(OBJECTS_PATH)%,$(DEPEND_PATH)%,$(@D))
330 @$(COMPILE_ENV) $(CXX) \
331 $(DEPEND_FLAGS) -MMD -MF $(SRC_DEPEND_SUBST) \
332 -o $@ $(CXXFLAGS) $(COMPILE_FLAGS) -c $<
333 @touch $@ # Force .o file to be newer than .d file.
334 $(GEN_OBJ_FULL): $(OBJECTS_PATH)/%.o: $(GEN_SRC_PATH)/%.cpp $(DEPEND_PATH)/%.d
335 @echo "Compiling $(patsubst $(GEN_SRC_PATH)/%,%,$<)..."
336 @mkdir -p $(@D)
337 @mkdir -p $(patsubst $(OBJECTS_PATH)%,$(DEPEND_PATH)%,$(@D))
338 @$(COMPILE_ENV) $(CXX) \
339 $(DEPEND_FLAGS) -MMD -MF $(GEN_DEPEND_SUBST) \
340 -o $@ $(CXXFLAGS) $(COMPILE_FLAGS) -c $<
341 @touch $@ # Force .o file to be newer than .d file.
342 # Generate dependencies that do not exist yet.
343 # This is only in case some .d files have been deleted;
344 # in normal operation this rule is never triggered.
345 $(DEPEND_FULL):
346
347 # Windows resources that are added to the executable.
348 ifeq ($(OPENMSX_TARGET_OS),mingw32)
349 $(RESOURCE_HEADER): forceversionextraction
350 @$(PYTHON) $(RESOURCE_SCRIPT) $@
351 $(RESOURCE_OBJ): $(RESOURCE_SRC) $(RESOURCE_HEADER)
352 @echo "Compiling resources..."
353 @mkdir -p $(@D)
354 @$(WINDRES) $(addprefix --include-dir=,$(^D)) -o $@ -i $<
355 endif
356
357 # Link executable.
358 $(BINARY_FULL): $(OBJECTS_FULL) $(GEN_OBJ_FULL) $(RESOURCE_OBJ)
359 ifeq ($(OPENMSX_SUBSET),)
360 @echo "Linking $(@F)..."
361 @mkdir -p $(@D)
362 @$(LINK_ENV) $(CXX) -o $@ $(CXXFLAGS) $^ $(LINK_FLAGS)
363 else
364 @echo "Not linking $(notdir $@) because only a subset was built."
365 endif
366
367 # Application folder.
368 ifeq ($(OPENMSX_TARGET_OS),darwin)
369 app: $(BINARY_FULL) $(PKGINFO_FULL) $(APP_PLIST) $(APP_RESOURCES)
370
371 $(PKGINFO_FULL):
372 @echo "Generating $(@F)..."
373 @mkdir -p $(@D)
374 @echo "APPLoMXD" > $@
375
376 $(APP_PLIST): $(APP_PATH)/Contents/%: $(APP_SUPPORT_PATH)/%
377 @echo "Generating $(@F)..."
378 @mkdir -p $(@D)
379 @sed -e 's/%ICON%/$(notdir $(APP_ICON))/' \
380 -e 's/%VERSION%/$(PACKAGE_DETAILED_VERSION)/' < $< > $@
381
382 $(APP_RESOURCES): $(APP_PATH)/Contents/Resources/%: $(APP_SUPPORT_PATH)/%
383 @echo "Copying $(@F)..."
384 @mkdir -p $(@D)
385 @cp $< $@
386 endif
387
388
389 # Source Packaging
390 # ================
391
392 dist:
393 @$(PYTHON) build/gitdist.py
394
395 endif # PLATFORM