add web build
This commit is contained in:
45
Makefile
45
Makefile
@@ -4,8 +4,7 @@
|
|||||||
SEXC ?= sexc
|
SEXC ?= sexc
|
||||||
CC ?= cc
|
CC ?= cc
|
||||||
|
|
||||||
BUILD_DIR := build
|
RAYLIB_LIB := build/libraylib.a
|
||||||
RAYLIB_LIB := $(BUILD_DIR)/libraylib.a
|
|
||||||
|
|
||||||
RAYLIB_PLATFORM ?= PLATFORM_DESKTOP
|
RAYLIB_PLATFORM ?= PLATFORM_DESKTOP
|
||||||
RAYLIB_BUILD_MODE ?= RELEASE
|
RAYLIB_BUILD_MODE ?= RELEASE
|
||||||
@@ -33,23 +32,55 @@ all: catch-phase
|
|||||||
catch-phase: $(OBJECTS) $(RAYLIB_LIB)
|
catch-phase: $(OBJECTS) $(RAYLIB_LIB)
|
||||||
$(CC) $(LDFLAGS) -o $@ $(OBJECTS) $(RAYLIB_LIB) $(RAYLIB_LIBS)
|
$(CC) $(LDFLAGS) -o $@ $(OBJECTS) $(RAYLIB_LIB) $(RAYLIB_LIBS)
|
||||||
|
|
||||||
$(BUILD_DIR):
|
|
||||||
mkdir -p $@
|
|
||||||
|
|
||||||
main.o: main.sex | $(OBJ_DIR)
|
main.o: main.sex | $(OBJ_DIR)
|
||||||
$(SEXC) $< -c -o $@ -- $(CFLAGS) $(INCLUDES)
|
$(SEXC) $< -c -o $@ -- $(CFLAGS) $(INCLUDES)
|
||||||
|
|
||||||
# raylib ------------------------------------------------------------
|
# raylib ------------------------------------------------------------
|
||||||
$(RAYLIB_LIB):
|
$(RAYLIB_LIB):
|
||||||
|
mkdir -p build
|
||||||
$(MAKE) -C $(RAYLIB_SRC) \
|
$(MAKE) -C $(RAYLIB_SRC) \
|
||||||
PLATFORM=$(RAYLIB_PLATFORM) \
|
PLATFORM=$(RAYLIB_PLATFORM) \
|
||||||
RAYLIB_LIBTYPE=STATIC \
|
RAYLIB_LIBTYPE=STATIC \
|
||||||
RAYLIB_BUILD_MODE=$(RAYLIB_BUILD_MODE) \
|
RAYLIB_BUILD_MODE=$(RAYLIB_BUILD_MODE) \
|
||||||
RAYLIB_RELEASE_PATH=$(abspath $(BUILD_DIR))
|
RAYLIB_RELEASE_PATH=$(abspath ./build)
|
||||||
|
|
||||||
|
# web build ---------------------------------------------------------
|
||||||
|
EMCC ?= emcc
|
||||||
|
EMAR ?= emar
|
||||||
|
WEB_SEXC := $(SEXC) --c-compiler=$(EMCC) --no-platform-features --features=emscripten
|
||||||
|
|
||||||
|
EMFLAGS := -O2 -DPLATFORM_WEB \
|
||||||
|
-sUSE_GLFW=3 \
|
||||||
|
-sTOTAL_MEMORY=134217728 \
|
||||||
|
-sFORCE_FILESYSTEM=1 \
|
||||||
|
--shell-file shell.html \
|
||||||
|
--preload-file ./res@/res
|
||||||
|
|
||||||
|
web/libraylib.web.a:
|
||||||
|
mkdir -p web
|
||||||
|
$(MAKE) -C $(RAYLIB_SRC) \
|
||||||
|
PLATFORM=PLATFORM_WEB \
|
||||||
|
RAYLIB_LIBTYPE=STATIC \
|
||||||
|
RAYLIB_BUILD_MODE=RELEASE \
|
||||||
|
GRAPHICS=GRAPHICS_API_OPENGL_ES2 \
|
||||||
|
RAYLIB_RELEASE_PATH=$(abspath ./web)
|
||||||
|
|
||||||
|
web/index.html: main.sex shell.html web/libraylib.web.a
|
||||||
|
$(WEB_SEXC) main.sex -o $@ -- \
|
||||||
|
-I$(RAYLIB_SRC) \
|
||||||
|
./web/libraylib.web.a \
|
||||||
|
$(EMFLAGS)
|
||||||
|
|
||||||
|
web: web/index.html
|
||||||
|
|
||||||
|
serve: web
|
||||||
|
python3 -m http.server -d web 8000
|
||||||
|
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(MAKE) -C $(RAYLIB_SRC) clean
|
$(MAKE) -C $(RAYLIB_SRC) clean
|
||||||
rm -rf $(BUILD_DIR)
|
rm -rf ./build ./web
|
||||||
rm -f catch-phase
|
rm -f catch-phase
|
||||||
|
|
||||||
.PHONY: all clean
|
.PHONY: all clean
|
||||||
|
|||||||
52
main.sex
52
main.sex
@@ -1,7 +1,11 @@
|
|||||||
(include raylib.h)
|
(include raylib.h)
|
||||||
|
|
||||||
(define WIN-WIDTH 1440)
|
#-emscripten (define WIN-WIDTH 1440)
|
||||||
(define WIN-HEIGHT 900)
|
#-emscripten (define WIN-HEIGHT 900)
|
||||||
|
#+emscripten (define WIN-WIDTH 960)
|
||||||
|
#+emscripten (define WIN-HEIGHT 600)
|
||||||
|
|
||||||
|
(var error i32 0)
|
||||||
|
|
||||||
(defmacro (call-and-check test msg code fn . args)
|
(defmacro (call-and-check test msg code fn . args)
|
||||||
`(do
|
`(do
|
||||||
@@ -9,19 +13,47 @@
|
|||||||
(if (! (,test))
|
(if (! (,test))
|
||||||
(do
|
(do
|
||||||
(TraceLog LOG-ERROR ,msg)
|
(TraceLog LOG-ERROR ,msg)
|
||||||
(return ,code)))))
|
(= error ,code)
|
||||||
|
(return)))))
|
||||||
|
|
||||||
(pub fn main ((argc int) (argv [* const char])) int
|
(fn update () void
|
||||||
|
(BeginDrawing)
|
||||||
|
(ClearBackground BLACK)
|
||||||
|
(DrawTriangleGradient
|
||||||
|
#(Vector2 : (- (/ WIN-WIDTH 2) 100) (+ (/ WIN-HEIGHT 2) 100.0f))
|
||||||
|
#(Vector2 : (+ (/ WIN-WIDTH 2) 100) (+ (/ WIN-HEIGHT 2) 100.0f))
|
||||||
|
#(Vector2 : (/ WIN-WIDTH 2) (- (/ WIN-HEIGHT 2) 100))
|
||||||
|
RED
|
||||||
|
GREEN
|
||||||
|
BLUE)
|
||||||
|
(EndDrawing))
|
||||||
|
|
||||||
|
(fn init () void
|
||||||
(TraceLog LOG-INFO "hello from Catch-Phase! initializing resources...")
|
(TraceLog LOG-INFO "hello from Catch-Phase! initializing resources...")
|
||||||
(call-and-check IsWindowReady "failed to create window" 1
|
(call-and-check IsWindowReady "failed to create window" 1
|
||||||
InitWindow WIN-WIDTH WIN-HEIGHT "Catch-Phase")
|
InitWindow WIN-WIDTH WIN-HEIGHT "Catch-Phase")
|
||||||
(call-and-check IsAudioDeviceReady "failed to init audio" 2
|
(call-and-check IsAudioDeviceReady "failed to init audio" 2
|
||||||
InitAudioDevice)
|
InitAudioDevice)
|
||||||
(while (! (WindowShouldClose))
|
(SetTargetFPS 60))
|
||||||
(BeginDrawing)
|
|
||||||
(ClearBackground BLACK)
|
(fn deinit () void
|
||||||
(DrawCircle (/ WIN-WIDTH 2) (/ WIN-HEIGHT 2) 100.0f RAYWHITE)
|
|
||||||
(EndDrawing))
|
|
||||||
(CloseAudioDevice)
|
(CloseAudioDevice)
|
||||||
(CloseWindow)
|
(CloseWindow))
|
||||||
|
|
||||||
|
#-emscripten
|
||||||
|
(pub fn main ((argc int) (argv [* const char])) int
|
||||||
|
(init)
|
||||||
|
(if (!= error 0)
|
||||||
|
(return error))
|
||||||
|
(while (! (WindowShouldClose))
|
||||||
|
(update))
|
||||||
|
(return 0))
|
||||||
|
|
||||||
|
#+emscripten
|
||||||
|
(include emscripten.h)
|
||||||
|
|
||||||
|
#+emscripten
|
||||||
|
(pub fn main ((argc int) (argv [* const char])) int
|
||||||
|
(init)
|
||||||
|
(emscripten-set-main-loop update 0 true)
|
||||||
(return 0))
|
(return 0))
|
||||||
|
|||||||
59
shell.html
Normal file
59
shell.html
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport"
|
||||||
|
content="width=device-width, initial-scale=1, user-scalable=no, viewport-fit=cover">
|
||||||
|
<title>Catch Phase</title>
|
||||||
|
<style>
|
||||||
|
html, body {
|
||||||
|
margin: 0;
|
||||||
|
height: 100%;
|
||||||
|
background: #05070d;
|
||||||
|
color: #7c8798;
|
||||||
|
font: 14px/1.5 system-ui, sans-serif;
|
||||||
|
overscroll-behavior: none;
|
||||||
|
}
|
||||||
|
body {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
canvas {
|
||||||
|
display: block;
|
||||||
|
aspect-ratio: 8 / 5;
|
||||||
|
width: 100vw;
|
||||||
|
max-width: calc(100vh * 8 / 5);
|
||||||
|
max-height: 100vh;
|
||||||
|
background: #05070d;
|
||||||
|
touch-action: none;
|
||||||
|
-webkit-user-select: none;
|
||||||
|
user-select: none;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
p {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0 16px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
@media (pointer: coarse) {
|
||||||
|
p { display: none; }
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<canvas id="canvas" tabindex="-1" oncontextmenu="event.preventDefault()"></canvas>
|
||||||
|
<p>Instructions go here.</p>
|
||||||
|
<script>
|
||||||
|
var Module = {
|
||||||
|
canvas: document.getElementById('canvas'),
|
||||||
|
print: console.log.bind(console),
|
||||||
|
printErr: console.error.bind(console),
|
||||||
|
};
|
||||||
|
addEventListener('load', () => Module.canvas.focus());
|
||||||
|
</script>
|
||||||
|
{{{ SCRIPT }}}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user