# WebUI C Tests # == 1. VARIABLES ============================================================= MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST))) PROJECT_DIR := $(dir $(MAKEFILE_PATH))/../ TEST_SRC := $(firstword $(MAKECMDGOALS)) TEST_OUT = $(patsubst %.c,%,$(TEST_SRC)) LIB_DIR := $(PROJECT_DIR)/dist ifeq ($(WEBUI_DEBUG), 1) LIB_DIR := $(LIB_DIR)/debug endif INCLUDE_DIR := $(PROJECT_DIR)/include WEBUI_LIB_NAME = webui-2 ifeq ($(WEBUI_USE_TLS), 1) WEBUI_LIB_NAME = webui-2-secure endif # Build the WebUI library if running via `make BUILD_LIB=true` CC ?= gcc BUILD_LIB ?= ifeq ($(CC), cc) ifeq ($(shell uname),Darwin) CC = clang else CC = gcc endif endif # BUILD FLAGS STATIC_BUILD_FLAGS = $(TEST_SRC) -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)" DYN_BUILD_FLAGS = $(TEST_SRC) -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)" # Platform conditions ifeq ($(OS),Windows_NT) # Windows PLATFORM := windows SHELL := CMD STATIC_BUILD_FLAGS += -l$(WEBUI_LIB_NAME)-static -lws2_32 -Wall -luser32 -static COPY_LIB_CMD := @copy "$(LIB_DIR)\$(WEBUI_LIB_NAME).dll" "$(WEBUI_LIB_NAME).dll" DYN_BUILD_FLAGS += "$(WEBUI_LIB_NAME).dll" -lws2_32 -Wall -luser32 STATIC_OUT := $(TEST_OUT).exe DYN_OUT := $(TEST_OUT)-dyn.exe LWS2_OPT := -lws2_32 -lole32 STRIP_OPT := --strip-all CONSOLE_APP := -Wl,-subsystem=console GUI_APP := -Wl,-subsystem=windows else STATIC_BUILD_FLAGS += -lpthread -lm -l$(WEBUI_LIB_NAME)-static DYN_BUILD_FLAGS += -lpthread -lm STATIC_OUT := $(TEST_OUT) DYN_OUT := $(TEST_OUT)-dyn ifeq ($(shell uname),Darwin) # MacOS PLATFORM := macos COPY_LIB_CMD := @cp "$(LIB_DIR)/lib$(WEBUI_LIB_NAME).dylib" "lib$(WEBUI_LIB_NAME).dylib" DYN_BUILD_FLAGS += -l$(WEBUI_LIB_NAME).dylib WKWEBKIT_LINK_FLAGS := -framework Cocoa -framework WebKit else # Linux PLATFORM := linux COPY_LIB_CMD := @cp "$(LIB_DIR)/lib$(WEBUI_LIB_NAME).so" "lib$(WEBUI_LIB_NAME).so" STATIC_BUILD_FLAGS += -ldl DYN_BUILD_FLAGS += -ldl -l$(WEBUI_LIB_NAME) STRIP_OPT := --strip-all ifeq ($(CC),clang) LLVM_OPT := llvm- endif endif endif # == 2.TARGETS ================================================================ *.c: all .PHONY: all all: release .PHONY: debug debug: ifeq ($(BUILD_LIB),true) @cd "$(PROJECT_DIR)" && $(MAKE) debug endif # Static with Debug info ifneq ($(WEBUI_USE_TLS), 1) @echo "Building '$(TEST_SRC)' ($(CC) debug static)..." @$(CC) -g $(CONSOLE_APP) $(STATIC_BUILD_FLAGS) $(LWS2_OPT) $(WKWEBKIT_LINK_FLAGS) -o $(STATIC_OUT) endif # Dynamic with Debug info @echo "Building '$(TEST_SRC)' ($(CC) debug dynamic)..." $(COPY_LIB_CMD) @$(CC) -g $(CONSOLE_APP) $(DYN_BUILD_FLAGS) $(LWS2_OPT) $(WKWEBKIT_LINK_FLAGS) -o $(DYN_OUT) # Clean ifeq ($(PLATFORM),windows) @- del *.o >nul 2>&1 else @- rm -f *.o @- rm -rf *.dSYM # macOS endif @echo "Done." .PHONY: .release release: ifeq ($(BUILD_LIB),true) @cd "$(PROJECT_DIR)" && $(MAKE) endif # Static Release ifneq ($(WEBUI_USE_TLS), 1) @echo "Building '$(TEST_SRC)' ($(CC) static)..." @$(CC) -Os $(GUI_APP) $(STATIC_BUILD_FLAGS) $(LWS2_OPT) $(WKWEBKIT_LINK_FLAGS) -o $(STATIC_OUT) @$(LLVM_OPT)strip $(STRIP_OPT) $(STATIC_OUT) endif # Dynamic Release @echo "Building '$(TEST_SRC)' ($(CC) dynamic)..." $(COPY_LIB_CMD) @$(CC) $(GUI_APP) $(DYN_BUILD_FLAGS) $(LWS2_OPT) $(WKWEBKIT_LINK_FLAGS) -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 .PHONY: --clean-linux --clean-linux: --clean-unix .PHONY: --clean-macos --clean-macos: clean-unix .PHONY: --clean-unix --clean-unix: - rm -f *.o - rm -f *.a - rm -f *.so - rm -f *.dylib - rm -rf *.dSYM .PHONY: --clean-windows --clean-windows: - del *.o >nul 2>&1 - del *.dll >nul 2>&1 - del *.a >nul 2>&1 - del *.exe >nul 2>&1