Skip to content

Commit

Permalink
further build system cleanup
Browse files Browse the repository at this point in the history
sonarqube target put aside (WIP)
modular meson targets
  • Loading branch information
jaromil committed Oct 10, 2024
1 parent 17bff9a commit b9a5649
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 174 deletions.
190 changes: 34 additions & 156 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,159 +3,46 @@
#
# SPDX-License-Identifier: AGPL-3.0-or-later

.PHONY: help

pwd := $(shell pwd)
# ARCH ?=$(shell uname -m)
PREFIX ?= /usr/local
# VERSION is set in src/Makefile
# Targets to be build in this order
BUILDS := apply-patches milagro lua54 embed-lua quantum-proof ed25519-donna mimalloc

# VERSION is set in build/init.mk
# DESTDIR is supported by install target

# include platform specific configurations pattern-matching target labels
include ${pwd}/build/config.mk

all:
@echo "Choose a target:"
@echo "- linux, linux-lib, linux-clang, linux-debug"
@echo "- javascript-web, javascript-wasm, javascript-demo, javascript-rn (need EMSDK)"
@echo "- linux-python3, linux-go, osx-python3, osx-go (language bindings)"
@echo "- osx, osx-lib, ios-lib, ios-armv7, ios-arm64, ios-sim (need Apple/OSX)"
@echo "- win, win-dll (cross-compile using MINGW on Linux)"
@echo "- musl, musl-local, musl-system (full static build)"
@echo "- android-arm android-x86 android-aarch64"
@echo "- cortex-arm, linux-riscv64, aarch64"
@echo "for android and ios see scripts in build/"

# if ! [ -r build/luac ]; then ${gcc} -I${luasrc} -o build/luac ${luasrc}/luac.c ${luasrc}/liblua.a -lm; fi

sonarqube:
@echo "Configure login token in build/sonarqube.sh"
cp -v build/sonar-project.properties .
./build/sonarqube.sh

embed-lua: lua_embed_opts := $(if ${COMPILE_LUA}, compile)
embed-lua:
@echo "Embedding all files in src/lua"
./build/embed-lualibs ${lua_embed_opts}
@echo "File generated: src/lualibs_detected.c"

src/zen_ecdh_factory.c:
${pwd}/build/codegen_ecdh_factory.sh ${ecdh_curve}

src/zen_ecp_factory.c:
${pwd}/build/codegen_ecp_factory.sh ${ecp_curve}

src/zen_big_factory.c:
${pwd}/build/codegen_ecp_factory.sh ${ecp_curve}

apply-patches: src/zen_ecdh_factory.c src/zen_ecp_factory.c src/zen_big_factory.c

# build target for javascript (emscripten)
javascript: ${BUILDS}
CC="${gcc}" AR="${ar}" CFLAGS="${cflags}" \
LDFLAGS="${ldflags}" LDADD="${ldadd}" \
make -C src js
@mkdir -p build/npm
@cp -v src/zenroom.js build/npm/

# build luarock module
include ${pwd}/build/luarock.mk

# experimental target for xtensa embedded boards
esp32: apply-patches milagro lua54
CC=${pwd}/build/xtensa-esp32-elf/bin/xtensa-esp32-elf-${gcc} \
LD=${pwd}/build/xtensa-esp32-elf/bin/xtensa-esp32-elf-ld \
CFLAGS="${cflags}" LDFLAGS="${ldflags}" LDADD="${ldadd}" \
$(MAKE) -C src linux

# static dependencies in lib
# lpeglabel:
# CC=${gcc} CFLAGS="${cflags} -I${pwd}/lib/lua54/src" AR="${ar}" $(MAKE) -C lib/lpeglabel

lua54:
CC="${lua_cc}" CFLAGS="${cflags} ${lua_cflags}" \
LDFLAGS="${ldflags}" AR="${ar}" RANLIB=${ranlib} \
$(MAKE) -C ${pwd}/lib/lua54/src liblua.a

android-lua54:
CC="${lua_cc}" CFLAGS="${cflags} ${lua_cflags}" \
LDFLAGS="${ldflags}" AR="${ar}" RANLIB=${ranlib} \
$(MAKE) -C ${pwd}/lib/lua54/src ${platform}

musl-lua54:
CC="${lua_cc}" CFLAGS="${cflags} ${lua_cflags}" \
LDFLAGS="${ldflags}" AR="${ar}" RANLIB=${ranlib} \
$(MAKE) -C ${pwd}/lib/lua54/src ${platform}

cortex-lua54:
CC="${lua_cc}" CFLAGS="${cflags} ${lua_cflags} -DLUA_BAREBONE" \
LDFLAGS="${ldflags}" AR="${ar}" RANLIB=${ranlib} \
$(MAKE) -C ${pwd}/lib/lua54/src ${platform}

