3rdparty.mk 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. # Compiles 3rd party libraries needed by openMSX.
  2. # It enables only the features needed by openMSX.
  3. ifeq ($(origin PYTHON),undefined)
  4. $(error You should pass PYTHON)
  5. endif
  6. ifeq ($(origin BUILD_PATH),undefined)
  7. $(error You should pass BUILD_PATH)
  8. endif
  9. ifeq ($(origin OPENMSX_TARGET_OS),undefined)
  10. $(error You should pass OPENMSX_TARGET_OS)
  11. endif
  12. ifeq ($(origin OPENMSX_TARGET_CPU),undefined)
  13. $(error You should pass OPENMSX_TARGET_CPU)
  14. endif
  15. .PHONY: all
  16. all: default
  17. # Get information about packages.
  18. -include derived/3rdparty/packages.mk
  19. ifneq ($(origin PACKAGE_SDL2),undefined)
  20. # These libraries are part of the base system, therefore we do not need to
  21. # link them statically for building a redistributable binary.
  22. SYSTEM_LIBS:=$(shell $(PYTHON) build/list_system_libs.py $(OPENMSX_TARGET_OS))
  23. # Compiler selection, compiler flags, SDK selection.
  24. # These variables are already exported, but we make it explicit here.
  25. export CC
  26. CC=$(_CC)
  27. TIMESTAMP_DIR:=$(BUILD_PATH)/timestamps
  28. BUILD_DIR:=$(BUILD_PATH)/build
  29. INSTALL_DIR:=$(BUILD_PATH)/install
  30. TOOLS_DIR:=$(BUILD_PATH)/tools
  31. # Create a GNU-style system tuple.
  32. # Unfortunately, these are very poorly standardized, so our aim is to
  33. # create tuples that are known to work, instead of using a consistent
  34. # algorithm across all platforms.
  35. ifeq ($(OPENMSX_TARGET_CPU),x86)
  36. TRIPLE_MACHINE:=i686
  37. else
  38. ifeq ($(OPENMSX_TARGET_CPU),ppc)
  39. TRIPLE_MACHINE:=powerpc
  40. else
  41. ifeq ($(OPENMSX_TARGET_CPU),ppc64)
  42. TRIPLE_MACHINE:=powerpc64
  43. else
  44. TRIPLE_MACHINE:=$(OPENMSX_TARGET_CPU)
  45. endif
  46. endif
  47. endif
  48. ifneq ($(filter android dingux,$(OPENMSX_TARGET_OS)),)
  49. TRIPLE_OS:=linux
  50. else
  51. TRIPLE_OS:=$(OPENMSX_TARGET_OS)
  52. endif
  53. TRIPLE_VENDOR:=unknown
  54. ifeq ($(OPENMSX_TARGET_OS),mingw-w64)
  55. TRIPLE_OS:=mingw32
  56. TRIPLE_VENDOR:=w64
  57. endif
  58. TARGET_TRIPLE:=$(TRIPLE_MACHINE)-$(TRIPLE_VENDOR)-$(TRIPLE_OS)
  59. # Libraries using old autoconf macros don't recognise Android as an OS,
  60. # so we have to tell those we're building for Linux instead.
  61. OLD_TARGET_TRIPLE:=$(TARGET_TRIPLE)
  62. # For all other libraries, we pass an Android-specific system tuple.
  63. # These are triples but instead of machine-vendor-os they use machine-os-abi.
  64. ifeq ($(OPENMSX_TARGET_OS),android)
  65. TARGET_TRIPLE:=$(TRIPLE_MACHINE)-$(TRIPLE_OS)-android
  66. ifeq ($(TRIPLE_MACHINE),arm)
  67. TARGET_TRIPLE:=$(TARGET_TRIPLE)eabi
  68. endif
  69. endif
  70. export PKG_CONFIG:=$(PWD)/$(TOOLS_DIR)/bin/$(TARGET_TRIPLE)-pkg-config
  71. # Ask the compiler for the names and locations of other toolchain components.
  72. # This works with GCC and Clang at least, so it should be pretty safe.
  73. export LD:=$(shell $(CC) -print-prog-name=ld)
  74. export AR:=$(shell $(CC) -print-prog-name=ar)
  75. export RANLIB:=$(shell $(CC) -print-prog-name=ranlib)
  76. export STRIP:=$(shell $(CC) -print-prog-name=strip)
  77. ifeq ($(TRIPLE_OS),mingw32)
  78. # SDL calls it WINDRES, Tcl calls it RC; provide both.
  79. export WINDRES
  80. export RC:=$(WINDRES)
  81. endif
  82. # Although X11 is available on Windows and Mac OS X, most people do not have
  83. # it installed, so do not link against it.
  84. ifeq ($(filter linux freebsd netbsd openbsd gnu,$(OPENMSX_TARGET_OS)),)
  85. USE_VIDEO_X11:=disable
  86. else
  87. USE_VIDEO_X11:=enable
  88. endif
  89. PACKAGES_BUILD:=$(shell $(PYTHON) build/3rdparty_libraries.py $(OPENMSX_TARGET_OS) $(LINK_MODE)) PKG_CONFIG
  90. PACKAGES_NOBUILD:=
  91. PACKAGES_3RD:=$(PACKAGES_BUILD) $(PACKAGES_NOBUILD)
  92. # Function which, given a variable name prefix and the variable's value,
  93. # returns the name of the package.
  94. findpackage=$(strip $(foreach PACKAGE,$(PACKAGES_3RD),$(if $(filter $(2),$($(1)_$(PACKAGE))),$(PACKAGE),)))
  95. # Function which, given a list of packages, produces a list of the install
  96. # timestamps for those packages.
  97. installdeps=$(foreach PACKAGE,$(1),$(TIMESTAMP_DIR)/install-$(PACKAGE_$(PACKAGE)))
  98. BUILD_TARGETS:=$(foreach PACKAGE,$(PACKAGES_BUILD),$(TIMESTAMP_DIR)/build-$(PACKAGE_$(PACKAGE)))
  99. INSTALL_BUILD_TARGETS:=$(call installdeps,$(PACKAGES_BUILD))
  100. INSTALL_NOBUILD_TARGETS:=$(call installdeps,$(PACKAGES_NOBUILD))
  101. INSTALL_PARAMS_GLEW:=\
  102. GLEW_DEST=$(PWD)/$(INSTALL_DIR) \
  103. LIBDIR=$(PWD)/$(INSTALL_DIR)/lib
  104. .PHONY: default
  105. default: $(INSTALL_BUILD_TARGETS) $(INSTALL_NOBUILD_TARGETS)
  106. .PHONY: clean
  107. clean:
  108. rm -rf $(SOURCE_DIR)
  109. rm -rf $(BUILD_DIR)
  110. rm -rf $(INSTALL_DIR)
  111. # Install.
  112. $(INSTALL_BUILD_TARGETS): $(TIMESTAMP_DIR)/install-%: $(TIMESTAMP_DIR)/build-%
  113. $(MAKE) -C $(BUILD_DIR)/$* install \
  114. $(MAKEVAR_OVERRIDE_$(call findpackage,PACKAGE,$*)) \
  115. $(INSTALL_PARAMS_$(call findpackage,PACKAGE,$*))
  116. mkdir -p $(@D)
  117. touch $@
  118. # Build.
  119. $(BUILD_TARGETS): $(TIMESTAMP_DIR)/build-%: $(BUILD_DIR)/%/Makefile
  120. $(MAKE) -C $(<D) $(MAKEVAR_OVERRIDE_$(call findpackage,PACKAGE,$*))
  121. mkdir -p $(@D)
  122. touch $@
  123. # Configure pkg-config.
  124. $(BUILD_DIR)/$(PACKAGE_PKG_CONFIG)/Makefile: \
  125. $(SOURCE_DIR)/$(PACKAGE_PKG_CONFIG)/.extracted
  126. mkdir -p $(@D)
  127. cd $(@D) && $(PWD)/$(<D)/configure \
  128. --with-internal-glib \
  129. --disable-host-tool \
  130. --program-prefix=$(TARGET_TRIPLE)- \
  131. --prefix=$(PWD)/$(TOOLS_DIR) \
  132. --libdir=$(PWD)/$(INSTALL_DIR)/lib \
  133. CC= LD= AR= RANLIB= STRIP=
  134. # Configure ALSA.
  135. $(BUILD_DIR)/$(PACKAGE_ALSA)/Makefile: \
  136. $(SOURCE_DIR)/$(PACKAGE_ALSA)/.extracted
  137. mkdir -p $(@D)
  138. cd $(@D) && $(PWD)/$(<D)/configure \
  139. --enable-static \
  140. --disable-shared \
  141. --enable-symbolic-functions \
  142. --disable-debug \
  143. --disable-aload \
  144. --disable-mixer \
  145. --enable-pcm \
  146. --disable-rawmidi \
  147. --disable-hwdep \
  148. --enable-seq \
  149. --disable-ucm \
  150. --disable-topology \
  151. --disable-alisp \
  152. --disable-old-symbols \
  153. --disable-python \
  154. --with-debug=no \
  155. --with-libdl=no \
  156. --with-pthread=yes \
  157. --with-librt=yes \
  158. --host=$(TARGET_TRIPLE) \
  159. --prefix=$(PWD)/$(INSTALL_DIR) \
  160. --libdir=$(PWD)/$(INSTALL_DIR)/lib \
  161. CFLAGS="$(_CFLAGS)" \
  162. CPPFLAGS="-I$(PWD)/$(INSTALL_DIR)/include" \
  163. LDFLAGS="$(_LDFLAGS) -L$(PWD)/$(INSTALL_DIR)/lib"
  164. # Configure SDL2.
  165. $(BUILD_DIR)/$(PACKAGE_SDL2)/Makefile: \
  166. $(SOURCE_DIR)/$(PACKAGE_SDL2)/.extracted \
  167. $(call installdeps,PKG_CONFIG $(filter ALSA,$(PACKAGES_3RD)))
  168. mkdir -p $(@D)
  169. cd $(@D) && \
  170. $(PWD)/$(<D)/configure \
  171. --$(USE_VIDEO_X11)-video-x11 \
  172. --disable-video-directfb \
  173. --disable-video-opengles1 \
  174. --disable-nas \
  175. --disable-esd \
  176. --disable-arts \
  177. --disable-shared \
  178. --host=$(TARGET_TRIPLE) \
  179. --prefix=$(PWD)/$(INSTALL_DIR) \
  180. --libdir=$(PWD)/$(INSTALL_DIR)/lib \
  181. CFLAGS="$(_CFLAGS)" \
  182. CPPFLAGS="-I$(PWD)/$(INSTALL_DIR)/include" \
  183. LDFLAGS="$(_LDFLAGS) -L$(PWD)/$(INSTALL_DIR)/lib"
  184. # Some modules are enabled because of internal SDL2 dependencies:
  185. # - "audio" depends on "atomic" and "threads"
  186. # - "joystick" depends on "haptic" (at least in the Windows back-end)
  187. # - OpenGL on Windows depends on "loadso"
  188. # Configure SDL2_ttf.
  189. $(BUILD_DIR)/$(PACKAGE_SDL2_TTF)/Makefile: \
  190. $(SOURCE_DIR)/$(PACKAGE_SDL2_TTF)/.extracted \
  191. $(call installdeps,PKG_CONFIG SDL2 FREETYPE)
  192. mkdir -p $(@D)
  193. cd $(@D) && $(PWD)/$(<D)/configure \
  194. --disable-sdltest \
  195. --disable-shared \
  196. --host=$(TARGET_TRIPLE) \
  197. --prefix=$(PWD)/$(INSTALL_DIR) \
  198. --libdir=$(PWD)/$(INSTALL_DIR)/lib \
  199. --$(subst disable,without,$(subst enable,with,$(USE_VIDEO_X11)))-x \
  200. CFLAGS="$(_CFLAGS)" \
  201. CPPFLAGS="-I$(PWD)/$(INSTALL_DIR)/include" \
  202. LDFLAGS="$(_LDFLAGS)"
  203. # Disable building of example programs.
  204. # This build fails on Android (SDL main issues), but on other platforms
  205. # we don't need these programs either.
  206. MAKEVAR_OVERRIDE_SDL2_TTF:=noinst_PROGRAMS=""
  207. # Configure libpng.
  208. $(BUILD_DIR)/$(PACKAGE_PNG)/Makefile: \
  209. $(SOURCE_DIR)/$(PACKAGE_PNG)/.extracted \
  210. $(call installdeps,$(filter-out $(SYSTEM_LIBS),ZLIB))
  211. mkdir -p $(@D)
  212. cd $(@D) && $(PWD)/$(<D)/configure \
  213. --disable-shared \
  214. --host=$(TARGET_TRIPLE) \
  215. --prefix=$(PWD)/$(INSTALL_DIR) \
  216. --libdir=$(PWD)/$(INSTALL_DIR)/lib \
  217. CFLAGS="$(_CFLAGS)" \
  218. CPPFLAGS="-I$(PWD)/$(INSTALL_DIR)/include" \
  219. LDFLAGS="$(_LDFLAGS) -L$(PWD)/$(INSTALL_DIR)/lib"
  220. # Configure FreeType.
  221. $(BUILD_DIR)/$(PACKAGE_FREETYPE)/Makefile: \
  222. $(SOURCE_DIR)/$(PACKAGE_FREETYPE)/.extracted \
  223. $(call installdeps,PKG_CONFIG)
  224. mkdir -p $(@D)
  225. cd $(@D) && $(PWD)/$(<D)/configure \
  226. --disable-shared \
  227. --without-zlib \
  228. --host=$(TARGET_TRIPLE) \
  229. --prefix=$(PWD)/$(INSTALL_DIR) \
  230. --libdir=$(PWD)/$(INSTALL_DIR)/lib \
  231. CFLAGS="$(_CFLAGS)" \
  232. LDFLAGS="$(_LDFLAGS)"
  233. # Configure zlib.
  234. # Although it uses "configure", zlib does not support building outside of the
  235. # source tree, so just copy everything over (it's a small package).
  236. $(BUILD_DIR)/$(PACKAGE_ZLIB)/Makefile: \
  237. $(SOURCE_DIR)/$(PACKAGE_ZLIB)/.extracted
  238. mkdir -p $(dir $(@D))
  239. rm -rf $(@D)
  240. cp -r $(<D) $(@D)
  241. cd $(@D) && ./configure \
  242. --prefix=$(PWD)/$(INSTALL_DIR) \
  243. --libdir=$(PWD)/$(INSTALL_DIR)/lib \
  244. --static
  245. # It is not possible to pass CFLAGS to zlib's configure.
  246. MAKEVAR_OVERRIDE_ZLIB:=CFLAGS="$(_CFLAGS)"
  247. # Note: zlib's Makefile uses LDFLAGS to link its examples, not the library
  248. # itself. If we mess with it, the build breaks.
  249. # Don't configure GLEW.
  250. # GLEW does not support building outside of the source tree, so just copy
  251. # everything over (it's a small package).
  252. $(BUILD_DIR)/$(PACKAGE_GLEW)/Makefile: \
  253. $(SOURCE_DIR)/$(PACKAGE_GLEW)/.extracted
  254. mkdir -p $(dir $(@D))
  255. rm -rf $(@D)
  256. cp -r $(<D) $(@D)
  257. # GLEW does not have a configure script to pass CFLAGS to.
  258. MAKEVAR_OVERRIDE_GLEW:=CC="$(_CC) $(_CFLAGS)" LD="$(_CC) $(_LDFLAGS)"
  259. # Tell GLEW to cross compile.
  260. ifeq ($(TRIPLE_OS),mingw32)
  261. MAKEVAR_OVERRIDE_GLEW+=SYSTEM=linux-mingw-w64
  262. else
  263. MAKEVAR_OVERRIDE_GLEW+=SYSTEM=$(TRIPLE_OS)
  264. endif
  265. # Configure Tcl.
  266. # Note: Tcl 8.6 includes some bundled extensions. We don't want these and there
  267. # is no configure flag to disable them, so we remove the pkgs/ directory
  268. # that they are in.
  269. # Note: Tcl seems to build either dynamic libs or static libs, which is why we
  270. # have to pass --disable-shared to configure.
  271. ifeq ($(TRIPLE_OS),mingw32)
  272. TCL_OS:=win
  273. else
  274. # Note: Use "unix" on Mac OS X as well. There is a "configure" script in
  275. # the "macosx" dir, but that is only intended for use with Xcode.
  276. TCL_OS:=unix
  277. endif
  278. CONFIGURE_OVERRIDE_TCL:=
  279. ifeq ($(OPENMSX_TARGET_OS),android)
  280. # nl_langinfo was introduced in API version 26, but for some reason configure
  281. # detects it on older API versions as well.
  282. CONFIGURE_OVERRIDE_TCL+=--disable-langinfo
  283. # The structs for 64-bit file offsets are already present in API version 14,
  284. # but the functions were only added in version 21. Tcl assumes that if the
  285. # structs are present, the functions are also present. So we override the
  286. # detection of the structs.
  287. CONFIGURE_OVERRIDE_TCL+=tcl_cv_struct_dirent64=no tcl_cv_struct_stat64=no
  288. endif
  289. $(BUILD_DIR)/$(PACKAGE_TCL)/Makefile: \
  290. $(SOURCE_DIR)/$(PACKAGE_TCL)/.extracted
  291. mkdir -p $(@D)
  292. rm -rf $(SOURCE_DIR)/$(PACKAGE_TCL)/pkgs/
  293. cd $(@D) && $(PWD)/$(<D)/$(TCL_OS)/configure \
  294. --host=$(TARGET_TRIPLE) \
  295. --prefix=$(PWD)/$(INSTALL_DIR) \
  296. --libdir=$(PWD)/$(INSTALL_DIR)/lib \
  297. --disable-shared \
  298. --disable-threads \
  299. --without-tzdata \
  300. $(CONFIGURE_OVERRIDE_TCL) \
  301. CFLAGS="$(_CFLAGS)" \
  302. LDFLAGS="$(_LDFLAGS)"
  303. # Configure Ogg, Vorbis and Theora for Laserdisc emulation.
  304. $(BUILD_DIR)/$(PACKAGE_OGG)/Makefile: \
  305. $(SOURCE_DIR)/$(PACKAGE_OGG)/.extracted \
  306. $(call installdeps,PKG_CONFIG)
  307. mkdir -p $(@D)
  308. cd $(@D) && $(PWD)/$(<D)/configure \
  309. --disable-shared \
  310. --host=$(TARGET_TRIPLE) \
  311. --prefix=$(PWD)/$(INSTALL_DIR) \
  312. --libdir=$(PWD)/$(INSTALL_DIR)/lib \
  313. CFLAGS="$(_CFLAGS)" \
  314. LDFLAGS="$(_LDFLAGS)"
  315. $(BUILD_DIR)/$(PACKAGE_VORBIS)/Makefile: \
  316. $(SOURCE_DIR)/$(PACKAGE_VORBIS)/.extracted \
  317. $(call installdeps,PKG_CONFIG OGG)
  318. mkdir -p $(@D)
  319. cd $(@D) && $(PWD)/$(<D)/configure \
  320. --disable-shared \
  321. --disable-oggtest \
  322. --host=$(TARGET_TRIPLE) \
  323. --prefix=$(PWD)/$(INSTALL_DIR) \
  324. --libdir=$(PWD)/$(INSTALL_DIR)/lib \
  325. --with-ogg=$(PWD)/$(INSTALL_DIR) \
  326. CFLAGS="$(_CFLAGS)" \
  327. LDFLAGS="$(_LDFLAGS)"
  328. # Note: According to its spec file, Theora has a build dependency on both
  329. # Ogg and Vorbis, a runtime dependency on Vorbis and a development
  330. # package dependency on Ogg.
  331. $(BUILD_DIR)/$(PACKAGE_THEORA)/Makefile: \
  332. $(SOURCE_DIR)/$(PACKAGE_THEORA)/.extracted \
  333. $(call installdeps,PKG_CONFIG OGG VORBIS)
  334. mkdir -p $(@D)
  335. cd $(@D) && $(PWD)/$(<D)/configure \
  336. --disable-shared \
  337. --disable-oggtest \
  338. --disable-vorbistest \
  339. --disable-sdltest \
  340. --disable-encode \
  341. --disable-examples \
  342. --host=$(OLD_TARGET_TRIPLE) \
  343. --prefix=$(PWD)/$(INSTALL_DIR) \
  344. --libdir=$(PWD)/$(INSTALL_DIR)/lib \
  345. --with-ogg=$(PWD)/$(INSTALL_DIR) \
  346. --with-vorbis=$(PWD)/$(INSTALL_DIR) \
  347. CFLAGS="$(_CFLAGS)" \
  348. LDFLAGS="$(_LDFLAGS)"
  349. endif
  350. # Rules for creating and updating generated Makefiles:
  351. derived/3rdparty/packages.mk: \
  352. build/3rdparty_packages2make.py build/packages.py
  353. mkdir -p $(@D)
  354. $(PYTHON) $< > $@