diff --git a/Makefile b/Makefile index 4258e4f7b4f1ab6d4bc3509bf94c0d7fffa18346..0242c381bd804f23f186636955ab984b7c64fe16 100644 --- a/Makefile +++ b/Makefile @@ -5,13 +5,21 @@ SRCS = core.c json.c http.c timer.c util.c log.c assert.c request.c env.c crypto.c sqlite.c fs.c process.c template.c ini.c path.c stash.c sqlite/sqlite3.c cjson/cJSON.c OBJS = $(SRCS:.c=.o) +MEX_ASSURE = zig make cmake flex bison +MEX_DESCRIPTION = "Lightweight Lua runtime powered by LuaJIT and libev" + +include makext.mk +help: .help + +build: .assure luna # Statically compiles luna binary + luna: $(OBJS) $(CC) $(CFLAGS) -static -o $@ $^ $(LIBS) %.o: %.c $(CC) $(CFLAGS) -c -o $@ $< -requirements: +requirements: .assure # Compiles all required libraries cd luajit/src && \ make clean && \ make -j`nproc` CC="zig cc -target x86_64-linux-musl" HOST_CC="gcc" BUILDMODE=static TARGET_LDFLAGS="-lunwind" @@ -64,7 +72,7 @@ -DBUILD_SHARED_LIBS=OFF \ -DBUILD_STATIC_LIBS=ON && \ make -j`nproc` -clean: +clean: # Cleans up build artefacts rm -f luna *.o .PHONY: clean requirements diff --git a/makext.mk b/makext.mk new file mode 100644 index 0000000000000000000000000000000000000000..bbfa148d98f5ae69c63cb95bf1efc1438d2f3b07 --- /dev/null +++ b/makext.mk @@ -0,0 +1,46 @@ +# Makext is a collection of useful extensions for Makefiles, aimed at +# simplifying and enhancing the functionality of Make-based projects. These +# extensions provide additional features and convenience functions to +# improve the build process, manage dependencies, and streamline common +# tasks. +# +# Visit the GitHub repository at https://github.com/mitjafelicijan/makext +# to learn more and contribute to the project. +# +# `makext` was written by Mitja Felicijan and is released under the BSD +# two-clause license, see the LICENSE file for more information. + +# Load environmental files from `MEX_ENVIRONMENT`. By default GNU make +# loads what is already in `env`. This extends it to other files. +ifdef MEX_ENVIRONMENT +TEMP_ENV_FILES=$(shell echo $(MEX_ENVIRONMENT) | tr ',' ' ') +$(foreach file,$(TEMP_ENV_FILES),$(eval include $(file))) +endif + +# Help extension that lists all the targets with descriptions +# and adds description and license information if data provided. +.PHONY: .help +.help: +ifdef MEX_DESCRIPTION + @printf "%s\n\n" $(MEX_DESCRIPTION) | fmt +endif + @echo "Targets:" + @grep -vE '^[[:space:]]' $(MAKEFILE_LIST) | grep -E '^.*:.* #' | sed -E 's/(.*):(.*):.*#(.*)/ \2###\3/' | column -t -s '###' +ifdef MEX_LICENSE + @printf "\n%s" $(MEX_LICENSE) | fmt +endif + +# Checks `MEX_ASSURE` variable if all the programs declared actually +# exist on a machine. If not this exists make with error. +.PHONY: .assure +.assure: +ifndef MEX_ASSURE + @printf "Variable MEX_ASSURE is not defined. Can not check for programs.\n" +else + @for prog in $(shell echo $(MEX_ASSURE)); do \ + if ! which $$prog > /dev/null; then \ + echo "Error: '$$prog' not found on this machine."; \ + exit 1; \ + fi; \ + done +endif