milagro-debug: milagro
milagro:
@echo "-- Building milagro (${system})"
if ! [ -r ${pwd}/lib/milagro-crypto-c/build/CMakeCache.txt ]; then \
cd ${pwd}/lib/milagro-crypto-c && \
mkdir -p build && \
cd build && \
CC=${gcc} LD=${ld} AR=${ar} \
cmake ../ -DCMAKE_C_FLAGS="${cflags}" -DCMAKE_SYSTEM_NAME="${system}" \
-DCMAKE_AR=${ar} -DCMAKE_C_COMPILER=${gcc} ${milagro_cmake_flags}; \
fi
if ! [ -r ${pwd}/lib/milagro-crypto-c/build/lib/libamcl_core.a ]; then \
RANLIB=${ranlib} LD=${ld} \
$(MAKE) -C ${pwd}/lib/milagro-crypto-c/build; \
fi

mimalloc-debug: mimalloc
mimalloc:
$(info -- Building mimalloc (${system}))
if ! [ -r ${pwd}/lib/mimalloc/build/CMakeCache.txt ]; then \
cd ${pwd}/lib/mimalloc && \
mkdir -p build && \
cd build && \
CC=${gcc} LD=${ld} AR=${AR} \
cmake ../ ${mimalloc_cmake_flags} \
-DCMAKE_C_FLAGS="${cflags} ${mimalloc_cflags}" \
-DCMAKE_SYSTEM_NAME="${system}" \
-DCMAKE_AR=${ar} -DCMAKE_C_COMPILER=${gcc} \
-DCMAKE_CXX_COMPILER=$(subst gcc,g++,${gcc}); \
fi
if ! [ -r ${pwd}/lib/mimalloc/build/libmimalloc-static.a ]; then \
RANLIB=${ranlib} LD=${ld} \
${MAKE} -C ${pwd}/lib/mimalloc/build; \
fi

quantum-proof-ccache: quantum-proof
quantum-proof-debug: quantum-proof
quantum-proof:
$(info -- Building Quantum-Proof libs)
CC="${quantum_proof_cc}" \
LD=${ld} \
AR=${ar} \
RANLIB=${ranlib} \
LD=${ld} \
CFLAGS="${quantum_proof_cflags} ${cflags}" \
LDFLAGS="${ldflags}" \
${MAKE} -C ${pwd}/lib/pqclean

check-milagro: milagro
CC=${gcc} CFLAGS="${cflags}" $(MAKE) -C ${pwd}/lib/milagro-crypto-c test

ed25519-donna-ccache: ed25519-donna
ed25519-donna:
echo "-- Building ED25519 for EDDSA"
CC="${ed25519_cc}" \
AR=${ar} \
CFLAGS="${cflags}" \
LDFLAGS="${ldflags}" \
$(MAKE) -C ${pwd}/lib/ed25519-donna
help:
@echo "✨ Welcome to the Zenroom build system"
@awk 'BEGIN {FS = ":.*##"; printf "🛟 Usage: make \033[36m<target>\033[0m\n👇🏽 List of targets:\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5)} ' Makefile

# help: ## 🛟 Show this help message
# @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m 👉 %-14s\033[0m %s\n", $$1, $$2}'

x86-linux: ## Dynamic executable for Linux x86 64bit
$(MAKE) -f build/linux.mk

x86-musl: ## Static executable for Linux x86 64bit
$(MAKE) -f build/musl-linux.mk

# bindings: ## Language binding for host platform
# $(MAKE) -f build/linux.mk deps zencode-exec

x86-win-exe: ## Executable for Windows x86 64bit
$(MAKE) -f build/win-exe.mk

x86-win-dll: ## Dynamic lib (DLL) for Windows x86 64bit
$(MAKE) -f build/win-dll.mk

arm64-ios: ## Dynamic lib (dylib) for Apple iOS ARM64
$(MAKE) -f build/apple-osx.mk ios-arm64

sim-ios: ## Dynamic lib (dylib) for Apple iOS simulator
$(MAKE) -f build/apple-ios.mk ios-sim

wasm: ## WebAssembly (WASM) for Javascript in-browser (Emscripten)
yarn --cwd bindings/javascript
yarn --cwd bindings/javascript build

# -------------------
# Test suites for all platforms
include ${pwd}/build/tests.mk

install: destbin=${DESTDIR}${PREFIX}/bin
install: destdocs=${DESTDIR}${PREFIX}/share/zenroom
Expand All @@ -169,12 +56,6 @@ install:
cp LICENSE.txt ${destdocs}/LICENSE.txt
cp ChangeLog.md ${destdocs}/ChangeLog.txt

install-lua: destlib=${LIBDIR}
install-lua:
mkdir -p ${destlib}
cp src/octet.so ${destlib}
cp src/ecdh.so ${destlib}

