From 2a121caf427100fd2854da84b9d3e11a74a3d760 Mon Sep 17 00:00:00 2001 From: Riley King-Saunders Date: Tue, 25 Nov 2025 00:04:24 +1100 Subject: [PATCH] Created main makefile - Need to add clean recipe `make modules debug|release MODULES...` Builds the provided list of lua modules in release/debug `make release` `make debug` Builds a debug build of the lbs program `make clean` TODO --- makefile | 132 +++++++++++++++++++++++++++---------------------------- 1 file changed, 65 insertions(+), 67 deletions(-) diff --git a/makefile b/makefile index d7cdb6d..774d8f0 100644 --- a/makefile +++ b/makefile @@ -1,72 +1,70 @@ -CXX := clang++ -CC := clang +CC=clang +CFLAGS = -Wall -Wextra -INCLUDES := include src thirdparty/luajit/src thirdparty/uniproc/include thirdparty/libgit2/include -LIBRARY_DIRECTORIES := thirdparty/luajit/src thirdparty/libgit2 -LINKER_INPUTS := lua51 luajit - -DEBUG_DEFINES := -DEFINES := - -CXX_FLAGS := -std=c11 -std=c++20 -g -O0 -CC_FLAGS := -std=c11 -g -O0 -CXX_DEBUG_FLAGS := -LNK_FLAGS := -g -O0 -LNK_DEBUG_FLAGS := - -LUAJUT_BUILD_CMD := call msvcbuild.bat - -.PHONY: all clean -all: build_deps link_lbs - -# From https://stackoverflow.com/a/18258352/8617429 -rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d)) -define \n - -endef -ifeq ($(OS), Windows_NT) - PLATFORM_SEPERATOR := & - touch = type nul > $(1) - rm = rmdir /S /Q $(1) > nul || (exit 0) - RM = del - mkdir = mkdir $(subst /,\,$(1)) > nul 2>&1 || (exit 0) - OUTPUT_NAME := lbs.exe +ifeq ($(OS),Windows_NT) + CFLAGS += -D WIN32 + ifeq ($(PROCESSOR_ARCHITEW6432),AMD64) + CFLAGS += -D AMD64 + else + ifeq ($(PROCESSOR_ARCHITECTURE),AMD64) + CFLAGS += -D AMD64 + endif + ifeq ($(PROCESSOR_ARCHITECTURE),x86) + CFLAGS += -D IA32 + endif + endif + + RELEASE_TARGET=bin/lbs.exe + DEBUG_TARGET=bin/lbs-dbg.exe else - PLATFORM_SEPERATOR := && - touch = touch $(1) - rm = rm -rf $(1) - RM = rm -f - mkdir = mkdir -p $(1) - OUTPUT_NAME := lbs + UNAME_S := $(shell uname -s) + ifeq ($(UNAME_S),Linux) + CFLAGS += -D LINUX + endif + ifeq ($(UNAME_S),Darwin) + CFLAGS += -D OSX + endif + UNAME_P := $(shell uname -p) + ifeq ($(UNAME_P),x86_64) + CFLAGS += -D AMD64 + endif + ifneq ($(filter %86,$(UNAME_P)),) + CFLAGS += -D IA32 + endif + ifneq ($(filter arm%,$(UNAME_P)),) + CFLAGS += -D ARM + endif + RELEASE_TARGET=bin/lbs + DEBUG_TARGET=bin/lbs-dbg endif + +# If the first argument is "modules"... +ifeq (modules,$(firstword $(MAKECMDGOALS))) + # use the rest as arguments for "run" + MODULE_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) + # ...and turn them into do-nothing targets + $(eval $(MODULE_ARGS):;@:) +endif + +rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d)) + +SRC_FILES=$(call rwildcard, src, *.c) +OBJ_FILES=$(addprefix obj/, $(SRC_FILES:.c=.o)) +modules: + cd modules && $(MAKE) $(MODULE_ARGS) + + +obj/src/%.o: src/%.c + $(CC) $(CFLAGS) -c $(@:obj/%.o=%.c) -o $@ + +release: $(RELEASE_TARGET) +$(RELEASE_TARGET): $(OBJ_FILES) + $(CC) $(LFLAGS) $^ -o $@ + +debug: $(DEBUG_TARGET) +$(DEBUG_TARGET): $(OBJ_FILES) + $(CC) $(LFLAGS) $^ -o $@ + clean: - $(call RM,$(call rwildcard, obj,*.o) build/$(OUTPUT_NAME)) - -SOURCE_FILES := $(call rwildcard,src,*.cpp,*.hpp) $(call rwildcard,thirdparty/uniproc/src,*.c) -OBJECT_FILES := $(foreach d,$(addsuffix .o,$(SOURCE_FILES)), obj/$(d)) - -obj/thirdparty/uniproc/src/%.c.o: thirdparty/uniproc/src/%.c - $(CC) -c $(CC_FLAGS) $(foreach inc,$(INCLUDES),-I$(inc)) $(foreach def,$(DEFINES),-D$(def)) $< -o $@ -obj/src/%.cpp.o: src/%.cpp - $(CXX) -c $(CXX_FLAGS) $(foreach inc,$(INCLUDES),-I$(inc)) $(foreach def,$(DEFINES),-D$(def)) $< -o $@ - -link_lbs: $(OBJECT_FILES) - $(CXX) $(LNK_FLAGS) $(LNK_FLAGS) $(foreach lib,$(LIBRARY_DIRECTORIES),-L$(lib)) $(foreach lnk,$(LINKER_INPUTS),-l$(lnk)) $^ -o build/$(OUTPUT_NAME) - -build_deps: .make/thirdparty_luajit .make/thirdparty_uniproc - -.make/thirdparty_luajit: - git submodule update --init --recursive --remote - cd thirdparty/luajit/src $(PLATFORM_SEPERATOR) $(LUAJUT_BUILD_CMD) - $(call touch,".make/thirdparty_luajit") - -.make/thirdparty_uniproc: - git submodule update --init --recursive --remote - $(call touch,".make/thirdparty_uniproc") - -.make/thirdparty_libgit2: - git submodule update --init --recursive --remote - cd thirdparty/libgit2 && mkdir build - cd thirdparty/libgit2/build && cmake .. && cmake --build . - $(call touch,".make/thirdparty_libgit2") + echo TODO