-
Notifications
You must be signed in to change notification settings - Fork 3
/
build-unix.janet
131 lines (119 loc) · 3.58 KB
/
build-unix.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
(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 source emsdk_env.sh?")
(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 ["make" "clean"] :px)
([e]
(eprintf "<<problem with make clean for janet>>")
(os/exit 1)))
(try
(os/execute ["make"] :px)
([e]
(eprintf "<<problem making 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 directory>>")
(os/exit 1)))
(try
(os/execute ["make" "clean"] :px)
([e]
(eprintf "<<problem with make clean for raylib>>")
(os/exit 1)))
(try
(os/execute ["make"
# XXX: causing emcc to fail at last step?
#"CFLAGS=-gsource-map"
"PLATFORM=PLATFORM_WEB" "-B" "-e"] :px)
([e]
(eprintf "<<problem building libjaylib.a>>")
(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"
#"-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"
"-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))