~rcr/rirc

ref: 3677744e47d9547597f5f28747614cb8d5437b8c rirc/Makefile -rw-r--r-- 2.9 KiB
3677744e — Richard Robbins fix debug build linker flags 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
VERSION := 0.1.5

PREFIX   ?= /usr/local
PATH_BIN := $(DESTDIR)$(PREFIX)/bin
PATH_MAN := $(DESTDIR)$(PREFIX)/share/man/man1

PATH_BUILD := build
PATH_LIB   := lib
PATH_SRC   := src
PATH_TEST  := test

include lib/mbedtls.Makefile

CONFIG := config.h

CFLAGS ?= -O2 -flto
CFLAGS += -DNDEBUG

CFLAGS_DEBUG += -O0 -g3 -Wall -Wextra -Werror

CLFAGS_RIRC += -std=c11 -I. -DVERSION=\"$(VERSION)\"
CLFAGS_RIRC += -D_POSIX_C_SOURCE=200809L
CLFAGS_RIRC += -D_DARWIN_C_SOURCE

LDFLAGS_RIRC += -lpthread

LDFLAGS ?= -flto
LDFLAGS += $(LDFLAGS_RIRC)

LDFLAGS_DEBUG ?=
LDFLAGS_DEBUG += $(LDFLAGS_RIRC)

SRC       := $(shell find $(PATH_SRC) -name '*.c' | sort)
SRC_GPERF := $(patsubst %, %.out, $(shell find $(PATH_SRC) -name '*.gperf'))

# Release objects, debug objects, testcases
OBJS_R := $(patsubst $(PATH_SRC)/%.c, $(PATH_BUILD)/%.o,    $(SRC))
OBJS_D := $(patsubst $(PATH_SRC)/%.c, $(PATH_BUILD)/%.db.o, $(SRC))
OBJS_T := $(patsubst $(PATH_SRC)/%.c, $(PATH_BUILD)/%.t,    $(SRC))
OBJS_T += $(PATH_BUILD)/utils/tree.t # Header only file

rirc: $(RIRC_LIBS) $(SRC_GPERF) $(OBJS_R)
	@echo "$(CC) $(LDFLAGS) $@"
	@$(CC) $(LDFLAGS) -o $@ $(OBJS_R) $(RIRC_LIBS)

rirc.debug: $(RIRC_LIBS) $(SRC_GPERF) $(OBJS_D)
	@echo "$(CC) $(LDFLAGS_DEBUG) $@"
	@$(CC) $(LDFLAGS_DEBUG) -o $@ $(OBJS_D) $(RIRC_LIBS)

$(PATH_BUILD)/%.o: $(PATH_SRC)/%.c $(CONFIG) | $(PATH_BUILD)
	@echo "$(CC) $(CFLAGS) $<"
	@$(CPP) $(CFLAGS) $(CLFAGS_RIRC) -MM -MP -MT $@ -MF $(@:.o=.o.d) $<
	@$(CC)  $(CFLAGS) $(CLFAGS_RIRC) -c -o $@ $<

$(PATH_BUILD)/%.db.o: $(PATH_SRC)/%.c $(CONFIG) | $(PATH_BUILD)
	@echo "$(CC) $(CFLAGS_DEBUG) $<"
	@$(CPP) $(CFLAGS_DEBUG) $(CLFAGS_RIRC) -MM -MP -MT $@ -MF $(@:.o=.o.d) $<
	@$(CC)  $(CFLAGS_DEBUG) $(CLFAGS_RIRC) -c -o $@ $<

$(PATH_BUILD)/%.t: $(PATH_TEST)/%.c $(SRC_GPERF) $(CONFIG) | $(PATH_BUILD)
	@rm -f $(@:.t=.td)
	@$(CPP) $(CFLAGS_DEBUG) $(CLFAGS_RIRC) -MM -MP -MT $@ -MF $(@:.t=.t.d) $<
	@$(CC)  $(CFLAGS_DEBUG) $(CLFAGS_RIRC) -c -o $(@:.t=.t.o) $<
	@$(CC)  $(CFLAGS_DEBUG) $(CLFAGS_RIRC) -o $@ $(@:.t=.t.o)
	@./$@ || mv $@ $(@:.t=.td)

$(PATH_BUILD):
	@mkdir -p $(patsubst $(PATH_SRC)%, $(PATH_BUILD)%, $(shell find $(PATH_SRC) -type d))

$(CONFIG):
	cp config.def.h config.h

%.gperf.out: %.gperf
	gperf --output-file=$@ $<

all:
	@$(MAKE) --silent rirc
	@$(MAKE) --silent rirc.debug

check: $(OBJS_T)
	@[ ! "$$(find $(PATH_BUILD) -name '*.td' -print -quit)" ] && echo OK

clean:
	@rm -rfv rirc rirc.debug $(SRC_GPERF) $(PATH_BUILD)

libs:
	@$(MAKE) --silent $(RIRC_LIBS)

install: rirc
	@sed "s/VERSION/$(VERSION)/g" < docs/rirc.1 > rirc.1
	mkdir -p $(PATH_BIN)
	mkdir -p $(PATH_MAN)
	cp -f rirc   $(PATH_BIN)
	cp -f rirc.1 $(PATH_MAN)
	chmod 755 $(PATH_BIN)/rirc
	chmod 644 $(PATH_MAN)/rirc.1

uninstall:
	rm -f $(PATH_BIN)/rirc
	rm -f $(PATH_MAN)/rirc.1

-include $(OBJS_R:.o=.o.d)
-include $(OBJS_D:.o=.o.d)
-include $(OBJS_T:.t=.t.d)

.DEFAULT_GOAL := rirc

.PHONY: all check clean libs install uninstall

.SUFFIXES: