Add Makefile
This commit is contained in:
parent
540d71ee3c
commit
da30923089
101
Makefile
Normal file
101
Makefile
Normal file
@ -0,0 +1,101 @@
|
||||
# This software is licensed by the MIT License, see LICENSE file
|
||||
# Copyright © 2022 Gregory Lirent
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
BUILD_PATH ?= ./bin
|
||||
LIB_NAME = cdsb
|
||||
|
||||
DEBUG_PATH = $(BUILD_PATH)/debug
|
||||
RELEASE_PATH = $(BUILD_PATH)/release
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
CC = clang
|
||||
MKDIR = mkdir -p
|
||||
RMRF = rm -rf
|
||||
AR = ar crs
|
||||
CP = cp
|
||||
|
||||
$(DEBUG_PATH)/obj/%.o: CFLAGS := $(CFLAGS) -DDEBUG -Og -fPIC -c -g3 -Wall
|
||||
$(RELEASE_PATH)/obj/%.o: CFLAGS := $(CFLAGS) -DNDEBUG -O2 -fPIC -c
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
debug: modules $(DEBUG_PATH)/lib$(LIB_NAME).a
|
||||
release: modules $(RELEASE_PATH)/lib$(LIB_NAME).a
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
c_objects = $(addsuffix .o,$(addprefix $(2),$(notdir $(basename $(wildcard $(1)*.c)))))
|
||||
|
||||
OBJECTS = $(call c_objects,./src/,)\
|
||||
$(call c_objects,./src/string/,string-)\
|
||||
$(call c_objects,./src/array/,array-)\
|
||||
$(call c_objects,./src/list/,list-)\
|
||||
$(call c_objects,./src/map/,map-)\
|
||||
$(call c_objects,./src/set/,set-)
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
$(DEBUG_PATH)/lib$(LIB_NAME).a: $(addprefix $(DEBUG_PATH)/obj/,$(OBJECTS)) | $(DEBUG_PATH)/
|
||||
$(RELEASE_PATH)/lib$(LIB_NAME).a: $(addprefix $(RELEASE_PATH)/obj/,$(OBJECTS)) | $(RELEASE_PATH)/
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
$(DEBUG_PATH)/obj/string-%.o: ./src/string/%.c | $(DEBUG_PATH)/obj/
|
||||
$(CC) $^ -o $@ $(CFLAGS)
|
||||
$(DEBUG_PATH)/obj/array-%.o: ./src/array/%.c | $(DEBUG_PATH)/obj/
|
||||
$(CC) $^ -o $@ $(CFLAGS)
|
||||
$(DEBUG_PATH)/obj/list-%.o: ./src/list/%.c | $(DEBUG_PATH)/obj/
|
||||
$(CC) $^ -o $@ $(CFLAGS)
|
||||
$(DEBUG_PATH)/obj/map-%.o: ./src/map/%.c | $(DEBUG_PATH)/obj/
|
||||
$(CC) $^ -o $@ $(CFLAGS)
|
||||
$(DEBUG_PATH)/obj/set-%.o: ./src/set/%.c | $(DEBUG_PATH)/obj/
|
||||
$(CC) $^ -o $@ $(CFLAGS)
|
||||
$(DEBUG_PATH)/obj/%.o: ./src/%.c | $(DEBUG_PATH)/obj/
|
||||
$(CC) $^ -o $@ $(CFLAGS)
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
$(RELEASE_PATH)/obj/string-%.o: ./src/string/%.c | $(RELEASE_PATH)/obj/
|
||||
$(CC) $^ -o $@ $(CFLAGS)
|
||||
$(RELEASE_PATH)/obj/array-%.o: ./src/array/%.c | $(RELEASE_PATH)/obj/
|
||||
$(CC) $^ -o $@ $(CFLAGS)
|
||||
$(RELEASE_PATH)/obj/list-%.o: ./src/list/%.c | $(RELEASE_PATH)/obj/
|
||||
$(CC) $^ -o $@ $(CFLAGS)
|
||||
$(RELEASE_PATH)/obj/map-%.o: ./src/map/%.c | $(RELEASE_PATH)/obj/
|
||||
$(CC) $^ -o $@ $(CFLAGS)
|
||||
$(RELEASE_PATH)/obj/set-%.o: ./src/set/%.c | $(RELEASE_PATH)/obj/
|
||||
$(CC) $^ -o $@ $(CFLAGS)
|
||||
$(RELEASE_PATH)/obj/%.o: ./src/%.c | $(RELEASE_PATH)/obj/
|
||||
$(CC) $^ -o $@ $(CFLAGS)
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
$(BUILD_PATH)/:
|
||||
$(MKDIR) $@
|
||||
$(DEBUG_PATH)/: | $(BUILD_PATH)/
|
||||
$(MKDIR) $@
|
||||
$(RELEASE_PATH)/: | $(BUILD_PATH)/
|
||||
$(MKDIR) $@
|
||||
$(DEBUG_PATH)/obj/: | $(DEBUG_PATH)/
|
||||
$(MKDIR) $@
|
||||
$(RELEASE_PATH)/obj/: | $(RELEASE_PATH)/
|
||||
$(MKDIR) $@
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
clean:
|
||||
$(RMRF) ./bin/
|
||||
cd ./modules/libunic && $(MAKE) clean
|
||||
|
||||
%.a:
|
||||
$(AR) $@ $^
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
modules: ./modules/libunic/bin/libunic.a
|
||||
|
||||
./modules/libunic/bin/libunic.a:
|
||||
cd ./modules/libunic && $(MAKE)
|
Loading…
Reference in New Issue
Block a user