libcdsb/tests/Makefile
2022-06-09 11:39:19 +03:00

101 lines
4.8 KiB
Makefile

# This software is licensed by the MIT License, see LICENSE file
# Copyright © 2022 Gregory Lirent
########################################################################################################################
BUILD_PATH ?= ./bin
########################################################################################################################
CC = clang
MKDIR = mkdir -p
RMRF = rm -rf
AR = ar crs
CP = cp
$(BUILD_PATH)/obj/%.o: CFLAGS := $(CFLAGS) -Og -fPIC -c -g3 -Wall
########################################################################################################################
c_objects = $(addsuffix .o,$(addprefix $(2),$(notdir $(basename $(wildcard $(1)*.c)))))
OBJECTS_TESTS := $(call c_objects,./src/,)
OBJECTS_BASE := $(call c_objects,../src/,)
OBJECTS_STRING := $(OBJECTS_BASE) $(call c_objects,../src/string/,string-)
OBJECTS_ARRAY := $(OBJECTS_BASE) $(call c_objects,../src/array/,array-)
OBJECTS_LIST := $(OBJECTS_BASE) $(call c_objects,../src/list/,list-)
OBJECTS_MAP := $(OBJECTS_BASE) $(call c_objects,../src/map/,map-)
OBJECTS_SET := $(OBJECTS_BASE) $(call c_objects,../src/set/,set-)
OBJECTS_BASE := $(addprefix $(BUILD_PATH)/obj/,$(OBJECTS_TESTS)) $(addprefix ../bin/debug/obj/,$(OBJECTS_BASE))
OBJECTS_STRING := $(addprefix $(BUILD_PATH)/obj/,$(OBJECTS_TESTS)) $(addprefix ../bin/debug/obj/,$(OBJECTS_STRING))
OBJECTS_ARRAY := $(addprefix $(BUILD_PATH)/obj/,$(OBJECTS_TESTS)) $(addprefix ../bin/debug/obj/,$(OBJECTS_ARRAY))
OBJECTS_LIST := $(addprefix $(BUILD_PATH)/obj/,$(OBJECTS_TESTS)) $(addprefix ../bin/debug/obj/,$(OBJECTS_LIST))
OBJECTS_MAP := $(addprefix $(BUILD_PATH)/obj/,$(OBJECTS_TESTS)) $(addprefix ../bin/debug/obj/,$(OBJECTS_MAP))
OBJECTS_SET := $(addprefix $(BUILD_PATH)/obj/,$(OBJECTS_TESTS)) $(addprefix ../bin/debug/obj/,$(OBJECTS_SET))
OBJECTS_STRING := $(OBJECTS_STRING) $(addprefix $(BUILD_PATH)/obj/,$(call c_objects,./src/string/src/,string-))
OBJECTS_ARRAY := $(OBJECTS_ARRAY) $(addprefix $(BUILD_PATH)/obj/,$(call c_objects,./src/array/src/,array-))
OBJECTS_LIST := $(OBJECTS_LIST) $(addprefix $(BUILD_PATH)/obj/,$(call c_objects,./src/list/src/,list-))
OBJECTS_MAP := $(OBJECTS_MAP) $(addprefix $(BUILD_PATH)/obj/,$(call c_objects,./src/map/src/,map-))
OBJECTS_SET := $(OBJECTS_SET) $(addprefix $(BUILD_PATH)/obj/,$(call c_objects,./src/set/src/,set-))
########################################################################################################################
tests: modules
tests: $(addprefix $(BUILD_PATH)/array-,$(notdir $(basename $(wildcard ./src/array/*.c))))
tests: $(addprefix $(BUILD_PATH)/string-,$(notdir $(basename $(wildcard ./src/string/*.c))))
tests: $(addprefix $(BUILD_PATH)/list-,$(notdir $(basename $(wildcard ./src/list/*.c))))
tests: $(addprefix $(BUILD_PATH)/map-,$(notdir $(basename $(wildcard ./src/map/*.c))))
tests: $(addprefix $(BUILD_PATH)/set-,$(notdir $(basename $(wildcard ./src/set/*.c))))
########################################################################################################################
$(BUILD_PATH)/obj/%.o: ./src/%.c | $(BUILD_PATH)/obj/
$(CC) $^ -o $@ $(CFLAGS)
$(BUILD_PATH)/obj/array-%.o: ./src/array/src/%.c | $(BUILD_PATH)/obj/
$(CC) $^ -o $@ $(CFLAGS)
$(BUILD_PATH)/obj/string-%.o: ./src/string/src/%.c | $(BUILD_PATH)/obj/
$(CC) $^ -o $@ $(CFLAGS)
$(BUILD_PATH)/obj/list-%.o: ./src/list/src/%.c | $(BUILD_PATH)/obj/
$(CC) $^ -o $@ $(CFLAGS)
$(BUILD_PATH)/obj/map-%.o: ./src/map/src/%.c | $(BUILD_PATH)/obj/
$(CC) $^ -o $@ $(CFLAGS)
$(BUILD_PATH)/obj/set-%.o: ./src/set/src/%.c | $(BUILD_PATH)/obj/
$(CC) $^ -o $@ $(CFLAGS)
$(BUILD_PATH)/array-%: ./src/array/%.c $(OBJECTS_ARRAY) | $(BUILD_PATH)/
$(CC) $^ -o $@ $(CFLAGS) -g3 -Wall
$(BUILD_PATH)/string-%: ./src/string/%.c $(OBJECTS_STRING) | $(BUILD_PATH)/
$(CC) $^ -o $@ ../modules/libunic/bin/libunic.a $(CFLAGS) -g3 -Wall
$(BUILD_PATH)/list-%: ./src/list/%.c $(OBJECTS_LIST) | $(BUILD_PATH)/
$(CC) $^ -o $@ $(CFLAGS) -g3 -Wall
$(BUILD_PATH)/map-%: ./src/map/%.c $(OBJECTS_MAP) | $(BUILD_PATH)/
$(CC) $^ -o $@ $(CFLAGS) -g3 -Wall
$(BUILD_PATH)/set-%: ./src/set/%.c $(OBJECTS_SET) | $(BUILD_PATH)/
$(CC) $^ -o $@ $(CFLAGS) -g3 -Wall
########################################################################################################################
$(BUILD_PATH)/:
$(MKDIR) $@
$(BUILD_PATH)/obj/: | $(BUILD_PATH)/
$(MKDIR) $@
########################################################################################################################
clean:
$(RMRF) ./bin/
cd ../ && $(MAKE) clean
########################################################################################################################
FORCE:
modules: ../bin/debug/libcdsb.a
../bin/debug/libcdsb.a: FORCE
cd ../ && $(MAKE) debug