summaryrefslogtreecommitdiffstatshomepage
path: root/scripts/genie.lua
blob: 34654a817f574848567947f26ffba17889a1bd41 (plain) (blame)
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
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
premake.check_paths = true
premake.make.override = { "TARGET" }
MAME_DIR = (path.getabsolute("..") .. "/")
local MAME_BUILD_DIR = (MAME_DIR .. ".build/")
local naclToolchain = ""


function includeosd()
	includedirs {
		MAME_DIR .. "src/osd",
	}
	if _OPTIONS["osd"]=="windows" then
		includedirs {
			MAME_DIR .. "src/osd/windows",
		}
	else
		includedirs {
			MAME_DIR .. "src/osd/sdl",
		}
	end
end

function str_to_version (str)
	local val = 0
	if (str == nil or str == '') then
		return val
	end
	local cnt = 10000
	for word in string.gmatch(str, '([^.]+)') do
		val = val + tonumber(word) * cnt
		cnt = cnt / 100
	end
    return val
end

CPUS = {}
SOUNDS  = {}
MACHINES  = {}
VIDEOS = {}
BUSES  = {}

newoption {
	trigger = "with-tools",
	description = "Enable building tools.",
} 

newoption {
	trigger = "osd",
	description = "Choose target OSD",
	allowed = {
		{ "osdmini",   "mini dummy OSD"         },
		{ "sdl",       "SDL"			        },
		{ "windows",   "Windows"                },
	},
}

newoption {
	trigger = "targetos",
	description = "Choose target OS",
	allowed = {
		{ "android",   "Android"          		},
		{ "asmjs",     "Emscripten/asm.js"      },
		{ "freebsd",   "FreeBSD"                },
		{ "linux",     "Linux"   				},
		{ "ios",       "iOS"              		},
		{ "nacl",      "Native Client"          },
		{ "macosx",    "OSX"                    },
		{ "windows",   "Windows"                },
	},
}

newoption {
	trigger = "target",
	description = "Building target",
}

newoption {
	trigger = "subtarget",
	description = "Building subtarget",
}

newoption {
	trigger = "gcc_version",
	description = "GCC compiler version",
}

newoption {
	trigger = "os_version",
	description = "OS version",
	value = "",
}

local os_version = str_to_version(_OPTIONS["os_version"])
USE_BGFX = 1
if (_OPTIONS["targetos"]=="macosx" and  os_version < 100700) then
	USE_BGFX = 0
end
GEN_DIR = MAME_BUILD_DIR .. "generated/"

if (_OPTIONS["target"] == _OPTIONS["subtarget"]) then
	solution (_OPTIONS["target"])
else
	solution (_OPTIONS["target"] .. _OPTIONS["subtarget"])
end	
	configurations {
		"Debug",
		"Release",
	}

	platforms {
		"x32",
		"x64",
		"Native", -- for targets where bitness is not specified
	}

	language "C++"

	flags {
		"StaticRuntime",
		"Unicode",
		"NoPCH",
	}
	
	configuration { "vs*" }
	flags {
		"ExtraWarnings",
		"FatalWarnings",
	}

	configuration {}
	
msgcompile ("Compiling $(subst ../../../,,$<)...")

msgcompile_objc ("Objective-C compiling $(subst ../../../,,$<)...")

msgresource ("Compiling resources $(subst ../../../,,$<)...")

msglinking ("Linking $(notdir $@)...")

msgarchiving ("Archiving $(notdir $@)...")

messageskip { "SkipCreatingMessage", "SkipBuildingMessage", "SkipCleaningMessage" }

if (not os.isfile(path.join("target", _OPTIONS["target"],_OPTIONS["subtarget"] .. ".lua"))) then
	error("File definition for TARGET=" .. _OPTIONS["target"] .. " SUBTARGET=" .. _OPTIONS["subtarget"] .. " does not exist")
end
dofile (path.join("target", _OPTIONS["target"],_OPTIONS["subtarget"] .. ".lua"))
	
configuration { "gmake" }
	flags {
		"SingleOutputDir",
	}

configuration { "x64", "Release" }
	targetsuffix "64"

configuration { "x64", "Debug" }
	targetsuffix "64d"

