-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
# WebUI Library | ||
|
||
# Flags | ||
# Allow to add arch-target for macOS CI cross compilation | ||
ARCH_TARGET ?= | ||
COMPILER ?= | ||
|
||
# Build Options | ||
CIVETWEB_BUILD_OPTS = -m64 -o civetweb.o -I "./include/" -c "./src/civetweb/civetweb.c" \ | ||
-DNDEBUG -DNO_CACHING -DNO_CGI -DNO_SSL -DUSE_WEBSOCKET | ||
WEBUI_BUILD_OPTS := -m64 -o webui.o -I "./include/" -c "./src/webui.c" | ||
|
||
# Output files | ||
# The static output is the same for all platforms | ||
# The dynamic output is platform dependent | ||
LIB_STATIC_OUT := libwebui-2-static-x64.a | ||
|
||
# Platform defaults and dynamic library outputs | ||
ifeq ($(OS),Windows_NT) | ||
# Windows | ||
PLATFORM := windows | ||
# TODO: finish MSVC than use dynamic build target based on mingw32-make or nmake command if none is specified | ||
BUILD_TARGET := --gcc-clang | ||
VALID_COMPILERS := gcc tcc msvc | ||
LIB_DYN_OUT := webui-2-x64.dll | ||
CIVETWEB_BUILD_OPTS += -DMUST_IMPLEMENT_CLOCK_GETTIME | ||
LWS2_OPT := -lws2_32 | ||
else | ||
BUILD_TARGET := --gcc-clang | ||
ifeq ($(shell uname),Darwin) | ||
# MacOS | ||
PLATFORM := macos | ||
VALID_COMPILERS := clang | ||
LIB_DYN_OUT := webui-2-x64.dylib | ||
ifeq ($(COMPILER),) | ||
COMPILER = clang | ||
endif | ||
else | ||
# Linux | ||
PLATFORM := linux | ||
VALID_COMPILERS := gcc clang | ||
LIB_DYN_OUT := webui-2-x64.so | ||
ifeq ($(COMPILER),) | ||
COMPILER = gcc | ||
else ifeq ($(COMPILER),clang) | ||
LLVM_OPT := llvm- | ||
endif | ||
endif | ||
endif | ||
|
||
# Targets | ||
|
||
all: release | ||
|
||
release: --eval-args client $(BUILD_TARGET)-release | ||
|
||
debug: --eval-args client $(BUILD_TARGET)-debug | ||
|
||
client: | ||
@echo "Build WebUI js client..." | ||
@src/client/build.sh | ||
|
||
# Internal Targets | ||
|
||
# Evaluate input arguments | ||
--eval-args: | ||
ifneq ($(filter $(COMPILER),$(VALID_COMPILERS)),$(COMPILER)) | ||
$(error Invalid compiler specified: `$(COMPILER)`) | ||
endif | ||
ifneq ($(ARCH_TARGET),) | ||
ifneq ($(PLATFORM),macos) | ||
$(error ARCH_TARGET is only available on macOS) | ||
else ifeq ($(ARCH_TARGET),arm64-apple-darwin) | ||
ARCH_TARGET := -target $(ARCH_TARGET) | ||
endif | ||
endif | ||
|
||
# TODO: TCC | ||
--gcc-clang-debug: client | ||
# Static with Debug info | ||
@echo "Build WebUI library ($(COMPILER) debug static)..." | ||
@$(COMPILER) $(CIVETWEB_BUILD_OPTS) -g | ||
@$(COMPILER) $(WEBUI_BUILD_OPTS) -g -DWEBUI_LOG | ||
@$(LLVM_OPT)ar rc $(LIB_STATIC_OUT) webui.o civetweb.o | ||
@$(LLVM_OPT)ranlib $(LIB_STATIC_OUT) | ||
# Dynamic with Debug info | ||
@echo "Build WebUI library ($(COMPILER) debug dynamic)..." | ||
@$(COMPILER) $(CIVETWEB_BUILD_OPTS) -g -fPIC | ||
@$(COMPILER) $(WEBUI_BUILD_OPTS) -g -fPIC -DWEBUI_LOG | ||
@$(COMPILER) $(LWS2_OPT) -shared -o $(LIB_DYN_OUT) webui.o civetweb.o -g | ||
# TODO: platform additional commands like `strip` on windows | ||
# Clean | ||
# TODO: platform clean | ||
@- rm -f *.o | ||
@echo "Done." | ||
|
||
--gcc-clang-release: client | ||
# Static Release | ||
@echo "Build WebUI library ($(COMPILER) release static)..." | ||
@$(COMPILER) $(ARCH_TARGET) $(CIVETWEB_BUILD_OPTS) -Os | ||
@$(COMPILER) $(ARCH_TARGET) $(WEBUI_BUILD_OPTS) -Os | ||
@$(LLVM_OPT)ar rc $(LIB_STATIC_OUT) webui.o civetweb.o | ||
@$(LLVM_OPT)ranlib $(LIB_STATIC_OUT) | ||
# Dynamic Release | ||
@echo "Build WebUI library ($(COMPILER) release dynamic)..." | ||
@$(COMPILER) $(ARCH_TARGET) $(CIVETWEB_BUILD_OPTS) -O3 -fPIC | ||
@$(COMPILER) $(ARCH_TARGET) $(WEBUI_BUILD_OPTS) -O3 -fPIC | ||
@$(COMPILER) $(ARCH_TARGET) $(LWS2_OPT) -shared -o $(LIB_DYN_OUT) webui.o civetweb.o | ||
# Clean | ||
@- rm -f *.o | ||
@echo "Done." | ||
|
||
# TODO: MSVC | ||
|
||
--clean-linux: | ||
- rm -f *.o | ||
- rm -f *.so | ||
- rm -f *.a | ||
|
||
--clean-macos: | ||
- rm -f *.o | ||
- rm -f *.dylib | ||
- rm -f *.a | ||
|
||
--clean-windows: | ||
- del *.obj >nul 2>&1 | ||
- del *.dll >nul 2>&1 | ||
- del *.ilk >nul 2>&1 | ||
- del *.pdb >nul 2>&1 | ||
- del *.lib >nul 2>&1 | ||
- del *.exp >nul 2>&1 | ||
|
||
# NOTES | ||
# .dyn to .dylib on macos | ||
|
||
# TODO: | ||
# client/build.bat for windows | ||
# silent client build | ||
# Update build section in ./README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
|
||
project_root=$(git rev-parse --show-toplevel) | ||
cd $project_root/src/client | ||
|
||
# TODO: silent arg | ||
# Transpiling TS to JS | ||
echo "Transpile and bundle TS sources to webui.js"; | ||
esbuild --bundle --target="chrome90,firefox90,safari15" --format=esm --tree-shaking=false --outdir=. ./webui.ts | ||
|
||
# Converting JS source to C-String using xxd | ||
echo "Converting JS source to C-String using xxd" | ||
# The path needs to match the path in webui.c, that's why we move up to src/ | ||
cd .. | ||
xxd -i client/webui.js client/webui.h | ||
|
||
echo "Finished." |