main.mk 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. # openMSX Build System
  2. # ====================
  3. #
  4. # This is the home made build system for openMSX, which replaced the
  5. # autoconf/automake combo.
  6. #
  7. # Used a lot of ideas from Peter Miller's excellent paper
  8. # "Recursive Make Considered Harmful".
  9. # http://miller.emu.id.au/pmiller/books/rmch/
  10. # Verbosity
  11. # =========
  12. # V=0: Summary only
  13. # V=1: Command only
  14. # V=2: Summary + command
  15. V?=0
  16. SUM:=@echo
  17. ifeq ($V,0)
  18. CMD:=@
  19. else
  20. CMD:=
  21. ifeq ($V,1)
  22. SUM:=@\#
  23. else ifneq ($V,2)
  24. $(warning Unsupported value for verbosity flag "V": $V)
  25. endif
  26. endif
  27. # Python Interpreter
  28. # ==================
  29. # We need Python from the 2.x series, version 2.6 or higher.
  30. # Usually this executable is available as just "python", but on some systems
  31. # you might have to be more specific, for example "python2" or "python2.6".
  32. # Or if the Python interpreter is not in the search path, you can specify its
  33. # full path.
  34. ifeq ($(PYTHON),)
  35. PYTHON:=$(shell build/python-search.sh)
  36. ifeq ($(PYTHON),)
  37. $(error No suitable Python interpreter found. Please install Python version 2.x where x >= 5. If your Python interpreter is installed in a non-standard location, please set the environment variable PYTHON to the full path of the interpreter binary.)
  38. endif
  39. endif
  40. $(info Using Python: $(PYTHON))
  41. # Delete on Error
  42. # ===============
  43. # Delete output if rule fails.
  44. # This is a flag that applies to all rules.
  45. .DELETE_ON_ERROR:
  46. # Logical Targets
  47. # ===============
  48. ifneq ($(words $(MAKECMDGOALS)),1)
  49. $(error main.mk can only handle once goal at a time)
  50. endif
  51. # TODO: "dist" and "createsubs" are missing
  52. # TODO: more missing?
  53. # Logical targets which require dependency files.
  54. DEPEND_TARGETS:=all default install run bindist
  55. # Logical targets which do not require dependency files.
  56. NODEPEND_TARGETS:=clean config probe 3rdparty run-3rdparty staticbindist
  57. # Mark all logical targets as such.
  58. .PHONY: $(DEPEND_TARGETS) $(NODEPEND_TARGETS)
  59. # Settings
  60. # ========
  61. #
  62. # There are platform specific settings and flavour specific settings.
  63. # platform: architecture, OS
  64. # flavour: optimisation levels, debugging, profiling
  65. # Function to check a variable has been defined and has a non-empty value.
  66. # Usage: $(call DEFCHECK,VARIABLE_NAME)
  67. DEFCHECK=$(strip \
  68. $(if $(filter _undefined,_$(origin $(1))), \
  69. $(error Variable $(1) is undefined) ) \
  70. )
  71. # Function to check a boolean variable has value "true" or "false".
  72. # Usage: $(call BOOLCHECK,VARIABLE_NAME)
  73. BOOLCHECK=$(DEFCHECK)$(strip \
  74. $(if $(filter-out _true _false,_$($(1))), \
  75. $(error Value of $(1) ("$($(1))") should be "true" or "false") ) \
  76. )
  77. # Will be added to by platform specific Makefile, by flavour specific Makefile
  78. # and by this Makefile.
  79. # Note: CXXFLAGS is overridable from the command line; COMPILE_FLAGS is not.
  80. # We use CXXFLAGS for flavour specific flags and COMPILE_FLAGS for
  81. # platform specific flags.
  82. CXXFLAGS:=
  83. COMPILE_FLAGS:=-pthread
  84. # Note: LDFLAGS are passed to the linker itself, LINK_FLAGS are passed to the
  85. # compiler in the link phase.
  86. LDFLAGS:=
  87. LINK_FLAGS:=-pthread
  88. # Flags that specify the target platform.
  89. # These should be inherited by the 3rd party libs Makefile.
  90. TARGET_FLAGS:=
  91. # Customisation
  92. # =============
  93. include build/custom.mk
  94. $(call DEFCHECK,INSTALL_BASE)
  95. $(call BOOLCHECK,VERSION_EXEC)
  96. $(call BOOLCHECK,SYMLINK_FOR_BINARY)
  97. $(call BOOLCHECK,INSTALL_CONTRIB)
  98. # Platforms
  99. # =========
  100. # Note:
  101. # A platform currently specifies both the host platform (performing the build)
  102. # and the target platform (running the created binary). When we have real
  103. # experience with cross-compilation, a more sophisticated system can be
  104. # designed.
  105. LINK_MODE:=$(if $(filter true,$(3RDPARTY_FLAG)),3RD_STA,SYS_DYN)
  106. # Do not perform autodetection if platform was specified by the user.
  107. ifneq ($(filter undefined,$(origin OPENMSX_TARGET_CPU) $(origin OPENMSX_TARGET_OS)),)
  108. DETECTSYS_SCRIPT:=build/detectsys.py
  109. LOCAL_PLATFORM:=$(shell $(PYTHON) $(DETECTSYS_SCRIPT))
  110. ifeq ($(LOCAL_PLATFORM),)
  111. $(error No platform specified using OPENMSX_TARGET_CPU and OPENMSX_TARGET_OS and autodetection of local platform failed)
  112. endif
  113. OPENMSX_TARGET_CPU:=$(word 1,$(LOCAL_PLATFORM))
  114. OPENMSX_TARGET_OS:=$(word 2,$(LOCAL_PLATFORM))
  115. endif # OPENMSX_TARGET_CPU && OPENMSX_TARGET_OS
  116. PLATFORM:=
  117. ifneq ($(origin OPENMSX_TARGET_OS),undefined)
  118. ifneq ($(origin OPENMSX_TARGET_CPU),undefined)
  119. PLATFORM:=$(OPENMSX_TARGET_CPU)-$(OPENMSX_TARGET_OS)
  120. endif
  121. endif
  122. # Ignore rest of Makefile if autodetection was not performed yet.
  123. # Note that the include above will force a reload of the Makefile.
  124. ifneq ($(PLATFORM),)
  125. # Default flavour.
  126. $(call DEFCHECK,OPENMSX_TARGET_CPU)
  127. ifeq ($(OPENMSX_TARGET_CPU),x86)
  128. ifeq ($(filter darwin%,$(OPENMSX_TARGET_OS)),)
  129. # To run openMSX with decent speed, at least a Pentium 2 class machine
  130. # is needed, so let's optimise for that.
  131. OPENMSX_FLAVOUR?=i686
  132. else
  133. # The system headers of OS X use SSE features, which are not available on
  134. # i686, so we only use the generic optimisation flags instead.
  135. OPENMSX_FLAVOUR?=opt
  136. endif
  137. else
  138. ifeq ($(OPENMSX_TARGET_CPU),ppc)
  139. OPENMSX_FLAVOUR?=ppc
  140. else
  141. ifeq ($(OPENMSX_TARGET_CPU),m68k)
  142. OPENMSX_FLAVOUR?=m68k
  143. else
  144. OPENMSX_FLAVOUR?=opt
  145. endif
  146. endif
  147. endif
  148. # Load OS specific settings.
  149. $(call DEFCHECK,OPENMSX_TARGET_OS)
  150. include build/platform-$(OPENMSX_TARGET_OS).mk
  151. # Check that all expected variables were defined by OS specific Makefile:
  152. # - library file name extension
  153. $(call DEFCHECK,LIBRARYEXT)
  154. # - executable file name extension
  155. $(call DEFCHECK,EXEEXT)
  156. # - platform supports symlinks?
  157. $(call BOOLCHECK,USE_SYMLINK)
  158. # Get CPU specific flags.
  159. TARGET_FLAGS+=$(shell $(PYTHON) build/cpu2flags.py $(OPENMSX_TARGET_CPU))
  160. # Flavours
  161. # ========
  162. # Load flavour specific settings.
  163. include build/flavour-$(OPENMSX_FLAVOUR).mk
  164. UNITTEST?=false
  165. # Paths
  166. # =====
  167. BUILD_PATH:=derived/$(PLATFORM)-$(OPENMSX_FLAVOUR)
  168. ifeq ($(3RDPARTY_FLAG),true)
  169. BUILD_PATH:=$(BUILD_PATH)-3rd
  170. endif
  171. # Own build of 3rd party libs.
  172. ifeq ($(3RDPARTY_FLAG),true)
  173. 3RDPARTY_INSTALL_DIR:=$(BUILD_PATH)/3rdparty/install
  174. endif
  175. SOURCES_PATH:=src
  176. BINARY_PATH:=$(BUILD_PATH)/bin
  177. BINARY_FILE:=openmsx$(EXEEXT)
  178. BINDIST_DIR:=$(BUILD_PATH)/bindist
  179. BINDIST_PACKAGE:=
  180. ifeq ($(VERSION_EXEC),true)
  181. REVISION:=$(shell PYTHONPATH=build $(PYTHON) -c \
  182. "import version; print version.extractRevisionString()" \
  183. )
  184. BINARY_FULL:=$(BINARY_PATH)/openmsx-$(REVISION)$(EXEEXT)
  185. else
  186. BINARY_FULL:=$(BINARY_PATH)/$(BINARY_FILE)
  187. endif
  188. LIBRARY_FILE:=openmsx$(LIBRARYEXT)
  189. LIBRARY_PATH:=$(BUILD_PATH)/lib
  190. LIBRARY_FULL:=$(LIBRARY_PATH)/$(LIBRARY_FILE)
  191. ifeq ($(OPENMSX_TARGET_OS),android)
  192. MAIN_EXECUTABLE:=$(LIBRARY_FULL)
  193. else
  194. MAIN_EXECUTABLE:=$(BINARY_FULL)
  195. endif
  196. BUILDINFO_SCRIPT:=build/buildinfo2code.py
  197. CONFIG_HEADER:=$(BUILD_PATH)/config/build-info.hh
  198. PROBE_SCRIPT:=build/probe.py
  199. PROBE_MAKE:=$(BUILD_PATH)/config/probed_defs.mk
  200. VERSION_SCRIPT:=build/version2code.py
  201. VERSION_HEADER:=$(BUILD_PATH)/config/Version.ii
  202. COMPONENTS_HEADER_SCRIPT:=build/components2code.py
  203. COMPONENTS_DEFS_SCRIPT:=build/components2defs.py
  204. COMPONENTS_HEADER:=$(BUILD_PATH)/config/components.hh
  205. COMPONENTS_DEFS:=$(BUILD_PATH)/config/components_defs.mk
  206. GENERATED_HEADERS:=$(VERSION_HEADER) $(CONFIG_HEADER) $(COMPONENTS_HEADER)
  207. # Configuration
  208. # =============
  209. ifneq ($(filter $(DEPEND_TARGETS),$(MAKECMDGOALS)),)
  210. -include $(PROBE_MAKE)
  211. -include $(COMPONENTS_DEFS)
  212. endif # goal requires dependencies
  213. # Filesets
  214. # ========
  215. SOURCE_DIRS:=$(sort $(shell find src -type d))
  216. SOURCES_FULL:=$(foreach dir,$(SOURCE_DIRS),$(sort $(wildcard $(dir)/*.cc)))
  217. SOURCES_FULL:=$(filter-out %Test.cc,$(SOURCES_FULL))
  218. SOURCES_FULL:=$(filter-out src/sound/generate%.cc,$(SOURCES_FULL))
  219. # TODO: This doesn't work since MAX_SCALE_FACTOR is not a Make variable,
  220. # only a #define in build-info.hh.
  221. ifeq ($(MAX_SCALE_FACTOR),1)
  222. define SOURCES_UPSCALE
  223. Scanline
  224. Scaler2 Scaler3
  225. Simple2xScaler Simple3xScaler
  226. SaI2xScaler SaI3xScaler
  227. Scale2xScaler Scale3xScaler
  228. HQ2xScaler HQ2xLiteScaler
  229. HQ3xScaler HQ3xLiteScaler
  230. RGBTriplet3xScaler MLAAScaler
  231. Multiply32
  232. endef
  233. SOURCES_FULL:=$(filter-out $(foreach src,$(strip $(SOURCES_UPSCALE)),src/video/scalers/$(src).cc),$(SOURCES_FULL))
  234. endif
  235. ifneq ($(COMPONENT_GL),true)
  236. SOURCES_FULL:=$(filter-out src/video/GL%.cc,$(SOURCES_FULL))
  237. SOURCES_FULL:=$(filter-out src/video/SDLGL%.cc,$(SOURCES_FULL))
  238. SOURCES_FULL:=$(filter-out src/video/scalers/GL%.cc,$(SOURCES_FULL))
  239. endif
  240. ifneq ($(COMPONENT_LASERDISC),true)
  241. SOURCES_FULL:=$(filter-out src/laserdisc/%.cc,$(SOURCES_FULL))
  242. SOURCES_FULL:=$(filter-out src/video/ld/%.cc,$(SOURCES_FULL))
  243. endif
  244. ifneq ($(COMPONENT_ALSAMIDI),true)
  245. SOURCES_FULL:=$(filter-out src/serial/MidiSessionALSA.cc,$(SOURCES_FULL))
  246. endif
  247. ifeq ($(UNITTEST),true)
  248. SOURCES_FULL:=$(filter-out src/main.cc,$(SOURCES_FULL))
  249. else
  250. SOURCES_FULL:=$(filter-out src/unittest/%.cc,$(SOURCES_FULL))
  251. endif
  252. # Apply subset to sources list.
  253. SOURCES_FULL:=$(filter $(SOURCES_PATH)/$(OPENMSX_SUBSET)%,$(SOURCES_FULL))
  254. ifeq ($(SOURCES_FULL),)
  255. $(error Sources list empty $(if \
  256. $(OPENMSX_SUBSET),after applying subset "$(OPENMSX_SUBSET)*"))
  257. endif
  258. SOURCES:=$(SOURCES_FULL:$(SOURCES_PATH)/%.cc=%)
  259. DEPEND_PATH:=$(BUILD_PATH)/dep
  260. DEPEND_FULL:=$(addsuffix .d,$(addprefix $(DEPEND_PATH)/,$(SOURCES)))
  261. OBJECTS_PATH:=$(BUILD_PATH)/obj
  262. OBJECTS_FULL:=$(addsuffix .o,$(addprefix $(OBJECTS_PATH)/,$(SOURCES)))
  263. ifneq ($(filter mingw%,$(OPENMSX_TARGET_OS)),)
  264. RESOURCE_SRC:=src/resource/openmsx.rc
  265. RESOURCE_OBJ:=$(OBJECTS_PATH)/resources.o
  266. RESOURCE_SCRIPT:=build/win_resource.py
  267. RESOURCE_HEADER:=$(BUILD_PATH)/config/resource-info.h
  268. else
  269. RESOURCE_OBJ:=
  270. endif
  271. # Compiler and Flags
  272. # ==================
  273. COMPILE_FLAGS+=$(TARGET_FLAGS)
  274. LINK_FLAGS+=$(TARGET_FLAGS)
  275. # Determine compiler.
  276. CXX?=g++
  277. WINDRES?=windres
  278. DEPEND_FLAGS:=
  279. ifneq ($(filter %clang++,$(CXX))$(filter clang++%,$(CXX)),)
  280. # Enable C++14 (supported since clang-3.5)
  281. COMPILE_FLAGS+=-std=c++14
  282. # Clang does support -Wunused-macros, but it triggers on SDL's headers,
  283. # causing way too many false positives that we cannot fix.
  284. COMPILE_FLAGS+=-Wall -Wextra -Wundef -Wno-invalid-offsetof -Wshadow
  285. # TODO: Remove the overloading from the code instead.
  286. COMPILE_FLAGS+=-Wno-overloaded-virtual
  287. # Hardware descriptions can contain constants that are not used in the code
  288. # but still useful as documentation.
  289. COMPILE_FLAGS+=-Wno-unused-const-variable
  290. CC:=$(subst clang++,clang,$(CXX))
  291. DEPEND_FLAGS+=-MP
  292. else
  293. ifneq ($(filter %g++,$(CXX))$(filter g++%,$(CXX))$(findstring /g++-,$(CXX)),)
  294. # Generic compilation flags.
  295. COMPILE_FLAGS+=-pipe
  296. # Enable C++11
  297. COMPILE_FLAGS+=-std=c++11
  298. # Stricter warning and error reporting.
  299. COMPILE_FLAGS+=-Wall -Wextra -Wundef -Wno-invalid-offsetof -Wunused-macros -Wdouble-promotion -Wmissing-declarations -Wshadow
  300. # Flag that is not accepted by old GCC versions.
  301. COMPILE_FLAGS+=$(shell \
  302. echo | $(CXX) -E -Wno-missing-field-initializers - >/dev/null 2>&1 \
  303. && echo -Wno-missing-field-initializers \
  304. )
  305. # When supported use c++14 (gcc-4.8 does not yet support this)
  306. COMPILE_FLAGS+=$(shell \
  307. echo | $(CXX) -E -std=c++14 - >/dev/null 2>&1 \
  308. && echo -std=c++14 \
  309. )
  310. # -Wzero-as-null-pointer-constant is available from gcc-4.7
  311. ## IMHO this is a useful but not very important warning. It triggers in
  312. ## quite a few places via macros defined in tcl8.5/tclDecls.h, so we can't
  313. ## easily suppress it. So for now I'll disable this warning again.
  314. ##COMPILE_FLAGS+=$(shell \
  315. ## echo | $(CXX) -E -Wzero-as-null-pointer-constant - >/dev/null 2>&1 \
  316. ## && echo -Wzero-as-null-pointer-constant \
  317. ## )
  318. # Empty definition of used headers, so header removal doesn't break things.
  319. DEPEND_FLAGS+=-MP
  320. # Plain C compiler, for the 3rd party libs.
  321. CC:=$(subst g++,gcc,$(CXX))
  322. else
  323. ifneq ($(filter %gcc,$(CXX))$(filter gcc%,$(CXX)),)
  324. $(error Set CXX to your "g++" executable instead of "gcc")
  325. else
  326. $(warning Unsupported compiler: $(CXX), please update Makefile)
  327. endif
  328. endif
  329. endif
  330. # Strip binary?
  331. OPENMSX_STRIP?=false
  332. $(call BOOLCHECK,OPENMSX_STRIP)
  333. STRIP_SEPARATE:=false
  334. ifeq ($(OPENMSX_STRIP),true)
  335. ifeq ($(OPENMSX_TARGET_OS),darwin)
  336. # Current (mid-2006) GCC 4.x for OS X will strip too many symbols,
  337. # resulting in a binary that cannot run.
  338. # However, the separate "strip" tool does work correctly.
  339. STRIP_SEPARATE:=true
  340. else
  341. # Tell GCC to produce a stripped binary.
  342. LINK_FLAGS+=-s
  343. endif
  344. endif
  345. # Determine common compile flags.
  346. COMPILE_FLAGS+=$(addprefix -I,$(SOURCE_DIRS) $(BUILD_PATH)/config)
  347. # Determine common link flags.
  348. LINK_FLAGS_PREFIX:=-Wl,
  349. LINK_FLAGS+=$(addprefix $(LINK_FLAGS_PREFIX),$(LDFLAGS))
  350. # Add compile and link flags for libraries (from COMPONENTS_DEFS).
  351. COMPILE_FLAGS+=$(LIBRARY_COMPILE_FLAGS)
  352. LINK_FLAGS+=$(LIBRARY_LINK_FLAGS)
  353. # Build Rules
  354. # ===========
  355. # Force a probe if "probe" target is passed explicitly.
  356. ifeq ($(MAKECMDGOALS),probe)
  357. probe: $(PROBE_MAKE)
  358. .PHONY: $(PROBE_MAKE)
  359. endif
  360. # Probe for headers and functions.
  361. $(PROBE_MAKE): $(PROBE_SCRIPT) build/custom.mk \
  362. build/systemfuncs2code.py build/systemfuncs.py
  363. $(CMD)$(PYTHON) $(PROBE_SCRIPT) \
  364. "$(CXX) $(TARGET_FLAGS)" \
  365. $(@D) $(OPENMSX_TARGET_OS) $(LINK_MODE) "$(3RDPARTY_INSTALL_DIR)"
  366. $(CMD)touch $@
  367. # Generate configuration header.
  368. # TODO: One platform file may include another, so the real solution would be
  369. # for the Python script to write dependency info.
  370. $(CONFIG_HEADER): $(BUILDINFO_SCRIPT) \
  371. build/custom.mk build/platform-$(OPENMSX_TARGET_OS).mk
  372. $(CMD)$(PYTHON) $(BUILDINFO_SCRIPT) $@ \
  373. $(OPENMSX_TARGET_OS) $(OPENMSX_TARGET_CPU) $(OPENMSX_FLAVOUR) \
  374. $(INSTALL_SHARE_DIR)
  375. $(CMD)touch $@
  376. # Generate version header.
  377. .PHONY: forceversionextraction
  378. forceversionextraction:
  379. $(VERSION_HEADER): forceversionextraction
  380. $(CMD)$(PYTHON) $(VERSION_SCRIPT) $@
  381. # Generate components header.
  382. $(COMPONENTS_HEADER): $(COMPONENTS_HEADER_SCRIPT) $(PROBE_MAKE) \
  383. build/components.py
  384. $(CMD)$(PYTHON) $(COMPONENTS_HEADER_SCRIPT) $@ $(PROBE_MAKE)
  385. $(CMD)touch $@
  386. # Generate components Makefile.
  387. $(COMPONENTS_DEFS): $(COMPONENTS_DEFS_SCRIPT) $(PROBE_MAKE) \
  388. build/components.py
  389. $(CMD)$(PYTHON) $(COMPONENTS_DEFS_SCRIPT) $@ $(PROBE_MAKE)
  390. $(CMD)touch $@
  391. # Default target.
  392. ifeq ($(OPENMSX_TARGET_OS),darwin)
  393. all: app
  394. else
  395. all: $(MAIN_EXECUTABLE)
  396. endif
  397. ifeq ($(COMPONENT_CORE),false)
  398. # Force new probe.
  399. config: $(PROBE_MAKE)
  400. $(CMD)mv $(PROBE_MAKE) $(PROBE_MAKE).failed
  401. @false
  402. else
  403. # Print configuration.
  404. config:
  405. @echo "Build configuration:"
  406. @echo " Platform: $(PLATFORM)"
  407. @echo " Flavour: $(OPENMSX_FLAVOUR)"
  408. @echo " Compiler: $(CXX)"
  409. @echo " Subset: $(if $(OPENMSX_SUBSET),$(OPENMSX_SUBSET)*,full build)"
  410. endif
  411. # Include dependency files.
  412. ifneq ($(filter $(DEPEND_TARGETS),$(MAKECMDGOALS)),)
  413. -include $(DEPEND_FULL)
  414. endif
  415. # Clean up build tree of current flavour.
  416. clean:
  417. $(SUM) "Cleaning up..."
  418. $(CMD)rm -rf $(BUILD_PATH)
  419. # Create Makefiles in source subdirectories, to conveniently build a subset.
  420. ifeq ($(MAKECMDGOALS),createsubs)
  421. # Function that concatenates list items to form a single string.
  422. # Usage: $(call JOIN,TEXT)
  423. JOIN=$(if $(1),$(firstword $(1))$(call JOIN,$(wordlist 2,999999,$(1))),)
  424. RELPATH=$(call JOIN,$(patsubst %,../,$(subst /, ,$(@:%/GNUmakefile=%))))
  425. SUB_MAKEFILES:=$(addsuffix GNUmakefile,$(sort $(dir $(SOURCES_FULL))))
  426. createsubs: $(SUB_MAKEFILES)
  427. $(SUB_MAKEFILES):
  428. $(SUM) "Creating $@..."
  429. $(CMD)echo "export OPENMSX_SUBSET=$(@:$(SOURCES_PATH)/%GNUmakefile=%)" > $@
  430. $(CMD)echo "all:" >> $@
  431. $(CMD)echo " @\$$(MAKE) -C $(RELPATH) -f build/main.mk all" >> $@
  432. # Force re-creation every time this target is run.
  433. .PHONY: $(SUB_MAKEFILES)
  434. endif
  435. # Compile and generate dependency files in one go.
  436. DEPEND_SUBST=$(patsubst $(SOURCES_PATH)/%.cc,$(DEPEND_PATH)/%.d,$<)
  437. $(OBJECTS_FULL): $(OBJECTS_PATH)/%.o: $(SOURCES_PATH)/%.cc $(DEPEND_PATH)/%.d \
  438. | config $(GENERATED_HEADERS)
  439. $(SUM) "Compiling $(patsubst $(SOURCES_PATH)/%,%,$<)..."
  440. $(CMD)mkdir -p $(@D)
  441. $(CMD)mkdir -p $(patsubst $(OBJECTS_PATH)%,$(DEPEND_PATH)%,$(@D))
  442. $(CMD)$(CXX) \
  443. $(DEPEND_FLAGS) -MMD -MF $(DEPEND_SUBST) \
  444. -o $@ $(CXXFLAGS) $(COMPILE_FLAGS) -c $<
  445. $(CMD)touch $@ # Force .o file to be newer than .d file.
  446. # Generate dependencies that do not exist yet.
  447. # This is only in case some .d files have been deleted;
  448. # in normal operation this rule is never triggered.
  449. $(DEPEND_FULL):
  450. # Windows resources that are added to the executable.
  451. ifneq ($(filter mingw%,$(OPENMSX_TARGET_OS)),)
  452. $(RESOURCE_HEADER): forceversionextraction | config
  453. $(CMD)$(PYTHON) $(RESOURCE_SCRIPT) $@
  454. $(RESOURCE_OBJ): $(RESOURCE_SRC) $(RESOURCE_HEADER)
  455. $(SUM) "Compiling resources..."
  456. $(CMD)mkdir -p $(@D)
  457. $(CMD)$(WINDRES) $(addprefix --include-dir=,$(^D)) -o $@ -i $<
  458. endif
  459. # Link executable.
  460. $(BINARY_FULL): $(OBJECTS_FULL) $(RESOURCE_OBJ)
  461. ifeq ($(OPENMSX_SUBSET),)
  462. $(SUM) "Linking $(notdir $@)..."
  463. $(CMD)mkdir -p $(@D)
  464. $(CMD)+$(CXX) -o $@ $(CXXFLAGS) $^ $(LINK_FLAGS)
  465. ifeq ($(STRIP_SEPARATE),true)
  466. $(SUM) "Stripping $(notdir $@)..."
  467. $(CMD)strip $@
  468. endif
  469. ifeq ($(USE_SYMLINK),true)
  470. $(CMD)ln -sf $(@:derived/%=%) derived/$(BINARY_FILE)
  471. else
  472. $(CMD)cp $@ derived/$(BINARY_FILE)
  473. endif
  474. else
  475. $(SUM) "Not linking $(notdir $@) because only a subset was built."
  476. endif # subset
  477. $(LIBRARY_FULL): $(OBJECTS_FULL) $(RESOURCE_OBJ)
  478. $(SUM) "Linking $(notdir $@)..."
  479. $(CMD)mkdir -p $(@D)
  480. $(CMD)$(CXX) -shared -o $@ $(CXXFLAGS) $^ $(LINK_FLAGS)
  481. # Run executable.
  482. run: all
  483. $(SUM) "Running $(notdir $(BINARY_FULL))..."
  484. $(CMD)$(BINARY_FULL)
  485. # Installation and Binary Packaging
  486. # =================================
  487. ifneq ($(filter $(MAKECMDGOALS),bindist)$(filter $(OPENMSX_TARGET_OS),darwin),)
  488. # Create binary distribution directory.
  489. BINDIST_DIR:=$(BUILD_PATH)/bindist
  490. BINDIST_PACKAGE:=
  491. # Override install locations.
  492. DESTDIR:=$(BINDIST_DIR)/install
  493. INSTALL_ROOT:=
  494. ifneq ($(filter mingw%,$(OPENMSX_TARGET_OS)),)
  495. # In Windows the "share" dir is expected at the same level as the executable,
  496. # so do not put the executable in "bin".
  497. INSTALL_BINARY_DIR:=$(INSTALL_ROOT)
  498. else
  499. INSTALL_BINARY_DIR:=$(INSTALL_ROOT)/bin
  500. endif
  501. INSTALL_SHARE_DIR:=$(INSTALL_ROOT)/share
  502. INSTALL_DOC_DIR:=$(INSTALL_ROOT)/doc
  503. # C-BIOS should be included.
  504. INSTALL_CONTRIB:=true
  505. # Do not display header and post-install instructions.
  506. INSTALL_VERBOSE:=false
  507. .PHONY: bindist bindistclean
  508. bindist: install
  509. # Force removal of old destination dir before installing to new dir.
  510. install: bindistclean
  511. bindistclean: $(MAIN_EXECUTABLE)
  512. $(SUM) "Removing any old binary package..."
  513. $(CMD)rm -rf $(BINDIST_DIR)
  514. $(CMD)$(if $(BINDIST_PACKAGE),rm -f $(BINDIST_PACKAGE),)
  515. $(SUM) "Creating binary package:"
  516. endif
  517. ifeq ($(OPENMSX_TARGET_OS),darwin)
  518. # Application directory for Darwin.
  519. # This handles the "bindist" target, but can also be used with the "install"
  520. # target to create an app folder but no DMG.
  521. include build/package-darwin/app.mk
  522. else
  523. ifeq ($(OPENMSX_TARGET_OS),dingux)
  524. # ZIP file package for Dingux.
  525. include build/package-dingux/opk.mk
  526. else
  527. # Note: Use OPENMSX_INSTALL only to create binary packages.
  528. # To change installation dir for actual installations, edit "custom.mk".
  529. OPENMSX_INSTALL?=$(INSTALL_BASE)
  530. # Allow full customization of locations, used by Debian packaging.
  531. INSTALL_BINARY_DIR?=$(OPENMSX_INSTALL)/bin
  532. INSTALL_SHARE_DIR?=$(OPENMSX_INSTALL)/share
  533. INSTALL_DOC_DIR?=$(OPENMSX_INSTALL)/doc
  534. INSTALL_VERBOSE?=true
  535. endif
  536. endif
  537. # DESTDIR is a convention shared by at least GNU and FreeBSD to specify a path
  538. # prefix that will be used for all installed files.
  539. install: $(MAIN_EXECUTABLE)
  540. $(CMD)$(PYTHON) build/install.py "$(DESTDIR)" \
  541. "$(INSTALL_BINARY_DIR)" "$(INSTALL_SHARE_DIR)" "$(INSTALL_DOC_DIR)" \
  542. $(MAIN_EXECUTABLE) $(OPENMSX_TARGET_OS) \
  543. $(INSTALL_VERBOSE) $(INSTALL_CONTRIB)
  544. # Source Packaging
  545. # ================
  546. dist:
  547. $(CMD)$(PYTHON) build/gitdist.py
  548. # Binary Packaging Using 3rd Party Libraries
  549. # ==========================================
  550. # Recursive invocation with 3RDPARTY_FLAG=true.
  551. 3rdparty:
  552. $(MAKE) -f build/main.mk run-3rdparty \
  553. OPENMSX_TARGET_CPU=$(OPENMSX_TARGET_CPU) \
  554. OPENMSX_TARGET_OS=$(OPENMSX_TARGET_OS) \
  555. OPENMSX_FLAVOUR=$(OPENMSX_FLAVOUR) \
  556. 3RDPARTY_FLAG=true \
  557. PYTHON=$(PYTHON)
  558. # Call third party Makefile with the right arguments.
  559. # This is an internal target, users should select "3rdparty" instead.
  560. run-3rdparty:
  561. $(MAKE) -f build/3rdparty.mk \
  562. BUILD_PATH=$(BUILD_PATH)/3rdparty \
  563. OPENMSX_TARGET_CPU=$(OPENMSX_TARGET_CPU) \
  564. OPENMSX_TARGET_OS=$(OPENMSX_TARGET_OS) \
  565. _CC=$(CC) _CFLAGS="$(TARGET_FLAGS) $(CXXFLAGS)" \
  566. _LDFLAGS="$(TARGET_FLAGS)" \
  567. WINDRES=$(WINDRES) \
  568. LINK_MODE=$(LINK_MODE) \
  569. PYTHON=$(PYTHON)
  570. staticbindist: 3rdparty
  571. $(MAKE) -f build/main.mk bindist \
  572. OPENMSX_TARGET_CPU=$(OPENMSX_TARGET_CPU) \
  573. OPENMSX_TARGET_OS=$(OPENMSX_TARGET_OS) \
  574. OPENMSX_FLAVOUR=$(OPENMSX_FLAVOUR) \
  575. 3RDPARTY_FLAG=true \
  576. PYTHON=$(PYTHON)
  577. endif # PLATFORM