clean:
rm -rf ${pwd}/meson
$(MAKE) clean -C ${pwd}/lib/lua54/src
Expand Down Expand Up @@ -202,9 +83,6 @@ clean-src:
rm -f src/zen_ecdh_factory.c src/zen_ecp_factory.c src/zen_big_factory.c
$(MAKE) clean -C src

distclean:
rm -rf ${musl}

# -------------------
# Parsing the documentation
needed-docs:
Expand Down
5 changes: 0 additions & 5 deletions build/luarock.mk

This file was deleted.

2 changes: 1 addition & 1 deletion build/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ zenroom_include_dirs = include_directories('../src')

milagro_include_dirs = include_directories('../lib/milagro-crypto-c/include')

milagro_generated_include_dirs = include_directories('milagro-crypto-c/include')
milagro_generated_include_dirs = include_directories('../lib/milagro-crypto-c/build/include')

mimalloc_include_dirs = include_directories('../lib/mimalloc/include')

Expand Down
29 changes: 17 additions & 12 deletions build/meson.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,29 @@ endif
# activate CCACHE etc.
include build/plugins.mk

all: deps prepare config ninja

# MAIN TARGETS
all: ${BUILD_DEPS} prepare
deps: ${BUILD_DEPS}

# subtargets
prepare:
mkdir -p meson
ln -sf ../lib/milagro-crypto-c/build meson/milagro-crypto-c
ln -sf ../lib/pqclean/libqpz.a meson/libqpz.a
ln -sf ../lib/lua54/src/liblua.a meson/liblua.a
ln -sf ../lib/ed25519-donna/libed25519.a meson/libed25519.a
ln -sf ../lib/mimalloc/build/libmimalloc-static.a meson/libmimalloc-static.a
ln -sf ../lib/tinycc/libtcc.a meson/libtcc.a

config:
CC="${zenroom_cc}" AR="${ar}" CFLAGS="${cflags}" \
LDFLAGS="${ldflags}" LDADD="${ldadd}" meson -Dexamples=true \
-Ddocs=true -Doptimization=3 -Decdh_curve=${ecdh_curve} \
-Decp_curve=${ecp_curve} -Ddefault_library=both build meson

ninja:
ninja -C meson
gcc: all

asan:
CC="clang" CXX="clang++" AR="llvm-ar" CFLAGS="-fsanitize=address \
Expand All @@ -34,16 +49,6 @@ asan:
-Db_sanitize=address build meson
ninja -C meson

# subtargets
prepare:
mkdir -p meson
ln -sf ../lib/milagro-crypto-c/build meson/milagro-crypto-c
ln -sf ../lib/pqclean/libqpz.a meson/libqpz.a
ln -sf ../lib/lua54/src/liblua.a meson/liblua.a
ln -sf ../lib/ed25519-donna/libed25519.a meson/libed25519.a
ln -sf ../lib/mimalloc/build/libmimalloc-static.a meson/libmimalloc-static.a
ln -sf ../lib/tinycc/libtcc.a meson/libtcc.a

prepare-test:
echo '#!/bin/sh' > ${pwd}/test/zenroom
echo "${pwd}/meson/zenroom "'$$*' >> ${pwd}/test/zenroom
Expand Down
1 change: 1 addition & 0 deletions build/scanbuild.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#!/bin/sh
# wrapper script passed to ninja in build/sonarqube.mk
scan-build -v -plist "$@"
31 changes: 31 additions & 0 deletions build/sonarqube.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

## Initialize build defaults
include build/init.mk

## TODO: test with sonarqube server (we moved out of ow2)
SONAR_LOGIN ?= ""
SONAR_HOST_URL := https://sonarqube.ow2.org
SCANBUILD_SCRIPT := $(pwd)/build/scanbuild.sh

# Needs clang-tools for scan-build

COMPILER := clang

cflags += ${cflags_debug} -fPIC
# activate CCACHE etc.
include build/plugins.mk

sonarqube: ## build a sonarqube cpp static analysis
$(info Configure login token in build/sonarqube.sh)
$(MAKE) -f build/meson.mk deps COMPILER=clang
$(MAKE) -f build/meson.mk prepare COMPILER=clang
$(MAKE) -f build/meson.mk config COMPILER=clang
SCANBUILD=${SCANBUILD_SCRIPT} ninja -C meson scan-build
@docker pull sonarqube
@cp -v build/sonar-project.properties .
@docker run --rm -e SONAR_HOST_URL=${SONAR_HOST_URL} \
-e SONAR_LOGIN=${SONAR_LOGIN} \
-v ${pwd}:/usr/src sonarsource/sonar-scanner-cli \
-Dsonar.projectKey=zenroom

# sonarqube debug -X

0 comments on commit b9a5649

Please sign in to comment.