From 5518a3e0444f50d5b43315af8a3dee945b752bbf Mon Sep 17 00:00:00 2001 From: Turiiya <34311583+ttytm@users.noreply.github.com> Date: Tue, 10 Oct 2023 01:55:03 +0200 Subject: [PATCH] Use `GNUmakefile` and `Makefile` to simplify MSVC compilation --- .editorconfig | 2 +- GNUmakefile | 146 ++++++++++++++ Makefile | 187 ++++++------------ Makefile.nmake | 73 ------- examples/C++/call_cpp_from_js/GNUmakefile | 120 +++++++++++ examples/C++/call_cpp_from_js/Makefile | 145 ++++---------- examples/C++/call_cpp_from_js/Makefile.nmake | 55 ------ examples/C++/call_js_from_cpp/GNUmakefile | 120 +++++++++++ examples/C++/call_js_from_cpp/Makefile | 145 ++++---------- examples/C++/call_js_from_cpp/Makefile.nmake | 55 ------ examples/C++/minimal/GNUmakefile | 120 +++++++++++ examples/C++/minimal/Makefile | 145 ++++---------- examples/C++/minimal/Makefile.nmake | 55 ------ examples/C++/serve_a_folder/GNUmakefile | 120 +++++++++++ examples/C++/serve_a_folder/Makefile | 145 ++++---------- examples/C++/serve_a_folder/Makefile.nmake | 55 ------ examples/C/README.md | 2 +- examples/C/call_c_from_js/GNUmakefile | 120 +++++++++++ examples/C/call_c_from_js/Makefile | 145 ++++---------- examples/C/call_c_from_js/Makefile.nmake | 55 ------ examples/C/call_js_from_c/GNUmakefile | 120 +++++++++++ examples/C/call_js_from_c/Makefile | 145 ++++---------- examples/C/call_js_from_c/Makefile.nmake | 55 ------ examples/C/minimal/GNUmakefile | 120 +++++++++++ examples/C/minimal/Makefile | 145 ++++---------- examples/C/minimal/Makefile.nmake | 55 ------ examples/C/serve_a_folder/GNUmakefile | 120 +++++++++++ examples/C/serve_a_folder/Makefile | 145 ++++---------- examples/C/serve_a_folder/Makefile.nmake | 55 ------ .../C/text-editor/{Makefile => GNUmakefile} | 0 30 files changed, 1485 insertions(+), 1485 deletions(-) create mode 100644 GNUmakefile delete mode 100644 Makefile.nmake create mode 100644 examples/C++/call_cpp_from_js/GNUmakefile delete mode 100644 examples/C++/call_cpp_from_js/Makefile.nmake create mode 100644 examples/C++/call_js_from_cpp/GNUmakefile delete mode 100644 examples/C++/call_js_from_cpp/Makefile.nmake create mode 100644 examples/C++/minimal/GNUmakefile delete mode 100644 examples/C++/minimal/Makefile.nmake create mode 100644 examples/C++/serve_a_folder/GNUmakefile delete mode 100644 examples/C++/serve_a_folder/Makefile.nmake create mode 100644 examples/C/call_c_from_js/GNUmakefile delete mode 100644 examples/C/call_c_from_js/Makefile.nmake create mode 100644 examples/C/call_js_from_c/GNUmakefile delete mode 100644 examples/C/call_js_from_c/Makefile.nmake create mode 100644 examples/C/minimal/GNUmakefile delete mode 100644 examples/C/minimal/Makefile.nmake create mode 100644 examples/C/serve_a_folder/GNUmakefile delete mode 100644 examples/C/serve_a_folder/Makefile.nmake rename examples/C/text-editor/{Makefile => GNUmakefile} (100%) diff --git a/.editorconfig b/.editorconfig index 497871ba..4dbfbb38 100644 --- a/.editorconfig +++ b/.editorconfig @@ -4,5 +4,5 @@ end_of_line = lf insert_final_newline = true trim_trailing_whitespace = true -[*.{c,cpp,h,hpp,Makefile,js,ts,css,html}] +[*.{c,cpp,h,hpp,Makefile,GNUmakefile,js,ts,css,html}] indent_style = tab diff --git a/GNUmakefile b/GNUmakefile new file mode 100644 index 00000000..7d469b08 --- /dev/null +++ b/GNUmakefile @@ -0,0 +1,146 @@ +# WebUI Library + +# == 1. VARIABLES ============================================================= + +MAKEFILE_DIR := $(shell git rev-parse --show-toplevel) +BUILD_DIR := $(MAKEFILE_DIR)/dist + +# ARGS +# Set a compiler when running on Linux via `make CC=gcc` / `make CC=clang` +CC = gcc +# Allow to add arch-target for macOS CI cross compilation +ARCH_TARGET ?= + +# BUILD FLAGS +CIVETWEB_BUILD_FLAGS := -o civetweb.o -I"$(MAKEFILE_DIR)/include/" -c "$(MAKEFILE_DIR)/src/civetweb/civetweb.c" +CIVETWEB_DEFINE_FLAGS = -DNDEBUG -DNO_CACHING -DNO_CGI -DNO_SSL -DUSE_WEBSOCKET +WEBUI_BUILD_FLAGS := -o webui.o -I"$(MAKEFILE_DIR)/include/" -c "$(MAKEFILE_DIR)/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.a + +# Platform defaults and dynamic library outputs +ifeq ($(OS),Windows_NT) + # Windows + SHELL := CMD + PLATFORM := windows + LIB_DYN_OUT := webui-2.dll + LWS2_OPT := -lws2_32 + CIVETWEB_DEFINE_FLAGS += -DMUST_IMPLEMENT_CLOCK_GETTIME +else ifeq ($(shell uname),Darwin) + # MacOS + PLATFORM := macos + CC = clang + LIB_DYN_OUT := webui-2.dylib +else + # Linux + PLATFORM := linux + LIB_DYN_OUT := webui-2.so + ifneq ($(filter $(CC),gcc clang aarch64-linux-gnu-gcc arm-linux-gnueabihf-gcc),$(CC)) + $(error Invalid compiler specified: `$(CC)`) + else ifeq ($(CC),clang) + LLVM_OPT := llvm- + endif +endif +# macOS can set `ARCH_TARGET=arm64` - intented for CI cross-compilation. +ifneq ($(ARCH_TARGET),) + ifneq ($(PLATFORM),macos) + $(error ARCH_TARGET is only available on macOS) + else ifeq ($(ARCH_TARGET),arm64) + TARGET := -target arm64-apple-darwin + endif +endif + +# == 2.TARGETS ================================================================ + +all: release + +debug: --debug + +release: --release + +clean: --clean-$(PLATFORM) + +# == 2.1 INTERNAL TARGETS ===================================================== + +--debug: +# Create build directory +ifeq ($(PLATFORM),windows) + @mkdir "$(BUILD_DIR)/debug" >nul 2>&1 ||: +else + @mkdir -p "$(BUILD_DIR)/debug" +endif +# Static with Debug info + @cd "$(BUILD_DIR)/debug" \ + && echo "Build WebUI library ($(CC) $(TARGET)debug static)..." \ + && $(CC) $(TARGET) $(CIVETWEB_BUILD_FLAGS) $(CIVETWEB_DEFINE_FLAGS) -g \ + && $(CC) $(TARGET) $(WEBUI_BUILD_FLAGS) -g -DWEBUI_LOG \ + && $(LLVM_OPT)ar rc $(LIB_STATIC_OUT) webui.o civetweb.o \ + && $(LLVM_OPT)ranlib $(LIB_STATIC_OUT) +# Dynamic with Debug info + @cd "$(BUILD_DIR)/debug" \ + && echo "Build WebUI library ($(CC) $(TARGET)debug dynamic)..." \ + && $(CC) $(TARGET) $(CIVETWEB_BUILD_FLAGS) $(CIVETWEB_DEFINE_FLAGS) -g -fPIC \ + && $(CC) $(TARGET) $(WEBUI_BUILD_FLAGS) -g -fPIC -DWEBUI_LOG \ + && $(CC) $(TARGET) -shared -o $(LIB_DYN_OUT) webui.o civetweb.o -g $(LWS2_OPT) +ifeq ($(PLATFORM),windows) + @cd "$(BUILD_DIR)/debug" && del *.o >nul 2>&1 +else + @rm -f $(BUILD_DIR)/debug/*.o +endif + @echo "Done." + +--release: +# Create build directory +ifeq ($(PLATFORM),windows) + @mkdir "$(BUILD_DIR)" >nul 2>&1 ||: +else + @mkdir -p "$(BUILD_DIR)" +endif +# Static Release + @cd "$(BUILD_DIR)" \ + && echo "Build WebUI library ($(CC) $(TARGET)release static)..." \ + && $(CC) $(TARGET) $(CIVETWEB_BUILD_FLAGS) $(CIVETWEB_DEFINE_FLAGS) -Os \ + && $(CC) $(TARGET) $(WEBUI_BUILD_FLAGS) -Os \ + && $(LLVM_OPT)ar rc $(LIB_STATIC_OUT) webui.o civetweb.o \ + && $(LLVM_OPT)ranlib $(LIB_STATIC_OUT) +# Dynamic Release + @cd "$(BUILD_DIR)" \ + && echo "Build WebUI library ($(CC) $(TARGET)release dynamic)..." \ + && $(CC) $(TARGET) $(CIVETWEB_BUILD_FLAGS) $(CIVETWEB_DEFINE_FLAGS) -Os -fPIC \ + && $(CC) $(TARGET) $(WEBUI_BUILD_FLAGS) -O3 -fPIC \ + && $(CC) $(TARGET) -shared -o $(LIB_DYN_OUT) webui.o civetweb.o $(LWS2_OPT) +# Clean +ifeq ($(PLATFORM),windows) + @strip --strip-unneeded $(BUILD_DIR)/$(LIB_DYN_OUT) + @cd "$(BUILD_DIR)" && del *.o >nul 2>&1 +else + @rm -f $(BUILD_DIR)/*.o +endif + @echo "Done." + +# PLATFROM CLEAN TARGETS + +--clean-linux: --clean-unix + +--clean-macos: --clean-unix + +--clean-unix: + @- cd "$(BUILD_DIR)" \ + && rm -f *.o \ + && rm -f *.so \ + && rm -f *.dylib \ + && rm -f *.a + +--clean-windows: + @- cd "$(BUILD_DIR)" \ + && del *.a >nul 2>&1 \ + && del *.o >nul 2>&1 \ + && del *.dll >nul 2>&1 \ + && del *.obj >nul 2>&1 \ + && del *.ilk >nul 2>&1 \ + && del *.pdb >nul 2>&1 \ + && del *.lib >nul 2>&1 \ + && del *.exp >nul 2>&1 diff --git a/Makefile b/Makefile index d318b669..878c613a 100644 --- a/Makefile +++ b/Makefile @@ -1,146 +1,73 @@ # WebUI Library +# Windows - Microsoft Visual C # == 1. VARIABLES ============================================================= -MAKEFILE_DIR := $(shell git rev-parse --show-toplevel) -BUILD_DIR := $(MAKEFILE_DIR)/dist - -# ARGS -# Set a compiler when running on Linux via `make CC=gcc` / `make CC=clang` -CC = gcc -# Allow to add arch-target for macOS CI cross compilation -ARCH_TARGET ?= - -# BUILD FLAGS -CIVETWEB_BUILD_FLAGS := -o civetweb.o -I"$(MAKEFILE_DIR)/include/" -c "$(MAKEFILE_DIR)/src/civetweb/civetweb.c" +# Build Flags +CIVETWEB_BUILD_FLAGS = /Fo"civetweb.obj" /c /EHsc "$(MAKEDIR)/src/civetweb/civetweb.c" /I"$(MAKEDIR)/src/civetweb/" CIVETWEB_DEFINE_FLAGS = -DNDEBUG -DNO_CACHING -DNO_CGI -DNO_SSL -DUSE_WEBSOCKET -WEBUI_BUILD_FLAGS := -o webui.o -I"$(MAKEFILE_DIR)/include/" -c "$(MAKEFILE_DIR)/src/webui.c" +WEBUI_BUILD_FLAGS = /Fo"webui.obj" /c /EHsc "$(MAKEDIR)/src/webui.c" /I"$(MAKEDIR)/include" -# OUTPUT FILES -# The static output is the same for all platforms -# The dynamic output is platform dependent -LIB_STATIC_OUT := libwebui-2-static.a - -# Platform defaults and dynamic library outputs -ifeq ($(OS),Windows_NT) - # Windows - SHELL := CMD - PLATFORM := windows - LIB_DYN_OUT := webui-2.dll - LWS2_OPT := -lws2_32 - CIVETWEB_DEFINE_FLAGS += -DMUST_IMPLEMENT_CLOCK_GETTIME -else ifeq ($(shell uname),Darwin) - # MacOS - PLATFORM := macos - CC = clang - LIB_DYN_OUT := webui-2.dylib -else - # Linux - PLATFORM := linux - LIB_DYN_OUT := webui-2.so - ifneq ($(filter $(CC),gcc clang aarch64-linux-gnu-gcc arm-linux-gnueabihf-gcc),$(CC)) - $(error Invalid compiler specified: `$(CC)`) - else ifeq ($(CC),clang) - LLVM_OPT := llvm- - endif -endif -# macOS can set `ARCH_TARGET=arm64` - intented for CI cross-compilation. -ifneq ($(ARCH_TARGET),) - ifneq ($(PLATFORM),macos) - $(error ARCH_TARGET is only available on macOS) - else ifeq ($(ARCH_TARGET),arm64) - TARGET := -target arm64-apple-darwin - endif -endif +# Output Commands +LIB_STATIC_OUT = /OUT:"webui-2-static.lib" "webui.obj" "civetweb.obj" +LIB_DYN_OUT = /DLL /OUT:"webui-2.dll" "webui.obj" "civetweb.obj" user32.lib Advapi32.lib # == 2.TARGETS ================================================================ all: release -debug: --debug - -release: --release - -clean: --clean-$(PLATFORM) - -# == 2.1 INTERNAL TARGETS ===================================================== - ---debug: -# Create build directory -ifeq ($(PLATFORM),windows) - @mkdir "$(BUILD_DIR)/debug" >nul 2>&1 ||: -else - @mkdir -p "$(BUILD_DIR)/debug" -endif +debug: + @- mkdir dist\debug >nul 2>&1 # Static with Debug info - @cd "$(BUILD_DIR)/debug" \ - && echo "Build WebUI library ($(CC) $(TARGET)debug static)..." \ - && $(CC) $(TARGET) $(CIVETWEB_BUILD_FLAGS) $(CIVETWEB_DEFINE_FLAGS) -g \ - && $(CC) $(TARGET) $(WEBUI_BUILD_FLAGS) -g -DWEBUI_LOG \ - && $(LLVM_OPT)ar rc $(LIB_STATIC_OUT) webui.o civetweb.o \ - && $(LLVM_OPT)ranlib $(LIB_STATIC_OUT) + @- cd $(MAKEDIR)/dist/debug + @echo Build WebUI Library (MSVC Debug Static)... + @cl /Zl /Zi $(CIVETWEB_BUILD_FLAGS) $(CIVETWEB_DEFINE_FLAGS) + @cl /Zl /Zi $(WEBUI_BUILD_FLAGS) /DWEBUI_LOG + @lib $(LIB_STATIC_OUT) # Dynamic with Debug info - @cd "$(BUILD_DIR)/debug" \ - && echo "Build WebUI library ($(CC) $(TARGET)debug dynamic)..." \ - && $(CC) $(TARGET) $(CIVETWEB_BUILD_FLAGS) $(CIVETWEB_DEFINE_FLAGS) -g -fPIC \ - && $(CC) $(TARGET) $(WEBUI_BUILD_FLAGS) -g -fPIC -DWEBUI_LOG \ - && $(CC) $(TARGET) -shared -o $(LIB_DYN_OUT) webui.o civetweb.o -g $(LWS2_OPT) -ifeq ($(PLATFORM),windows) - @cd "$(BUILD_DIR)/debug" && del *.o >nul 2>&1 -else - @rm -f $(BUILD_DIR)/debug/*.o -endif - @echo "Done." - ---release: -# Create build directory -ifeq ($(PLATFORM),windows) - @mkdir "$(BUILD_DIR)" >nul 2>&1 ||: -else - @mkdir -p "$(BUILD_DIR)" -endif -# Static Release - @cd "$(BUILD_DIR)" \ - && echo "Build WebUI library ($(CC) $(TARGET)release static)..." \ - && $(CC) $(TARGET) $(CIVETWEB_BUILD_FLAGS) $(CIVETWEB_DEFINE_FLAGS) -Os \ - && $(CC) $(TARGET) $(WEBUI_BUILD_FLAGS) -Os \ - && $(LLVM_OPT)ar rc $(LIB_STATIC_OUT) webui.o civetweb.o \ - && $(LLVM_OPT)ranlib $(LIB_STATIC_OUT) -# Dynamic Release - @cd "$(BUILD_DIR)" \ - && echo "Build WebUI library ($(CC) $(TARGET)release dynamic)..." \ - && $(CC) $(TARGET) $(CIVETWEB_BUILD_FLAGS) $(CIVETWEB_DEFINE_FLAGS) -Os -fPIC \ - && $(CC) $(TARGET) $(WEBUI_BUILD_FLAGS) -O3 -fPIC \ - && $(CC) $(TARGET) -shared -o $(LIB_DYN_OUT) webui.o civetweb.o $(LWS2_OPT) + @echo Build WebUI Library (MSVC Debug Dynamic)... + @cl /Zi $(CIVETWEB_BUILD_FLAGS) $(CIVETWEB_DEFINE_FLAGS) + @cl /Zi $(WEBUI_BUILD_FLAGS) /DWEBUI_LOG + @link $(LIB_DYN_OUT) +# Move into `debug/` dir + @- move webui-2-static.lib "debug\" + @- move webui-2.dll "debug\" # Clean -ifeq ($(PLATFORM),windows) - @strip --strip-unneeded $(BUILD_DIR)/$(LIB_DYN_OUT) - @cd "$(BUILD_DIR)" && del *.o >nul 2>&1 -else - @rm -f $(BUILD_DIR)/*.o -endif - @echo "Done." + @- del *.pdb >nul 2>&1 + @- del *.obj >nul 2>&1 + @- del *.ilk >nul 2>&1 + @- del *.pdb >nul 2>&1 + @- del *.exp >nul 2>&1 + @echo Done. -# PLATFROM CLEAN TARGETS +release: + @- mkdir dist >nul 2>&1 + @- cd $(MAKEDIR)/dist +# Static Release + @echo Build WebUI Library (MSVC Release Static)... + @cl /Zl $(CIVETWEB_BUILD_FLAGS) $(CIVETWEB_DEFINE_FLAGS) + @cl /Zl $(WEBUI_BUILD_FLAGS) + @lib $(LIB_STATIC_OUT) +# Dynamic Release + @echo Build WebUI Library (MSVC Release Dynamic)... + @cl $(CIVETWEB_BUILD_FLAGS) $(CIVETWEB_DEFINE_FLAGS) + @cl $(WEBUI_BUILD_FLAGS) + @link $(LIB_DYN_OUT) +# Clean + @- del *.pdb >nul 2>&1 + @- del *.obj >nul 2>&1 + @- del *.ilk >nul 2>&1 + @- del *.pdb >nul 2>&1 + @- del *.exp >nul 2>&1 + @- echo Done. ---clean-linux: --clean-unix - ---clean-macos: --clean-unix - ---clean-unix: - @- cd "$(BUILD_DIR)" \ - && rm -f *.o \ - && rm -f *.so \ - && rm -f *.dylib \ - && rm -f *.a - ---clean-windows: - @- cd "$(BUILD_DIR)" \ - && del *.a >nul 2>&1 \ - && del *.o >nul 2>&1 \ - && del *.dll >nul 2>&1 \ - && del *.obj >nul 2>&1 \ - && del *.ilk >nul 2>&1 \ - && del *.pdb >nul 2>&1 \ - && del *.lib >nul 2>&1 \ - && del *.exp >nul 2>&1 +clean: + @- cd $(BUILD_DIR) + @- del *.pdb >nul 2>&1 + @- del *.obj >nul 2>&1 + @- del *.ilk >nul 2>&1 + @- del *.pdb >nul 2>&1 + @- del *.exp >nul 2>&1 + @- del *.dll >nul 2>&1 + @- del *.lib >nul 2>&1 + @- echo Done. diff --git a/Makefile.nmake b/Makefile.nmake deleted file mode 100644 index 878c613a..00000000 --- a/Makefile.nmake +++ /dev/null @@ -1,73 +0,0 @@ -# WebUI Library -# Windows - Microsoft Visual C - -# == 1. VARIABLES ============================================================= - -# Build Flags -CIVETWEB_BUILD_FLAGS = /Fo"civetweb.obj" /c /EHsc "$(MAKEDIR)/src/civetweb/civetweb.c" /I"$(MAKEDIR)/src/civetweb/" -CIVETWEB_DEFINE_FLAGS = -DNDEBUG -DNO_CACHING -DNO_CGI -DNO_SSL -DUSE_WEBSOCKET -WEBUI_BUILD_FLAGS = /Fo"webui.obj" /c /EHsc "$(MAKEDIR)/src/webui.c" /I"$(MAKEDIR)/include" - -# Output Commands -LIB_STATIC_OUT = /OUT:"webui-2-static.lib" "webui.obj" "civetweb.obj" -LIB_DYN_OUT = /DLL /OUT:"webui-2.dll" "webui.obj" "civetweb.obj" user32.lib Advapi32.lib - -# == 2.TARGETS ================================================================ - -all: release - -debug: - @- mkdir dist\debug >nul 2>&1 -# Static with Debug info - @- cd $(MAKEDIR)/dist/debug - @echo Build WebUI Library (MSVC Debug Static)... - @cl /Zl /Zi $(CIVETWEB_BUILD_FLAGS) $(CIVETWEB_DEFINE_FLAGS) - @cl /Zl /Zi $(WEBUI_BUILD_FLAGS) /DWEBUI_LOG - @lib $(LIB_STATIC_OUT) -# Dynamic with Debug info - @echo Build WebUI Library (MSVC Debug Dynamic)... - @cl /Zi $(CIVETWEB_BUILD_FLAGS) $(CIVETWEB_DEFINE_FLAGS) - @cl /Zi $(WEBUI_BUILD_FLAGS) /DWEBUI_LOG - @link $(LIB_DYN_OUT) -# Move into `debug/` dir - @- move webui-2-static.lib "debug\" - @- move webui-2.dll "debug\" -# Clean - @- del *.pdb >nul 2>&1 - @- del *.obj >nul 2>&1 - @- del *.ilk >nul 2>&1 - @- del *.pdb >nul 2>&1 - @- del *.exp >nul 2>&1 - @echo Done. - -release: - @- mkdir dist >nul 2>&1 - @- cd $(MAKEDIR)/dist -# Static Release - @echo Build WebUI Library (MSVC Release Static)... - @cl /Zl $(CIVETWEB_BUILD_FLAGS) $(CIVETWEB_DEFINE_FLAGS) - @cl /Zl $(WEBUI_BUILD_FLAGS) - @lib $(LIB_STATIC_OUT) -# Dynamic Release - @echo Build WebUI Library (MSVC Release Dynamic)... - @cl $(CIVETWEB_BUILD_FLAGS) $(CIVETWEB_DEFINE_FLAGS) - @cl $(WEBUI_BUILD_FLAGS) - @link $(LIB_DYN_OUT) -# Clean - @- del *.pdb >nul 2>&1 - @- del *.obj >nul 2>&1 - @- del *.ilk >nul 2>&1 - @- del *.pdb >nul 2>&1 - @- del *.exp >nul 2>&1 - @- echo Done. - -clean: - @- cd $(BUILD_DIR) - @- del *.pdb >nul 2>&1 - @- del *.obj >nul 2>&1 - @- del *.ilk >nul 2>&1 - @- del *.pdb >nul 2>&1 - @- del *.exp >nul 2>&1 - @- del *.dll >nul 2>&1 - @- del *.lib >nul 2>&1 - @- echo Done. diff --git a/examples/C++/call_cpp_from_js/GNUmakefile b/examples/C++/call_cpp_from_js/GNUmakefile new file mode 100644 index 00000000..fffcb366 --- /dev/null +++ b/examples/C++/call_cpp_from_js/GNUmakefile @@ -0,0 +1,120 @@ +# WebUI C++ Example + +# == 1. VARIABLES ============================================================= + +PROJECT_DIR := $(shell git rev-parse --show-toplevel) +LIB_DIR := $(PROJECT_DIR)/dist +INCLUDE_DIR := $(PROJECT_DIR)/include + +# ARGS +# Set a compiler when running on Linux via `make CC=g++` / `make CC=clang` +CXX = g++ +# Build the WebUI library if running via `make BUILD_LIB=true` +BUILD_LIB ?= + +# BUILD FLAGS +STATIC_BUILD_FLAGS = -std=c++17 -lstdc++ main.cpp -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)" +DYN_BUILD_FLAGS = -std=c++17 -lstdc++ main.cpp -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)" + +# Platform conditions +ifeq ($(OS),Windows_NT) + # Windows + PLATFORM := windows + SHELL := CMD + STATIC_BUILD_FLAGS += -lwebui-2-static -lws2_32 -Wall -Wl,-subsystem=console -luser32 -static + DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.dll" -lws2_32 -Wall -Wl,-subsystem=console -luser32 + STATIC_OUT := main.exe + DYN_OUT := main-dyn.exe + LWS2_OPT := -lws2_32 + STRIP_OPT := --strip-all +else + STATIC_BUILD_FLAGS += -lpthread -lm -lwebui-2-static + DYN_BUILD_FLAGS += -lpthread -lm + STATIC_OUT := main + DYN_OUT := main-dyn + ifeq ($(shell uname),Darwin) + # MacOS + PLATFORM := macos + DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.dylib" + CXX = clang + else + # Linux + PLATFORM := linux + DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.so" + STRIP_OPT := --strip-all + ifeq ($(CXX),clang) + LLVM_OPT := llvm- + endif + endif +endif + +# == 2.TARGETS ================================================================ + +all: release + +debug: LIB_DIR := $(LIB_DIR)/debug +debug: --validate-args +ifeq ($(BUILD_LIB),true) + @cd "$(PROJECT_DIR)" && $(MAKE) debug +endif +# Static with Debug info + @echo "Build C99 Example ($(CXX) debug static)..." + @$(CXX) -g $(STATIC_BUILD_FLAGS) $(LWS2_OPT) -o $(STATIC_OUT) +# Dynamic with Debug info + @echo "Build C99 Example ($(CXX) debug dynamic)..." + @$(CXX) -g $(DYN_BUILD_FLAGS) $(LWS2_OPT) -o $(DYN_OUT) +# Clean +ifeq ($(PLATFORM),windows) + @- del *.o >nul 2>&1 +else + @- rm -f *.o + @- rm -rf *.dSYM # macOS +endif + @echo "Done." + +release: --validate-args +ifeq ($(BUILD_LIB),true) + @cd "$(PROJECT_DIR)" && $(MAKE) +endif +# Static Release + @echo "Build C99 Example ($(CXX) release static)..." + @$(CXX) -Os $(STATIC_BUILD_FLAGS) $(LWS2_OPT) -o $(STATIC_OUT) + @$(LLVM_OPT)strip $(STRIP_OPT) $(STATIC_OUT) +# Dynamic Release + @echo "Build C99 Example ($(CXX) release dynamic)..." + @$(CXX) $(DYN_BUILD_FLAGS) $(LWS2_OPT) -o $(DYN_OUT) + @$(LLVM_OPT)strip $(STRIP_OPT) $(DYN_OUT) +# Clean +ifeq ($(PLATFORM),windows) + @- del *.o >nul 2>&1 +else + @- rm -f *.o + @- rm -rf *.dSYM # macOS +endif + @echo "Done." + +clean: --clean-$(PLATFORM) + +# INTERNAL TARGETS + +--validate-args: +ifneq ($(filter $(CXX),g++ clang),$(CXX)) + $(error Invalid compiler specified: `$(CXX)`) +endif + +--clean-linux: --clean-unix + +--clean-macos: --clean-unix + +--clean-unix: + - rm -f *.o + - rm -f *.a + - rm -f *.so + - rm -f *.dylib + - rm -rf *.dSYM + +--clean-windows: + - del *.o >nul 2>&1 + - del *.dll >nul 2>&1 + - del *.a >nul 2>&1 + - del *.exe >nul 2>&1 diff --git a/examples/C++/call_cpp_from_js/Makefile b/examples/C++/call_cpp_from_js/Makefile index fffcb366..1cdfcb2a 100644 --- a/examples/C++/call_cpp_from_js/Makefile +++ b/examples/C++/call_cpp_from_js/Makefile @@ -1,120 +1,55 @@ # WebUI C++ Example +# Windows - Microsoft Visual C++ -# == 1. VARIABLES ============================================================= +SHELL = CMD +LIB_DIR = ../../../dist +INCLUDE_DIR = ../../../include -PROJECT_DIR := $(shell git rev-parse --show-toplevel) -LIB_DIR := $(PROJECT_DIR)/dist -INCLUDE_DIR := $(PROJECT_DIR)/include - -# ARGS -# Set a compiler when running on Linux via `make CC=g++` / `make CC=clang` -CXX = g++ -# Build the WebUI library if running via `make BUILD_LIB=true` -BUILD_LIB ?= - -# BUILD FLAGS -STATIC_BUILD_FLAGS = -std=c++17 -lstdc++ main.cpp -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)" -DYN_BUILD_FLAGS = -std=c++17 -lstdc++ main.cpp -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)" - -# Platform conditions -ifeq ($(OS),Windows_NT) - # Windows - PLATFORM := windows - SHELL := CMD - STATIC_BUILD_FLAGS += -lwebui-2-static -lws2_32 -Wall -Wl,-subsystem=console -luser32 -static - DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.dll" -lws2_32 -Wall -Wl,-subsystem=console -luser32 - STATIC_OUT := main.exe - DYN_OUT := main-dyn.exe - LWS2_OPT := -lws2_32 - STRIP_OPT := --strip-all -else - STATIC_BUILD_FLAGS += -lpthread -lm -lwebui-2-static - DYN_BUILD_FLAGS += -lpthread -lm - STATIC_OUT := main - DYN_OUT := main-dyn - ifeq ($(shell uname),Darwin) - # MacOS - PLATFORM := macos - DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.dylib" - CXX = clang - else - # Linux - PLATFORM := linux - DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.so" - STRIP_OPT := --strip-all - ifeq ($(CXX),clang) - LLVM_OPT := llvm- - endif - endif -endif - -# == 2.TARGETS ================================================================ +# Build the WebUI library if running `nmake BUILD_LIB=true` +BUILD_LIB = all: release -debug: LIB_DIR := $(LIB_DIR)/debug -debug: --validate-args -ifeq ($(BUILD_LIB),true) - @cd "$(PROJECT_DIR)" && $(MAKE) debug -endif +debug: +!IF "$(BUILD_LIB)" == "true" + @cd "$(LIB_DIR)" && cd .. && $(MAKE) debug +!ENDIF # Static with Debug info - @echo "Build C99 Example ($(CXX) debug static)..." - @$(CXX) -g $(STATIC_BUILD_FLAGS) $(LWS2_OPT) -o $(STATIC_OUT) + @echo Build C++ Example (Debug Static)... + @cl /Zi /EHsc /std:c++17 main.cpp /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)/debug" /MACHINE:X64 /SUBSYSTEM:CONSOLE webui-2-static.lib user32.lib Advapi32.lib /OUT:main.exe 1>NUL 2>&1 # Dynamic with Debug info - @echo "Build C99 Example ($(CXX) debug dynamic)..." - @$(CXX) -g $(DYN_BUILD_FLAGS) $(LWS2_OPT) -o $(DYN_OUT) + @echo Build C++ Example (Debug Dynamic)... + @cl /Zi /EHsc /std:c++17 main.cpp /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)/debug" /MACHINE:X64 /SUBSYSTEM:CONSOLE webui-2.lib user32.lib Advapi32.lib /OUT:main-dyn.exe 1>NUL 2>&1 # Clean -ifeq ($(PLATFORM),windows) - @- del *.o >nul 2>&1 -else - @- rm -f *.o - @- rm -rf *.dSYM # macOS -endif - @echo "Done." + @- del *.exp >nul 2>&1 + @- del *.ilk >nul 2>&1 + @- del *.lib >nul 2>&1 + @- del *.obj >nul 2>&1 + @- del *.pdb >nul 2>&1 + @echo Done. -release: --validate-args -ifeq ($(BUILD_LIB),true) - @cd "$(PROJECT_DIR)" && $(MAKE) -endif +release: +!IF "$(BUILD_LIB)" == "true" + @cd "$(LIB_DIR)" && cd .. && $(MAKE) +!ENDIF # Static Release - @echo "Build C99 Example ($(CXX) release static)..." - @$(CXX) -Os $(STATIC_BUILD_FLAGS) $(LWS2_OPT) -o $(STATIC_OUT) - @$(LLVM_OPT)strip $(STRIP_OPT) $(STATIC_OUT) + @echo Build C++ Example (Release Static)... + @cl /EHsc /std:c++17 main.cpp /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)" /MACHINE:X64 /SUBSYSTEM:WINDOWS webui-2-static.lib user32.lib Advapi32.lib /OUT:main.exe 1>NUL 2>&1 # Dynamic Release - @echo "Build C99 Example ($(CXX) release dynamic)..." - @$(CXX) $(DYN_BUILD_FLAGS) $(LWS2_OPT) -o $(DYN_OUT) - @$(LLVM_OPT)strip $(STRIP_OPT) $(DYN_OUT) + @echo Build C++ Example (Release Dynamic)... + @cl /EHsc /std:c++17 main.cpp /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)" /MACHINE:X64 /SUBSYSTEM:WINDOWS webui-2.lib user32.lib Advapi32.lib /OUT:main-dyn.exe 1>NUL 2>&1 # Clean -ifeq ($(PLATFORM),windows) - @- del *.o >nul 2>&1 -else - @- rm -f *.o - @- rm -rf *.dSYM # macOS -endif - @echo "Done." + @- del *.exp >nul 2>&1 + @- del *.ilk >nul 2>&1 + @- del *.lib >nul 2>&1 + @- del *.obj >nul 2>&1 + @- del *.pdb >nul 2>&1 + @echo Done. -clean: --clean-$(PLATFORM) - -# INTERNAL TARGETS - ---validate-args: -ifneq ($(filter $(CXX),g++ clang),$(CXX)) - $(error Invalid compiler specified: `$(CXX)`) -endif - ---clean-linux: --clean-unix - ---clean-macos: --clean-unix - ---clean-unix: - - rm -f *.o - - rm -f *.a - - rm -f *.so - - rm -f *.dylib - - rm -rf *.dSYM - ---clean-windows: - - del *.o >nul 2>&1 - - del *.dll >nul 2>&1 - - del *.a >nul 2>&1 +clean: + - del *.obj >nul 2>&1 + - del *.ilk >nul 2>&1 + - del *.pdb >nul 2>&1 + - del *.exp >nul 2>&1 - del *.exe >nul 2>&1 + - del *.lib >nul 2>&1 diff --git a/examples/C++/call_cpp_from_js/Makefile.nmake b/examples/C++/call_cpp_from_js/Makefile.nmake deleted file mode 100644 index 2e433a2d..00000000 --- a/examples/C++/call_cpp_from_js/Makefile.nmake +++ /dev/null @@ -1,55 +0,0 @@ -# WebUI C++ Example -# Windows - Microsoft Visual C++ - -SHELL = CMD -LIB_DIR = ../../../dist -INCLUDE_DIR = ../../../include - -# Build the WebUI library if running `nmake -f Makefile.nmake BUILD_LIB=true` -BUILD_LIB = - -all: release - -debug: -!IF "$(BUILD_LIB)" == "true" - @cd "$(LIB_DIR)" && cd .. && $(MAKE) -f Makefile.nmake debug -!ENDIF -# Static with Debug info - @echo Build C++ Example (Debug Static)... - @cl /Zi /EHsc /std:c++17 main.cpp /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)/debug" /MACHINE:X64 /SUBSYSTEM:CONSOLE webui-2-static.lib user32.lib Advapi32.lib /OUT:main.exe 1>NUL 2>&1 -# Dynamic with Debug info - @echo Build C++ Example (Debug Dynamic)... - @cl /Zi /EHsc /std:c++17 main.cpp /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)/debug" /MACHINE:X64 /SUBSYSTEM:CONSOLE webui-2.lib user32.lib Advapi32.lib /OUT:main-dyn.exe 1>NUL 2>&1 -# Clean - @- del *.exp >nul 2>&1 - @- del *.ilk >nul 2>&1 - @- del *.lib >nul 2>&1 - @- del *.obj >nul 2>&1 - @- del *.pdb >nul 2>&1 - @echo Done. - -release: -!IF "$(BUILD_LIB)" == "true" - @cd "$(LIB_DIR)" && cd .. && $(MAKE) -f Makefile.nmake -!ENDIF -# Static Release - @echo Build C++ Example (Release Static)... - @cl /EHsc /std:c++17 main.cpp /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)" /MACHINE:X64 /SUBSYSTEM:WINDOWS webui-2-static.lib user32.lib Advapi32.lib /OUT:main.exe 1>NUL 2>&1 -# Dynamic Release - @echo Build C++ Example (Release Dynamic)... - @cl /EHsc /std:c++17 main.cpp /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)" /MACHINE:X64 /SUBSYSTEM:WINDOWS webui-2.lib user32.lib Advapi32.lib /OUT:main-dyn.exe 1>NUL 2>&1 -# Clean - @- del *.exp >nul 2>&1 - @- del *.ilk >nul 2>&1 - @- del *.lib >nul 2>&1 - @- del *.obj >nul 2>&1 - @- del *.pdb >nul 2>&1 - @echo Done. - -clean: - - del *.obj >nul 2>&1 - - del *.ilk >nul 2>&1 - - del *.pdb >nul 2>&1 - - del *.exp >nul 2>&1 - - del *.exe >nul 2>&1 - - del *.lib >nul 2>&1 diff --git a/examples/C++/call_js_from_cpp/GNUmakefile b/examples/C++/call_js_from_cpp/GNUmakefile new file mode 100644 index 00000000..fffcb366 --- /dev/null +++ b/examples/C++/call_js_from_cpp/GNUmakefile @@ -0,0 +1,120 @@ +# WebUI C++ Example + +# == 1. VARIABLES ============================================================= + +PROJECT_DIR := $(shell git rev-parse --show-toplevel) +LIB_DIR := $(PROJECT_DIR)/dist +INCLUDE_DIR := $(PROJECT_DIR)/include + +# ARGS +# Set a compiler when running on Linux via `make CC=g++` / `make CC=clang` +CXX = g++ +# Build the WebUI library if running via `make BUILD_LIB=true` +BUILD_LIB ?= + +# BUILD FLAGS +STATIC_BUILD_FLAGS = -std=c++17 -lstdc++ main.cpp -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)" +DYN_BUILD_FLAGS = -std=c++17 -lstdc++ main.cpp -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)" + +# Platform conditions +ifeq ($(OS),Windows_NT) + # Windows + PLATFORM := windows + SHELL := CMD + STATIC_BUILD_FLAGS += -lwebui-2-static -lws2_32 -Wall -Wl,-subsystem=console -luser32 -static + DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.dll" -lws2_32 -Wall -Wl,-subsystem=console -luser32 + STATIC_OUT := main.exe + DYN_OUT := main-dyn.exe + LWS2_OPT := -lws2_32 + STRIP_OPT := --strip-all +else + STATIC_BUILD_FLAGS += -lpthread -lm -lwebui-2-static + DYN_BUILD_FLAGS += -lpthread -lm + STATIC_OUT := main + DYN_OUT := main-dyn + ifeq ($(shell uname),Darwin) + # MacOS + PLATFORM := macos + DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.dylib" + CXX = clang + else + # Linux + PLATFORM := linux + DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.so" + STRIP_OPT := --strip-all + ifeq ($(CXX),clang) + LLVM_OPT := llvm- + endif + endif +endif + +# == 2.TARGETS ================================================================ + +all: release + +debug: LIB_DIR := $(LIB_DIR)/debug +debug: --validate-args +ifeq ($(BUILD_LIB),true) + @cd "$(PROJECT_DIR)" && $(MAKE) debug +endif +# Static with Debug info + @echo "Build C99 Example ($(CXX) debug static)..." + @$(CXX) -g $(STATIC_BUILD_FLAGS) $(LWS2_OPT) -o $(STATIC_OUT) +# Dynamic with Debug info + @echo "Build C99 Example ($(CXX) debug dynamic)..." + @$(CXX) -g $(DYN_BUILD_FLAGS) $(LWS2_OPT) -o $(DYN_OUT) +# Clean +ifeq ($(PLATFORM),windows) + @- del *.o >nul 2>&1 +else + @- rm -f *.o + @- rm -rf *.dSYM # macOS +endif + @echo "Done." + +release: --validate-args +ifeq ($(BUILD_LIB),true) + @cd "$(PROJECT_DIR)" && $(MAKE) +endif +# Static Release + @echo "Build C99 Example ($(CXX) release static)..." + @$(CXX) -Os $(STATIC_BUILD_FLAGS) $(LWS2_OPT) -o $(STATIC_OUT) + @$(LLVM_OPT)strip $(STRIP_OPT) $(STATIC_OUT) +# Dynamic Release + @echo "Build C99 Example ($(CXX) release dynamic)..." + @$(CXX) $(DYN_BUILD_FLAGS) $(LWS2_OPT) -o $(DYN_OUT) + @$(LLVM_OPT)strip $(STRIP_OPT) $(DYN_OUT) +# Clean +ifeq ($(PLATFORM),windows) + @- del *.o >nul 2>&1 +else + @- rm -f *.o + @- rm -rf *.dSYM # macOS +endif + @echo "Done." + +clean: --clean-$(PLATFORM) + +# INTERNAL TARGETS + +--validate-args: +ifneq ($(filter $(CXX),g++ clang),$(CXX)) + $(error Invalid compiler specified: `$(CXX)`) +endif + +--clean-linux: --clean-unix + +--clean-macos: --clean-unix + +--clean-unix: + - rm -f *.o + - rm -f *.a + - rm -f *.so + - rm -f *.dylib + - rm -rf *.dSYM + +--clean-windows: + - del *.o >nul 2>&1 + - del *.dll >nul 2>&1 + - del *.a >nul 2>&1 + - del *.exe >nul 2>&1 diff --git a/examples/C++/call_js_from_cpp/Makefile b/examples/C++/call_js_from_cpp/Makefile index fffcb366..1cdfcb2a 100644 --- a/examples/C++/call_js_from_cpp/Makefile +++ b/examples/C++/call_js_from_cpp/Makefile @@ -1,120 +1,55 @@ # WebUI C++ Example +# Windows - Microsoft Visual C++ -# == 1. VARIABLES ============================================================= +SHELL = CMD +LIB_DIR = ../../../dist +INCLUDE_DIR = ../../../include -PROJECT_DIR := $(shell git rev-parse --show-toplevel) -LIB_DIR := $(PROJECT_DIR)/dist -INCLUDE_DIR := $(PROJECT_DIR)/include - -# ARGS -# Set a compiler when running on Linux via `make CC=g++` / `make CC=clang` -CXX = g++ -# Build the WebUI library if running via `make BUILD_LIB=true` -BUILD_LIB ?= - -# BUILD FLAGS -STATIC_BUILD_FLAGS = -std=c++17 -lstdc++ main.cpp -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)" -DYN_BUILD_FLAGS = -std=c++17 -lstdc++ main.cpp -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)" - -# Platform conditions -ifeq ($(OS),Windows_NT) - # Windows - PLATFORM := windows - SHELL := CMD - STATIC_BUILD_FLAGS += -lwebui-2-static -lws2_32 -Wall -Wl,-subsystem=console -luser32 -static - DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.dll" -lws2_32 -Wall -Wl,-subsystem=console -luser32 - STATIC_OUT := main.exe - DYN_OUT := main-dyn.exe - LWS2_OPT := -lws2_32 - STRIP_OPT := --strip-all -else - STATIC_BUILD_FLAGS += -lpthread -lm -lwebui-2-static - DYN_BUILD_FLAGS += -lpthread -lm - STATIC_OUT := main - DYN_OUT := main-dyn - ifeq ($(shell uname),Darwin) - # MacOS - PLATFORM := macos - DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.dylib" - CXX = clang - else - # Linux - PLATFORM := linux - DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.so" - STRIP_OPT := --strip-all - ifeq ($(CXX),clang) - LLVM_OPT := llvm- - endif - endif -endif - -# == 2.TARGETS ================================================================ +# Build the WebUI library if running `nmake BUILD_LIB=true` +BUILD_LIB = all: release -debug: LIB_DIR := $(LIB_DIR)/debug -debug: --validate-args -ifeq ($(BUILD_LIB),true) - @cd "$(PROJECT_DIR)" && $(MAKE) debug -endif +debug: +!IF "$(BUILD_LIB)" == "true" + @cd "$(LIB_DIR)" && cd .. && $(MAKE) debug +!ENDIF # Static with Debug info - @echo "Build C99 Example ($(CXX) debug static)..." - @$(CXX) -g $(STATIC_BUILD_FLAGS) $(LWS2_OPT) -o $(STATIC_OUT) + @echo Build C++ Example (Debug Static)... + @cl /Zi /EHsc /std:c++17 main.cpp /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)/debug" /MACHINE:X64 /SUBSYSTEM:CONSOLE webui-2-static.lib user32.lib Advapi32.lib /OUT:main.exe 1>NUL 2>&1 # Dynamic with Debug info - @echo "Build C99 Example ($(CXX) debug dynamic)..." - @$(CXX) -g $(DYN_BUILD_FLAGS) $(LWS2_OPT) -o $(DYN_OUT) + @echo Build C++ Example (Debug Dynamic)... + @cl /Zi /EHsc /std:c++17 main.cpp /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)/debug" /MACHINE:X64 /SUBSYSTEM:CONSOLE webui-2.lib user32.lib Advapi32.lib /OUT:main-dyn.exe 1>NUL 2>&1 # Clean -ifeq ($(PLATFORM),windows) - @- del *.o >nul 2>&1 -else - @- rm -f *.o - @- rm -rf *.dSYM # macOS -endif - @echo "Done." + @- del *.exp >nul 2>&1 + @- del *.ilk >nul 2>&1 + @- del *.lib >nul 2>&1 + @- del *.obj >nul 2>&1 + @- del *.pdb >nul 2>&1 + @echo Done. -release: --validate-args -ifeq ($(BUILD_LIB),true) - @cd "$(PROJECT_DIR)" && $(MAKE) -endif +release: +!IF "$(BUILD_LIB)" == "true" + @cd "$(LIB_DIR)" && cd .. && $(MAKE) +!ENDIF # Static Release - @echo "Build C99 Example ($(CXX) release static)..." - @$(CXX) -Os $(STATIC_BUILD_FLAGS) $(LWS2_OPT) -o $(STATIC_OUT) - @$(LLVM_OPT)strip $(STRIP_OPT) $(STATIC_OUT) + @echo Build C++ Example (Release Static)... + @cl /EHsc /std:c++17 main.cpp /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)" /MACHINE:X64 /SUBSYSTEM:WINDOWS webui-2-static.lib user32.lib Advapi32.lib /OUT:main.exe 1>NUL 2>&1 # Dynamic Release - @echo "Build C99 Example ($(CXX) release dynamic)..." - @$(CXX) $(DYN_BUILD_FLAGS) $(LWS2_OPT) -o $(DYN_OUT) - @$(LLVM_OPT)strip $(STRIP_OPT) $(DYN_OUT) + @echo Build C++ Example (Release Dynamic)... + @cl /EHsc /std:c++17 main.cpp /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)" /MACHINE:X64 /SUBSYSTEM:WINDOWS webui-2.lib user32.lib Advapi32.lib /OUT:main-dyn.exe 1>NUL 2>&1 # Clean -ifeq ($(PLATFORM),windows) - @- del *.o >nul 2>&1 -else - @- rm -f *.o - @- rm -rf *.dSYM # macOS -endif - @echo "Done." + @- del *.exp >nul 2>&1 + @- del *.ilk >nul 2>&1 + @- del *.lib >nul 2>&1 + @- del *.obj >nul 2>&1 + @- del *.pdb >nul 2>&1 + @echo Done. -clean: --clean-$(PLATFORM) - -# INTERNAL TARGETS - ---validate-args: -ifneq ($(filter $(CXX),g++ clang),$(CXX)) - $(error Invalid compiler specified: `$(CXX)`) -endif - ---clean-linux: --clean-unix - ---clean-macos: --clean-unix - ---clean-unix: - - rm -f *.o - - rm -f *.a - - rm -f *.so - - rm -f *.dylib - - rm -rf *.dSYM - ---clean-windows: - - del *.o >nul 2>&1 - - del *.dll >nul 2>&1 - - del *.a >nul 2>&1 +clean: + - del *.obj >nul 2>&1 + - del *.ilk >nul 2>&1 + - del *.pdb >nul 2>&1 + - del *.exp >nul 2>&1 - del *.exe >nul 2>&1 + - del *.lib >nul 2>&1 diff --git a/examples/C++/call_js_from_cpp/Makefile.nmake b/examples/C++/call_js_from_cpp/Makefile.nmake deleted file mode 100644 index 2e433a2d..00000000 --- a/examples/C++/call_js_from_cpp/Makefile.nmake +++ /dev/null @@ -1,55 +0,0 @@ -# WebUI C++ Example -# Windows - Microsoft Visual C++ - -SHELL = CMD -LIB_DIR = ../../../dist -INCLUDE_DIR = ../../../include - -# Build the WebUI library if running `nmake -f Makefile.nmake BUILD_LIB=true` -BUILD_LIB = - -all: release - -debug: -!IF "$(BUILD_LIB)" == "true" - @cd "$(LIB_DIR)" && cd .. && $(MAKE) -f Makefile.nmake debug -!ENDIF -# Static with Debug info - @echo Build C++ Example (Debug Static)... - @cl /Zi /EHsc /std:c++17 main.cpp /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)/debug" /MACHINE:X64 /SUBSYSTEM:CONSOLE webui-2-static.lib user32.lib Advapi32.lib /OUT:main.exe 1>NUL 2>&1 -# Dynamic with Debug info - @echo Build C++ Example (Debug Dynamic)... - @cl /Zi /EHsc /std:c++17 main.cpp /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)/debug" /MACHINE:X64 /SUBSYSTEM:CONSOLE webui-2.lib user32.lib Advapi32.lib /OUT:main-dyn.exe 1>NUL 2>&1 -# Clean - @- del *.exp >nul 2>&1 - @- del *.ilk >nul 2>&1 - @- del *.lib >nul 2>&1 - @- del *.obj >nul 2>&1 - @- del *.pdb >nul 2>&1 - @echo Done. - -release: -!IF "$(BUILD_LIB)" == "true" - @cd "$(LIB_DIR)" && cd .. && $(MAKE) -f Makefile.nmake -!ENDIF -# Static Release - @echo Build C++ Example (Release Static)... - @cl /EHsc /std:c++17 main.cpp /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)" /MACHINE:X64 /SUBSYSTEM:WINDOWS webui-2-static.lib user32.lib Advapi32.lib /OUT:main.exe 1>NUL 2>&1 -# Dynamic Release - @echo Build C++ Example (Release Dynamic)... - @cl /EHsc /std:c++17 main.cpp /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)" /MACHINE:X64 /SUBSYSTEM:WINDOWS webui-2.lib user32.lib Advapi32.lib /OUT:main-dyn.exe 1>NUL 2>&1 -# Clean - @- del *.exp >nul 2>&1 - @- del *.ilk >nul 2>&1 - @- del *.lib >nul 2>&1 - @- del *.obj >nul 2>&1 - @- del *.pdb >nul 2>&1 - @echo Done. - -clean: - - del *.obj >nul 2>&1 - - del *.ilk >nul 2>&1 - - del *.pdb >nul 2>&1 - - del *.exp >nul 2>&1 - - del *.exe >nul 2>&1 - - del *.lib >nul 2>&1 diff --git a/examples/C++/minimal/GNUmakefile b/examples/C++/minimal/GNUmakefile new file mode 100644 index 00000000..fffcb366 --- /dev/null +++ b/examples/C++/minimal/GNUmakefile @@ -0,0 +1,120 @@ +# WebUI C++ Example + +# == 1. VARIABLES ============================================================= + +PROJECT_DIR := $(shell git rev-parse --show-toplevel) +LIB_DIR := $(PROJECT_DIR)/dist +INCLUDE_DIR := $(PROJECT_DIR)/include + +# ARGS +# Set a compiler when running on Linux via `make CC=g++` / `make CC=clang` +CXX = g++ +# Build the WebUI library if running via `make BUILD_LIB=true` +BUILD_LIB ?= + +# BUILD FLAGS +STATIC_BUILD_FLAGS = -std=c++17 -lstdc++ main.cpp -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)" +DYN_BUILD_FLAGS = -std=c++17 -lstdc++ main.cpp -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)" + +# Platform conditions +ifeq ($(OS),Windows_NT) + # Windows + PLATFORM := windows + SHELL := CMD + STATIC_BUILD_FLAGS += -lwebui-2-static -lws2_32 -Wall -Wl,-subsystem=console -luser32 -static + DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.dll" -lws2_32 -Wall -Wl,-subsystem=console -luser32 + STATIC_OUT := main.exe + DYN_OUT := main-dyn.exe + LWS2_OPT := -lws2_32 + STRIP_OPT := --strip-all +else + STATIC_BUILD_FLAGS += -lpthread -lm -lwebui-2-static + DYN_BUILD_FLAGS += -lpthread -lm + STATIC_OUT := main + DYN_OUT := main-dyn + ifeq ($(shell uname),Darwin) + # MacOS + PLATFORM := macos + DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.dylib" + CXX = clang + else + # Linux + PLATFORM := linux + DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.so" + STRIP_OPT := --strip-all + ifeq ($(CXX),clang) + LLVM_OPT := llvm- + endif + endif +endif + +# == 2.TARGETS ================================================================ + +all: release + +debug: LIB_DIR := $(LIB_DIR)/debug +debug: --validate-args +ifeq ($(BUILD_LIB),true) + @cd "$(PROJECT_DIR)" && $(MAKE) debug +endif +# Static with Debug info + @echo "Build C99 Example ($(CXX) debug static)..." + @$(CXX) -g $(STATIC_BUILD_FLAGS) $(LWS2_OPT) -o $(STATIC_OUT) +# Dynamic with Debug info + @echo "Build C99 Example ($(CXX) debug dynamic)..." + @$(CXX) -g $(DYN_BUILD_FLAGS) $(LWS2_OPT) -o $(DYN_OUT) +# Clean +ifeq ($(PLATFORM),windows) + @- del *.o >nul 2>&1 +else + @- rm -f *.o + @- rm -rf *.dSYM # macOS +endif + @echo "Done." + +release: --validate-args +ifeq ($(BUILD_LIB),true) + @cd "$(PROJECT_DIR)" && $(MAKE) +endif +# Static Release + @echo "Build C99 Example ($(CXX) release static)..." + @$(CXX) -Os $(STATIC_BUILD_FLAGS) $(LWS2_OPT) -o $(STATIC_OUT) + @$(LLVM_OPT)strip $(STRIP_OPT) $(STATIC_OUT) +# Dynamic Release + @echo "Build C99 Example ($(CXX) release dynamic)..." + @$(CXX) $(DYN_BUILD_FLAGS) $(LWS2_OPT) -o $(DYN_OUT) + @$(LLVM_OPT)strip $(STRIP_OPT) $(DYN_OUT) +# Clean +ifeq ($(PLATFORM),windows) + @- del *.o >nul 2>&1 +else + @- rm -f *.o + @- rm -rf *.dSYM # macOS +endif + @echo "Done." + +clean: --clean-$(PLATFORM) + +# INTERNAL TARGETS + +--validate-args: +ifneq ($(filter $(CXX),g++ clang),$(CXX)) + $(error Invalid compiler specified: `$(CXX)`) +endif + +--clean-linux: --clean-unix + +--clean-macos: --clean-unix + +--clean-unix: + - rm -f *.o + - rm -f *.a + - rm -f *.so + - rm -f *.dylib + - rm -rf *.dSYM + +--clean-windows: + - del *.o >nul 2>&1 + - del *.dll >nul 2>&1 + - del *.a >nul 2>&1 + - del *.exe >nul 2>&1 diff --git a/examples/C++/minimal/Makefile b/examples/C++/minimal/Makefile index fffcb366..1cdfcb2a 100644 --- a/examples/C++/minimal/Makefile +++ b/examples/C++/minimal/Makefile @@ -1,120 +1,55 @@ # WebUI C++ Example +# Windows - Microsoft Visual C++ -# == 1. VARIABLES ============================================================= +SHELL = CMD +LIB_DIR = ../../../dist +INCLUDE_DIR = ../../../include -PROJECT_DIR := $(shell git rev-parse --show-toplevel) -LIB_DIR := $(PROJECT_DIR)/dist -INCLUDE_DIR := $(PROJECT_DIR)/include - -# ARGS -# Set a compiler when running on Linux via `make CC=g++` / `make CC=clang` -CXX = g++ -# Build the WebUI library if running via `make BUILD_LIB=true` -BUILD_LIB ?= - -# BUILD FLAGS -STATIC_BUILD_FLAGS = -std=c++17 -lstdc++ main.cpp -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)" -DYN_BUILD_FLAGS = -std=c++17 -lstdc++ main.cpp -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)" - -# Platform conditions -ifeq ($(OS),Windows_NT) - # Windows - PLATFORM := windows - SHELL := CMD - STATIC_BUILD_FLAGS += -lwebui-2-static -lws2_32 -Wall -Wl,-subsystem=console -luser32 -static - DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.dll" -lws2_32 -Wall -Wl,-subsystem=console -luser32 - STATIC_OUT := main.exe - DYN_OUT := main-dyn.exe - LWS2_OPT := -lws2_32 - STRIP_OPT := --strip-all -else - STATIC_BUILD_FLAGS += -lpthread -lm -lwebui-2-static - DYN_BUILD_FLAGS += -lpthread -lm - STATIC_OUT := main - DYN_OUT := main-dyn - ifeq ($(shell uname),Darwin) - # MacOS - PLATFORM := macos - DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.dylib" - CXX = clang - else - # Linux - PLATFORM := linux - DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.so" - STRIP_OPT := --strip-all - ifeq ($(CXX),clang) - LLVM_OPT := llvm- - endif - endif -endif - -# == 2.TARGETS ================================================================ +# Build the WebUI library if running `nmake BUILD_LIB=true` +BUILD_LIB = all: release -debug: LIB_DIR := $(LIB_DIR)/debug -debug: --validate-args -ifeq ($(BUILD_LIB),true) - @cd "$(PROJECT_DIR)" && $(MAKE) debug -endif +debug: +!IF "$(BUILD_LIB)" == "true" + @cd "$(LIB_DIR)" && cd .. && $(MAKE) debug +!ENDIF # Static with Debug info - @echo "Build C99 Example ($(CXX) debug static)..." - @$(CXX) -g $(STATIC_BUILD_FLAGS) $(LWS2_OPT) -o $(STATIC_OUT) + @echo Build C++ Example (Debug Static)... + @cl /Zi /EHsc /std:c++17 main.cpp /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)/debug" /MACHINE:X64 /SUBSYSTEM:CONSOLE webui-2-static.lib user32.lib Advapi32.lib /OUT:main.exe 1>NUL 2>&1 # Dynamic with Debug info - @echo "Build C99 Example ($(CXX) debug dynamic)..." - @$(CXX) -g $(DYN_BUILD_FLAGS) $(LWS2_OPT) -o $(DYN_OUT) + @echo Build C++ Example (Debug Dynamic)... + @cl /Zi /EHsc /std:c++17 main.cpp /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)/debug" /MACHINE:X64 /SUBSYSTEM:CONSOLE webui-2.lib user32.lib Advapi32.lib /OUT:main-dyn.exe 1>NUL 2>&1 # Clean -ifeq ($(PLATFORM),windows) - @- del *.o >nul 2>&1 -else - @- rm -f *.o - @- rm -rf *.dSYM # macOS -endif - @echo "Done." + @- del *.exp >nul 2>&1 + @- del *.ilk >nul 2>&1 + @- del *.lib >nul 2>&1 + @- del *.obj >nul 2>&1 + @- del *.pdb >nul 2>&1 + @echo Done. -release: --validate-args -ifeq ($(BUILD_LIB),true) - @cd "$(PROJECT_DIR)" && $(MAKE) -endif +release: +!IF "$(BUILD_LIB)" == "true" + @cd "$(LIB_DIR)" && cd .. && $(MAKE) +!ENDIF # Static Release - @echo "Build C99 Example ($(CXX) release static)..." - @$(CXX) -Os $(STATIC_BUILD_FLAGS) $(LWS2_OPT) -o $(STATIC_OUT) - @$(LLVM_OPT)strip $(STRIP_OPT) $(STATIC_OUT) + @echo Build C++ Example (Release Static)... + @cl /EHsc /std:c++17 main.cpp /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)" /MACHINE:X64 /SUBSYSTEM:WINDOWS webui-2-static.lib user32.lib Advapi32.lib /OUT:main.exe 1>NUL 2>&1 # Dynamic Release - @echo "Build C99 Example ($(CXX) release dynamic)..." - @$(CXX) $(DYN_BUILD_FLAGS) $(LWS2_OPT) -o $(DYN_OUT) - @$(LLVM_OPT)strip $(STRIP_OPT) $(DYN_OUT) + @echo Build C++ Example (Release Dynamic)... + @cl /EHsc /std:c++17 main.cpp /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)" /MACHINE:X64 /SUBSYSTEM:WINDOWS webui-2.lib user32.lib Advapi32.lib /OUT:main-dyn.exe 1>NUL 2>&1 # Clean -ifeq ($(PLATFORM),windows) - @- del *.o >nul 2>&1 -else - @- rm -f *.o - @- rm -rf *.dSYM # macOS -endif - @echo "Done." + @- del *.exp >nul 2>&1 + @- del *.ilk >nul 2>&1 + @- del *.lib >nul 2>&1 + @- del *.obj >nul 2>&1 + @- del *.pdb >nul 2>&1 + @echo Done. -clean: --clean-$(PLATFORM) - -# INTERNAL TARGETS - ---validate-args: -ifneq ($(filter $(CXX),g++ clang),$(CXX)) - $(error Invalid compiler specified: `$(CXX)`) -endif - ---clean-linux: --clean-unix - ---clean-macos: --clean-unix - ---clean-unix: - - rm -f *.o - - rm -f *.a - - rm -f *.so - - rm -f *.dylib - - rm -rf *.dSYM - ---clean-windows: - - del *.o >nul 2>&1 - - del *.dll >nul 2>&1 - - del *.a >nul 2>&1 +clean: + - del *.obj >nul 2>&1 + - del *.ilk >nul 2>&1 + - del *.pdb >nul 2>&1 + - del *.exp >nul 2>&1 - del *.exe >nul 2>&1 + - del *.lib >nul 2>&1 diff --git a/examples/C++/minimal/Makefile.nmake b/examples/C++/minimal/Makefile.nmake deleted file mode 100644 index 2e433a2d..00000000 --- a/examples/C++/minimal/Makefile.nmake +++ /dev/null @@ -1,55 +0,0 @@ -# WebUI C++ Example -# Windows - Microsoft Visual C++ - -SHELL = CMD -LIB_DIR = ../../../dist -INCLUDE_DIR = ../../../include - -# Build the WebUI library if running `nmake -f Makefile.nmake BUILD_LIB=true` -BUILD_LIB = - -all: release - -debug: -!IF "$(BUILD_LIB)" == "true" - @cd "$(LIB_DIR)" && cd .. && $(MAKE) -f Makefile.nmake debug -!ENDIF -# Static with Debug info - @echo Build C++ Example (Debug Static)... - @cl /Zi /EHsc /std:c++17 main.cpp /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)/debug" /MACHINE:X64 /SUBSYSTEM:CONSOLE webui-2-static.lib user32.lib Advapi32.lib /OUT:main.exe 1>NUL 2>&1 -# Dynamic with Debug info - @echo Build C++ Example (Debug Dynamic)... - @cl /Zi /EHsc /std:c++17 main.cpp /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)/debug" /MACHINE:X64 /SUBSYSTEM:CONSOLE webui-2.lib user32.lib Advapi32.lib /OUT:main-dyn.exe 1>NUL 2>&1 -# Clean - @- del *.exp >nul 2>&1 - @- del *.ilk >nul 2>&1 - @- del *.lib >nul 2>&1 - @- del *.obj >nul 2>&1 - @- del *.pdb >nul 2>&1 - @echo Done. - -release: -!IF "$(BUILD_LIB)" == "true" - @cd "$(LIB_DIR)" && cd .. && $(MAKE) -f Makefile.nmake -!ENDIF -# Static Release - @echo Build C++ Example (Release Static)... - @cl /EHsc /std:c++17 main.cpp /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)" /MACHINE:X64 /SUBSYSTEM:WINDOWS webui-2-static.lib user32.lib Advapi32.lib /OUT:main.exe 1>NUL 2>&1 -# Dynamic Release - @echo Build C++ Example (Release Dynamic)... - @cl /EHsc /std:c++17 main.cpp /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)" /MACHINE:X64 /SUBSYSTEM:WINDOWS webui-2.lib user32.lib Advapi32.lib /OUT:main-dyn.exe 1>NUL 2>&1 -# Clean - @- del *.exp >nul 2>&1 - @- del *.ilk >nul 2>&1 - @- del *.lib >nul 2>&1 - @- del *.obj >nul 2>&1 - @- del *.pdb >nul 2>&1 - @echo Done. - -clean: - - del *.obj >nul 2>&1 - - del *.ilk >nul 2>&1 - - del *.pdb >nul 2>&1 - - del *.exp >nul 2>&1 - - del *.exe >nul 2>&1 - - del *.lib >nul 2>&1 diff --git a/examples/C++/serve_a_folder/GNUmakefile b/examples/C++/serve_a_folder/GNUmakefile new file mode 100644 index 00000000..fffcb366 --- /dev/null +++ b/examples/C++/serve_a_folder/GNUmakefile @@ -0,0 +1,120 @@ +# WebUI C++ Example + +# == 1. VARIABLES ============================================================= + +PROJECT_DIR := $(shell git rev-parse --show-toplevel) +LIB_DIR := $(PROJECT_DIR)/dist +INCLUDE_DIR := $(PROJECT_DIR)/include + +# ARGS +# Set a compiler when running on Linux via `make CC=g++` / `make CC=clang` +CXX = g++ +# Build the WebUI library if running via `make BUILD_LIB=true` +BUILD_LIB ?= + +# BUILD FLAGS +STATIC_BUILD_FLAGS = -std=c++17 -lstdc++ main.cpp -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)" +DYN_BUILD_FLAGS = -std=c++17 -lstdc++ main.cpp -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)" + +# Platform conditions +ifeq ($(OS),Windows_NT) + # Windows + PLATFORM := windows + SHELL := CMD + STATIC_BUILD_FLAGS += -lwebui-2-static -lws2_32 -Wall -Wl,-subsystem=console -luser32 -static + DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.dll" -lws2_32 -Wall -Wl,-subsystem=console -luser32 + STATIC_OUT := main.exe + DYN_OUT := main-dyn.exe + LWS2_OPT := -lws2_32 + STRIP_OPT := --strip-all +else + STATIC_BUILD_FLAGS += -lpthread -lm -lwebui-2-static + DYN_BUILD_FLAGS += -lpthread -lm + STATIC_OUT := main + DYN_OUT := main-dyn + ifeq ($(shell uname),Darwin) + # MacOS + PLATFORM := macos + DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.dylib" + CXX = clang + else + # Linux + PLATFORM := linux + DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.so" + STRIP_OPT := --strip-all + ifeq ($(CXX),clang) + LLVM_OPT := llvm- + endif + endif +endif + +# == 2.TARGETS ================================================================ + +all: release + +debug: LIB_DIR := $(LIB_DIR)/debug +debug: --validate-args +ifeq ($(BUILD_LIB),true) + @cd "$(PROJECT_DIR)" && $(MAKE) debug +endif +# Static with Debug info + @echo "Build C99 Example ($(CXX) debug static)..." + @$(CXX) -g $(STATIC_BUILD_FLAGS) $(LWS2_OPT) -o $(STATIC_OUT) +# Dynamic with Debug info + @echo "Build C99 Example ($(CXX) debug dynamic)..." + @$(CXX) -g $(DYN_BUILD_FLAGS) $(LWS2_OPT) -o $(DYN_OUT) +# Clean +ifeq ($(PLATFORM),windows) + @- del *.o >nul 2>&1 +else + @- rm -f *.o + @- rm -rf *.dSYM # macOS +endif + @echo "Done." + +release: --validate-args +ifeq ($(BUILD_LIB),true) + @cd "$(PROJECT_DIR)" && $(MAKE) +endif +# Static Release + @echo "Build C99 Example ($(CXX) release static)..." + @$(CXX) -Os $(STATIC_BUILD_FLAGS) $(LWS2_OPT) -o $(STATIC_OUT) + @$(LLVM_OPT)strip $(STRIP_OPT) $(STATIC_OUT) +# Dynamic Release + @echo "Build C99 Example ($(CXX) release dynamic)..." + @$(CXX) $(DYN_BUILD_FLAGS) $(LWS2_OPT) -o $(DYN_OUT) + @$(LLVM_OPT)strip $(STRIP_OPT) $(DYN_OUT) +# Clean +ifeq ($(PLATFORM),windows) + @- del *.o >nul 2>&1 +else + @- rm -f *.o + @- rm -rf *.dSYM # macOS +endif + @echo "Done." + +clean: --clean-$(PLATFORM) + +# INTERNAL TARGETS + +--validate-args: +ifneq ($(filter $(CXX),g++ clang),$(CXX)) + $(error Invalid compiler specified: `$(CXX)`) +endif + +--clean-linux: --clean-unix + +--clean-macos: --clean-unix + +--clean-unix: + - rm -f *.o + - rm -f *.a + - rm -f *.so + - rm -f *.dylib + - rm -rf *.dSYM + +--clean-windows: + - del *.o >nul 2>&1 + - del *.dll >nul 2>&1 + - del *.a >nul 2>&1 + - del *.exe >nul 2>&1 diff --git a/examples/C++/serve_a_folder/Makefile b/examples/C++/serve_a_folder/Makefile index fffcb366..1cdfcb2a 100644 --- a/examples/C++/serve_a_folder/Makefile +++ b/examples/C++/serve_a_folder/Makefile @@ -1,120 +1,55 @@ # WebUI C++ Example +# Windows - Microsoft Visual C++ -# == 1. VARIABLES ============================================================= +SHELL = CMD +LIB_DIR = ../../../dist +INCLUDE_DIR = ../../../include -PROJECT_DIR := $(shell git rev-parse --show-toplevel) -LIB_DIR := $(PROJECT_DIR)/dist -INCLUDE_DIR := $(PROJECT_DIR)/include - -# ARGS -# Set a compiler when running on Linux via `make CC=g++` / `make CC=clang` -CXX = g++ -# Build the WebUI library if running via `make BUILD_LIB=true` -BUILD_LIB ?= - -# BUILD FLAGS -STATIC_BUILD_FLAGS = -std=c++17 -lstdc++ main.cpp -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)" -DYN_BUILD_FLAGS = -std=c++17 -lstdc++ main.cpp -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)" - -# Platform conditions -ifeq ($(OS),Windows_NT) - # Windows - PLATFORM := windows - SHELL := CMD - STATIC_BUILD_FLAGS += -lwebui-2-static -lws2_32 -Wall -Wl,-subsystem=console -luser32 -static - DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.dll" -lws2_32 -Wall -Wl,-subsystem=console -luser32 - STATIC_OUT := main.exe - DYN_OUT := main-dyn.exe - LWS2_OPT := -lws2_32 - STRIP_OPT := --strip-all -else - STATIC_BUILD_FLAGS += -lpthread -lm -lwebui-2-static - DYN_BUILD_FLAGS += -lpthread -lm - STATIC_OUT := main - DYN_OUT := main-dyn - ifeq ($(shell uname),Darwin) - # MacOS - PLATFORM := macos - DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.dylib" - CXX = clang - else - # Linux - PLATFORM := linux - DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.so" - STRIP_OPT := --strip-all - ifeq ($(CXX),clang) - LLVM_OPT := llvm- - endif - endif -endif - -# == 2.TARGETS ================================================================ +# Build the WebUI library if running `nmake BUILD_LIB=true` +BUILD_LIB = all: release -debug: LIB_DIR := $(LIB_DIR)/debug -debug: --validate-args -ifeq ($(BUILD_LIB),true) - @cd "$(PROJECT_DIR)" && $(MAKE) debug -endif +debug: +!IF "$(BUILD_LIB)" == "true" + @cd "$(LIB_DIR)" && cd .. && $(MAKE) debug +!ENDIF # Static with Debug info - @echo "Build C99 Example ($(CXX) debug static)..." - @$(CXX) -g $(STATIC_BUILD_FLAGS) $(LWS2_OPT) -o $(STATIC_OUT) + @echo Build C++ Example (Debug Static)... + @cl /Zi /EHsc /std:c++17 main.cpp /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)/debug" /MACHINE:X64 /SUBSYSTEM:CONSOLE webui-2-static.lib user32.lib Advapi32.lib /OUT:main.exe 1>NUL 2>&1 # Dynamic with Debug info - @echo "Build C99 Example ($(CXX) debug dynamic)..." - @$(CXX) -g $(DYN_BUILD_FLAGS) $(LWS2_OPT) -o $(DYN_OUT) + @echo Build C++ Example (Debug Dynamic)... + @cl /Zi /EHsc /std:c++17 main.cpp /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)/debug" /MACHINE:X64 /SUBSYSTEM:CONSOLE webui-2.lib user32.lib Advapi32.lib /OUT:main-dyn.exe 1>NUL 2>&1 # Clean -ifeq ($(PLATFORM),windows) - @- del *.o >nul 2>&1 -else - @- rm -f *.o - @- rm -rf *.dSYM # macOS -endif - @echo "Done." + @- del *.exp >nul 2>&1 + @- del *.ilk >nul 2>&1 + @- del *.lib >nul 2>&1 + @- del *.obj >nul 2>&1 + @- del *.pdb >nul 2>&1 + @echo Done. -release: --validate-args -ifeq ($(BUILD_LIB),true) - @cd "$(PROJECT_DIR)" && $(MAKE) -endif +release: +!IF "$(BUILD_LIB)" == "true" + @cd "$(LIB_DIR)" && cd .. && $(MAKE) +!ENDIF # Static Release - @echo "Build C99 Example ($(CXX) release static)..." - @$(CXX) -Os $(STATIC_BUILD_FLAGS) $(LWS2_OPT) -o $(STATIC_OUT) - @$(LLVM_OPT)strip $(STRIP_OPT) $(STATIC_OUT) + @echo Build C++ Example (Release Static)... + @cl /EHsc /std:c++17 main.cpp /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)" /MACHINE:X64 /SUBSYSTEM:WINDOWS webui-2-static.lib user32.lib Advapi32.lib /OUT:main.exe 1>NUL 2>&1 # Dynamic Release - @echo "Build C99 Example ($(CXX) release dynamic)..." - @$(CXX) $(DYN_BUILD_FLAGS) $(LWS2_OPT) -o $(DYN_OUT) - @$(LLVM_OPT)strip $(STRIP_OPT) $(DYN_OUT) + @echo Build C++ Example (Release Dynamic)... + @cl /EHsc /std:c++17 main.cpp /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)" /MACHINE:X64 /SUBSYSTEM:WINDOWS webui-2.lib user32.lib Advapi32.lib /OUT:main-dyn.exe 1>NUL 2>&1 # Clean -ifeq ($(PLATFORM),windows) - @- del *.o >nul 2>&1 -else - @- rm -f *.o - @- rm -rf *.dSYM # macOS -endif - @echo "Done." + @- del *.exp >nul 2>&1 + @- del *.ilk >nul 2>&1 + @- del *.lib >nul 2>&1 + @- del *.obj >nul 2>&1 + @- del *.pdb >nul 2>&1 + @echo Done. -clean: --clean-$(PLATFORM) - -# INTERNAL TARGETS - ---validate-args: -ifneq ($(filter $(CXX),g++ clang),$(CXX)) - $(error Invalid compiler specified: `$(CXX)`) -endif - ---clean-linux: --clean-unix - ---clean-macos: --clean-unix - ---clean-unix: - - rm -f *.o - - rm -f *.a - - rm -f *.so - - rm -f *.dylib - - rm -rf *.dSYM - ---clean-windows: - - del *.o >nul 2>&1 - - del *.dll >nul 2>&1 - - del *.a >nul 2>&1 +clean: + - del *.obj >nul 2>&1 + - del *.ilk >nul 2>&1 + - del *.pdb >nul 2>&1 + - del *.exp >nul 2>&1 - del *.exe >nul 2>&1 + - del *.lib >nul 2>&1 diff --git a/examples/C++/serve_a_folder/Makefile.nmake b/examples/C++/serve_a_folder/Makefile.nmake deleted file mode 100644 index 2e433a2d..00000000 --- a/examples/C++/serve_a_folder/Makefile.nmake +++ /dev/null @@ -1,55 +0,0 @@ -# WebUI C++ Example -# Windows - Microsoft Visual C++ - -SHELL = CMD -LIB_DIR = ../../../dist -INCLUDE_DIR = ../../../include - -# Build the WebUI library if running `nmake -f Makefile.nmake BUILD_LIB=true` -BUILD_LIB = - -all: release - -debug: -!IF "$(BUILD_LIB)" == "true" - @cd "$(LIB_DIR)" && cd .. && $(MAKE) -f Makefile.nmake debug -!ENDIF -# Static with Debug info - @echo Build C++ Example (Debug Static)... - @cl /Zi /EHsc /std:c++17 main.cpp /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)/debug" /MACHINE:X64 /SUBSYSTEM:CONSOLE webui-2-static.lib user32.lib Advapi32.lib /OUT:main.exe 1>NUL 2>&1 -# Dynamic with Debug info - @echo Build C++ Example (Debug Dynamic)... - @cl /Zi /EHsc /std:c++17 main.cpp /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)/debug" /MACHINE:X64 /SUBSYSTEM:CONSOLE webui-2.lib user32.lib Advapi32.lib /OUT:main-dyn.exe 1>NUL 2>&1 -# Clean - @- del *.exp >nul 2>&1 - @- del *.ilk >nul 2>&1 - @- del *.lib >nul 2>&1 - @- del *.obj >nul 2>&1 - @- del *.pdb >nul 2>&1 - @echo Done. - -release: -!IF "$(BUILD_LIB)" == "true" - @cd "$(LIB_DIR)" && cd .. && $(MAKE) -f Makefile.nmake -!ENDIF -# Static Release - @echo Build C++ Example (Release Static)... - @cl /EHsc /std:c++17 main.cpp /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)" /MACHINE:X64 /SUBSYSTEM:WINDOWS webui-2-static.lib user32.lib Advapi32.lib /OUT:main.exe 1>NUL 2>&1 -# Dynamic Release - @echo Build C++ Example (Release Dynamic)... - @cl /EHsc /std:c++17 main.cpp /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)" /MACHINE:X64 /SUBSYSTEM:WINDOWS webui-2.lib user32.lib Advapi32.lib /OUT:main-dyn.exe 1>NUL 2>&1 -# Clean - @- del *.exp >nul 2>&1 - @- del *.ilk >nul 2>&1 - @- del *.lib >nul 2>&1 - @- del *.obj >nul 2>&1 - @- del *.pdb >nul 2>&1 - @echo Done. - -clean: - - del *.obj >nul 2>&1 - - del *.ilk >nul 2>&1 - - del *.pdb >nul 2>&1 - - del *.exp >nul 2>&1 - - del *.exe >nul 2>&1 - - del *.lib >nul 2>&1 diff --git a/examples/C/README.md b/examples/C/README.md index f752485f..2f708b56 100644 --- a/examples/C/README.md +++ b/examples/C/README.md @@ -20,7 +20,7 @@ To build an example, cd into its directory and run the make command. mingw32-make # MSVC - nmake -f Makefile.nmake + nmake ``` - **Linux** diff --git a/examples/C/call_c_from_js/GNUmakefile b/examples/C/call_c_from_js/GNUmakefile new file mode 100644 index 00000000..06100a03 --- /dev/null +++ b/examples/C/call_c_from_js/GNUmakefile @@ -0,0 +1,120 @@ +# WebUI C99 Example + +# == 1. VARIABLES ============================================================= + +PROJECT_DIR := $(shell git rev-parse --show-toplevel) +LIB_DIR := $(PROJECT_DIR)/dist +INCLUDE_DIR := $(PROJECT_DIR)/include + +# ARGS +# Set a compiler when running on Linux via `make CC=gcc` / `make CC=clang` +CC = gcc +# Build the WebUI library if running via `make BUILD_LIB=true` +BUILD_LIB ?= + +# BUILD FLAGS +STATIC_BUILD_FLAGS = main.c -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)" +DYN_BUILD_FLAGS = main.c -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)" + +# Platform conditions +ifeq ($(OS),Windows_NT) + # Windows + PLATFORM := windows + SHELL := CMD + STATIC_BUILD_FLAGS += -lwebui-2-static -lws2_32 -Wall -Wl,-subsystem=console -luser32 -static + DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.dll" -lws2_32 -Wall -Wl,-subsystem=console -luser32 + STATIC_OUT := main.exe + DYN_OUT := main-dyn.exe + LWS2_OPT := -lws2_32 + STRIP_OPT := --strip-all +else + STATIC_BUILD_FLAGS += -lpthread -lm -lwebui-2-static + DYN_BUILD_FLAGS += -lpthread -lm + STATIC_OUT := main + DYN_OUT := main-dyn + ifeq ($(shell uname),Darwin) + # MacOS + PLATFORM := macos + CC = clang + DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.dylib" + else + # Linux + PLATFORM := linux + DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.so" + STRIP_OPT := --strip-all + ifeq ($(CC),clang) + LLVM_OPT := llvm- + endif + endif +endif + +# == 2.TARGETS ================================================================ + +all: release + +debug: LIB_DIR := $(LIB_DIR)/debug +debug: --validate-args +ifeq ($(BUILD_LIB),true) + @cd "$(PROJECT_DIR)" && $(MAKE) debug +endif +# Static with Debug info + @echo "Build C99 Example ($(CC) debug static)..." + @$(CC) -g $(STATIC_BUILD_FLAGS) $(LWS2_OPT) -o $(STATIC_OUT) +# Dynamic with Debug info + @echo "Build C99 Example ($(CC) debug dynamic)..." + @$(CC) -g $(DYN_BUILD_FLAGS) $(LWS2_OPT) -o $(DYN_OUT) +# Clean +ifeq ($(PLATFORM),windows) + @- del *.o >nul 2>&1 +else + @- rm -f *.o + @- rm -rf *.dSYM # macOS +endif + @echo "Done." + +release: --validate-args +ifeq ($(BUILD_LIB),true) + @cd "$(PROJECT_DIR)" && $(MAKE) +endif +# Static Release + @echo "Build C99 Example ($(CC) release static)..." + @$(CC) -Os $(STATIC_BUILD_FLAGS) $(LWS2_OPT) -o $(STATIC_OUT) + @$(LLVM_OPT)strip $(STRIP_OPT) $(STATIC_OUT) +# Dynamic Release + @echo "Build C99 Example ($(CC) release dynamic)..." + @$(CC) $(DYN_BUILD_FLAGS) $(LWS2_OPT) -o $(DYN_OUT) + @$(LLVM_OPT)strip $(STRIP_OPT) $(DYN_OUT) +# Clean +ifeq ($(PLATFORM),windows) + @- del *.o >nul 2>&1 +else + @- rm -f *.o + @- rm -rf *.dSYM # macOS +endif + @echo "Done." + +clean: --clean-$(PLATFORM) + +# INTERNAL TARGETS + +--validate-args: +ifneq ($(filter $(CC),gcc clang),$(CC)) + $(error Invalid compiler specified: `$(CC)`) +endif + +--clean-linux: --clean-unix + +--clean-macos: --clean-unix + +--clean-unix: + - rm -f *.o + - rm -f *.a + - rm -f *.so + - rm -f *.dylib + - rm -rf *.dSYM + +--clean-windows: + - del *.o >nul 2>&1 + - del *.dll >nul 2>&1 + - del *.a >nul 2>&1 + - del *.exe >nul 2>&1 diff --git a/examples/C/call_c_from_js/Makefile b/examples/C/call_c_from_js/Makefile index 06100a03..5dcddb7b 100644 --- a/examples/C/call_c_from_js/Makefile +++ b/examples/C/call_c_from_js/Makefile @@ -1,120 +1,55 @@ # WebUI C99 Example +# Windows - Microsoft Visual C -# == 1. VARIABLES ============================================================= +SHELL = CMD +LIB_DIR = ../../../dist +INCLUDE_DIR = ../../../include -PROJECT_DIR := $(shell git rev-parse --show-toplevel) -LIB_DIR := $(PROJECT_DIR)/dist -INCLUDE_DIR := $(PROJECT_DIR)/include - -# ARGS -# Set a compiler when running on Linux via `make CC=gcc` / `make CC=clang` -CC = gcc -# Build the WebUI library if running via `make BUILD_LIB=true` -BUILD_LIB ?= - -# BUILD FLAGS -STATIC_BUILD_FLAGS = main.c -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)" -DYN_BUILD_FLAGS = main.c -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)" - -# Platform conditions -ifeq ($(OS),Windows_NT) - # Windows - PLATFORM := windows - SHELL := CMD - STATIC_BUILD_FLAGS += -lwebui-2-static -lws2_32 -Wall -Wl,-subsystem=console -luser32 -static - DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.dll" -lws2_32 -Wall -Wl,-subsystem=console -luser32 - STATIC_OUT := main.exe - DYN_OUT := main-dyn.exe - LWS2_OPT := -lws2_32 - STRIP_OPT := --strip-all -else - STATIC_BUILD_FLAGS += -lpthread -lm -lwebui-2-static - DYN_BUILD_FLAGS += -lpthread -lm - STATIC_OUT := main - DYN_OUT := main-dyn - ifeq ($(shell uname),Darwin) - # MacOS - PLATFORM := macos - CC = clang - DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.dylib" - else - # Linux - PLATFORM := linux - DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.so" - STRIP_OPT := --strip-all - ifeq ($(CC),clang) - LLVM_OPT := llvm- - endif - endif -endif - -# == 2.TARGETS ================================================================ +# Build the WebUI library if running `nmake BUILD_LIB=true` +BUILD_LIB = all: release -debug: LIB_DIR := $(LIB_DIR)/debug -debug: --validate-args -ifeq ($(BUILD_LIB),true) - @cd "$(PROJECT_DIR)" && $(MAKE) debug -endif +debug: +!IF "$(BUILD_LIB)" == "true" + @cd "$(LIB_DIR)" && cd .. && $(MAKE) debug +!ENDIF # Static with Debug info - @echo "Build C99 Example ($(CC) debug static)..." - @$(CC) -g $(STATIC_BUILD_FLAGS) $(LWS2_OPT) -o $(STATIC_OUT) + @echo Build C99 Example (Static Debug)... + @cl /Zi main.c /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)/debug" /MACHINE:X64 /SUBSYSTEM:CONSOLE webui-2-static.lib user32.lib Advapi32.lib /OUT:main.exe 1>NUL 2>&1 # Dynamic with Debug info - @echo "Build C99 Example ($(CC) debug dynamic)..." - @$(CC) -g $(DYN_BUILD_FLAGS) $(LWS2_OPT) -o $(DYN_OUT) + @echo Build C99 Example (Dynamic Debug)... + @cl /Zi main.c /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)/debug" /MACHINE:X64 /SUBSYSTEM:CONSOLE webui-2.lib user32.lib Advapi32.lib /OUT:main-dyn.exe 1>NUL 2>&1 # Clean -ifeq ($(PLATFORM),windows) - @- del *.o >nul 2>&1 -else - @- rm -f *.o - @- rm -rf *.dSYM # macOS -endif - @echo "Done." + @- del *.exp >nul 2>&1 + @- del *.ilk >nul 2>&1 + @- del *.lib >nul 2>&1 + @- del *.obj >nul 2>&1 + @- del *.pdb >nul 2>&1 + @echo Done. -release: --validate-args -ifeq ($(BUILD_LIB),true) - @cd "$(PROJECT_DIR)" && $(MAKE) -endif +release: +!IF "$(BUILD_LIB)" == "true" + @cd "$(LIB_DIR)" && cd .. && $(MAKE) +!ENDIF # Static Release - @echo "Build C99 Example ($(CC) release static)..." - @$(CC) -Os $(STATIC_BUILD_FLAGS) $(LWS2_OPT) -o $(STATIC_OUT) - @$(LLVM_OPT)strip $(STRIP_OPT) $(STATIC_OUT) + @echo Build C99 Example (Static Release)... + @cl main.c /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)" /MACHINE:X64 /SUBSYSTEM:WINDOWS webui-2-static.lib user32.lib Advapi32.lib /OUT:main.exe 1>NUL 2>&1 # Dynamic Release - @echo "Build C99 Example ($(CC) release dynamic)..." - @$(CC) $(DYN_BUILD_FLAGS) $(LWS2_OPT) -o $(DYN_OUT) - @$(LLVM_OPT)strip $(STRIP_OPT) $(DYN_OUT) + @echo Build C99 Example (Dynamic Release)... + @cl main.c /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)" /MACHINE:X64 /SUBSYSTEM:WINDOWS webui-2.lib user32.lib Advapi32.lib /OUT:main-dyn.exe 1>NUL 2>&1 # Clean -ifeq ($(PLATFORM),windows) - @- del *.o >nul 2>&1 -else - @- rm -f *.o - @- rm -rf *.dSYM # macOS -endif - @echo "Done." + @- del *.exp >nul 2>&1 + @- del *.ilk >nul 2>&1 + @- del *.lib >nul 2>&1 + @- del *.obj >nul 2>&1 + @- del *.pdb >nul 2>&1 + @echo Done. -clean: --clean-$(PLATFORM) - -# INTERNAL TARGETS - ---validate-args: -ifneq ($(filter $(CC),gcc clang),$(CC)) - $(error Invalid compiler specified: `$(CC)`) -endif - ---clean-linux: --clean-unix - ---clean-macos: --clean-unix - ---clean-unix: - - rm -f *.o - - rm -f *.a - - rm -f *.so - - rm -f *.dylib - - rm -rf *.dSYM - ---clean-windows: - - del *.o >nul 2>&1 - - del *.dll >nul 2>&1 - - del *.a >nul 2>&1 +clean: + - del *.obj >nul 2>&1 + - del *.ilk >nul 2>&1 + - del *.pdb >nul 2>&1 + - del *.exp >nul 2>&1 - del *.exe >nul 2>&1 + - del *.lib >nul 2>&1 diff --git a/examples/C/call_c_from_js/Makefile.nmake b/examples/C/call_c_from_js/Makefile.nmake deleted file mode 100644 index 9794e26f..00000000 --- a/examples/C/call_c_from_js/Makefile.nmake +++ /dev/null @@ -1,55 +0,0 @@ -# WebUI C99 Example -# Windows - Microsoft Visual C - -SHELL = CMD -LIB_DIR = ../../../dist -INCLUDE_DIR = ../../../include - -# Build the WebUI library if running `nmake -f Makefile.nmake BUILD_LIB=true` -BUILD_LIB = - -all: release - -debug: -!IF "$(BUILD_LIB)" == "true" - @cd "$(LIB_DIR)" && cd .. && $(MAKE) -f Makefile.nmake debug -!ENDIF -# Static with Debug info - @echo Build C99 Example (Static Debug)... - @cl /Zi main.c /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)/debug" /MACHINE:X64 /SUBSYSTEM:CONSOLE webui-2-static.lib user32.lib Advapi32.lib /OUT:main.exe 1>NUL 2>&1 -# Dynamic with Debug info - @echo Build C99 Example (Dynamic Debug)... - @cl /Zi main.c /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)/debug" /MACHINE:X64 /SUBSYSTEM:CONSOLE webui-2.lib user32.lib Advapi32.lib /OUT:main-dyn.exe 1>NUL 2>&1 -# Clean - @- del *.exp >nul 2>&1 - @- del *.ilk >nul 2>&1 - @- del *.lib >nul 2>&1 - @- del *.obj >nul 2>&1 - @- del *.pdb >nul 2>&1 - @echo Done. - -release: -!IF "$(BUILD_LIB)" == "true" - @cd "$(LIB_DIR)" && cd .. && $(MAKE) -f Makefile.nmake -!ENDIF -# Static Release - @echo Build C99 Example (Static Release)... - @cl main.c /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)" /MACHINE:X64 /SUBSYSTEM:WINDOWS webui-2-static.lib user32.lib Advapi32.lib /OUT:main.exe 1>NUL 2>&1 -# Dynamic Release - @echo Build C99 Example (Dynamic Release)... - @cl main.c /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)" /MACHINE:X64 /SUBSYSTEM:WINDOWS webui-2.lib user32.lib Advapi32.lib /OUT:main-dyn.exe 1>NUL 2>&1 -# Clean - @- del *.exp >nul 2>&1 - @- del *.ilk >nul 2>&1 - @- del *.lib >nul 2>&1 - @- del *.obj >nul 2>&1 - @- del *.pdb >nul 2>&1 - @echo Done. - -clean: - - del *.obj >nul 2>&1 - - del *.ilk >nul 2>&1 - - del *.pdb >nul 2>&1 - - del *.exp >nul 2>&1 - - del *.exe >nul 2>&1 - - del *.lib >nul 2>&1 diff --git a/examples/C/call_js_from_c/GNUmakefile b/examples/C/call_js_from_c/GNUmakefile new file mode 100644 index 00000000..06100a03 --- /dev/null +++ b/examples/C/call_js_from_c/GNUmakefile @@ -0,0 +1,120 @@ +# WebUI C99 Example + +# == 1. VARIABLES ============================================================= + +PROJECT_DIR := $(shell git rev-parse --show-toplevel) +LIB_DIR := $(PROJECT_DIR)/dist +INCLUDE_DIR := $(PROJECT_DIR)/include + +# ARGS +# Set a compiler when running on Linux via `make CC=gcc` / `make CC=clang` +CC = gcc +# Build the WebUI library if running via `make BUILD_LIB=true` +BUILD_LIB ?= + +# BUILD FLAGS +STATIC_BUILD_FLAGS = main.c -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)" +DYN_BUILD_FLAGS = main.c -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)" + +# Platform conditions +ifeq ($(OS),Windows_NT) + # Windows + PLATFORM := windows + SHELL := CMD + STATIC_BUILD_FLAGS += -lwebui-2-static -lws2_32 -Wall -Wl,-subsystem=console -luser32 -static + DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.dll" -lws2_32 -Wall -Wl,-subsystem=console -luser32 + STATIC_OUT := main.exe + DYN_OUT := main-dyn.exe + LWS2_OPT := -lws2_32 + STRIP_OPT := --strip-all +else + STATIC_BUILD_FLAGS += -lpthread -lm -lwebui-2-static + DYN_BUILD_FLAGS += -lpthread -lm + STATIC_OUT := main + DYN_OUT := main-dyn + ifeq ($(shell uname),Darwin) + # MacOS + PLATFORM := macos + CC = clang + DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.dylib" + else + # Linux + PLATFORM := linux + DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.so" + STRIP_OPT := --strip-all + ifeq ($(CC),clang) + LLVM_OPT := llvm- + endif + endif +endif + +# == 2.TARGETS ================================================================ + +all: release + +debug: LIB_DIR := $(LIB_DIR)/debug +debug: --validate-args +ifeq ($(BUILD_LIB),true) + @cd "$(PROJECT_DIR)" && $(MAKE) debug +endif +# Static with Debug info + @echo "Build C99 Example ($(CC) debug static)..." + @$(CC) -g $(STATIC_BUILD_FLAGS) $(LWS2_OPT) -o $(STATIC_OUT) +# Dynamic with Debug info + @echo "Build C99 Example ($(CC) debug dynamic)..." + @$(CC) -g $(DYN_BUILD_FLAGS) $(LWS2_OPT) -o $(DYN_OUT) +# Clean +ifeq ($(PLATFORM),windows) + @- del *.o >nul 2>&1 +else + @- rm -f *.o + @- rm -rf *.dSYM # macOS +endif + @echo "Done." + +release: --validate-args +ifeq ($(BUILD_LIB),true) + @cd "$(PROJECT_DIR)" && $(MAKE) +endif +# Static Release + @echo "Build C99 Example ($(CC) release static)..." + @$(CC) -Os $(STATIC_BUILD_FLAGS) $(LWS2_OPT) -o $(STATIC_OUT) + @$(LLVM_OPT)strip $(STRIP_OPT) $(STATIC_OUT) +# Dynamic Release + @echo "Build C99 Example ($(CC) release dynamic)..." + @$(CC) $(DYN_BUILD_FLAGS) $(LWS2_OPT) -o $(DYN_OUT) + @$(LLVM_OPT)strip $(STRIP_OPT) $(DYN_OUT) +# Clean +ifeq ($(PLATFORM),windows) + @- del *.o >nul 2>&1 +else + @- rm -f *.o + @- rm -rf *.dSYM # macOS +endif + @echo "Done." + +clean: --clean-$(PLATFORM) + +# INTERNAL TARGETS + +--validate-args: +ifneq ($(filter $(CC),gcc clang),$(CC)) + $(error Invalid compiler specified: `$(CC)`) +endif + +--clean-linux: --clean-unix + +--clean-macos: --clean-unix + +--clean-unix: + - rm -f *.o + - rm -f *.a + - rm -f *.so + - rm -f *.dylib + - rm -rf *.dSYM + +--clean-windows: + - del *.o >nul 2>&1 + - del *.dll >nul 2>&1 + - del *.a >nul 2>&1 + - del *.exe >nul 2>&1 diff --git a/examples/C/call_js_from_c/Makefile b/examples/C/call_js_from_c/Makefile index 06100a03..5dcddb7b 100644 --- a/examples/C/call_js_from_c/Makefile +++ b/examples/C/call_js_from_c/Makefile @@ -1,120 +1,55 @@ # WebUI C99 Example +# Windows - Microsoft Visual C -# == 1. VARIABLES ============================================================= +SHELL = CMD +LIB_DIR = ../../../dist +INCLUDE_DIR = ../../../include -PROJECT_DIR := $(shell git rev-parse --show-toplevel) -LIB_DIR := $(PROJECT_DIR)/dist -INCLUDE_DIR := $(PROJECT_DIR)/include - -# ARGS -# Set a compiler when running on Linux via `make CC=gcc` / `make CC=clang` -CC = gcc -# Build the WebUI library if running via `make BUILD_LIB=true` -BUILD_LIB ?= - -# BUILD FLAGS -STATIC_BUILD_FLAGS = main.c -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)" -DYN_BUILD_FLAGS = main.c -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)" - -# Platform conditions -ifeq ($(OS),Windows_NT) - # Windows - PLATFORM := windows - SHELL := CMD - STATIC_BUILD_FLAGS += -lwebui-2-static -lws2_32 -Wall -Wl,-subsystem=console -luser32 -static - DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.dll" -lws2_32 -Wall -Wl,-subsystem=console -luser32 - STATIC_OUT := main.exe - DYN_OUT := main-dyn.exe - LWS2_OPT := -lws2_32 - STRIP_OPT := --strip-all -else - STATIC_BUILD_FLAGS += -lpthread -lm -lwebui-2-static - DYN_BUILD_FLAGS += -lpthread -lm - STATIC_OUT := main - DYN_OUT := main-dyn - ifeq ($(shell uname),Darwin) - # MacOS - PLATFORM := macos - CC = clang - DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.dylib" - else - # Linux - PLATFORM := linux - DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.so" - STRIP_OPT := --strip-all - ifeq ($(CC),clang) - LLVM_OPT := llvm- - endif - endif -endif - -# == 2.TARGETS ================================================================ +# Build the WebUI library if running `nmake BUILD_LIB=true` +BUILD_LIB = all: release -debug: LIB_DIR := $(LIB_DIR)/debug -debug: --validate-args -ifeq ($(BUILD_LIB),true) - @cd "$(PROJECT_DIR)" && $(MAKE) debug -endif +debug: +!IF "$(BUILD_LIB)" == "true" + @cd "$(LIB_DIR)" && cd .. && $(MAKE) debug +!ENDIF # Static with Debug info - @echo "Build C99 Example ($(CC) debug static)..." - @$(CC) -g $(STATIC_BUILD_FLAGS) $(LWS2_OPT) -o $(STATIC_OUT) + @echo Build C99 Example (Static Debug)... + @cl /Zi main.c /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)/debug" /MACHINE:X64 /SUBSYSTEM:CONSOLE webui-2-static.lib user32.lib Advapi32.lib /OUT:main.exe 1>NUL 2>&1 # Dynamic with Debug info - @echo "Build C99 Example ($(CC) debug dynamic)..." - @$(CC) -g $(DYN_BUILD_FLAGS) $(LWS2_OPT) -o $(DYN_OUT) + @echo Build C99 Example (Dynamic Debug)... + @cl /Zi main.c /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)/debug" /MACHINE:X64 /SUBSYSTEM:CONSOLE webui-2.lib user32.lib Advapi32.lib /OUT:main-dyn.exe 1>NUL 2>&1 # Clean -ifeq ($(PLATFORM),windows) - @- del *.o >nul 2>&1 -else - @- rm -f *.o - @- rm -rf *.dSYM # macOS -endif - @echo "Done." + @- del *.exp >nul 2>&1 + @- del *.ilk >nul 2>&1 + @- del *.lib >nul 2>&1 + @- del *.obj >nul 2>&1 + @- del *.pdb >nul 2>&1 + @echo Done. -release: --validate-args -ifeq ($(BUILD_LIB),true) - @cd "$(PROJECT_DIR)" && $(MAKE) -endif +release: +!IF "$(BUILD_LIB)" == "true" + @cd "$(LIB_DIR)" && cd .. && $(MAKE) +!ENDIF # Static Release - @echo "Build C99 Example ($(CC) release static)..." - @$(CC) -Os $(STATIC_BUILD_FLAGS) $(LWS2_OPT) -o $(STATIC_OUT) - @$(LLVM_OPT)strip $(STRIP_OPT) $(STATIC_OUT) + @echo Build C99 Example (Static Release)... + @cl main.c /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)" /MACHINE:X64 /SUBSYSTEM:WINDOWS webui-2-static.lib user32.lib Advapi32.lib /OUT:main.exe 1>NUL 2>&1 # Dynamic Release - @echo "Build C99 Example ($(CC) release dynamic)..." - @$(CC) $(DYN_BUILD_FLAGS) $(LWS2_OPT) -o $(DYN_OUT) - @$(LLVM_OPT)strip $(STRIP_OPT) $(DYN_OUT) + @echo Build C99 Example (Dynamic Release)... + @cl main.c /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)" /MACHINE:X64 /SUBSYSTEM:WINDOWS webui-2.lib user32.lib Advapi32.lib /OUT:main-dyn.exe 1>NUL 2>&1 # Clean -ifeq ($(PLATFORM),windows) - @- del *.o >nul 2>&1 -else - @- rm -f *.o - @- rm -rf *.dSYM # macOS -endif - @echo "Done." + @- del *.exp >nul 2>&1 + @- del *.ilk >nul 2>&1 + @- del *.lib >nul 2>&1 + @- del *.obj >nul 2>&1 + @- del *.pdb >nul 2>&1 + @echo Done. -clean: --clean-$(PLATFORM) - -# INTERNAL TARGETS - ---validate-args: -ifneq ($(filter $(CC),gcc clang),$(CC)) - $(error Invalid compiler specified: `$(CC)`) -endif - ---clean-linux: --clean-unix - ---clean-macos: --clean-unix - ---clean-unix: - - rm -f *.o - - rm -f *.a - - rm -f *.so - - rm -f *.dylib - - rm -rf *.dSYM - ---clean-windows: - - del *.o >nul 2>&1 - - del *.dll >nul 2>&1 - - del *.a >nul 2>&1 +clean: + - del *.obj >nul 2>&1 + - del *.ilk >nul 2>&1 + - del *.pdb >nul 2>&1 + - del *.exp >nul 2>&1 - del *.exe >nul 2>&1 + - del *.lib >nul 2>&1 diff --git a/examples/C/call_js_from_c/Makefile.nmake b/examples/C/call_js_from_c/Makefile.nmake deleted file mode 100644 index 9794e26f..00000000 --- a/examples/C/call_js_from_c/Makefile.nmake +++ /dev/null @@ -1,55 +0,0 @@ -# WebUI C99 Example -# Windows - Microsoft Visual C - -SHELL = CMD -LIB_DIR = ../../../dist -INCLUDE_DIR = ../../../include - -# Build the WebUI library if running `nmake -f Makefile.nmake BUILD_LIB=true` -BUILD_LIB = - -all: release - -debug: -!IF "$(BUILD_LIB)" == "true" - @cd "$(LIB_DIR)" && cd .. && $(MAKE) -f Makefile.nmake debug -!ENDIF -# Static with Debug info - @echo Build C99 Example (Static Debug)... - @cl /Zi main.c /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)/debug" /MACHINE:X64 /SUBSYSTEM:CONSOLE webui-2-static.lib user32.lib Advapi32.lib /OUT:main.exe 1>NUL 2>&1 -# Dynamic with Debug info - @echo Build C99 Example (Dynamic Debug)... - @cl /Zi main.c /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)/debug" /MACHINE:X64 /SUBSYSTEM:CONSOLE webui-2.lib user32.lib Advapi32.lib /OUT:main-dyn.exe 1>NUL 2>&1 -# Clean - @- del *.exp >nul 2>&1 - @- del *.ilk >nul 2>&1 - @- del *.lib >nul 2>&1 - @- del *.obj >nul 2>&1 - @- del *.pdb >nul 2>&1 - @echo Done. - -release: -!IF "$(BUILD_LIB)" == "true" - @cd "$(LIB_DIR)" && cd .. && $(MAKE) -f Makefile.nmake -!ENDIF -# Static Release - @echo Build C99 Example (Static Release)... - @cl main.c /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)" /MACHINE:X64 /SUBSYSTEM:WINDOWS webui-2-static.lib user32.lib Advapi32.lib /OUT:main.exe 1>NUL 2>&1 -# Dynamic Release - @echo Build C99 Example (Dynamic Release)... - @cl main.c /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)" /MACHINE:X64 /SUBSYSTEM:WINDOWS webui-2.lib user32.lib Advapi32.lib /OUT:main-dyn.exe 1>NUL 2>&1 -# Clean - @- del *.exp >nul 2>&1 - @- del *.ilk >nul 2>&1 - @- del *.lib >nul 2>&1 - @- del *.obj >nul 2>&1 - @- del *.pdb >nul 2>&1 - @echo Done. - -clean: - - del *.obj >nul 2>&1 - - del *.ilk >nul 2>&1 - - del *.pdb >nul 2>&1 - - del *.exp >nul 2>&1 - - del *.exe >nul 2>&1 - - del *.lib >nul 2>&1 diff --git a/examples/C/minimal/GNUmakefile b/examples/C/minimal/GNUmakefile new file mode 100644 index 00000000..06100a03 --- /dev/null +++ b/examples/C/minimal/GNUmakefile @@ -0,0 +1,120 @@ +# WebUI C99 Example + +# == 1. VARIABLES ============================================================= + +PROJECT_DIR := $(shell git rev-parse --show-toplevel) +LIB_DIR := $(PROJECT_DIR)/dist +INCLUDE_DIR := $(PROJECT_DIR)/include + +# ARGS +# Set a compiler when running on Linux via `make CC=gcc` / `make CC=clang` +CC = gcc +# Build the WebUI library if running via `make BUILD_LIB=true` +BUILD_LIB ?= + +# BUILD FLAGS +STATIC_BUILD_FLAGS = main.c -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)" +DYN_BUILD_FLAGS = main.c -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)" + +# Platform conditions +ifeq ($(OS),Windows_NT) + # Windows + PLATFORM := windows + SHELL := CMD + STATIC_BUILD_FLAGS += -lwebui-2-static -lws2_32 -Wall -Wl,-subsystem=console -luser32 -static + DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.dll" -lws2_32 -Wall -Wl,-subsystem=console -luser32 + STATIC_OUT := main.exe + DYN_OUT := main-dyn.exe + LWS2_OPT := -lws2_32 + STRIP_OPT := --strip-all +else + STATIC_BUILD_FLAGS += -lpthread -lm -lwebui-2-static + DYN_BUILD_FLAGS += -lpthread -lm + STATIC_OUT := main + DYN_OUT := main-dyn + ifeq ($(shell uname),Darwin) + # MacOS + PLATFORM := macos + CC = clang + DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.dylib" + else + # Linux + PLATFORM := linux + DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.so" + STRIP_OPT := --strip-all + ifeq ($(CC),clang) + LLVM_OPT := llvm- + endif + endif +endif + +# == 2.TARGETS ================================================================ + +all: release + +debug: LIB_DIR := $(LIB_DIR)/debug +debug: --validate-args +ifeq ($(BUILD_LIB),true) + @cd "$(PROJECT_DIR)" && $(MAKE) debug +endif +# Static with Debug info + @echo "Build C99 Example ($(CC) debug static)..." + @$(CC) -g $(STATIC_BUILD_FLAGS) $(LWS2_OPT) -o $(STATIC_OUT) +# Dynamic with Debug info + @echo "Build C99 Example ($(CC) debug dynamic)..." + @$(CC) -g $(DYN_BUILD_FLAGS) $(LWS2_OPT) -o $(DYN_OUT) +# Clean +ifeq ($(PLATFORM),windows) + @- del *.o >nul 2>&1 +else + @- rm -f *.o + @- rm -rf *.dSYM # macOS +endif + @echo "Done." + +release: --validate-args +ifeq ($(BUILD_LIB),true) + @cd "$(PROJECT_DIR)" && $(MAKE) +endif +# Static Release + @echo "Build C99 Example ($(CC) release static)..." + @$(CC) -Os $(STATIC_BUILD_FLAGS) $(LWS2_OPT) -o $(STATIC_OUT) + @$(LLVM_OPT)strip $(STRIP_OPT) $(STATIC_OUT) +# Dynamic Release + @echo "Build C99 Example ($(CC) release dynamic)..." + @$(CC) $(DYN_BUILD_FLAGS) $(LWS2_OPT) -o $(DYN_OUT) + @$(LLVM_OPT)strip $(STRIP_OPT) $(DYN_OUT) +# Clean +ifeq ($(PLATFORM),windows) + @- del *.o >nul 2>&1 +else + @- rm -f *.o + @- rm -rf *.dSYM # macOS +endif + @echo "Done." + +clean: --clean-$(PLATFORM) + +# INTERNAL TARGETS + +--validate-args: +ifneq ($(filter $(CC),gcc clang),$(CC)) + $(error Invalid compiler specified: `$(CC)`) +endif + +--clean-linux: --clean-unix + +--clean-macos: --clean-unix + +--clean-unix: + - rm -f *.o + - rm -f *.a + - rm -f *.so + - rm -f *.dylib + - rm -rf *.dSYM + +--clean-windows: + - del *.o >nul 2>&1 + - del *.dll >nul 2>&1 + - del *.a >nul 2>&1 + - del *.exe >nul 2>&1 diff --git a/examples/C/minimal/Makefile b/examples/C/minimal/Makefile index 06100a03..5dcddb7b 100644 --- a/examples/C/minimal/Makefile +++ b/examples/C/minimal/Makefile @@ -1,120 +1,55 @@ # WebUI C99 Example +# Windows - Microsoft Visual C -# == 1. VARIABLES ============================================================= +SHELL = CMD +LIB_DIR = ../../../dist +INCLUDE_DIR = ../../../include -PROJECT_DIR := $(shell git rev-parse --show-toplevel) -LIB_DIR := $(PROJECT_DIR)/dist -INCLUDE_DIR := $(PROJECT_DIR)/include - -# ARGS -# Set a compiler when running on Linux via `make CC=gcc` / `make CC=clang` -CC = gcc -# Build the WebUI library if running via `make BUILD_LIB=true` -BUILD_LIB ?= - -# BUILD FLAGS -STATIC_BUILD_FLAGS = main.c -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)" -DYN_BUILD_FLAGS = main.c -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)" - -# Platform conditions -ifeq ($(OS),Windows_NT) - # Windows - PLATFORM := windows - SHELL := CMD - STATIC_BUILD_FLAGS += -lwebui-2-static -lws2_32 -Wall -Wl,-subsystem=console -luser32 -static - DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.dll" -lws2_32 -Wall -Wl,-subsystem=console -luser32 - STATIC_OUT := main.exe - DYN_OUT := main-dyn.exe - LWS2_OPT := -lws2_32 - STRIP_OPT := --strip-all -else - STATIC_BUILD_FLAGS += -lpthread -lm -lwebui-2-static - DYN_BUILD_FLAGS += -lpthread -lm - STATIC_OUT := main - DYN_OUT := main-dyn - ifeq ($(shell uname),Darwin) - # MacOS - PLATFORM := macos - CC = clang - DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.dylib" - else - # Linux - PLATFORM := linux - DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.so" - STRIP_OPT := --strip-all - ifeq ($(CC),clang) - LLVM_OPT := llvm- - endif - endif -endif - -# == 2.TARGETS ================================================================ +# Build the WebUI library if running `nmake BUILD_LIB=true` +BUILD_LIB = all: release -debug: LIB_DIR := $(LIB_DIR)/debug -debug: --validate-args -ifeq ($(BUILD_LIB),true) - @cd "$(PROJECT_DIR)" && $(MAKE) debug -endif +debug: +!IF "$(BUILD_LIB)" == "true" + @cd "$(LIB_DIR)" && cd .. && $(MAKE) debug +!ENDIF # Static with Debug info - @echo "Build C99 Example ($(CC) debug static)..." - @$(CC) -g $(STATIC_BUILD_FLAGS) $(LWS2_OPT) -o $(STATIC_OUT) + @echo Build C99 Example (Static Debug)... + @cl /Zi main.c /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)/debug" /MACHINE:X64 /SUBSYSTEM:CONSOLE webui-2-static.lib user32.lib Advapi32.lib /OUT:main.exe 1>NUL 2>&1 # Dynamic with Debug info - @echo "Build C99 Example ($(CC) debug dynamic)..." - @$(CC) -g $(DYN_BUILD_FLAGS) $(LWS2_OPT) -o $(DYN_OUT) + @echo Build C99 Example (Dynamic Debug)... + @cl /Zi main.c /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)/debug" /MACHINE:X64 /SUBSYSTEM:CONSOLE webui-2.lib user32.lib Advapi32.lib /OUT:main-dyn.exe 1>NUL 2>&1 # Clean -ifeq ($(PLATFORM),windows) - @- del *.o >nul 2>&1 -else - @- rm -f *.o - @- rm -rf *.dSYM # macOS -endif - @echo "Done." + @- del *.exp >nul 2>&1 + @- del *.ilk >nul 2>&1 + @- del *.lib >nul 2>&1 + @- del *.obj >nul 2>&1 + @- del *.pdb >nul 2>&1 + @echo Done. -release: --validate-args -ifeq ($(BUILD_LIB),true) - @cd "$(PROJECT_DIR)" && $(MAKE) -endif +release: +!IF "$(BUILD_LIB)" == "true" + @cd "$(LIB_DIR)" && cd .. && $(MAKE) +!ENDIF # Static Release - @echo "Build C99 Example ($(CC) release static)..." - @$(CC) -Os $(STATIC_BUILD_FLAGS) $(LWS2_OPT) -o $(STATIC_OUT) - @$(LLVM_OPT)strip $(STRIP_OPT) $(STATIC_OUT) + @echo Build C99 Example (Static Release)... + @cl main.c /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)" /MACHINE:X64 /SUBSYSTEM:WINDOWS webui-2-static.lib user32.lib Advapi32.lib /OUT:main.exe 1>NUL 2>&1 # Dynamic Release - @echo "Build C99 Example ($(CC) release dynamic)..." - @$(CC) $(DYN_BUILD_FLAGS) $(LWS2_OPT) -o $(DYN_OUT) - @$(LLVM_OPT)strip $(STRIP_OPT) $(DYN_OUT) + @echo Build C99 Example (Dynamic Release)... + @cl main.c /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)" /MACHINE:X64 /SUBSYSTEM:WINDOWS webui-2.lib user32.lib Advapi32.lib /OUT:main-dyn.exe 1>NUL 2>&1 # Clean -ifeq ($(PLATFORM),windows) - @- del *.o >nul 2>&1 -else - @- rm -f *.o - @- rm -rf *.dSYM # macOS -endif - @echo "Done." + @- del *.exp >nul 2>&1 + @- del *.ilk >nul 2>&1 + @- del *.lib >nul 2>&1 + @- del *.obj >nul 2>&1 + @- del *.pdb >nul 2>&1 + @echo Done. -clean: --clean-$(PLATFORM) - -# INTERNAL TARGETS - ---validate-args: -ifneq ($(filter $(CC),gcc clang),$(CC)) - $(error Invalid compiler specified: `$(CC)`) -endif - ---clean-linux: --clean-unix - ---clean-macos: --clean-unix - ---clean-unix: - - rm -f *.o - - rm -f *.a - - rm -f *.so - - rm -f *.dylib - - rm -rf *.dSYM - ---clean-windows: - - del *.o >nul 2>&1 - - del *.dll >nul 2>&1 - - del *.a >nul 2>&1 +clean: + - del *.obj >nul 2>&1 + - del *.ilk >nul 2>&1 + - del *.pdb >nul 2>&1 + - del *.exp >nul 2>&1 - del *.exe >nul 2>&1 + - del *.lib >nul 2>&1 diff --git a/examples/C/minimal/Makefile.nmake b/examples/C/minimal/Makefile.nmake deleted file mode 100644 index 9794e26f..00000000 --- a/examples/C/minimal/Makefile.nmake +++ /dev/null @@ -1,55 +0,0 @@ -# WebUI C99 Example -# Windows - Microsoft Visual C - -SHELL = CMD -LIB_DIR = ../../../dist -INCLUDE_DIR = ../../../include - -# Build the WebUI library if running `nmake -f Makefile.nmake BUILD_LIB=true` -BUILD_LIB = - -all: release - -debug: -!IF "$(BUILD_LIB)" == "true" - @cd "$(LIB_DIR)" && cd .. && $(MAKE) -f Makefile.nmake debug -!ENDIF -# Static with Debug info - @echo Build C99 Example (Static Debug)... - @cl /Zi main.c /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)/debug" /MACHINE:X64 /SUBSYSTEM:CONSOLE webui-2-static.lib user32.lib Advapi32.lib /OUT:main.exe 1>NUL 2>&1 -# Dynamic with Debug info - @echo Build C99 Example (Dynamic Debug)... - @cl /Zi main.c /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)/debug" /MACHINE:X64 /SUBSYSTEM:CONSOLE webui-2.lib user32.lib Advapi32.lib /OUT:main-dyn.exe 1>NUL 2>&1 -# Clean - @- del *.exp >nul 2>&1 - @- del *.ilk >nul 2>&1 - @- del *.lib >nul 2>&1 - @- del *.obj >nul 2>&1 - @- del *.pdb >nul 2>&1 - @echo Done. - -release: -!IF "$(BUILD_LIB)" == "true" - @cd "$(LIB_DIR)" && cd .. && $(MAKE) -f Makefile.nmake -!ENDIF -# Static Release - @echo Build C99 Example (Static Release)... - @cl main.c /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)" /MACHINE:X64 /SUBSYSTEM:WINDOWS webui-2-static.lib user32.lib Advapi32.lib /OUT:main.exe 1>NUL 2>&1 -# Dynamic Release - @echo Build C99 Example (Dynamic Release)... - @cl main.c /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)" /MACHINE:X64 /SUBSYSTEM:WINDOWS webui-2.lib user32.lib Advapi32.lib /OUT:main-dyn.exe 1>NUL 2>&1 -# Clean - @- del *.exp >nul 2>&1 - @- del *.ilk >nul 2>&1 - @- del *.lib >nul 2>&1 - @- del *.obj >nul 2>&1 - @- del *.pdb >nul 2>&1 - @echo Done. - -clean: - - del *.obj >nul 2>&1 - - del *.ilk >nul 2>&1 - - del *.pdb >nul 2>&1 - - del *.exp >nul 2>&1 - - del *.exe >nul 2>&1 - - del *.lib >nul 2>&1 diff --git a/examples/C/serve_a_folder/GNUmakefile b/examples/C/serve_a_folder/GNUmakefile new file mode 100644 index 00000000..06100a03 --- /dev/null +++ b/examples/C/serve_a_folder/GNUmakefile @@ -0,0 +1,120 @@ +# WebUI C99 Example + +# == 1. VARIABLES ============================================================= + +PROJECT_DIR := $(shell git rev-parse --show-toplevel) +LIB_DIR := $(PROJECT_DIR)/dist +INCLUDE_DIR := $(PROJECT_DIR)/include + +# ARGS +# Set a compiler when running on Linux via `make CC=gcc` / `make CC=clang` +CC = gcc +# Build the WebUI library if running via `make BUILD_LIB=true` +BUILD_LIB ?= + +# BUILD FLAGS +STATIC_BUILD_FLAGS = main.c -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)" +DYN_BUILD_FLAGS = main.c -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)" + +# Platform conditions +ifeq ($(OS),Windows_NT) + # Windows + PLATFORM := windows + SHELL := CMD + STATIC_BUILD_FLAGS += -lwebui-2-static -lws2_32 -Wall -Wl,-subsystem=console -luser32 -static + DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.dll" -lws2_32 -Wall -Wl,-subsystem=console -luser32 + STATIC_OUT := main.exe + DYN_OUT := main-dyn.exe + LWS2_OPT := -lws2_32 + STRIP_OPT := --strip-all +else + STATIC_BUILD_FLAGS += -lpthread -lm -lwebui-2-static + DYN_BUILD_FLAGS += -lpthread -lm + STATIC_OUT := main + DYN_OUT := main-dyn + ifeq ($(shell uname),Darwin) + # MacOS + PLATFORM := macos + CC = clang + DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.dylib" + else + # Linux + PLATFORM := linux + DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.so" + STRIP_OPT := --strip-all + ifeq ($(CC),clang) + LLVM_OPT := llvm- + endif + endif +endif + +# == 2.TARGETS ================================================================ + +all: release + +debug: LIB_DIR := $(LIB_DIR)/debug +debug: --validate-args +ifeq ($(BUILD_LIB),true) + @cd "$(PROJECT_DIR)" && $(MAKE) debug +endif +# Static with Debug info + @echo "Build C99 Example ($(CC) debug static)..." + @$(CC) -g $(STATIC_BUILD_FLAGS) $(LWS2_OPT) -o $(STATIC_OUT) +# Dynamic with Debug info + @echo "Build C99 Example ($(CC) debug dynamic)..." + @$(CC) -g $(DYN_BUILD_FLAGS) $(LWS2_OPT) -o $(DYN_OUT) +# Clean +ifeq ($(PLATFORM),windows) + @- del *.o >nul 2>&1 +else + @- rm -f *.o + @- rm -rf *.dSYM # macOS +endif + @echo "Done." + +release: --validate-args +ifeq ($(BUILD_LIB),true) + @cd "$(PROJECT_DIR)" && $(MAKE) +endif +# Static Release + @echo "Build C99 Example ($(CC) release static)..." + @$(CC) -Os $(STATIC_BUILD_FLAGS) $(LWS2_OPT) -o $(STATIC_OUT) + @$(LLVM_OPT)strip $(STRIP_OPT) $(STATIC_OUT) +# Dynamic Release + @echo "Build C99 Example ($(CC) release dynamic)..." + @$(CC) $(DYN_BUILD_FLAGS) $(LWS2_OPT) -o $(DYN_OUT) + @$(LLVM_OPT)strip $(STRIP_OPT) $(DYN_OUT) +# Clean +ifeq ($(PLATFORM),windows) + @- del *.o >nul 2>&1 +else + @- rm -f *.o + @- rm -rf *.dSYM # macOS +endif + @echo "Done." + +clean: --clean-$(PLATFORM) + +# INTERNAL TARGETS + +--validate-args: +ifneq ($(filter $(CC),gcc clang),$(CC)) + $(error Invalid compiler specified: `$(CC)`) +endif + +--clean-linux: --clean-unix + +--clean-macos: --clean-unix + +--clean-unix: + - rm -f *.o + - rm -f *.a + - rm -f *.so + - rm -f *.dylib + - rm -rf *.dSYM + +--clean-windows: + - del *.o >nul 2>&1 + - del *.dll >nul 2>&1 + - del *.a >nul 2>&1 + - del *.exe >nul 2>&1 diff --git a/examples/C/serve_a_folder/Makefile b/examples/C/serve_a_folder/Makefile index 06100a03..5dcddb7b 100644 --- a/examples/C/serve_a_folder/Makefile +++ b/examples/C/serve_a_folder/Makefile @@ -1,120 +1,55 @@ # WebUI C99 Example +# Windows - Microsoft Visual C -# == 1. VARIABLES ============================================================= +SHELL = CMD +LIB_DIR = ../../../dist +INCLUDE_DIR = ../../../include -PROJECT_DIR := $(shell git rev-parse --show-toplevel) -LIB_DIR := $(PROJECT_DIR)/dist -INCLUDE_DIR := $(PROJECT_DIR)/include - -# ARGS -# Set a compiler when running on Linux via `make CC=gcc` / `make CC=clang` -CC = gcc -# Build the WebUI library if running via `make BUILD_LIB=true` -BUILD_LIB ?= - -# BUILD FLAGS -STATIC_BUILD_FLAGS = main.c -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)" -DYN_BUILD_FLAGS = main.c -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)" - -# Platform conditions -ifeq ($(OS),Windows_NT) - # Windows - PLATFORM := windows - SHELL := CMD - STATIC_BUILD_FLAGS += -lwebui-2-static -lws2_32 -Wall -Wl,-subsystem=console -luser32 -static - DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.dll" -lws2_32 -Wall -Wl,-subsystem=console -luser32 - STATIC_OUT := main.exe - DYN_OUT := main-dyn.exe - LWS2_OPT := -lws2_32 - STRIP_OPT := --strip-all -else - STATIC_BUILD_FLAGS += -lpthread -lm -lwebui-2-static - DYN_BUILD_FLAGS += -lpthread -lm - STATIC_OUT := main - DYN_OUT := main-dyn - ifeq ($(shell uname),Darwin) - # MacOS - PLATFORM := macos - CC = clang - DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.dylib" - else - # Linux - PLATFORM := linux - DYN_BUILD_FLAGS += "$(LIB_DIR)/webui-2.so" - STRIP_OPT := --strip-all - ifeq ($(CC),clang) - LLVM_OPT := llvm- - endif - endif -endif - -# == 2.TARGETS ================================================================ +# Build the WebUI library if running `nmake BUILD_LIB=true` +BUILD_LIB = all: release -debug: LIB_DIR := $(LIB_DIR)/debug -debug: --validate-args -ifeq ($(BUILD_LIB),true) - @cd "$(PROJECT_DIR)" && $(MAKE) debug -endif +debug: +!IF "$(BUILD_LIB)" == "true" + @cd "$(LIB_DIR)" && cd .. && $(MAKE) debug +!ENDIF # Static with Debug info - @echo "Build C99 Example ($(CC) debug static)..." - @$(CC) -g $(STATIC_BUILD_FLAGS) $(LWS2_OPT) -o $(STATIC_OUT) + @echo Build C99 Example (Static Debug)... + @cl /Zi main.c /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)/debug" /MACHINE:X64 /SUBSYSTEM:CONSOLE webui-2-static.lib user32.lib Advapi32.lib /OUT:main.exe 1>NUL 2>&1 # Dynamic with Debug info - @echo "Build C99 Example ($(CC) debug dynamic)..." - @$(CC) -g $(DYN_BUILD_FLAGS) $(LWS2_OPT) -o $(DYN_OUT) + @echo Build C99 Example (Dynamic Debug)... + @cl /Zi main.c /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)/debug" /MACHINE:X64 /SUBSYSTEM:CONSOLE webui-2.lib user32.lib Advapi32.lib /OUT:main-dyn.exe 1>NUL 2>&1 # Clean -ifeq ($(PLATFORM),windows) - @- del *.o >nul 2>&1 -else - @- rm -f *.o - @- rm -rf *.dSYM # macOS -endif - @echo "Done." + @- del *.exp >nul 2>&1 + @- del *.ilk >nul 2>&1 + @- del *.lib >nul 2>&1 + @- del *.obj >nul 2>&1 + @- del *.pdb >nul 2>&1 + @echo Done. -release: --validate-args -ifeq ($(BUILD_LIB),true) - @cd "$(PROJECT_DIR)" && $(MAKE) -endif +release: +!IF "$(BUILD_LIB)" == "true" + @cd "$(LIB_DIR)" && cd .. && $(MAKE) +!ENDIF # Static Release - @echo "Build C99 Example ($(CC) release static)..." - @$(CC) -Os $(STATIC_BUILD_FLAGS) $(LWS2_OPT) -o $(STATIC_OUT) - @$(LLVM_OPT)strip $(STRIP_OPT) $(STATIC_OUT) + @echo Build C99 Example (Static Release)... + @cl main.c /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)" /MACHINE:X64 /SUBSYSTEM:WINDOWS webui-2-static.lib user32.lib Advapi32.lib /OUT:main.exe 1>NUL 2>&1 # Dynamic Release - @echo "Build C99 Example ($(CC) release dynamic)..." - @$(CC) $(DYN_BUILD_FLAGS) $(LWS2_OPT) -o $(DYN_OUT) - @$(LLVM_OPT)strip $(STRIP_OPT) $(DYN_OUT) + @echo Build C99 Example (Dynamic Release)... + @cl main.c /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)" /MACHINE:X64 /SUBSYSTEM:WINDOWS webui-2.lib user32.lib Advapi32.lib /OUT:main-dyn.exe 1>NUL 2>&1 # Clean -ifeq ($(PLATFORM),windows) - @- del *.o >nul 2>&1 -else - @- rm -f *.o - @- rm -rf *.dSYM # macOS -endif - @echo "Done." + @- del *.exp >nul 2>&1 + @- del *.ilk >nul 2>&1 + @- del *.lib >nul 2>&1 + @- del *.obj >nul 2>&1 + @- del *.pdb >nul 2>&1 + @echo Done. -clean: --clean-$(PLATFORM) - -# INTERNAL TARGETS - ---validate-args: -ifneq ($(filter $(CC),gcc clang),$(CC)) - $(error Invalid compiler specified: `$(CC)`) -endif - ---clean-linux: --clean-unix - ---clean-macos: --clean-unix - ---clean-unix: - - rm -f *.o - - rm -f *.a - - rm -f *.so - - rm -f *.dylib - - rm -rf *.dSYM - ---clean-windows: - - del *.o >nul 2>&1 - - del *.dll >nul 2>&1 - - del *.a >nul 2>&1 +clean: + - del *.obj >nul 2>&1 + - del *.ilk >nul 2>&1 + - del *.pdb >nul 2>&1 + - del *.exp >nul 2>&1 - del *.exe >nul 2>&1 + - del *.lib >nul 2>&1 diff --git a/examples/C/serve_a_folder/Makefile.nmake b/examples/C/serve_a_folder/Makefile.nmake deleted file mode 100644 index 9794e26f..00000000 --- a/examples/C/serve_a_folder/Makefile.nmake +++ /dev/null @@ -1,55 +0,0 @@ -# WebUI C99 Example -# Windows - Microsoft Visual C - -SHELL = CMD -LIB_DIR = ../../../dist -INCLUDE_DIR = ../../../include - -# Build the WebUI library if running `nmake -f Makefile.nmake BUILD_LIB=true` -BUILD_LIB = - -all: release - -debug: -!IF "$(BUILD_LIB)" == "true" - @cd "$(LIB_DIR)" && cd .. && $(MAKE) -f Makefile.nmake debug -!ENDIF -# Static with Debug info - @echo Build C99 Example (Static Debug)... - @cl /Zi main.c /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)/debug" /MACHINE:X64 /SUBSYSTEM:CONSOLE webui-2-static.lib user32.lib Advapi32.lib /OUT:main.exe 1>NUL 2>&1 -# Dynamic with Debug info - @echo Build C99 Example (Dynamic Debug)... - @cl /Zi main.c /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)/debug" /MACHINE:X64 /SUBSYSTEM:CONSOLE webui-2.lib user32.lib Advapi32.lib /OUT:main-dyn.exe 1>NUL 2>&1 -# Clean - @- del *.exp >nul 2>&1 - @- del *.ilk >nul 2>&1 - @- del *.lib >nul 2>&1 - @- del *.obj >nul 2>&1 - @- del *.pdb >nul 2>&1 - @echo Done. - -release: -!IF "$(BUILD_LIB)" == "true" - @cd "$(LIB_DIR)" && cd .. && $(MAKE) -f Makefile.nmake -!ENDIF -# Static Release - @echo Build C99 Example (Static Release)... - @cl main.c /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)" /MACHINE:X64 /SUBSYSTEM:WINDOWS webui-2-static.lib user32.lib Advapi32.lib /OUT:main.exe 1>NUL 2>&1 -# Dynamic Release - @echo Build C99 Example (Dynamic Release)... - @cl main.c /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)" /MACHINE:X64 /SUBSYSTEM:WINDOWS webui-2.lib user32.lib Advapi32.lib /OUT:main-dyn.exe 1>NUL 2>&1 -# Clean - @- del *.exp >nul 2>&1 - @- del *.ilk >nul 2>&1 - @- del *.lib >nul 2>&1 - @- del *.obj >nul 2>&1 - @- del *.pdb >nul 2>&1 - @echo Done. - -clean: - - del *.obj >nul 2>&1 - - del *.ilk >nul 2>&1 - - del *.pdb >nul 2>&1 - - del *.exp >nul 2>&1 - - del *.exe >nul 2>&1 - - del *.lib >nul 2>&1 diff --git a/examples/C/text-editor/Makefile b/examples/C/text-editor/GNUmakefile similarity index 100% rename from examples/C/text-editor/Makefile rename to examples/C/text-editor/GNUmakefile