summaryrefslogtreecommitdiffstats
path: root/docs/release/scripts/src/osd/sdl_cfg.lua
blob: 26850d4ec85b263f1300a7b5e73bc85188d9e856 (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
-- license:BSD-3-Clause
-- copyright-holders:MAMEdev Team

dofile('modules.lua')

forcedincludes {
	MAME_DIR .. "src/osd/sdl/sdlprefix.h"
}

if _OPTIONS["USE_TAPTUN"]=="1" or _OPTIONS["USE_PCAP"]=="1" then
	defines {
		"USE_NETWORK",
	}
	if _OPTIONS["USE_TAPTUN"]=="1" then
		defines {
			"OSD_NET_USE_TAPTUN",
		}
	end
	if _OPTIONS["USE_PCAP"]=="1" then
		defines {
			"OSD_NET_USE_PCAP",
		}
	end
end

if _OPTIONS["NO_OPENGL"]~="1" and _OPTIONS["USE_DISPATCH_GL"]~="1" and _OPTIONS["MESA_INSTALL_ROOT"] then
	includedirs {
		path.join(_OPTIONS["MESA_INSTALL_ROOT"],"include"),
	}
end

if _OPTIONS["SDL_INI_PATH"]~=nil then
	defines {
		"'INI_PATH=\"" .. _OPTIONS["SDL_INI_PATH"] .. "\"'",
	}
end

if _OPTIONS["NO_X11"]=="1" then
	defines {
		"SDLMAME_NO_X11",
	}
else
	defines {
		"SDLMAME_X11",
	}
	includedirs {
		"/usr/X11/include",
		"/usr/X11R6/include",
		"/usr/openwin/include",
	}
end

if _OPTIONS["NO_USE_XINPUT"]=="1" then
	defines {
		"USE_XINPUT=0",
	}
else
	defines {
		"USE_XINPUT=1",
		"USE_XINPUT_DEBUG=0",
	}
end

if _OPTIONS["NO_USE_XINPUT_WII_LIGHTGUN_HACK"]=="1" then
	defines {
		"USE_XINPUT_WII_LIGHTGUN_HACK=0",
	}
else
	defines {
		"USE_XINPUT_WII_LIGHTGUN_HACK=1",
	}
end

if _OPTIONS["NO_USE_MIDI"]~="1" and _OPTIONS["targetos"]=="linux" then
	buildoptions {
		backtick(pkgconfigcmd() .. " --cflags alsa"),
	}
end

defines {
	"SDLMAME_SDL2=1",
}
if _OPTIONS["SDL2_MULTIAPI"]=="1" then
	defines {
		"SDL2_MULTIAPI",
	}
end

defines {
	"OSD_SDL",
}

if BASE_TARGETOS=="unix" then
	defines {
		"SDLMAME_UNIX",
	}
	if _OPTIONS["targetos"]=="macosx" then
		if _OPTIONS["with-bundled-sdl2"]==nil then
			if _OPTIONS["USE_LIBSDL"]~="1" then
				buildoptions {
					"-F" .. _OPTIONS["SDL_FRAMEWORK_PATH"],
				}
			else
				defines {
					"MACOSX_USE_LIBSDL",
				}
				buildoptions {
					backtick(sdlconfigcmd() .. " --cflags | sed 's:/SDL2::'"),
				}
			end
		end
	else
		buildoptions {
			backtick(sdlconfigcmd() .. " --cflags"),
		}
		if _OPTIONS["targetos"]~="asmjs" then
			buildoptions {
				backtick(pkgconfigcmd() .. " --cflags fontconfig"),
			}
		end
	end
end

if _OPTIONS["targetos"]=="windows" then
	configuration { "mingw* or vs*" }
		defines {
			"UNICODE",
			"_UNICODE",
			"_WIN32_WINNT=0x0501",
			"WIN32_LEAN_AND_MEAN",
			"NOMINMAX",
		}

	configuration { }

elseif _OPTIONS["targetos"]=="linux" then
	if _OPTIONS["QT_HOME"]~=nil then
		buildoptions {
			"-I" .. backtick(_OPTIONS["QT_HOME"] .. "/bin/qmake -query QT_INSTALL_HEADERS"),
		}
	else
		buildoptions {
			backtick(pkgconfigcmd() .. " --cflags Qt5Widgets"),
		}
	end
elseif _OPTIONS["targetos"]=="macosx" then
	defines {
		"SDLMAME_MACOSX",
		"SDLMAME_DARWIN",
	}
elseif _OPTIONS["targetos"]=="freebsd" then
	buildoptions {
		-- /usr/local/include is not considered a system include director on FreeBSD.  GL.h resides there and throws warnings
		"-isystem /usr/local/include",
	}
end

configuration { "osx*" }
	includedirs {
		MAME_DIR .. "3rdparty/bx/include/compat/osx",
	}

configuration { "freebsd" }
	includedirs {
		MAME_DIR .. "3rdparty/bx/include/compat/freebsd",
	}

configuration { "netbsd" }
	includedirs {
		MAME_DIR .. "3rdparty/bx/include/compat/freebsd",
	}

configuration { }
span> (auxlen > count) return -1; // we now know how long the char is, now compute it for (i = 0; i < auxlen; i++) { auxchar = utf8char[i]; // all auxillary chars must be between 0x80-0xbf if ((auxchar & 0xc0) != 0x80) return -1; c = c << 6; c |= auxchar & 0x3f; } // make sure that this char is above the minimum if (c < minchar) return -1; *uchar = c; return auxlen + 1; } //------------------------------------------------- // uchar_from_utf16 - convert a UTF-16 sequence // into a unicode character //------------------------------------------------- int uchar_from_utf16(unicode_char *uchar, const utf16_char *utf16char, size_t count) { int rc = -1; // validate parameters if (utf16char == nullptr || count == 0) return 0; // handle the two-byte case if (utf16char[0] >= 0xd800 && utf16char[0] <= 0xdbff) { if (count > 1 && utf16char[1] >= 0xdc00 && utf16char[1] <= 0xdfff) { *uchar = 0x10000 + ((utf16char[0] & 0x3ff) * 0x400) + (utf16char[1] & 0x3ff); rc = 2; } } // handle the one-byte case else if (utf16char[0] < 0xdc00 || utf16char[0] > 0xdfff) { *uchar = utf16char[0]; rc = 1; } return rc; } //------------------------------------------------- // uchar_from_utf16f - convert a UTF-16 sequence // into a unicode character from a flipped // byte order //------------------------------------------------- int uchar_from_utf16f(unicode_char *uchar, const utf16_char *utf16char, size_t count) { utf16_char buf[2] = {0}; if (count > 0) buf[0] = FLIPENDIAN_INT16(utf16char[0]); if (count > 1) buf[1] = FLIPENDIAN_INT16(utf16char[1]); return uchar_from_utf16(uchar, buf, count); } //------------------------------------------------- // utf8_from_uchar - convert a unicode character // into a UTF-8 sequence //------------------------------------------------- int utf8_from_uchar(char *utf8string, size_t count, unicode_char uchar) { int rc = 0; // error on invalid characters if (!uchar_isvalid(uchar)) return -1; // based on the value, output the appropriate number of bytes if (uchar < 0x80) { // unicode char 0x00000000 - 0x0000007F if (count < 1) return -1; utf8string[rc++] = (char) uchar; } else if (uchar < 0x800) { // unicode char 0x00000080 - 0x000007FF if (count < 2) return -1; utf8string[rc++] = ((char) (uchar >> 6)) | 0xC0; utf8string[rc++] = ((char) ((uchar >> 0) & 0x3F)) | 0x80; } else if (uchar < 0x10000) { // unicode char 0x00000800 - 0x0000FFFF if (count < 3) return -1; utf8string[rc++] = ((char) (uchar >> 12)) | 0xE0; utf8string[rc++] = ((char) ((uchar >> 6) & 0x3F)) | 0x80; utf8string[rc++] = ((char) ((uchar >> 0) & 0x3F)) | 0x80; } else if (uchar < 0x00200000) { // unicode char 0x00010000 - 0x001FFFFF if (count < 4) return -1; utf8string[rc++] = ((char) (uchar >> 18)) | 0xF0; utf8string[rc++] = ((char) ((uchar >> 12) & 0x3F)) | 0x80; utf8string[rc++] = ((char) ((uchar >> 6) & 0x3F)) | 0x80; utf8string[rc++] = ((char) ((uchar >> 0) & 0x3F)) | 0x80; } else if (uchar < 0x04000000) { // unicode char 0x00200000 - 0x03FFFFFF if (count < 5) return -1; utf8string[rc++] = ((char) (uchar >> 24)) | 0xF8; utf8string[rc++] = ((char) ((uchar >> 18) & 0x3F)) | 0x80; utf8string[rc++] = ((char) ((uchar >> 12) & 0x3F)) | 0x80; utf8string[rc++] = ((char) ((uchar >> 6) & 0x3F)) | 0x80; utf8string[rc++] = ((char) ((uchar >> 0) & 0x3F)) | 0x80; } else if (uchar < 0x80000000) { // unicode char 0x04000000 - 0x7FFFFFFF if (count < 6) return -1; utf8string[rc++] = ((char) (uchar >> 30)) | 0xFC; utf8string[rc++] = ((char) ((uchar >> 24) & 0x3F)) | 0x80; utf8string[rc++] = ((char) ((uchar >> 18) & 0x3F)) | 0x80; utf8string[rc++] = ((char) ((uchar >> 12) & 0x3F)) | 0x80; utf8string[rc++] = ((char) ((uchar >> 6) & 0x3F)) | 0x80; utf8string[rc++] = ((char) ((uchar >> 0) & 0x3F)) | 0x80; } else rc = -1; return rc; } //------------------------------------------------- // utf8_from_uchar - convert a unicode character // into a UTF-8 sequence //------------------------------------------------- std::string utf8_from_uchar(unicode_char uchar) { char buffer[UTF8_CHAR_MAX]; auto len = utf8_from_uchar(buffer, ARRAY_LENGTH(buffer), uchar); return std::string(buffer, len); } //------------------------------------------------- // utf16_from_uchar - convert a unicode character // into a UTF-16 sequence //------------------------------------------------- int utf16_from_uchar(utf16_char *utf16string, size_t count, unicode_char uchar) { int rc; // error on invalid characters if (!uchar_isvalid(uchar)) return -1; // single word case if (uchar < 0x10000) { if (count < 1) return -1; utf16string[0] = (utf16_char) uchar; rc = 1; } // double word case else if (uchar < 0x100000) { if (count < 2) return -1; utf16string[0] = ((uchar >> 10) & 0x03ff) | 0xd800; utf16string[1] = ((uchar >> 0) & 0x03ff) | 0xdc00; rc = 2; } else return -1; return rc; } //------------------------------------------------- // utf16_from_uchar - convert a unicode character // into a UTF-16 sequence with flipped endianness //------------------------------------------------- int utf16f_from_uchar(utf16_char *utf16string, size_t count, unicode_char uchar) { int rc; utf16_char buf[2] = { 0, 0 }; rc = utf16_from_uchar(buf, count, uchar); if (rc >= 1) utf16string[0] = FLIPENDIAN_INT16(buf[0]); if (rc >= 2) utf16string[1] = FLIPENDIAN_INT16(buf[1]); return rc; } //------------------------------------------------- // utf8_previous_char - return a pointer to the // previous character in a string //------------------------------------------------- /** * @fn const char *utf8_previous_char(const char *utf8string) * * @brief UTF 8 previous character. * * @param utf8string The UTF 8string. * * @return null if it fails, else a char*. */ const char *utf8_previous_char(const char *utf8string) { while ((*--utf8string & 0xc0) == 0x80) ; return utf8string; } //------------------------------------------------- // utf8_is_valid_string - return true if the // given string is a properly formed sequence of // UTF-8 characters //------------------------------------------------- /** * @fn int utf8_is_valid_string(const char *utf8string) * * @brief UTF 8 is valid string. * * @param utf8string The UTF 8string. * * @return An int. */ bool utf8_is_valid_string(const char *utf8string) { int remaining_length = strlen(utf8string); while (*utf8string != 0) { unicode_char uchar = 0; int charlen; // extract the current character and verify it charlen = uchar_from_utf8(&uchar, utf8string, remaining_length); if (charlen <= 0 || uchar == 0 || !uchar_isvalid(uchar)) return false; // advance utf8string += charlen; remaining_length -= charlen; } return true; }