configuration { "x32", "Release" }
	targetsuffix ""

configuration { "x32", "Debug" }
	targetsuffix "d"

configuration { "Native", "Release" }
	targetsuffix ""

configuration { "Native", "Debug" }
	targetsuffix "d"

configuration { }

dofile ("toolchain.lua")


if _OPTIONS["osd"]=="windows" then
	forcedincludes {
		MAME_DIR .. "src/osd/windows/winprefix.h"
	}
elseif _OPTIONS["osd"]=="sdl" then
	forcedincludes {
		MAME_DIR .. "src/osd/sdl/sdlprefix.h"
	}
end

-- Avoid error when invoking genie --help.
if (_ACTION == nil) then return false end

-- define PTR64 if we are a 64-bit target
configuration { "x64" }
	defines { "PTR64=1" }

-- map the INLINE to something digestible by GCC
configuration { "gmake" }
	buildoptions_cpp {
		"-DINLINE=\"static inline\"",
	}
	buildoptions_objc {
		"-DINLINE=\"static inline\"",
	}
configuration { "vs*" }
	defines {
		"INLINE=static inline",
	}

-- define MAME_DEBUG if we are a debugging build
configuration { "Debug" }
	defines {
		"MAME_DEBUG",
		"MAME_PROFILER", -- define MAME_PROFILER if we are a profiling build
	}
configuration { "Release" }
	defines {
		"NDEBUG",
	}

