forked from nebiun/MAME4Wii
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
616 lines (476 loc) · 15.6 KB
/
makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
###########################################################################
#
# makefile
#
# Core makefile for building MAME and derivatives
#
# Copyright (c) Nicola Salmoria and the MAME Team.
# Visit http://mamedev.org for licensing and usage restrictions.
#
###########################################################################
ifeq ($(strip $(DEVKITPPC)),)
$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC")
endif
include $(DEVKITPPC)/wii_rules
###########################################################################
################# BEGIN USER-CONFIGURABLE OPTIONS #####################
###########################################################################
#-------------------------------------------------
# specify core target: mame, mess, etc.
# specify subtarget: mame, mess, tiny, etc.
# build rules will be included from
# src/$(TARGET)/$(SUBTARGET).mak
#-------------------------------------------------
ifndef TARGET
TARGET = mame
endif
ifndef SUBTARGET
SUBTARGET = 4wii
endif
#-------------------------------------------------
# specify OSD layer: windows, sdl, etc.
# build rules will be included from
# src/osd/$(OSD)/$(OSD).mak
#-------------------------------------------------
ifndef OSD
OSD = wii
endif
ifndef CROSS_BUILD_OSD
CROSS_BUILD_OSD = $(OSD)
endif
#-------------------------------------------------
# specify OS target, which further differentiates
# the underlying OS; supported values are:
# win32, unix, macosx, os2
#-------------------------------------------------
ifndef TARGETOS
ifeq ($(OSD),windows)
TARGETOS = win32
else
TARGETOS = unix
endif
endif
#-------------------------------------------------
# configure name of final executable
#-------------------------------------------------
# uncomment and specify prefix to be added to the name
# PREFIX =
# uncomment and specify suffix to be added to the name
# SUFFIX =
#-------------------------------------------------
# specify architecture-specific optimizations
#-------------------------------------------------
# uncomment and specify architecture-specific optimizations here
# some examples:
# optimize for I686: ARCHOPTS = -march=pentiumpro
# optimize for Core 2: ARCHOPTS = -march=pentium-m -msse3
# optimize for G4: ARCHOPTS = -mcpu=G4
# note that we leave this commented by default so that you can
# configure this in your environment and never have to think about it
ARCHOPTS = -mrvl -mcpu=750 -meabi -mhard-float
#-------------------------------------------------
# specify program options; see each option below
# for details
#-------------------------------------------------
# uncomment next line to build a debug version
# DEBUG = 1
# uncomment next line to include the internal profiler
# PROFILER = 1
# uncomment the force the universal DRC to always use the C backend
# you may need to do this if your target architecture does not have
# a native backend
# FORCE_DRC_C_BACKEND = 1
#-------------------------------------------------
# specify build options; see each option below
# for details
#-------------------------------------------------
# uncomment next line if you are building for a 64-bit target
# PTR64 = 1
# uncomment next line if you are building for a big-endian target
BIGENDIAN = 1
# uncomment next line to build expat as part of MAME build
# BUILD_EXPAT = 1
# uncomment next line to build zlib as part of MAME build
# BUILD_ZLIB = 1
# uncomment next line to include the symbols
# SYMBOLS = 1
# uncomment next line to include profiling information from the compiler
# PROFILE = 1
# uncomment next line to generate a link map for exception handling in windows
# MAP = 1
# uncomment next line to generate verbose build information
# VERBOSE = 1
# specify optimization level or leave commented to use the default
# (default is OPTIMIZE = 3 normally, or OPTIMIZE = 0 with symbols)
# OPTIMIZE = 3
# experimental: uncomment to compile everything as C++ for stricter type checking
# CPP_COMPILE = 1
###########################################################################
################## END USER-CONFIGURABLE OPTIONS ######################
###########################################################################
#-------------------------------------------------
# sanity check the configuration
#-------------------------------------------------
# specify a default optimization level if none explicitly stated
ifndef OPTIMIZE
ifndef SYMBOLS
OPTIMIZE = 3
else
OPTIMIZE = 0
endif
endif
# profiler defaults to on for DEBUG builds
ifdef DEBUG
ifndef PROFILER
PROFILER = 1
endif
endif
#-------------------------------------------------
# platform-specific definitions
#-------------------------------------------------
# extension for executables
EXE =
ifeq ($(TARGETOS),win32)
EXE = .exe
endif
ifeq ($(TARGETOS),os2)
EXE = .exe
endif
ifndef BUILD_EXE
BUILD_EXE = $(EXE)
endif
CCEXE = .exe
# compiler, linker and utilities
AR = @$(PREFIX)ar
CC = $(PREFIX)gcc
CXX = @$(PREFIX)g++
LD = $(CC)
MD = -mkdir$(EXE)
RM = @rm -f
#-------------------------------------------------
# form the name of the executable
#-------------------------------------------------
# debug builds just get the 'd' suffix and nothing more
ifdef DEBUG
DEBUGSUFFIX = d
endif
# cpp builds get a 'pp' suffix
ifdef CPP_COMPILE
CPPSUFFIX = pp
endif
# the name is just 'target' if no subtarget; otherwise it is
# the concatenation of the two (e.g., mametiny)
ifeq ($(TARGET),$(SUBTARGET))
NAME = $(TARGET)
else
NAME = $(TARGET)$(SUBTARGET)
endif
# fullname is prefix+name+suffix+debugsuffix
FULLNAME = $(PREFIX)$(NAME)$(CPPSUFFIX)$(SUFFIX)$(DEBUGSUFFIX)
# add an EXE suffix to get the final emulator name
EMULATOR = $(FULLNAME).elf
EMULATORDOL = $(FULLNAME).dol
#-------------------------------------------------
# source and object locations
#-------------------------------------------------
# all sources are under the src/ directory
SRC = src
# build the targets in different object dirs, so they can co-exist
OBJ = obj/$(OSD)/$(FULLNAME)
#-------------------------------------------------
# compile-time definitions
#-------------------------------------------------
# CR/LF setup: use both on win32/os2, CR only on everything else
DEFS = -DCRLF=2
ifeq ($(TARGETOS),win32)
DEFS = -DCRLF=3
endif
ifeq ($(TARGETOS),os2)
DEFS = -DCRLF=3
endif
# map the INLINE to something digestible by GCC
DEFS += -DINLINE="static __inline__"
# define LSB_FIRST if we are a little-endian target
ifndef BIGENDIAN
DEFS += -DLSB_FIRST
endif
# define PTR64 if we are a 64-bit target
ifdef PTR64
DEFS += -DPTR64
endif
# define MAME_DEBUG if we are a debugging build
ifdef DEBUG
DEFS += -DMAME_DEBUG
endif
# define MAME_PROFILER if we are a profiling build
ifdef PROFILER
DEFS += -DMAME_PROFILER
endif
#-------------------------------------------------
# compile flags
# CCOMFLAGS are common flags
# CONLYFLAGS are flags only used when compiling for C
# CPPONLYFLAGS are flags only used when compiling for C++
#-------------------------------------------------
# start with empties for everything
CCOMFLAGS =
CONLYFLAGS =
CPPONLYFLAGS =
# we compile C-only to C89 standard with GNU extensions
# we compile C++ code to C++98 standard with GNU extensions
CONLYFLAGS += -std=gnu11
CPPONLYFLAGS += -x c++ -std=gnu++11
# this speeds it up a bit by piping between the preprocessor/compiler/assembler
CCOMFLAGS += -pipe
# add -g if we need symbols, and ensure we have frame pointers
ifdef SYMBOLS
CCOMFLAGS += -g -fno-omit-frame-pointer
endif
# add -v if we need verbose build information
ifdef VERBOSE
CCOMFLAGS += -v
endif
# add profiling information for the compiler
ifdef PROFILE
CCOMFLAGS += -pg
endif
# add the optimization flag
CCOMFLAGS += -O$(OPTIMIZE)
CCOMFLAGS += $(MACHDEP)
CCOMFLAGS += $(GAME_LIST)
CCOMFLAGS += -DWII_VERSION=\"$(WII_VERSION)\"
CCOMFLAGS += -DWII_BUILD=\"$(WII_BUILD)\"
# if we are optimizing, include optimization options
# and make all errors into warnings
ifneq ($(OPTIMIZE),0)
ifneq ($(TARGETOS),os2)
ifndef IA64
CCOMFLAGS += -fno-strict-aliasing $(ARCHOPTS)
else
endif
else
CCOMFLAGS += -fno-strict-aliasing $(ARCHOPTS)
endif
endif
# add a basic set of warnings
CCOMFLAGS += \
-Wall \
-Wcast-align \
-Wundef \
-Wformat-security \
-Wwrite-strings \
-Wno-sign-compare
# warnings only applicable to C compiles
CONLYFLAGS += \
-Wpointer-arith \
-Wbad-function-cast \
# -Wstrict-prototypes
# this warning is not supported on the os2 compilers
ifneq ($(TARGETOS),os2)
CONLYFLAGS += -Wdeclaration-after-statement
endif
#-------------------------------------------------
# include paths
#-------------------------------------------------
# add core include paths
CCOMFLAGS += \
-I$(SRC)/$(TARGET) \
-I$(SRC)/$(TARGET)/includes \
-I$(OBJ)/$(TARGET)/layout \
-I$(SRC)/emu \
-I$(OBJ)/emu \
-I$(OBJ)/emu/layout \
-I$(SRC)/lib/util \
-I$(SRC)/osd \
-I$(SRC)/osd/$(OSD) \
# CFLAGS is defined based on C or C++ targets
# (remember, expansion only happens when used, so doing it here is ok)
ifdef CPP_COMPILE
CFLAGS = $(CCOMFLAGS) $(CPPONLYFLAGS)
else
CFLAGS = $(CCOMFLAGS) $(CONLYFLAGS)
endif
#-------------------------------------------------
# linking flags
#-------------------------------------------------
# LDFLAGS are used generally; LDFLAGSEMULATOR are additional
# flags only used when linking the core emulator
LDFLAGS =
ifneq ($(TARGETOS),macosx)
ifneq ($(TARGETOS),os2)
ifneq ($(TARGETOS),solaris)
LDFLAGS = -Wl,--warn-common
endif
endif
endif
LDFLAGSEMULATOR =
# add profiling information for the linker
ifdef PROFILE
LDFLAGS += -pg
endif
# strip symbols and other metadata in non-symbols and non profiling builds
ifndef SYMBOLS
ifndef PROFILE
ifneq ($(TARGETOS),macosx)
#LDFLAGS += -s
endif
endif
endif
# output a map file (emulator only)
ifdef MAP
LDFLAGSEMULATOR += -Wl,-Map,$(FULLNAME).map
endif
LDFLAGS += $(MACHDEP) -L$(LIBOGC_LIB)
#-------------------------------------------------
# define the standard object directory; other
# projects can add their object directories to
# this variable
#-------------------------------------------------
OBJDIRS = $(OBJ)
#-------------------------------------------------
# define standard libarires for CPU and sounds
#-------------------------------------------------
LIBEMU = $(OBJ)/libemu.a
LIBCPU = $(OBJ)/libcpu.a
LIBDASM = $(OBJ)/libdasm.a
LIBSOUND = $(OBJ)/libsound.a
LIBUTIL = $(OBJ)/libutil.a
LIBOCORE = $(OBJ)/libocore.a
LIBOSD = $(OBJ)/libosd.a
VERSIONOBJ = $(OBJ)/version.o
#-------------------------------------------------
# either build or link against the included
# libraries
#-------------------------------------------------
# start with an empty set of libs
LIBS =
# add expat XML library
ifdef BUILD_EXPAT
CCOMFLAGS += -I$(SRC)/lib/expat
EXPAT = $(OBJ)/libexpat.a
else
LIBS += -lexpat
EXPAT =
endif
# add ZLIB compression library
ifdef BUILD_ZLIB
CCOMFLAGS += -I$(SRC)/lib/zlib
ZLIB = $(OBJ)/libz.a
else
LIBS += -lz
ZLIB =
endif
#---------------------------------------------------------------------------------
# build a list of include paths
#---------------------------------------------------------------------------------
INCLUDE := $(foreach dir,$(PORTLIBS),-I$(dir)/include) \
-I$(LIBOGC_INC)
#---------------------------------------------------------------------------------
# build a list of library paths
#---------------------------------------------------------------------------------
LIBPATHS := $(foreach dir,$(PORTLIBS),-L$(dir)/lib) \
-L$(LIBOGC_LIB)
#LIBS += -ldb -lfat -logc -lwiiuse -lbte -lasnd -lwiikeyboard -lm
LIBS += -lfat -lwiiuse -lbte -lasnd -logc -lm $(LIBPATHS)
CFLAGS += -I$(INCLUDE) -D__WII__
#-------------------------------------------------
# 'all' target needs to go here, before the
# include files which define additional targets
#-------------------------------------------------
all: maketree buildtools emulator
#-------------------------------------------------
# defines needed by multiple make files
#-------------------------------------------------
BUILDSRC = $(SRC)/build
BUILDOBJ = $(OBJ)/build
BUILDOUT = $(BUILDOBJ)
#-------------------------------------------------
# include the various .mak files
#-------------------------------------------------
# include OSD-specific rules first
include $(SRC)/osd/$(OSD)/$(OSD).mak
# then the various core pieces
include $(SRC)/$(TARGET)/$(SUBTARGET).mak
include $(SRC)/emu/emu.mak
include $(SRC)/lib/lib.mak
include $(SRC)/build/build.mak
-include $(SRC)/osd/$(CROSS_BUILD_OSD)/build.mak
# combine the various definitions to one
CDEFS = $(DEFS) $(COREDEFS) $(SOUNDDEFS)
#-------------------------------------------------
# primary targets
#-------------------------------------------------
emulator: maketree $(BUILD) $(EMULATORDOL)
buildtools: maketree $(BUILD)
maketree: $(sort $(OBJDIRS))
clean: $(OSDCLEAN)
@echo Deleting object tree $(OBJ)...
$(RM) -r $(OBJ)
@echo Deleting $(EMULATOR)...
$(RM) $(EMULATOR)
@echo Deleting $(EMULATORDOL)...
$(RM) $(EMULATORDOL)
@echo Deleting $(TOOLS)...
$(RM) $(TOOLS)
ifdef MAP
@echo Deleting $(FULLNAME).map...
$(RM) $(FULLNAME).map
endif
#-------------------------------------------------
# directory targets
#-------------------------------------------------
$(sort $(OBJDIRS)):
$(MD) -p $@
$(OBJ)/build/file2str$(CCEXE):
mkdir -p $(OBJ)/build
cp -t $(OBJ)/build prec-build/file2str$(CCEXE)
$(OBJ)/build/m68kmake$(CCEXE):
cp -t $(OBJ)/build prec-build/m68kmake$(CCEXE)
$(OBJ)/build/png2bdc$(CCEXE):
cp -t $(OBJ)/build prec-build/png2bdc$(CCEXE)
$(OBJ)/build/tmsmake$(CCEXE):
cp -t $(OBJ)/build prec-build/tmsmake$(CCEXE)
$(OBJ)/build/verinfo$(CCEXE):
cp -t $(OBJ)/build prec-build/verinfo$(CCEXE)
#-------------------------------------------------
# executable targets and dependencies
#-------------------------------------------------
ifndef EXECUTABLE_DEFINED
# always recompile the version string
$(VERSIONOBJ): $(DRVLIBS) $(LIBOSD) $(LIBEMU) $(LIBCPU) $(LIBSOUND) $(LIBUTIL) $(EXPAT) $(ZLIB) $(LIBOCORE) $(RESFILE)
$(EMULATOR): $(VERSIONOBJ) $(DRVLIBS) $(LIBOSD) $(LIBEMU) $(LIBCPU) $(LIBDASM) $(LIBSOUND) $(LIBUTIL) $(EXPAT) $(ZLIB) $(LIBOCORE) $(RESFILE)
@echo Linking $@...
# TODO: Figure out the correct order to put the libraries so I don't have to include them twice
$(LD) $(LDFLAGS) $(LDFLAGSEMULATOR) $(LIBS) $^ $(LIBS) -o $@
$(EMULATORDOL): $(EMULATOR)
@echo Making $@...
@elf2dol $^ $@
endif
#-------------------------------------------------
# generic rules
#-------------------------------------------------
$(OBJ)/%.o: $(SRC)/%.c | $(OSPREBUILD)
@echo Compiling $<...
$(CC) $(CDEFS) $(CFLAGS) -c $< -o $@
$(OBJ)/%.pp: $(SRC)/%.c | $(OSPREBUILD)
@echo Compiling $<...
$(CC) $(CDEFS) $(CFLAGS) -E $< -o $@
$(OBJ)/%.s: $(SRC)/%.c | $(OSPREBUILD)
@echo Compiling $<...
$(CC) $(CDEFS) $(CFLAGS) -S $< -o $@
$(OBJ)/%.lh: $(SRC)/%.lay $(FILE2STR)
@echo Converting $<...
@$(FILE2STR) $< $@ layout_$(basename $(notdir $<))
$(OBJ)/%.fh: $(SRC)/%.png $(PNG2BDC) $(FILE2STR)
@echo Converting $<...
@$(PNG2BDC) $< $(OBJ)/temp.bdc
@$(FILE2STR) $(OBJ)/temp.bdc $@ font_$(basename $(notdir $<)) UINT8
$(OBJ)/%.a:
@echo Archiving $@...
$(RM) $@
$(AR) -cr $@ $^
ifeq ($(TARGETOS),macosx)
$(OBJ)/%.o: $(SRC)/%.m | $(OSPREBUILD)
@echo Objective-C compiling $<...
$(CC) $(CDEFS) $(CFLAGS) -c $< -o $@
endif