Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: use a single Makefile #155

Merged
merged 7 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,24 @@ jobs:
uses: ilammy/msvc-dev-cmd@v1
- name: Build
run: |
cd build\/${{ runner.os }}\${{ matrix.compiler }}
mkdir dist
if ('${{ matrix.compiler }}' -eq 'MSVC') {
nmake
nmake -f Makefile.nmake
} else {
mingw32-make
}
- name: Prepare Artifact
shell: bash
run: |
rm build/${{ runner.os }}/README.md
rm build/${{ runner.os }}/${{ matrix.compiler }}/Makefile
cp -r include build/${{ runner.os }}/${{ matrix.compiler }}
cp -r include dist
artifact=${{ runner.os }}-${{ matrix.compiler }}-x64
# Add the ARTIFACT name(`,,` ^= lowercase shell param) as GitHub environment variable.
echo "ARTIFACT=${artifact,,}" >> $GITHUB_ENV
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.ARTIFACT }}
path: build/${{ runner.os }}/${{ matrix.compiler }}
path: dist
- name: Release Artifact
if: github.ref_type == 'tag'
uses: softprops/action-gh-release@v1
Expand All @@ -92,25 +90,22 @@ jobs:
fail-on-cache-miss: true
- name: Build
run: |
cd build//${{ runner.os }}/${{ matrix.compiler }}
if [ "${{ matrix.compiler }}" == "Clang" ]; then
sudo ln -s llvm-ar-13 /usr/bin/llvm-ar
sudo ln -s llvm-ranlib-13 /usr/bin/llvm-ranlib
fi
make
- name: Prepare Artifact
run: |
rm build/${{ runner.os }}/README.md
rm build/${{ runner.os }}/${{ matrix.compiler }}/Makefile
cp -r include build/${{ runner.os }}/${{ matrix.compiler }}
cp -r include dist
artifact=${{ runner.os }}-${{ matrix.compiler }}-x64
# Add the ARTIFACT name(`,,` ^= lowercase shell param) as GitHub environment variable.
echo "ARTIFACT=${artifact,,}" >> $GITHUB_ENV
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.ARTIFACT }}
path: build/${{ runner.os }}/${{ matrix.compiler }}
path: dist
- name: Release Artifact
if: github.ref_type == 'tag'
uses: softprops/action-gh-release@v1
Expand All @@ -135,21 +130,18 @@ jobs:
fail-on-cache-miss: true
- name: Build
run: |
cd build//${{ runner.os }}/${{ matrix.compiler }}
make
- name: Prepare Artifacts
run: |
rm build/${{ runner.os }}/README.md
rm build/${{ runner.os }}/${{ matrix.compiler }}/Makefile
cp -r include build/${{ runner.os }}/${{ matrix.compiler }}
cp -r include dist
# Add the ARTIFACT name(lowercased) as GitHub environment variable.
artifact=$(echo ${{ runner.os }}-${{ matrix.compiler }}-x64 | tr '[:upper:]' '[:lower:]')
echo "ARTIFACT=$artifact" >> $GITHUB_ENV
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.ARTIFACT }}
path: build/${{ runner.os }}/${{ matrix.compiler }}
path: dist
- name: Release Artifact
if: github.ref_type == 'tag'
uses: softprops/action-gh-release@v1
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Build
build/
*.exe
*.ilk
*.pdb
Expand Down
193 changes: 193 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
# WebUI Library

# == 1. VARIABLES =============================================================

MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
MAKEFILE_DIR := $(dir $(MAKEFILE_PATH))
BUILD_DIR := $(MAKEFILE_DIR)/dist

# Args
# Allow to add arch-target for macOS CI cross compilation
ARCH_TARGET ?=
COMPILER ?=

# Build flags
CIVETWEB_BUILD_FLAGS = -m64 -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 := -m64 -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-x64.a

# Platform defaults and dynamic library outputs
ifeq ($(OS),Windows_NT)
# Windows
PLATFORM := windows
VALID_COMPILERS := gcc tcc
LIB_DYN_OUT := webui-2-x64.dll
LWS2_OPT := -lws2_32
ifeq ($(COMPILER),tcc)
BUILD_TARGET := --tcc
else
BUILD_TARGET := --gcc-clang
COMPILER = gcc
endif
else
BUILD_TARGET := --gcc-clang
ifeq ($(shell uname),Darwin)
# MacOS
PLATFORM := macos
VALID_COMPILERS := clang
LIB_DYN_OUT := webui-2-x64.dylib
ifeq ($(COMPILER),)
COMPILER = clang
endif
else
# Linux
PLATFORM := linux
VALID_COMPILERS := gcc clang
LIB_DYN_OUT := webui-2-x64.so
ifeq ($(COMPILER),)
COMPILER = gcc
else ifeq ($(COMPILER),clang)
LLVM_OPT := llvm-
endif
endif
endif

