This repository has been archived by the owner on Sep 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
/
msys2_setup_ocemu.sh
199 lines (199 loc) · 5.83 KB
/
msys2_setup_ocemu.sh
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
#!/bin/bash
if [ "$MSYSTEM" = "MSYS" ]; then
echo This script does not work in a 'MSYS2 Shell', use a 'MinGW-w64 Win Shell'
exit 1
fi
case ${PWD} in *\ * ) echo "Your path has spaces in it which may prevent this script from building correctly."; read -p "Press [Enter] key to continue." ;; esac
case "$MSYSTEM" in
MINGW32) MACHINE_TYPE="i686"
;;
MINGW64) MACHINE_TYPE="x86_64"
;;
*) echo "Unknown environment: $MSYSTEM"
exit 1
;;
esac
echo "Building OCEmu dependencies for $MACHINE_TYPE"
pacman --needed --noconfirm -S mingw-w64-${MACHINE_TYPE}-toolchain winpty patch make git subversion mingw-w64-${MACHINE_TYPE}-SDL2
mkdir mingw-w64-lua
cd mingw-w64-lua
curl -L https://github.com/Alexpux/MINGW-packages/raw/541d0da31a4d2e648689655e49ddfffbe7ff5dfe/mingw-w64-lua/PKGBUILD -o PKGBUILD
curl -L https://github.com/Alexpux/MINGW-packages/raw/541d0da31a4d2e648689655e49ddfffbe7ff5dfe/mingw-w64-lua/implib.patch -o implib.patch
curl -L https://github.com/Alexpux/MINGW-packages/raw/541d0da31a4d2e648689655e49ddfffbe7ff5dfe/mingw-w64-lua/lua.pc -o lua.pc
curl -L https://github.com/Alexpux/MINGW-packages/raw/541d0da31a4d2e648689655e49ddfffbe7ff5dfe/mingw-w64-lua/searchpath.patch -o searchpath.patch
makepkg-mingw
if [ ! -e mingw-w64-${MACHINE_TYPE}-lua-5.2.4-1-any.pkg.tar.xz ]; then
echo "Failed to build lua"
exit 1
fi
pacman --noconfirm -U mingw-w64-${MACHINE_TYPE}-lua-5.2.4-1-any.pkg.tar.xz
cd ..
rm -r mingw-w64-lua
if [ -e src/extras ]; then
read -p "src/extras already exists, remove? [y/N] " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]] || [ -z $REPLY ]; then
echo "Not removing existing folder."
exit 1
fi
rm -r src/extras
fi
mkdir src/extras
if [ ! -e src/extras ]; then
echo "Failed to create src/extras folder"
exit 1
fi
cd src/extras
git clone -b v_1_6_3 --depth=1 https://github.com/keplerproject/luafilesystem.git
if [ ! -e luafilesystem ]; then
echo "Failed to download luafilesystem"
exit 1
fi
cd luafilesystem
cat << 'EOF' > lfs_mingw.patch
--- Makefile-old 2015-06-27 10:27:22.594787200 -0600
+++ Makefile 2015-06-27 10:27:32.306801800 -0600
@@ -12 +12 @@
-lib: src/lfs.so
+lib: src/lfs.dll
@@ -14,2 +14,2 @@
-src/lfs.so: $(OBJS)
- MACOSX_DEPLOYMENT_TARGET="10.3"; export MACOSX_DEPLOYMENT_TARGET; $(CC) $(CFLAGS) $(LIB_OPTION) -o src/lfs.so $(OBJS)
+src/lfs.dll: $(OBJS)
+ MACOSX_DEPLOYMENT_TARGET="10.3"; export MACOSX_DEPLOYMENT_TARGET; $(CC) $(CFLAGS) $(LIB_OPTION) -o src/lfs.dll $(OBJS) -llua
@@ -18 +18 @@
- LUA_CPATH=./src/?.so lua tests/test.lua
+ LUA_CPATH=./src/?.dll lua tests/test.lua
@@ -22 +22 @@
- cp src/lfs.so $(LUA_LIBDIR)
+ cp src/lfs.dll $(LUA_LIBDIR)
@@ -25 +25 @@
- rm -f src/lfs.so $(OBJS)
+ rm -f src/lfs.dll $(OBJS)
EOF
patch < lfs_mingw.patch
make
if [ ! -e src/lfs.dll ]; then
echo "Failed to build luafilesystem"
exit 1
fi
mv src/lfs.dll ..
cd ..
rm -r luafilesystem
git clone -b 0.1.1 --depth=1 https://github.com/starwing/luautf8.git
if [ ! -e luautf8 ]; then
echo "Failed to download luautf8"
exit 1
fi
cd luautf8
gcc -O2 -c -o lutf8lib.o lutf8lib.c
gcc -O -shared -o lua-utf8.dll lutf8lib.o -llua
if [ ! -e lua-utf8.dll ]; then
echo "Failed to build luautf8"
exit 1
fi
mv lua-utf8.dll ..
cd ..
rm -r luautf8
git clone --depth=1 https://github.com/gamax92/luaffifb.git
if [ ! -e luaffifb ]; then
echo "Failed to download luaffifb"
exit 1
fi
cd luaffifb
cat << 'EOF' > luaffifb_mingw.patch
--- Makefile-old 2015-06-27 10:41:00.288971000 -0600
+++ Makefile.mingw 2015-06-27 10:41:18.062998000 -0600
@@ -6,2 +6,3 @@
-LUA_CFLAGS=`$(PKG_CONFIG) --cflags lua5.2 2>/dev/null || $(PKG_CONFIG) --cflags lua`
-SOCFLAGS=`$(PKG_CONFIG) --libs lua5.2 2>/dev/null || $(PKG_CONFIG) --libs lua`
+LUA_CFLAGS=
+SOCFLAGS=-llua
+CC=gcc
EOF
patch < luaffifb_mingw.patch
make -f Makefile.mingw ffi.dll
if [ ! -e ffi.dll ]; then
echo "Failed to build luaffifb"
exit 1
fi
mv ffi.dll ..
cd ..
rm -r luaffifb
git clone -b v3.0-rc1 --depth=1 https://github.com/diegonehab/luasocket.git
if [ ! -e luasocket ]; then
echo "Failed to download luasocket"
exit 1
fi
cd luasocket
LUALIB_mingw=-llua LUAV=5.2 make mingw
if [ ! -e src/mime.dll.1.0.3 ]; then
echo "Failed to build luasocket"
exit 1
fi
prefix=../.. PLAT=mingw CDIR_mingw= LDIR_mingw= make install
cd ..
rm -r luasocket
git clone -b luasec-0.5 --depth=1 https://github.com/brunoos/luasec.git
if [ ! -e luasec ]; then
echo "Failed to download luasec"
exit 1
fi
cd luasec
cat << 'EOF' > luasec_mingw.patch
--- src/luasocket/Makefile-old 2015-06-27 11:28:34.279159900 -0600
+++ src/luasocket/Makefile 2015-06-27 11:31:17.381422000 -0600
@@ -5 +5 @@
- usocket.o
+ wsocket.o
@@ -26 +26 @@
-usocket.o: usocket.c socket.h io.h timeout.h usocket.h
+wsocket.o: wsocket.c socket.h io.h timeout.h wsocket.h
--- src/Makefile-old 2015-06-27 11:54:34.670465000 -0600
+++ src/Makefile 2015-06-27 11:54:42.310475600 -0600
@@ -1 +1 @@
-CMOD=ssl.so
+CMOD=ssl.dll
@@ -53 +53 @@
- $(LD) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
+ $(LD) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) -llua -lws2_32
EOF
patch -p0 < luasec_mingw.patch
INC_PATH= LD=gcc CC=gcc make linux
if [ ! -e src/ssl.dll ]; then
echo "Failed to build luasec"
exit 1
fi
DESTDIR=../.. LUAPATH= LUACPATH= make install
cd ..
rm -r luasec
cd ..
echo "Built dependencies!"
gcc -s -o OCEmu.exe winstub.c -Wl,--subsystem,windows -mwindows -llua
case "$MACHINE_TYPE" in
i686)
cp /mingw32/bin/lua52.dll .
cp /mingw32/bin/libgcc_s_dw2-1.dll .
cp /mingw32/bin/libwinpthread-1.dll .
cp /mingw32/bin/libeay32.dll .
cp /mingw32/bin/ssleay32.dll .
cp /mingw32/bin/SDL2.dll .
;;
x86_64)
cp /mingw64/bin/lua52.dll .
cp /mingw64/bin/libgcc_s_seh-1.dll .
cp /mingw64/bin/libwinpthread-1.dll .
cp /mingw64/bin/libeay32.dll .
cp /mingw64/bin/ssleay32.dll .
cp /mingw64/bin/SDL2.dll .
;;
esac
strip -s OCEmu.exe *.dll extras/*.dll extras/*/core.dll
date '+%Y%m%d%H%M%S' > builddate.txt
cd ..
echo "Built everything!"
read -p "Download required resources? [Y/n] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]] || [ -z $REPLY ]; then
make all
fi