-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
75 lines (61 loc) · 2.25 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
# CATCHME
.PHONY: all clean install uninstall
CC = musl-gcc
PROJ_NAME = catchme
SRC_DIR= $(PROJ_NAME)/
PREFIX = /usr/local
MANPREFIX = $(PREFIX)/share/man
OUT_DIR := out
# RELEASE or DEBUG
BUILD_MODE ?= RELEASE
# Define compiler flags:
# -Wall turns on most, but not all, compiler warnings
# -std=c99 defines C language mode (standard C from 1999 revision)
# -D_DEFAULT_SOURCE required for timespec
# -Werror=pointer-arith catch unportable code that does direct arithmetic on void pointers
CFLAGS := -Wall -std=c99 -D_DEFAULT_SOURCE -Werror=pointer-arith
# C Pre Processor Flags
CPPFLAGS := -I. -I./catchme/external/ -I./catchme/external/json-c/
# -L linker flags
LDFLAGS := -L/usr/lib/musl/lib/ -Llib/ -Wl,--gc-sections
# -l lib flags
LDLIBS := -static /usr/lib/musl/lib/libc.a -lm -ljson-c
EXE := $(OUT_DIR)/$(PROJ_NAME)
SRC := $(wildcard $(SRC_DIR)/*.c)
OBJ := $(SRC:$(SRC_DIR)/%.c=$(SRC_DIR)/%.o)
ifeq ($(BUILD_MODE),DEBUG)
# -g include debug information on compilation
# additional warnings
# -MD generate dependency files
CFLAGS += -D_DEBUG -g -Wextra -Wpedantic -Wformat=2 -Wno-unused-parameter -Wshadow -Wwrite-strings -Wstrict-prototypes -Wold-style-definition -Wredundant-decls -Wnested-externs -Wmissing-include-dirs -MD
endif
ifeq ($(BUILD_MODE),RELEASE)
# -O3 defines optimization level
# -s strip unnecessary symbols from build
CFLAGS += -s -O2 -fdata-sections -ffunction-sections
endif
all: $(EXE)
$(EXE): $(OBJ) | $(OUT_DIR)
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
%.o: %.c | $(OBJ_DIR)
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
$(OUT_DIR):
mkdir -p $@
install: all
@echo "INSTALL bin/$(PROJ_NAME)"
mkdir -p $(DESTDIR)$(PREFIX)/bin
cp out/$(PROJ_NAME) $(DESTDIR)$(PREFIX)/bin/
chmod 755 $(DESTDIR)$(PREFIX)/bin/$(PROJ_NAME)
# @echo "INSTALL $(PROJ_NAME).1"
# mkdir -p $(DESTDIR)$(MANPREFIX)/man1
# chmod 644 $(DESTDIR)$(MANPREFIX)/man1/$(PROJ_NAME).1
uninstall:
@echo "REMOVE bin/$(PROJ_NAME)"
rm -f $(DESTDIR)$(PREFIX)/bin/$(PROJ_NAME)
# @echo "REMOVE $(PROJ_NAME).1"
# rm -f $(DESTDIR)$(MANPREFIX)/man1/$(PROJ_NAME).1
clean:
rm -fv $(OUT_DIR)/* *.o $(OBJ_DIR)/*.d
rmdir $(OBJ_DIR) 2>/dev/null
rmdir $(OUT_DIR) 2>/dev/null
-include $(OBJ:.o=.d)