configuration { }
	-- CR/LF setup: use both on win32/os2, CR only on everything else
	if _OPTIONS["targetos"]=="windows" or _OPTIONS["targetos"]=="os2" then
		defines {
			"CRLF=3",
		}
	else
		defines {
			"CRLF=2",
		}
	end


	-- define LSB_FIRST if we are a little-endian target
	defines {
		"LSB_FIRST",
	}

	-- define USE_NETWORK if networking is enabled (not OS/2 and hasn't been disabled)
	if not _OPTIONS["targetos"]=="os2" then
		defines {
			"USE_NETWORK",
		}
	end
	-- need to ensure FLAC functions are statically linked
	defines {
		"FLAC__NO_DLL",
	}

-- define USE_SYSTEM_JPEGLIB if library shipped with MAME is not used
--ifneq ($(BUILD_JPEGLIB),1)
--DEFS += -DUSE_SYSTEM_JPEGLIB
--endif

--ifdef FASTDEBUG
--DEFS += -DMAME_DEBUG_FAST
--endif

	--To support casting in Lua 5.3
	defines {
		"LUA_COMPAT_APIINTCASTS",
	}

	if _ACTION == "gmake" then

	--we compile C-only to C89 standard with GNU extensions
	buildoptions_c {
		"-std=gnu89",

	}
	--we compile C++ code to C++98 standard with GNU extensions
	buildoptions_cpp {
		"-x c++",
		"-std=gnu++98",
	}

	buildoptions_objc {
		"-x objective-c++",
	}
--ifdef CPP11
--CPPONLYFLAGS += -x c++ -std=gnu++11
--else

-- this speeds it up a bit by piping between the preprocessor/compiler/assembler
	if not ("pnacl" == _OPTIONS["gcc"]) then
		buildoptions {
			"--pipe",
		}
	end
-- add -g if we need symbols, and ensure we have frame pointers
--ifdef SYMBOLS
--CCOMFLAGS += -g$(SYMLEVEL) -fno-omit-frame-pointer -fno-optimize-sibling-calls
--endif

--# we need to disable some additional implicit optimizations for profiling
--ifdef PROFILE
--CCOMFLAGS += -mno-omit-leaf-frame-pointer
--endif

-- add -v if we need verbose build information
--ifdef VERBOSE
--CCOMFLAGS += -v
--endif

-- only show deprecation warnings when enabled
--ifndef DEPRECATED
	buildoptions {
		"-Wno-deprecated-declarations"
	}
--endif

-- add profiling information for the compiler
--ifdef PROFILE
--CCOMFLAGS += -pg
--endif

--# add the optimization flag
	buildoptions {
		"-O3",
		"-fno-strict-aliasing"
	}

	-- add the error warning flag
	--ifndef NOWERROR
	buildoptions {
		"-Werror",
	}


-- if we are optimizing, include optimization options
--ifneq ($(OPTIMIZE),0)
--CCOMFLAGS += -fno-strict-aliasing $(ARCHOPTS)
--ifdef LTO
--CCOMFLAGS += -flto
--endif
--endif

--ifdef SSE2
--CCOMFLAGS += -msse2
--endif

--ifdef OPENMP
--CCOMFLAGS += -fopenmp
--else
--CCOMFLAGS += -Wno-unknown-pragmas
--endif
	buildoptions {
		"-Wno-unknown-pragmas",
	}
-- add a basic set of warnings
	buildoptions {
		"-Wall",
		"-Wcast-align",
		"-Wundef",
		"-Wformat-security",
		"-Wwrite-strings",
		"-Wno-sign-compare",
		"-Wno-conversion",
	}
-- warnings only applicable to C compiles
	buildoptions_c {
		"-Wpointer-arith",
		"-Wbad-function-cast",
		"-Wstrict-prototypes",
	}

-- warnings only applicable to OBJ-C compiles
	buildoptions_objc {
		"-Wpointer-arith",
	}

-- warnings only applicable to C++ compiles
	buildoptions_cpp {
		"-Woverloaded-virtual",
	}

--ifdef SANITIZE
--CCOMFLAGS += -fsanitize=$(SANITIZE)

--ifneq (,$(findstring thread,$(SANITIZE)))
--CCOMFLAGS += -fPIE
--endif
--endif


		
		local version = str_to_version(_OPTIONS["gcc_version"])
		if string.find(_OPTIONS["gcc"], "clang") then
			buildoptions {
				"-Wno-cast-align",
				"-Wno-tautological-compare",
				"-Wno-dynamic-class-memaccess",
				"-Wno-self-assign-field",
			}
			
			if (version >= 30400) then
				buildoptions {
					"-Wno-inline-new-delete",
					"-Wno-constant-logical-operand",
				}
			end
			if (version >= 30500) then
				buildoptions {
					"-Wno-absolute-value",
					"-Wno-unknown-warning-option",
					"-Wno-extern-c-compat",
				}
			end
		else
			if (version >= 40700) then
				buildoptions {
					"-Wno-narrowing",
					"-Wno-attributes"
				}
			end
			if (version >= 40800) then
				-- array bounds checking seems to be buggy in 4.8.1 (try it on video/stvvdp1.c and video/model1.c without -Wno-array-bounds)
				buildoptions {
					"-Wno-unused-variable",
					"-Wno-array-bounds"
				}
			end
		end
	end
--ifeq ($(findstring arm,$(UNAME)),arm)
--	CCOMFLAGS += -Wno-cast-align
--endif

if not toolchain(MAME_BUILD_DIR) then
	return -- no action specified
end
	
configuration { "asmjs" }
	buildoptions {
		"-std=gnu89",
		"-Wno-implicit-function-declaration",
	}
	buildoptions_cpp {
		"-x c++",
		"-std=gnu++98",
	}
	archivesplit_size "20"

configuration { "android*" }
	buildoptions_cpp {
		"-x c++",
		"-std=gnu++98",
	}
	archivesplit_size "20"

configuration { "pnacl" }
	buildoptions {
		"-std=gnu89",
		"-Wno-inline-new-delete",
	}
	buildoptions_cpp {
		"-x c++",
		"-std=gnu++98",
	}
	archivesplit_size "20"

configuration { "nacl*" }
	buildoptions_cpp {
		"-x c++",
		"-std=gnu++98",
	}
	archivesplit_size "20"

configuration { "linux-*" }
		linkoptions {
			"-Wl,--gc-sections",
			"`sdl2-config --libs`",
		}
		links {
			"pthread",
			"SDL2",
			"SDL2_ttf",
			"asound",
			"dl",
			"fontconfig",
			"freetype",
			"GL",
			"m",
			"util",
			"X11",
			"Xinerama",
		}

configuration { "osx*" }

		links {
			"Cocoa.framework",
			"OpenGL.framework",
			"CoreAudio.framework",
			"CoreMIDI.framework",
			"SDL2.framework",
			"pthread",
		}


configuration { "mingw*" }
		defines {
			"main=utf8_main",
		}
		linkoptions {
			"-Wl,--gc-sections",
			"-static-libgcc",
			"-static-libstdc++",
			"-municode",
		}
		if _OPTIONS["osd"]=="sdl" then
			linkoptions {
				"-Wl,--allow-multiple-definition",
				"-static"
			}
			links {
				"opengl32",
				"SDL2",
				"Imm32",
				"version",
				"ole32",
				"oleaut32",
			}
		end
		links {
			"user32",
			"gdi32",
			"dsound",
			"dxguid",
			"winmm",
			"advapi32",
			"comctl32",
			"shlwapi",
			"wsock32",
			"dinput8",
			"comdlg32",
		}

configuration { "vs*" }
		defines {
			"main=utf8_main",
		}
		defines {
			"XML_STATIC",
			"WIN32",
			"_WIN32",
			"_CRT_NONSTDC_NO_DEPRECATE",
			"_CRT_SECURE_NO_DEPRECATE",
		}
		links {
			"user32",
			"gdi32",
			"dsound",
			"dxguid",
			"winmm",
			"advapi32",
			"comctl32",
			"shlwapi",
			"wsock32",
			"dinput8",
			"comdlg32",
		}

		buildoptions {
			"/wd4025",
			"/wd4003",
			"/wd4018",
			"/wd4061",
			"/wd4100",
			"/wd4127",
			"/wd4131",
			"/wd4141",
			"/wd4146",
			"/wd4150",
			"/wd4189",
			"/wd4191",
			"/wd4201",
			"/wd4232",
			"/wd4242",
			"/wd4244",
			"/wd4250",
			"/wd4255",
			"/wd4296",
			"/wd4306",
			"/wd4310",
			"/wd4312",
			"/wd4324",
			"/wd4347",
			"/wd4435",
			"/wd4510",
			"/wd4512",
			"/wd4514",
			"/wd4571",
			"/wd4610",
			"/wd4611",
			"/wd4619",
			"/wd4625",
			"/wd4626",
			"/wd4640",
			"/wd4668",
			"/wd4702",
			"/wd4706",
			"/wd4710",
			"/wd4711",
			"/wd4805",
			"/wd4820",
			"/wd4826",
			"/wd4365",
			"/wd4389",
			"/wd4245",
			"/wd4388",
			"/wd4267",
			"/wd4005",
			"/wd4350",
			"/wd4996",
			"/wd4191",
			"/wd4060",
			"/wd4065",
			"/wd4640",
			"/wd4290",
			"/wd4355",
			"/wd4800",
			"/wd4371",
			"/wd4548",
		}
		linkoptions {
			"/ignore:4221", -- LNK4221: This object file does not define any previously undefined public symbols, so it will not be used by any link operation that consumes this library
		}
		includedirs {
			MAME_DIR .. "3rdparty/dxsdk/Include"
		}

configuration { "x32", "vs*" }
		libdirs {
			MAME_DIR .. "3rdparty/dxsdk/lib/x86",
		}

configuration { "x64", "vs*" }
		libdirs {
			MAME_DIR .. "3rdparty/dxsdk/lib/x64",
		}

configuration { }

group "libs"
dofile(path.join("src", "3rdparty.lua"))
dofile(path.join("src", "lib.lua"))

group "core"

dofile(path.join("src", "osd.lua"))
dofile(path.join("src", "emu.lua"))
emuProject(_OPTIONS["target"],_OPTIONS["subtarget"])

group "drivers"
createProjects(_OPTIONS["target"],_OPTIONS["subtarget"])
group "emulator"
dofile(path.join("src", "main.lua"))
if (_OPTIONS["target"] == _OPTIONS["subtarget"]) then
	startproject (_OPTIONS["target"])
else
	startproject (_OPTIONS["target"] .. _OPTIONS["subtarget"])
end	
mainProject(_OPTIONS["target"],_OPTIONS["subtarget"])

if _OPTIONS["with-tools"] then
	group "tools"
	dofile(path.join("src", "tools.lua"))
end

if (_ACTION == "gmake" and _OPTIONS["gcc"]=='asmjs') then 
	strip()
end