diff options
author | Aleksey Veresov <aleksey@veresov.pro> | 2020-03-16 19:33:58 +0300 |
---|---|---|
committer | Aleksey Veresov <aleksey@veresov.pro> | 2020-03-16 19:33:58 +0300 |
commit | d9f19275d0549c4b9c3402e1fd28c71627507557 (patch) | |
tree | 0f6130f1eeefc182f93c52c400f0c1b84a3a0eb9 /Makefile | |
parent | c5d69441bd43ace9d9c2b03a89aa0ed4871c288d (diff) | |
download | magi-d9f19275d0549c4b9c3402e1fd28c71627507557.tar magi-d9f19275d0549c4b9c3402e1fd28c71627507557.tar.xz magi-d9f19275d0549c4b9c3402e1fd28c71627507557.zip |
[magi]
Diffstat (limited to 'Makefile')
-rw-r--r-- | Makefile | 71 |
1 files changed, 52 insertions, 19 deletions
@@ -1,56 +1,89 @@ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Compilation Options # Debug mode (allowing to debug the library via gdb): -# DEBUG = yes +# DEBUG = yes +# Specify directory to store object files: +OBJ_DIR = build # Optional modules (remove unwanted ones): -MODULES = cgi fastcgi loadfile urlenc +MODULES = cgi fastcgi loadfile urlenc +# Examples to build with 'examples' target: +EXAMPLES = append cookie echo upload # Specify your favourite C compiler here: -CC = gcc +CC = gcc # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Preparations -LIB = libmagi.a +LIB = libmagi.a # Compile under the most strict conditions: -CFLAGS = -xc -ansi -pedantic -Wall -Wextra +CFLAGS = -xc -ansi -pedantic -Wall -Wextra # Debug and optimisation are not compatible: ifeq '$(DEBUG)' 'yes' -CFLAGS += -g -O0 +CFLAGS += -g -O0 else -CFLAGS += -O3 -static +CFLAGS += -O3 -static endif # Interfacial files to compile: -INTER = cookie error file param request response $(MODULES) +INTER = cookie error file param request response $(MODULES) # Object files listing: -INC_DIR = include/magi -SRC_DIR = src -INTER_H = $(foreach name,$(INTER),$(INC_DIR)/$(name).h) -INTER_C = $(foreach name,$(INTER),$(SRC_DIR)/$(name).c) -INNER_H = $(wildcard $(SRC_DIR)/*.h) -INNER_C = $(INNER_H:.h=.c) -SRC = $(INTER_C) $(INNER_C) -OBJ = $(SRC:.c=.o) +INC_DIR = include/magi +SRC_DIR = src +INTER_H = $(foreach name,$(INTER),$(INC_DIR)/$(name).h) +INTER_C = $(foreach name,$(INTER),$(SRC_DIR)/$(name).c) +INNER_H = $(wildcard $(SRC_DIR)/*.h) +INNER_C = $(INNER_H:.h=.c) +SRC = $(INTER_C) $(INNER_C) +NAMES = $(notdir $(SRC:.c=)) +OBJ = $(foreach name,$(NAMES),$(OBJ_DIR)/$(name).o) + +EXDIR = examples +EXSRC = $(foreach ex,$(EXAMPLES),$(EXDIR)/$(ex).c) # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Targets +.PHONY: default clean examples + # 'make' produces library by default: -default: $(LIB) +default: $(OBJ_DIR) $(LIB) # Cleaning means removing everything automatically produced: clean: - rm -f $(OBJ) $(LIB) + rm -rf $(OBJ_DIR) $(LIB) $(EXAMPLES) deps.mk + +examples: default $(EXAMPLES) # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Compilation # Compile object files from corresponding source and header: -%.o: %.c +$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(CC) $(CFLAGS) -I $(INC_DIR) -c $< -o $@ # Packing object files into library: $(LIB): $(OBJ) ar rcs $@ $^ + +# Making directory for object files: +$(OBJ_DIR): + mkdir $@ + +# Compile executables from corresponding sources and library: +%: $(EXDIR)/%.c + $(CC) $(CFLAGS) -I include $< -L. -lmagi -o $@ + + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# Dependencies +deps.mk: $(SRC) + echo '' > deps.mk + for t in $(NAMES); do \ + $(CC) -I $(INC_DIR) -MT $(OBJ_DIR)/$${t}.o -MM $(SRC_DIR)/$${t}.c >> $@; \ + done + +ifneq (clean, $(MAKECMDGOALS)) +-include deps.mk +endif |