2023-08-21 02:07:35 +02:00
|
|
|
# WebUI Library
|
|
|
|
|
|
|
|
# == 1. VARIABLES =============================================================
|
|
|
|
|
2023-09-04 23:50:34 +02:00
|
|
|
MAKEFILE_DIR := $(shell git rev-parse --show-toplevel)
|
2023-08-24 03:48:46 +02:00
|
|
|
BUILD_DIR := $(MAKEFILE_DIR)/dist
|
2023-08-21 02:07:35 +02:00
|
|
|
|
2023-09-07 05:34:32 +02:00
|
|
|
# ARGS
|
|
|
|
# Set a compiler when running on Linux via `make CC=gcc` / `make CC=clang`
|
|
|
|
CC = gcc
|
2023-08-21 02:07:35 +02:00
|
|
|
# Allow to add arch-target for macOS CI cross compilation
|
|
|
|
ARCH_TARGET ?=
|
|
|
|
|
2023-09-07 05:34:32 +02:00
|
|
|
# BUILD FLAGS
|
2023-09-28 19:16:59 +02:00
|
|
|
CIVETWEB_BUILD_FLAGS := -o civetweb.o -I"$(MAKEFILE_DIR)/include/" -c "$(MAKEFILE_DIR)/src/civetweb/civetweb.c"
|
2023-08-21 02:07:35 +02:00
|
|
|
CIVETWEB_DEFINE_FLAGS = -DNDEBUG -DNO_CACHING -DNO_CGI -DNO_SSL -DUSE_WEBSOCKET
|
2023-09-28 19:16:59 +02:00
|
|
|
WEBUI_BUILD_FLAGS := -o webui.o -I"$(MAKEFILE_DIR)/include/" -c "$(MAKEFILE_DIR)/src/webui.c"
|
2023-08-21 02:07:35 +02:00
|
|
|
|
2023-09-07 05:34:32 +02:00
|
|
|
# OUTPUT FILES
|
2023-08-21 02:07:35 +02:00
|
|
|
# The static output is the same for all platforms
|
|
|
|
# The dynamic output is platform dependent
|
2023-08-25 20:38:49 +02:00
|
|
|
LIB_STATIC_OUT := libwebui-2-static.a
|
2023-08-21 02:07:35 +02:00
|
|
|
|
|
|
|
# Platform defaults and dynamic library outputs
|
|
|
|
ifeq ($(OS),Windows_NT)
|
|
|
|
# Windows
|
2023-09-08 12:45:49 +02:00
|
|
|
SHELL := CMD
|
2023-08-21 02:07:35 +02:00
|
|
|
PLATFORM := windows
|
2023-08-25 20:38:49 +02:00
|
|
|
LIB_DYN_OUT := webui-2.dll
|
2023-08-21 02:07:35 +02:00
|
|
|
LWS2_OPT := -lws2_32
|
2023-09-06 14:52:59 +02:00
|
|
|
CIVETWEB_DEFINE_FLAGS += -DMUST_IMPLEMENT_CLOCK_GETTIME
|
2023-09-07 05:34:32 +02:00
|
|
|
else ifeq ($(shell uname),Darwin)
|
|
|
|
# MacOS
|
|
|
|
PLATFORM := macos
|
|
|
|
CC = clang
|
|
|
|
LIB_DYN_OUT := webui-2.dylib
|
2023-08-21 02:07:35 +02:00
|
|
|
else
|
2023-09-07 05:34:32 +02:00
|
|
|
# Linux
|
|
|
|
PLATFORM := linux
|
|
|
|
LIB_DYN_OUT := webui-2.so
|
2023-09-28 19:16:59 +02:00
|
|
|
ifneq ($(filter $(CC),gcc clang aarch64-linux-gnu-gcc arm-linux-gnueabihf-gcc),$(CC))
|
|
|
|
$(error Invalid compiler specified: `$(CC)`)
|
|
|
|
else ifeq ($(CC),clang)
|
2023-09-07 05:34:32 +02:00
|
|
|
LLVM_OPT := llvm-
|
2023-08-21 02:07:35 +02:00
|
|
|
endif
|
|
|
|
endif
|
2023-09-28 19:16:59 +02:00
|
|
|
# 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
|
2023-08-21 02:07:35 +02:00
|
|
|
|
|
|
|
# == 2.TARGETS ================================================================
|
|
|
|
|
|
|
|
all: release
|
|
|
|
|
2023-09-28 19:16:59 +02:00
|
|
|
debug: --debug
|
2023-08-21 02:07:35 +02:00
|
|
|
|
2023-09-28 19:16:59 +02:00
|
|
|
release: --release
|
2023-08-21 02:07:35 +02:00
|
|
|
|
|
|
|
clean: --clean-$(PLATFORM)
|
|
|
|
|
2023-09-07 05:34:32 +02:00
|
|
|
# == 2.1 INTERNAL TARGETS =====================================================
|
2023-08-21 02:07:35 +02:00
|
|
|
|
2023-09-06 14:52:59 +02:00
|
|
|
--debug:
|
2023-09-08 12:45:49 +02:00
|
|
|
# Create build directory
|
|
|
|
ifeq ($(PLATFORM),windows)
|
|
|
|
@mkdir "$(BUILD_DIR)/debug" >nul 2>&1 ||:
|
|
|
|
else
|
|
|
|
@mkdir -p "$(BUILD_DIR)/debug"
|
|
|
|
endif
|
2023-08-21 02:07:35 +02:00
|
|
|
# Static with Debug info
|
2023-09-08 12:45:49 +02:00
|
|
|
@cd "$(BUILD_DIR)/debug" \
|
2023-09-28 19:16:59 +02:00
|
|
|
&& 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 \
|
2023-08-21 02:07:35 +02:00
|
|
|
&& $(LLVM_OPT)ar rc $(LIB_STATIC_OUT) webui.o civetweb.o \
|
|
|
|
&& $(LLVM_OPT)ranlib $(LIB_STATIC_OUT)
|
|
|
|
# Dynamic with Debug info
|
2023-09-08 12:45:49 +02:00
|
|
|
@cd "$(BUILD_DIR)/debug" \
|
2023-09-28 19:16:59 +02:00
|
|
|
&& 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)
|
2023-08-21 02:07:35 +02:00
|
|
|
ifeq ($(PLATFORM),windows)
|
2023-09-08 12:45:49 +02:00
|
|
|
@cd "$(BUILD_DIR)/debug" && del *.o >nul 2>&1
|
2023-08-21 02:07:35 +02:00
|
|
|
else
|
2023-09-08 12:45:49 +02:00
|
|
|
@rm -f $(BUILD_DIR)/debug/*.o
|
2023-08-21 02:07:35 +02:00
|
|
|
endif
|
|
|
|
@echo "Done."
|
|
|
|
|
2023-09-06 14:52:59 +02:00
|
|
|
--release:
|
2023-09-08 12:45:49 +02:00
|
|
|
# Create build directory
|
|
|
|
ifeq ($(PLATFORM),windows)
|
|
|
|
@mkdir "$(BUILD_DIR)" >nul 2>&1 ||:
|
|
|
|
else
|
|
|
|
@mkdir -p "$(BUILD_DIR)"
|
|
|
|
endif
|
2023-08-21 02:07:35 +02:00
|
|
|
# Static Release
|
2023-08-23 23:38:25 +02:00
|
|
|
@cd "$(BUILD_DIR)" \
|
2023-09-28 19:16:59 +02:00
|
|
|
&& echo "Build WebUI library ($(CC) $(TARGET)release static)..." \
|
|
|
|
&& $(CC) $(TARGET) $(CIVETWEB_BUILD_FLAGS) $(CIVETWEB_DEFINE_FLAGS) -Os \
|
|
|
|
&& $(CC) $(TARGET) $(WEBUI_BUILD_FLAGS) -Os \
|
2023-08-21 02:07:35 +02:00
|
|
|
&& $(LLVM_OPT)ar rc $(LIB_STATIC_OUT) webui.o civetweb.o \
|
|
|
|
&& $(LLVM_OPT)ranlib $(LIB_STATIC_OUT)
|
|
|
|
# Dynamic Release
|
2023-08-23 23:38:25 +02:00
|
|
|
@cd "$(BUILD_DIR)" \
|
2023-09-28 19:16:59 +02:00
|
|
|
&& 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)
|
2023-08-21 02:07:35 +02:00
|
|
|
# Clean
|
|
|
|
ifeq ($(PLATFORM),windows)
|
|
|
|
@strip --strip-unneeded $(BUILD_DIR)/$(LIB_DYN_OUT)
|
2023-09-08 12:45:49 +02:00
|
|
|
@cd "$(BUILD_DIR)" && del *.o >nul 2>&1
|
2023-08-21 02:07:35 +02:00
|
|
|
else
|
2023-09-08 12:45:49 +02:00
|
|
|
@rm -f $(BUILD_DIR)/*.o
|
2023-08-21 02:07:35 +02:00
|
|
|
endif
|
|
|
|
@echo "Done."
|
|
|
|
|
2023-09-07 05:34:32 +02:00
|
|
|
# PLATFROM CLEAN TARGETS
|
2023-08-21 02:07:35 +02:00
|
|
|
|
|
|
|
--clean-linux: --clean-unix
|
|
|
|
|
|
|
|
--clean-macos: --clean-unix
|
|
|
|
|
|
|
|
--clean-unix:
|
2023-08-23 23:38:25 +02:00
|
|
|
@- cd "$(BUILD_DIR)" \
|
2023-08-21 02:07:35 +02:00
|
|
|
&& rm -f *.o \
|
|
|
|
&& rm -f *.so \
|
|
|
|
&& rm -f *.dylib \
|
|
|
|
&& rm -f *.a
|
|
|
|
|
|
|
|
--clean-windows:
|
2023-08-23 23:38:25 +02:00
|
|
|
@- cd "$(BUILD_DIR)" \
|
2023-08-21 02:07:35 +02:00
|
|
|
&& 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
|