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