2023-10-28 19:51:02 -04:00
|
|
|
# WebUI C Example
|
2023-10-10 01:55:03 +02:00
|
|
|
|
|
|
|
# == 1. VARIABLES =============================================================
|
|
|
|
|
|
|
|
PROJECT_DIR := $(shell git rev-parse --show-toplevel)
|
2023-10-25 20:16:57 -04:00
|
|
|
TARGET := $(firstword $(MAKECMDGOALS))
|
2023-10-10 01:55:03 +02:00
|
|
|
LIB_DIR := $(PROJECT_DIR)/dist
|
2023-10-25 20:16:57 -04:00
|
|
|
ifeq ($(TARGET), debug)
|
|
|
|
LIB_DIR := $(LIB_DIR)/debug
|
|
|
|
endif
|
2023-10-10 01:55:03 +02:00
|
|
|
INCLUDE_DIR := $(PROJECT_DIR)/include
|
2023-10-23 17:58:39 -04:00
|
|
|
WEBUI_LIB_NAME = webui-2
|
|
|
|
ifeq ($(WEBUI_USE_TLS), 1)
|
|
|
|
WEBUI_LIB_NAME = webui-2-secure
|
|
|
|
endif
|
2023-10-10 01:55:03 +02:00
|
|
|
|
|
|
|
# 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
|
2023-10-23 17:58:39 -04:00
|
|
|
STATIC_BUILD_FLAGS += -l$(WEBUI_LIB_NAME)-static -lws2_32 -Wall -luser32 -static
|
2023-10-25 20:16:57 -04:00
|
|
|
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
|
2023-10-10 01:55:03 +02:00
|
|
|
STATIC_OUT := main.exe
|
|
|
|
DYN_OUT := main-dyn.exe
|
|
|
|
LWS2_OPT := -lws2_32
|
|
|
|
STRIP_OPT := --strip-all
|
2023-10-25 20:16:57 -04:00
|
|
|
CONSOLE_APP := -Wl,-subsystem=console
|
|
|
|
GUI_APP := -Wl,-subsystem=windows
|
2023-10-10 01:55:03 +02:00
|
|
|
else
|
2023-10-23 17:58:39 -04:00
|
|
|
STATIC_BUILD_FLAGS += -lpthread -lm -l$(WEBUI_LIB_NAME)-static
|
2023-10-10 01:55:03 +02:00
|
|
|
DYN_BUILD_FLAGS += -lpthread -lm
|
|
|
|
STATIC_OUT := main
|
|
|
|
DYN_OUT := main-dyn
|
2023-10-25 20:16:57 -04:00
|
|
|
CONSOLE_APP :=
|
|
|
|
GUI_APP :=
|
2023-10-10 01:55:03 +02:00
|
|
|
ifeq ($(shell uname),Darwin)
|
|
|
|
# MacOS
|
|
|
|
PLATFORM := macos
|
|
|
|
CC = clang
|
2023-10-25 20:16:57 -04:00
|
|
|
COPY_LIB_CMD := @cp "$(LIB_DIR)/$(WEBUI_LIB_NAME).dylib" "$(WEBUI_LIB_NAME).dylib"
|
|
|
|
DYN_BUILD_FLAGS += "./$(WEBUI_LIB_NAME).dylib"
|
2023-10-10 01:55:03 +02:00
|
|
|
else
|
|
|
|
# Linux
|
|
|
|
PLATFORM := linux
|
2023-10-25 20:16:57 -04:00
|
|
|
COPY_LIB_CMD := @cp "$(LIB_DIR)/$(WEBUI_LIB_NAME).so" "$(WEBUI_LIB_NAME).so"
|
|
|
|
DYN_BUILD_FLAGS += "./$(WEBUI_LIB_NAME).so"
|
2023-10-10 01:55:03 +02:00
|
|
|
STRIP_OPT := --strip-all
|
|
|
|
ifeq ($(CC),clang)
|
|
|
|
LLVM_OPT := llvm-
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
# == 2.TARGETS ================================================================
|
|
|
|
|
|
|
|
all: release
|
|
|
|
|
|
|
|
debug: --validate-args
|
|
|
|
ifeq ($(BUILD_LIB),true)
|
|
|
|
@cd "$(PROJECT_DIR)" && $(MAKE) debug
|
|
|
|
endif
|
|
|
|
# Static with Debug info
|
2023-10-23 17:58:39 -04:00
|
|
|
ifneq ($(WEBUI_USE_TLS), 1)
|
2023-10-28 19:51:02 -04:00
|
|
|
@echo "Build C Example ($(CC) debug static)..."
|
2023-10-25 20:16:57 -04:00
|
|
|
@$(CC) -g $(CONSOLE_APP) $(STATIC_BUILD_FLAGS) $(LWS2_OPT) -o $(STATIC_OUT)
|
2023-10-23 17:58:39 -04:00
|
|
|
endif
|
2023-10-10 01:55:03 +02:00
|
|
|
# Dynamic with Debug info
|
2023-10-28 19:51:02 -04:00
|
|
|
@echo "Build C Example ($(CC) debug dynamic)..."
|
2023-10-25 20:16:57 -04:00
|
|
|
$(COPY_LIB_CMD)
|
|
|
|
@$(CC) -g $(CONSOLE_APP) $(DYN_BUILD_FLAGS) $(LWS2_OPT) -o $(DYN_OUT)
|
2023-10-10 01:55:03 +02:00
|
|
|
# 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
|
2023-10-23 17:58:39 -04:00
|
|
|
ifneq ($(WEBUI_USE_TLS), 1)
|
2023-10-28 19:51:02 -04:00
|
|
|
@echo "Build C Example ($(CC) release static)..."
|
2023-10-25 20:16:57 -04:00
|
|
|
@$(CC) -Os $(GUI_APP) $(STATIC_BUILD_FLAGS) $(LWS2_OPT) -o $(STATIC_OUT)
|
2023-10-10 01:55:03 +02:00
|
|
|
@$(LLVM_OPT)strip $(STRIP_OPT) $(STATIC_OUT)
|
2023-10-23 17:58:39 -04:00
|
|
|
endif
|
2023-10-10 01:55:03 +02:00
|
|
|
# Dynamic Release
|
2023-10-28 19:51:02 -04:00
|
|
|
@echo "Build C Example ($(CC) release dynamic)..."
|
2023-10-25 20:16:57 -04:00
|
|
|
$(COPY_LIB_CMD)
|
|
|
|
@$(CC) $(GUI_APP) $(DYN_BUILD_FLAGS) $(LWS2_OPT) -o $(DYN_OUT)
|
2023-10-10 01:55:03 +02:00
|
|
|
@$(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:
|
2023-10-27 11:58:26 -04:00
|
|
|
ifneq ($(filter $(CC),gcc clang aarch64-linux-gnu-gcc arm-linux-gnueabihf-gcc musl-gcc),$(CC))
|
|
|
|
$(error Invalid compiler specified: `$(CC)`)
|
2023-10-10 01:55:03 +02:00
|
|
|
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
|