Makefile 3.07 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
### Colours ###
COL_BLACK = \033[01;30m
COL_GREEN = \033[01;32m
COL_BLUE = \033[01;34m
COL_RED = \033[01;31m
COL_YELLOW = \033[01;33m
COL_VIOLET = \033[01;35m
COL_CYAN = \033[01;36m
COL_WHITE = \033[01;37m
COL_END = \033[0m

12
INC_DIRS = obj/ src/ src/hash/ src/dns/ src/other/ src/server/ src/zoneparser/ src/tests src/tests/libtap src/dnslib/ src/stat src/alloc/
13
SRC_DIRS = src/
14
TESTS_DIR = src/tests/
15
ZONEC_DIR = src/zoneparser/
16
OBJ_DIR = obj/
17
BIN_DIR = bin/
18

19 20 21
YACC = yacc
LEX  = flex

22
VPATH += ${SRC_DIRS} ${INC_DIRS} ${OBJ_DIR}
23

24 25 26
PARSER_OBJ  = $(OBJ_DIR)zparser
LEXER_OBJ   = $(OBJ_DIR)zlexer
PARSER_FILES = $(PARSER_OBJ).c $(LEXER_OBJ).c
27
TESTS_FILES = $(TESTS_DIR)/main.c $(TESTS_DIR)/libtap/tap.c
28
ZONEC_FILES = $(ZONEC_DIR)/main.c
29

30 31 32
SRC_FILES = $(shell find $(SRC_DIRS) ! -path "*/tests/*" -name "*.c" ! -name "main.c")

OBJS = $(PARSER_OBJ).c $(LEXER_OBJ).o $(addprefix $(OBJ_DIR), $(addsuffix .o, $(basename $(notdir $(SRC_FILES)))))
33 34

CC = gcc
35 36 37
CFLAGS_DEBUG = -g -O0
CFLAGS_OPTIMAL = -O2 -funroll-loops -fomit-frame-pointer
CFLAGS += -Wall -std=gnu99 -D _XOPEN_SOURCE=600 -D_GNU_SOURCE
38
LDFLAGS += -lpthread -lurcu -lrt -lm
39

40
all: cutedns unittests zoneparser
41 42 43 44 45
ifeq ($(DEBUG),1)
CFLAGS += $(CFLAGS_DEBUG)
else
CFLAGS += $(CFLAGS_OPTIMAL)
endif
46 47 48 49 50 51 52

### Dependencies ###
DEPEND = $(CC) $(addprefix -I ,$(INC_DIRS)) -MM $(SRC_FILES)   2>/dev/null | sed "s%^\([^\ \t\n]*\.o\)%$(OBJ_DIR)/\1%"

Makefile.depend:
	@$(DEPEND) > Makefile.depend

53
$(LEXER_OBJ).c: $(ZONEC_DIR)/zlexer.lex
54 55
	$(LEX) -i -t $< >> $@

56 57
$(PARSER_OBJ).c $(PARSER_OBJ).h: $(ZONEC_DIR)/zparser.y
	$(YACC) -d -o $(PARSER_OBJ).c $(ZONEC_DIR)/zparser.y
58

59
# cutedns
60
cutedns: Makefile.depend $(PARSER_FILES) $(OBJS) $(SRC_DIRS)main.c
61
	@echo "$(COL_WHITE)Linking... $(COL_YELLOW)${BIN_DIR}$@$(COL_END) <-- $(COL_CYAN)$(OBJS) $(SRC_DIRS)main.c$(COL_END)"
62 63
	@$(CC) $(CFLAGS) $(addprefix -I ,$(INC_DIRS)) $(LDFLAGS) $(OBJS) $(SRC_DIRS)main.c -o ${BIN_DIR}$@

64
zoneparser: Makefile.depend cutedns $(OBJS) $(PARSER_FILES) $(ZPARSER_FILES)
65 66 67
	@echo "$(COL_WHITE)Linking... $(COL_YELLOW)${BIN_DIR}$@$(COL_END) <-- $(COL_CYAN)$(PARSER_FILES) $(OBJS) $(ZONEC_FILES)$(COL_END)"
	@$(CC) $(CFLAGS) $(addprefix -I ,$(INC_DIRS)) $(LDFLAGS) $(OBJS) $(ZONEC_FILES) -o ${BIN_DIR}$@

68
unittests: Makefile.depend cutedns $(OBJS) $(TESTS_FILES)
69
	@echo "$(COL_WHITE)Linking... $(COL_YELLOW)${BIN_DIR}$@$(COL_END) <-- $(COL_CYAN)$(OBJS) $(TESTS_FILES)$(COL_END)"
70 71 72 73
	@$(CC) $(CFLAGS) $(addprefix -I ,$(INC_DIRS)) $(LDFLAGS) $(OBJS) $(TESTS_FILES) -o ${BIN_DIR}$@

test: unittests
	@bin/unittests samples/example.com.zone
74

75
.PHONY: Makefile.depend
76 77 78 79 80 81 82 83
.INTERMEDIATE: Makefile.depend

-include Makefile.depend

.SUFFIXES:

### Generic Rules ###

84
$(OBJ_DIR)%.o : %.c
85
	@echo "$(COL_WHITE)Compiling $(COL_CYAN)$@: $(COL_BLUE)$< $(COL_END)"
86
	@$(CC) $(CFLAGS) $(addprefix -I ,$(INC_DIRS)) -c -o $@ $<
87

88 89
### Cleaning and documentation ###
.PHONY: clean doc
90
clean:
91 92
	@echo "$(COL_WHITE)Cleaning flex & bison files ...$(COL_RED)"
	@rm -vf $(OBJ_DIR)zlexer.c $(OBJ_DIR)zparser.h $(OBJ_DIR)zparser.c
93 94 95
	@echo "$(COL_WHITE)Cleaning object files...$(COL_RED)"
	@rm -vf ${OBJ_DIR}/*.o
	@echo "$(COL_WHITE)done$(COL_END)"
96 97 98

doc:
	@doxygen "Doxyfile"