mirror of
https://github.com/thepigeongenerator/mcaselector-lite.git
synced 2025-12-17 07:35:45 +01:00
add test compilation / running to makefile
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -13,5 +13,7 @@
|
|||||||
*.out
|
*.out
|
||||||
/bin/
|
/bin/
|
||||||
/obj/
|
/obj/
|
||||||
|
/test/bin/
|
||||||
|
/test/obj/
|
||||||
*.lock
|
*.lock
|
||||||
compile_commands.json
|
compile_commands.json
|
||||||
|
|||||||
18
makefile
18
makefile
@@ -43,9 +43,13 @@ DIR_BIN := bin/$(ARCH)/$(PROF)
|
|||||||
DIR_OBJ := obj/$(ARCH)/$(PROF)
|
DIR_OBJ := obj/$(ARCH)/$(PROF)
|
||||||
BIN := $(DIR_BIN)/$(NAME)$(EXT)
|
BIN := $(DIR_BIN)/$(NAME)$(EXT)
|
||||||
|
|
||||||
C_SRC := $(shell find src/ -name '*.c')
|
C_SRC := $(shell find src/ -name '*.c')
|
||||||
C_OBJ := $(patsubst src/%,$(DIR_OBJ)/%,$(C_SRC:.c=.o))
|
C_OBJ := $(patsubst src/%,$(DIR_OBJ)/%,$(C_SRC:.c=.o))
|
||||||
C_DEP := $(C_OBJ:.o=.d)
|
C_DEP := $(C_OBJ:.o=.d)
|
||||||
|
C_TSRC := $(shell find test/src/ -name '*.c')
|
||||||
|
C_TOBJ := $(patsubst test/src/%,test/$(DIR_OBJ)/%,$(C_TSRC:.c=.o))
|
||||||
|
C_TDEP := $(C_TOBJ:.o=.d)
|
||||||
|
C_TOBJ += $(filter-out $(DIR_OBJ)/main.o, $(C_OBJ))
|
||||||
|
|
||||||
COMPILE_COMMANDS := $(DIR_OBJ)/compile_commands.json
|
COMPILE_COMMANDS := $(DIR_OBJ)/compile_commands.json
|
||||||
endif
|
endif
|
||||||
@@ -83,16 +87,19 @@ endef
|
|||||||
# compiles and executes the produced binary
|
# compiles and executes the produced binary
|
||||||
run: compile; cd $(DIR_BIN) && ./$(NAME)$(EXT)
|
run: compile; cd $(DIR_BIN) && ./$(NAME)$(EXT)
|
||||||
compile: compile_commands $(BIN)
|
compile: compile_commands $(BIN)
|
||||||
|
run-test: compile-test; cd test/$(DIR_BIN) && ./test$(EXT)
|
||||||
|
compile-test: test/$(DIR_BIN)/test$(EXT)
|
||||||
|
|
||||||
.NOTPARALLEL:
|
.NOTPARALLEL:
|
||||||
clean:
|
clean:
|
||||||
@$(call warn,"cleaning!")
|
@$(call warn,"cleaning!")
|
||||||
rm -rf bin/ obj/ compile_commands.json
|
rm -rf bin/ obj/ test/obj test/bin compile_commands.json
|
||||||
# TODO: write a structure for the unit tests in this
|
|
||||||
|
|
||||||
# compilation macros
|
# compilation macros
|
||||||
$(eval $(call link_bin,$(BIN),$(C_OBJ))) # link the binary
|
$(eval $(call link_bin,$(BIN),$(C_OBJ))) # link the binary
|
||||||
$(eval $(call compile_obj,$(DIR_OBJ),src)) # compile the objects for the binary
|
$(eval $(call compile_obj,$(DIR_OBJ),src)) # compile the objects for the binary
|
||||||
|
$(eval $(call link_bin,test/$(DIR_BIN)/test$(EXT),$(C_TOBJ))) # link the testing binary
|
||||||
|
$(eval $(call compile_obj,test/$(DIR_OBJ),test/src)) # compile the objects for the testing binary
|
||||||
|
|
||||||
# update compile commands if the makefile has been updated (for linting)
|
# update compile commands if the makefile has been updated (for linting)
|
||||||
compile_commands: # default, empty rule
|
compile_commands: # default, empty rule
|
||||||
@@ -118,3 +125,4 @@ endif
|
|||||||
|
|
||||||
# include the dependencies
|
# include the dependencies
|
||||||
-include $(C_DEP)
|
-include $(C_DEP)
|
||||||
|
-include $(C_TDEP)
|
||||||
|
|||||||
Reference in New Issue
Block a user