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