-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild-windows.janet
151 lines (139 loc) · 4.38 KB
/
build-windows.janet
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
(def out-dir "public")
(def port "8000")
(def preload-dir "resources")
###########################################################################
(def start (os/clock))
(unless (os/getenv "EMSDK")
(eprintf "emsdk environment not detected: try emsdk_env.bat?")
(os/exit 1))
(prinf "\n[ensuring existence of directory: %p]..." out-dir)
(try
(os/mkdir out-dir)
([e]
(eprintf "<<problem with mkdir for: %p>>" out-dir)
(os/exit 1)))
(unless (os/getenv "JAYLIB_WASM_DEMO_SKIP_DEPS")
#
(printf "\n[preparing amalgamated janet.c and related]...")
(let [old-dir (os/cwd)]
(try
(os/cd "janet")
([e]
(eprintf "<<failed to cd to janet directory>>")
(os/exit 1)))
(try
(os/execute ["build_win.bat" "clean"] :px)
([e]
(eprintf "<<problem with cleaning for janet>>")
(os/exit 1)))
(try
(os/execute ["build_win.bat"] :px)
([e]
(eprintf "<<problem building janet>>")
(os/exit 1)))
#
(try
(os/cd old-dir)
([e]
(eprintf "<<problem restoring current directory>>")
(os/exit 1))))
#
(printf "\n[preparing HTML5-aware libraylib.a]...")
(let [old-dir (os/cwd)]
(try
(os/cd "jaylib/raylib/src")
([e]
(eprintf "<<failed to cd to jaylib/raylib/src directory>>")
(os/exit 1)))
(def commands
[["emcc.bat"
"-c" "rcore.c" "-Os" "-Wall" "-gsource-map"
"-DPLATFORM_WEB" "-DGRAPHICS_API_OPENGL_ES2"]
["emcc.bat"
"-c" "rshapes.c" "-Os" "-Wall" "-gsource-map"
"-DPLATFORM_WEB" "-DGRAPHICS_API_OPENGL_ES2"]
["emcc.bat"
"-c" "rtextures.c" "-Os" "-Wall" "-gsource-map"
"-DPLATFORM_WEB" "-DGRAPHICS_API_OPENGL_ES2"]
["emcc.bat"
"-c" "rtext.c" "-Os" "-Wall" "-gsource-map"
"-DPLATFORM_WEB" "-DGRAPHICS_API_OPENGL_ES2"]
["emcc.bat"
"-c" "rmodels.c" "-Os" "-Wall" "-gsource-map"
"-DPLATFORM_WEB" "-DGRAPHICS_API_OPENGL_ES2"]
["emcc.bat"
"-c" "utils.c" "-Os" "-Wall" "-gsource-map" "-DPLATFORM_WEB"]
["emcc.bat"
"-c" "raudio.c" "-Os" "-Wall" "-gsource-map" "-DPLATFORM_WEB"]
["emar.bat"
"rcs" "libraylib.a"
"rcore.o" "rshapes.o" "rtextures.o" "rtext.o" "rmodels.o"
"utils.o" "raudio.o"]])
(each cmd commands
(try
(os/execute cmd :px)
([e]
(eprintf "<<problem building libraylib.a: %p>>" cmd)
(os/exit 1))))
(try
(os/cd old-dir)
([e]
(eprintf "<<problem restoring current directory>>")
(os/exit 1))))
#
(printf "\n[preparing jaylib.janet shim]...")
(try
(os/execute ["janet"
"make-jaylib-janet-shim.janet"
"jaylib/src"
(string preload-dir "/jaylib.janet")] :px)
([e]
(eprintf "<<problem creating jaylib.janet shim>>")
(os/exit 1))))
(printf "\n[copying logo into place]...")
(try
(spit (string out-dir "/jaylib-logo.png")
(slurp "jaylib-logo.png"))
([e]
(eprintf "<<problem copying logo>>"
(os/exit 1))))
(printf "\n[compiling with emcc]...")
(try
(os/execute ["emcc.bat"
#"-v"
"-Wall"
# debugging
"-g3"
#"-gsource-map"
"-DPLATFORM_WEB"
"-o" (string out-dir "/main.html")
"main.c"
"janet/build/c/janet.c"
"jaylib/raylib/src/libraylib.a"
"-Ijanet/build"
"-Ijanet/src/conf"
"-Ijanet/src/include"
"-Ijaylib/src"
"-Ijaylib/raylib/src"
"--preload-file" preload-dir
"--source-map-base" (string "http://localhost:" port "/")
"--shell-file" "shell.html"
# -O0 for dev, -Os for non-ASYNCIFY, -O3 for ASYNCIFY
"-O0"
#"-Os"
#"-O3" "-s" "ASYNCIFY"
"-s" "ASSERTIONS=2"
"-s" "ALLOW_MEMORY_GROWTH=1"
"-s" "FORCE_FILESYSTEM=1"
"-s" "USE_GLFW=3"
"-s" `EXPORTED_RUNTIME_METHODS=['cwrap']`
"-s" "AGGRESSIVE_VARIABLE_ELIMINATION=1"
#"-s" "MINIFY_HTML=0"
]
:px)
([e]
(eprintf "<<problem compiling with emcc>>")
(os/exit 1)))
(print)
(def end (os/clock))
(printf "Completed in %p seconds" (- end start))