# == 2.TARGETS ================================================================

all: release

release: --setup $(BUILD_TARGET)-release

debug: --setup $(BUILD_TARGET)-debug

clean: --clean-$(PLATFORM)

# == 2.1 Internal Targets =====================================================

# Prepare build dir and evaluate input arguments
--setup:
# Create build directory
ifeq ($(PLATFORM),windows)
@-$(shell if not exist $(BUILD_DIR) mkdir -p "$(BUILD_DIR)" >nul 2>&1)
else
@mkdir -p $(BUILD_DIR)
endif
# If a compiler is specified check if it's valid
ifneq ($(filter $(COMPILER),$(VALID_COMPILERS)),$(COMPILER))
$(error Invalid compiler specified: `$(COMPILER)`)
endif
# Arch target is for CI cross-compilation
ifneq ($(ARCH_TARGET),)
ifneq ($(PLATFORM),macos)
$(error ARCH_TARGET is only available on macOS)
else ifeq ($(ARCH_TARGET),arm64-apple-darwin)
ARCH_TARGET := -target $(ARCH_TARGET)
endif
endif

# == 2.1.1 GCC / CLANG ========================================================

--gcc-clang-debug:
# Static with Debug info
@cd $(BUILD_DIR) \
&& echo "Build WebUI library ($(COMPILER) debug static)..." \
&& $(COMPILER) $(CIVETWEB_BUILD_FLAGS) $(CIVETWEB_DEFINE_FLAGS) -g \
&& $(COMPILER) $(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) \
&& echo "Build WebUI library ($(COMPILER) debug dynamic)..." \
&& $(COMPILER) $(CIVETWEB_BUILD_FLAGS) $(CIVETWEB_DEFINE_FLAGS) -g -fPIC \
&& $(COMPILER) $(WEBUI_BUILD_FLAGS) -g -fPIC -DWEBUI_LOG \
&& $(COMPILER) -shared -o $(LIB_DYN_OUT) webui.o civetweb.o -g $(LWS2_OPT)
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."

