3rdparty.mk 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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 SDL2.
  135. $(BUILD_DIR)/$(PACKAGE_SDL2)/Makefile: \
  136. $(SOURCE_DIR)/$(PACKAGE_SDL2)/.extracted \
  137. $(call installdeps,PKG_CONFIG)
  138. mkdir -p $(@D)
  139. cd $(@D) && \
  140. $(PWD)/$(<D)/configure \
  141. --$(USE_VIDEO_X11)-video-x11 \
  142. --disable-video-directfb \
  143. --disable-video-opengles1 \
  144. --disable-nas \
  145. --disable-esd \
  146. --disable-arts \
  147. --disable-shared \
  148. $(if $(filter %clang,$(CC)),--disable-arm-simd,) \
  149. --host=$(TARGET_TRIPLE) \
  150. --prefix=$(PWD)/$(INSTALL_DIR) \
  151. --libdir=$(PWD)/$(INSTALL_DIR)/lib \
  152. CFLAGS="$(_CFLAGS)" \
  153. CPPFLAGS="-I$(PWD)/$(INSTALL_DIR)/include" \
  154. LDFLAGS="$(_LDFLAGS) -L$(PWD)/$(INSTALL_DIR)/lib"
  155. # Some modules are enabled because of internal SDL2 dependencies:
  156. # - "audio" depends on "atomic" and "threads"
  157. # - "joystick" depends on "haptic" (at least in the Windows back-end)
  158. # - OpenGL on Windows depends on "loadso"
  159. # Configure SDL2_ttf.
  160. $(BUILD_DIR)/$(PACKAGE_SDL2_TTF)/Makefile: \
  161. $(SOURCE_DIR)/$(PACKAGE_SDL2_TTF)/.extracted \
  162. $(call installdeps,PKG_CONFIG SDL2 FREETYPE)
  163. mkdir -p $(@D)
  164. cd $(@D) && $(PWD)/$(<D)/configure \
  165. --disable-sdltest \
  166. --disable-shared \
  167. --host=$(TARGET_TRIPLE) \
  168. --prefix=$(PWD)/$(INSTALL_DIR) \
  169. --libdir=$(PWD)/$(INSTALL_DIR)/lib \
  170. --$(subst disable,without,$(subst enable,with,$(USE_VIDEO_X11)))-x \
  171. CFLAGS="$(_CFLAGS)" \
  172. CPPFLAGS="-I$(PWD)/$(INSTALL_DIR)/include" \
  173. LDFLAGS="$(_LDFLAGS)"
  174. # Disable building of example programs.
  175. # This build fails on Android (SDL main issues), but on other platforms
  176. # we don't need these programs either.
  177. MAKEVAR_OVERRIDE_SDL2_TTF:=noinst_PROGRAMS=""
  178. # Configure libpng.
  179. $(BUILD_DIR)/$(PACKAGE_PNG)/Makefile: \
  180. $(SOURCE_DIR)/$(PACKAGE_PNG)/.extracted \
  181. $(call installdeps,$(filter-out $(SYSTEM_LIBS),ZLIB))
  182. mkdir -p $(@D)
  183. cd $(@D) && $(PWD)/$(<D)/configure \
  184. --disable-shared \
  185. --host=$(TARGET_TRIPLE) \
  186. --prefix=$(PWD)/$(INSTALL_DIR) \
  187. --libdir=$(PWD)/$(INSTALL_DIR)/lib \
  188. CFLAGS="$(_CFLAGS)" \
  189. CPPFLAGS="-I$(PWD)/$(INSTALL_DIR)/include" \
  190. LDFLAGS="$(_LDFLAGS) -L$(PWD)/$(INSTALL_DIR)/lib"
  191. # Configure FreeType.
  192. $(BUILD_DIR)/$(PACKAGE_FREETYPE)/Makefile: \
  193. $(SOURCE_DIR)/$(PACKAGE_FREETYPE)/.extracted \
  194. $(call installdeps,PKG_CONFIG)
  195. mkdir -p $(@D)
  196. cd $(@D) && $(PWD)/$(<D)/configure \
  197. --disable-shared \
  198. --without-zlib \
  199. --host=$(TARGET_TRIPLE) \
  200. --prefix=$(PWD)/$(INSTALL_DIR) \
  201. --libdir=$(PWD)/$(INSTALL_DIR)/lib \
  202. CFLAGS="$(_CFLAGS)" \
  203. LDFLAGS="$(_LDFLAGS)"
  204. # Configure zlib.
  205. # Although it uses "configure", zlib does not support building outside of the
  206. # source tree, so just copy everything over (it's a small package).
  207. $(BUILD_DIR)/$(PACKAGE_ZLIB)/Makefile: \
  208. $(SOURCE_DIR)/$(PACKAGE_ZLIB)/.extracted
  209. mkdir -p $(dir $(@D))
  210. rm -rf $(@D)
  211. cp -r $(<D) $(@D)
  212. cd $(@D) && ./configure \
  213. --prefix=$(PWD)/$(INSTALL_DIR) \
  214. --libdir=$(PWD)/$(INSTALL_DIR)/lib \
  215. --static
  216. # It is not possible to pass CFLAGS to zlib's configure.
  217. MAKEVAR_OVERRIDE_ZLIB:=CFLAGS="$(_CFLAGS)"
  218. # Note: zlib's Makefile uses LDFLAGS to link its examples, not the library
  219. # itself. If we mess with it, the build breaks.
  220. # Don't configure GLEW.
  221. # GLEW does not support building outside of the source tree, so just copy
  222. # everything over (it's a small package).
  223. $(BUILD_DIR)/$(PACKAGE_GLEW)/Makefile: \
  224. $(SOURCE_DIR)/$(PACKAGE_GLEW)/.extracted
  225. mkdir -p $(dir $(@D))
  226. rm -rf $(@D)
  227. cp -r $(<D) $(@D)
  228. # GLEW does not have a configure script to pass CFLAGS to.
  229. MAKEVAR_OVERRIDE_GLEW:=CC="$(_CC) $(_CFLAGS)" LD="$(_CC) $(_LDFLAGS)"
  230. # Tell GLEW to cross compile.
  231. ifeq ($(TRIPLE_OS),mingw32)
  232. MAKEVAR_OVERRIDE_GLEW+=SYSTEM=linux-mingw-w64
  233. else
  234. MAKEVAR_OVERRIDE_GLEW+=SYSTEM=$(TRIPLE_OS)
  235. endif
  236. # Configure Tcl.
  237. # Note: Tcl 8.6 includes some bundled extensions. We don't want these and there
  238. # is no configure flag to disable them, so we remove the pkgs/ directory
  239. # that they are in.
  240. # Note: Tcl seems to build either dynamic libs or static libs, which is why we
  241. # have to pass --disable-shared to configure.
  242. ifeq ($(TRIPLE_OS),mingw32)
  243. TCL_OS:=win
  244. else
  245. # Note: Use "unix" on Mac OS X as well. There is a "configure" script in
  246. # the "macosx" dir, but that is only intended for use with Xcode.
  247. TCL_OS:=unix
  248. endif
  249. CONFIGURE_OVERRIDE_TCL:=
  250. ifeq ($(OPENMSX_TARGET_OS),android)
  251. # nl_langinfo was introduced in API version 26, but for some reason configure
  252. # detects it on older API versions as well.
  253. CONFIGURE_OVERRIDE_TCL+=--disable-langinfo
  254. # The structs for 64-bit file offsets are already present in API version 14,
  255. # but the functions were only added in version 21. Tcl assumes that if the
  256. # structs are present, the functions are also present. So we override the
  257. # detection of the structs.
  258. CONFIGURE_OVERRIDE_TCL+=tcl_cv_struct_dirent64=no tcl_cv_struct_stat64=no
  259. endif
  260. $(BUILD_DIR)/$(PACKAGE_TCL)/Makefile: \
  261. $(SOURCE_DIR)/$(PACKAGE_TCL)/.extracted
  262. mkdir -p $(@D)
  263. rm -rf $(SOURCE_DIR)/$(PACKAGE_TCL)/pkgs/
  264. cd $(@D) && $(PWD)/$(<D)/$(TCL_OS)/configure \
  265. --host=$(TARGET_TRIPLE) \
  266. --prefix=$(PWD)/$(INSTALL_DIR) \
  267. --libdir=$(PWD)/$(INSTALL_DIR)/lib \
  268. --disable-shared \
  269. --disable-threads \
  270. --without-tzdata \
  271. $(CONFIGURE_OVERRIDE_TCL) \
  272. CFLAGS="$(_CFLAGS)" \
  273. LDFLAGS="$(_LDFLAGS)"
  274. # Configure Ogg, Vorbis and Theora for Laserdisc emulation.
  275. $(BUILD_DIR)/$(PACKAGE_OGG)/Makefile: \
  276. $(SOURCE_DIR)/$(PACKAGE_OGG)/.extracted \
  277. $(call installdeps,PKG_CONFIG)
  278. mkdir -p $(@D)
  279. cd $(@D) && $(PWD)/$(<D)/configure \
  280. --disable-shared \
  281. --host=$(TARGET_TRIPLE) \
  282. --prefix=$(PWD)/$(INSTALL_DIR) \
  283. --libdir=$(PWD)/$(INSTALL_DIR)/lib \
  284. CFLAGS="$(_CFLAGS)" \
  285. LDFLAGS="$(_LDFLAGS)"
  286. $(BUILD_DIR)/$(PACKAGE_VORBIS)/Makefile: \
  287. $(SOURCE_DIR)/$(PACKAGE_VORBIS)/.extracted \
  288. $(call installdeps,PKG_CONFIG OGG)
  289. mkdir -p $(@D)
  290. cd $(@D) && $(PWD)/$(<D)/configure \
  291. --disable-shared \
  292. --disable-oggtest \
  293. --host=$(TARGET_TRIPLE) \
  294. --prefix=$(PWD)/$(INSTALL_DIR) \
  295. --libdir=$(PWD)/$(INSTALL_DIR)/lib \
  296. --with-ogg=$(PWD)/$(INSTALL_DIR) \
  297. CFLAGS="$(_CFLAGS)" \
  298. LDFLAGS="$(_LDFLAGS)"
  299. # Note: According to its spec file, Theora has a build dependency on both
  300. # Ogg and Vorbis, a runtime dependency on Vorbis and a development
  301. # package dependency on Ogg.
  302. $(BUILD_DIR)/$(PACKAGE_THEORA)/Makefile: \
  303. $(SOURCE_DIR)/$(PACKAGE_THEORA)/.extracted \
  304. $(call installdeps,PKG_CONFIG OGG VORBIS)
  305. mkdir -p $(@D)
  306. cd $(@D) && $(PWD)/$(<D)/configure \
  307. --disable-shared \
  308. --disable-oggtest \
  309. --disable-vorbistest \
  310. --disable-sdltest \
  311. --disable-encode \
  312. --disable-examples \
  313. --host=$(OLD_TARGET_TRIPLE) \
  314. --prefix=$(PWD)/$(INSTALL_DIR) \
  315. --libdir=$(PWD)/$(INSTALL_DIR)/lib \
  316. --with-ogg=$(PWD)/$(INSTALL_DIR) \
  317. --with-vorbis=$(PWD)/$(INSTALL_DIR) \
  318. CFLAGS="$(_CFLAGS)" \
  319. LDFLAGS="$(_LDFLAGS)"
  320. endif
  321. # Rules for creating and updating generated Makefiles:
  322. derived/3rdparty/packages.mk: \
  323. build/3rdparty_packages2make.py build/packages.py
  324. mkdir -p $(@D)
  325. $(PYTHON) $< > $@