Add Makefile
This commit is contained in:
parent
0cea19dbea
commit
6292a9c866
78
Makefile
Normal file
78
Makefile
Normal file
@ -0,0 +1,78 @@
|
||||
# This software is licensed by the MIT License, see LICENSE file
|
||||
# Copyright © 2022 Gregory Lirent
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
BUILD_PATH ?= ./bin
|
||||
LIB_NAME = cjsonp
|
||||
|
||||
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 -O0 -fPIC -c -g3 -Wall
|
||||
$(RELEASE_PATH)/obj/%.o: CFLAGS := $(CFLAGS) -DNDEBUG -O2 -fPIC -c
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
debug: ./modules/libcdsb/bin/debug/libcdsb.a $(DEBUG_PATH)/lib$(LIB_NAME).a
|
||||
release: ./modules/libcdsb/bin/release/libcdsb.a $(RELEASE_PATH)/lib$(LIB_NAME).a
|
||||
examples: debug $(addprefix $(BUILD_PATH)/,$(notdir $(basename $(wildcard ./*.c))))
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
c_objects = $(addsuffix .o,$(addprefix $(2),$(notdir $(basename $(wildcard $(1)*.c)))))
|
||||
OBJECTS = $(call c_objects,./src/,)
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
$(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/%.o: ./src/%.c | $(DEBUG_PATH)/obj/
|
||||
$(CC) $^ -o $@ $(CFLAGS)
|
||||
$(RELEASE_PATH)/obj/%.o: ./src/%.c | $(RELEASE_PATH)/obj/
|
||||
$(CC) $^ -o $@ $(CFLAGS)
|
||||
$(BUILD_PATH)/%: ./%.c $(DEBUG_PATH)/lib$(LIB_NAME).a ./modules/libcdsb/bin/debug/libcdsb.a ./modules/libcdsb/modules/libunic/bin/libunic.a | $(BUILD_PATH)/
|
||||
$(CC) $^ -o $@ $(CFLAGS) -g3 -Wall
|
||||
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
$(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/
|
||||
|
||||
%.a:
|
||||
$(AR) $@ $?
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
FORCE:
|
||||
|
||||
./modules/libcdsb/bin/debug/libcdsb.a: FORCE
|
||||
cd ./modules/libcdsb && $(MAKE) debug
|
||||
|
||||
./modules/libcdsb/bin/release/libcdsb.a: FORCE
|
||||
cd ./modules/libcdsb && $(MAKE) release
|
Loading…
Reference in New Issue
Block a user