main.mk 19 KB

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