--gcc-clang-release:
# Static Release
@cd $(BUILD_DIR) \
&& echo "Build WebUI library ($(COMPILER) release static)..." \
&& $(COMPILER) $(ARCH_TARGET) $(CIVETWEB_BUILD_FLAGS) $(CIVETWEB_DEFINE_FLAGS) -Os \
&& $(COMPILER) $(ARCH_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 ($(COMPILER) release dynamic)..." \
&& $(COMPILER) $(ARCH_TARGET) $(CIVETWEB_BUILD_FLAGS) $(CIVETWEB_DEFINE_FLAGS) -Os -fPIC \
&& $(COMPILER) $(ARCH_TARGET) $(WEBUI_BUILD_FLAGS) -O3 -fPIC \
&& $(COMPILER) $(ARCH_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."

# == 2.1.2 TCC ================================================================

--tcc-debug:
# Static with Debug info
@cd $(BUILD_DIR) \
&& echo "Build WebUI library ($(COMPILER) debug static)..." \
&& $(COMPILER) $(CIVETWEB_BUILD_FLAGS) $(CIVETWEB_DEFINE_FLAGS) -g \
&& $(COMPILER) $(WEBUI_BUILD_FLAGS) -g -w -DWEBUI_LOG \
&& $(LLVM_OPT)ar rc $(LIB_STATIC_OUT) webui.o civetweb.o
ifeq ($(PLATFORM),windows)
@-cd $(BUILD_DIR) && del *.o >nul 2>&1
else
@- rm -f $(BUILD_DIR)/*.o
endif
@echo "Done."

--tcc-release:
# Static Release
@cd $(BUILD_DIR) \
&& echo "Build WebUI library ($(COMPILER) release static)..." \
&& $(COMPILER) $(CIVETWEB_BUILD_FLAGS) $(CIVETWEB_DEFINE_FLAGS) \
&& $(COMPILER) $(WEBUI_BUILD_FLAGS) -w \
&& $(LLVM_OPT)ar rc $(LIB_STATIC_OUT) webui.o civetweb.o
# Clean
ifeq ($(PLATFORM),windows)
@-cd $(BUILD_DIR) && del *.o >nul 2>&1
else
@- rm -f $(BUILD_DIR)/*.o
endif
@echo "Done."

# == 2.1.3 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
64 changes: 64 additions & 0 deletions Makefile.nmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# WebUI Library
# Windows - Microsoft Visual C

# == 1. VARIABLES =============================================================

# Paths
MAKEFILE_DIR = ./
BUILD_DIR = $(MAKEFILE_DIR)/dist

# Build Flags
CIVETWEB_BUILD_FLAGS = /Focivetweb.obj /c /EHsc "$(MAKEFILE_DIR)/src/civetweb/civetweb.c" /I "$(MAKEFILE_DIR)/src/civetweb/"
CIVETWEB_DEFINE_FLAGS = -DNDEBUG -DNO_CACHING -DNO_CGI -DNO_SSL -DUSE_WEBSOCKET
WEBUI_BUILD_FLAGS = /Fowebui.obj /c /EHsc "$(MAKEFILE_DIR)/src/webui.c" /I "$(MAKEFILE_DIR)include"

# Output Commands
LIB_STATIC_OUT = /OUT:webui-2-static-x64.lib webui.obj civetweb.obj
LIB_DYN_OUT = /DLL /OUT:webui-2-x64.dll webui.obj civetweb.obj user32.lib Advapi32.lib

# == 2.TARGETS ================================================================

all: release

debug:
# Static with Debug info
@echo Build WebUI Library (MSVC Debug Static)...
@cl /Zl /Zi $(CIVETWEB_BUILD_FLAGS) $(CIVETWEB_DEFINE_FLAGS) 1>NUL 2>&1
@cl /Zl /Zi $(WEBUI_BUILD_FLAGS) /DWEBUI_LOG 1>NUL 2>&1
@lib $(LIB_STATIC_OUT) 1>NUL 2>&1
# Dynamic with Debug info
@echo Build WebUI Library (MSVC Debug Dynamic)...
@cl /Zi $(CIVETWEB_BUILD_FLAGS) $(CIVETWEB_DEFINE_FLAGS) 1>NUL 2>&1
@cl /Zi $(WEBUI_BUILD_FLAGS) /DWEBUI_LOG 1>NUL 2>&1
@link $(LIB_DYN_OUT) 1>NUL 2>&1
# Clean
@-cd $(BUILD_DIR) && del *.o >nul 2>&1
@echo Done.

release:
# Static Release
@echo Build WebUI Library (MSVC Release Static)...
@cl /Zl $(CIVETWEB_BUILD_FLAGS) $(CIVETWEB_DEFINE_FLAGS) 1>NUL 2>&1
@cl /Zl $(WEBUI_BUILD_FLAGS) 1>NUL 2>&1
@lib $(LIB_STATIC_OUT) 1>NUL 2>&1
# Dynamic Release
@echo Build WebUI Library (MSVC Release Dynamic)...
@cl $(CIVETWEB_BUILD_FLAGS) $(CIVETWEB_DEFINE_FLAGS) 1>NUL 2>&1
@cl $(WEBUI_BUILD_FLAGS) 1>NUL 2>&1
@link $(LIB_DYN_OUT) 1>NUL 2>&1
# Clean
@-cd $(BUILD_DIR) \
&& - 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 *.obj >nul 2>&1 \
&& del *.dll >nul 2>&1 \
&& del *.ilk >nul 2>&1 \
&& del *.pdb >nul 2>&1 \
&& del *.lib >nul 2>&1 \
&& del *.exp >nul 2>&1
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,26 @@ Think of WebUI like a WebView controller, but instead of embedding the WebView c

## Build

- [Windows](https://github.com/webui-dev/webui/tree/main/build/Windows)
- [Linux](https://github.com/webui-dev/webui/tree/main/build/Linux)
- [macOS](https://github.com/webui-dev/webui/tree/main/build/macOS)
- **Windows**
```powershell
# GCC
mingw32-make
# TCC
mingw32-make COMPILER=tcc
# MSVC
nmake
```
- **Linux**
```sh
# GCC
make
# Clang
make COMPILER=clang
```
- **macOS**
```sh
make
```

## Examples

Expand Down
Loading