varch/makefile
2024-10-20 20:23:15 +08:00

98 lines
3.4 KiB
Makefile

##################################################################################
### config
##################################################################################
CC = gcc
AR = ar
BUILT_DIR = built
TARGET = app
LIB = varch
##################################################################################
### source locations
##################################################################################
WORKSPACE = source
TESTSPACE = test
APPLICATION_PATH = $(WORKSPACE)/00_application
GENDATA_PATH = $(WORKSPACE)/01_general
VSTD_PATH = $(WORKSPACE)/02_vstd
CONTAINER_PATH = $(WORKSPACE)/03_container
ALGORITHM_PATH = $(WORKSPACE)/04_algorithm
PARSER_PATH = $(WORKSPACE)/05_parser
##################################################################################
### sources and head path
##################################################################################
include $(TESTSPACE)/test.mk
INCLUDE += $(APPLICATION_PATH)
INCLUDE += $(GENDATA_PATH)
INCLUDE += $(VSTD_PATH)
INCLUDE += $(CONTAINER_PATH)
INCLUDE += $(ALGORITHM_PATH)
INCLUDE += $(PARSER_PATH)
LIBSRCS += $(APPLICATION_PATH)/init.c
LIBSRCS += $(wildcard $(APPLICATION_PATH)/console/*.c)
LIBSRCS += $(wildcard $(GENDATA_PATH)/*.c)
LIBSRCS += $(wildcard $(VSTD_PATH)/*.c)
LIBSRCS += $(wildcard $(CONTAINER_PATH)/*.c)
LIBSRCS += $(wildcard $(ALGORITHM_PATH)/*.c)
LIBSRCS += $(wildcard $(PARSER_PATH)/*.c)
TESTSRC += $(APPLICATION_PATH)/main.c
TESTSRC += $(TEST_SRC)
##################################################################################
### targets and recipes
##################################################################################
INCS = $(addprefix -I,$(INCLUDE))
OBJP = $(BUILT_DIR)/obj
BINP = $(BUILT_DIR)/bin
LIBO = $(patsubst %.c, $(OBJP)/%.o, $(LIBSRCS))
TSTO = $(patsubst %.c, $(OBJP)/%.o, $(TESTSRC))
OBJS = $(LIBO) $(TSTO)
TARP = $(BINP)/$(TARGET)
LIBN = lib$(LIB)
LIBA = $(BUILT_DIR)/$(LIBN).a
LIBP ?= /usr
# link
${TARP}:$(OBJS)
mkdir -p $(dir $@)
# @ $(CC) $(OBJS) -o $(TARP) -lm -lX11 -lpthread
@ $(CC) $(CFLAG) $(OBJS) -o $(TARP) -lm -lpthread
# compile
$(OBJP)/%.o:%.c
@ mkdir -p $(dir $@)
@ echo "compiling $(notdir $<)"
@ $(CC) $(CFLAG) $(INCS) -c $< -o $@
.PHONY:clean
clean:
@echo "remove app and objs files ..."
@ rm $(BUILT_DIR)/$(WORKSPACE) -rf
@ rm $(BUILT_DIR)/* -rf
.PHONY:install
install:$(LIBO)
@ $(AR) -crv $(LIBA) $(LIBO)
@ mkdir -p $(LIBP)/include/$(LIB)
@ find $(INCLUDE) -name "*.h" -exec cp {} $(LIBP)/include/$(LIB) \;
@ mv -f $(LIBA) $(LIBP)/lib \
&& ( echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" && \
echo "[INFO] varch install success !!!" && \
echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") \
|| ( echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" && \
echo "[ERROR] varch install fail !!!" && \
echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" && \
rm $(LIBP)/include/$(LIB) -rf )
# @ ldconfig
.PHONY:uninstall
uninstall:
@ rm $(BUILT_DIR)/$(LIB) -rf
@ rm $(LIBP)/lib/$(LIBN).a
@ rm $(LIBP)/include/$(LIB) -rf
# @ ldconfig