-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
114 lines (86 loc) · 2.98 KB
/
Makefile
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
111
112
113
114
MAJOR?=0
MINOR?=1
VERSION=$(MAJOR).$(MINOR)
BIN := bridge
TEST_EXEC = tests
# Specify the source files, excluding the test and the main source file
MAIN_SRC = bridge.c
SRCS = $(filter-out tests.c $(MAIN_SRC), $(wildcard *.c))
TEST_SRC = tests.c
OBJDIR := obj
TEST_OBJDIR := test_obj
DEPDIR := $(OBJDIR)/.deps
# object files, auto generated from source files
OBJS := $(patsubst %,$(OBJDIR)/%.o,$(basename $(SRCS)))
TEST_OBJS := $(patsubst %,$(TEST_OBJDIR)/%.o,$(basename $(SRCS)))
TEST_OBJS += $(TEST_OBJDIR)/$(basename $(TEST_SRC)).o
# dependency files, auto generated from source files
DEPS := $(patsubst %,$(DEPDIR)/%.d,$(basename $(SRCS)))
# compilers (at least gcc and clang) don't create the subdirectories automatically
$(shell mkdir -p $(dir $(OBJS)) >/dev/null)
$(shell mkdir -p $(dir $(TEST_OBJS)) >/dev/null)
$(shell mkdir -p $(dir $(DEPS)) >/dev/null)
CC=gcc
CFLAGS+=-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -march=x86-64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection
LDLIBS=-lqpid-proton -lpthread
LDFLAGS+=-Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1
DEPFLAGS = -MT $@ -MD -MP -MF $(DEPDIR)/$*.Td
# compile C source files
COMPILE.c = $(CC) $(DEPFLAGS) $(CFLAGS) $(CPPFLAGS) -c -o $@
# link object files to binary
LINK.o = $(LD) $(LDFLAGS) $(CFLAGS) $(LDLIBS) -o $@
# precompile step
PRECOMPILE =
# postcompile step
POSTCOMPILE = mv -f $(DEPDIR)/$*.Td $(DEPDIR)/$*.d
HUB_NAMESPACE = "localhost"
BRIDGE_IMAGE_NAME = "sgbridge"
all: $(BIN)
debug: CFLAGS=-Wall -g
debug: all
.PHONY: clean
clean:
rm -fr $(OBJDIR) $(TEST_OBJDIR) $(DEPDIR)
.PHONY: clean-image
clean-image: version-check
@echo "+ $@"
@podman rmi ${HUB_NAMESPACE}/${BUILDER_IMAGE_NAME}:latest || true
.PHONY: image
image: version-check
@echo "+ $@"
@buildah bud -t ${HUB_NAMESPACE}/${BRIDGE_IMAGE_NAME}:latest -f build/Dockerfile .
@echo 'Done.'
$(BIN): $(OBJS) $(OBJDIR)/$(basename $(MAIN_SRC)).o
$(CC) -o $@ $^ $(LDFLAGS) $(CFLAGS) $(LDLIBS)
$(OBJDIR)/%.o: %.c %.h
$(OBJDIR)/%.o: %.c $(DEPDIR)/%.d %.h
$(PRECOMPILE)
$(COMPILE.c) $<
$(POSTCOMPILE)
$(OBJDIR)/%.o : %.c $(DEPDIR)/%.d %.h | $(DEPDIR)
$(COMPILE.c) $(OUTPUT_OPTION) $<
.PRECIOUS: $(DEPDIR)/%.d
$(DEPDIR)/%.d: ;
# Build unit test executable
$(TEST_EXEC): $(TEST_OBJS)
$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS)
# Compile unit test file
$(TEST_OBJDIR)/%.o: %.c
@mkdir -p $(TEST_OBJDIR)
$(CC) $(CFLAGS) -c -o $@ $<
# Run unit tests
test: $(TEST_EXEC)
@$(TEST_EXEC)
#################################
# Utilities
#################################
.PHONY: version-check
version-check:
@echo "+ $@"
ifdef VERSION
@echo "VERSION is ${VERSION}"
else
@echo "VERSION is not set!"
@false;
endif
-include $(DEPS)