-
-
Notifications
You must be signed in to change notification settings - Fork 49
/
Makefile
198 lines (164 loc) Β· 4.67 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# General
CC = gcc
LD = gcc
RM = rm -rf
RMDIR = rmdir
INSTALL = install
# Config
TARGET = tldr
SRCDIR = src
OBJDIR = obj
BINDIR = .
MANDIR = man
# CFLAGS, LDFLAGS, CPPFLAGS, PREFIX can be overriden on CLI
CFLAGS := -ggdb -O0 -ftrapv
CPPFLAGS :=
LDFLAGS :=
PREFIX := /usr/local
TARGET_ARCH :=
# Compiler Flags
ALL_CFLAGS := $(CFLAGS)
ALL_CFLAGS += -Wall -Wextra -pedantic
ALL_CFLAGS += -fno-strict-aliasing
ALL_CFLAGS += -Wuninitialized -Winit-self -Wfloat-equal
ALL_CFLAGS += -Wshadow -Wc++-compat -Wcast-qual -Wcast-align
ALL_CFLAGS += -Wconversion -Wsign-conversion -Wno-cast-qual
ALL_CFLAGS += -Wno-multichar -Wpacked -Wstrict-overflow -Wvla
ALL_CFLAGS += -Wformat -Wno-format-zero-length -Wstrict-prototypes
ifeq ($(CC),clang)
ALL_CFLAGS += -Wno-unknown-warning-option
endif
# Version Generation
HAS_GIT := $(shell type git > /dev/null 2>&1 && echo "1" || echo "0")
IS_GITREPO := $(shell [ -d .git ] && echo "1" || echo "0")
ifeq (0,$(filter 0,$(HAS_GIT) $(IS_GITREPO)))
VER := v1.6.1
else
VER := $(shell git describe --tags --always --dirty)
endif
# Set Flags
ALL_CPPFLAGS := $(CPPFLAGS) -DVERSION='"$(VER)"'
ALL_LDFLAGS := $(LDFLAGS) -L/usr/lib
ALL_LDLIBS := -lc -lm -lcurl -lzip
ALL_CPPFLAGS += -D_GNU_SOURCE
ALL_CPPFLAGS += $(shell pkg-config --cflags libzip)
ALL_CPPFLAGS += -I/usr/include
ALL_CPPFLAGS += -I/usr/local/include
ALL_LDFLAGS += -L/usr/local/lib
ifneq (,$(wildcard /opt/homebrew/.*))
ALL_CCPFLAGS += -I/opt/homebrew/include
ALL_CPPFLAGS += -I/opt/homebrew/lib
endif
ifneq (,$(wildcard /usr/local/opt/curl/.*))
ALL_CPPFLAGS += -I/usr/local/opt/curl/include
ALL_LDFLAGS += -L/usr/local/opt/curl/lib
endif
ifneq (,$(wildcard /opt/homebrew/opt/curl/.))
ALL_CPPFLAGS += -I/opt/homebrew/opt/curl/include
ALL_LDFLAGS += -L/opt/homebrew/opt/curl/lib
endif
ifneq (,$(wildcard /usr/local/opt/libzip/.))
ALL_CPPFLAGS += -I/usr/local/opt/libzip/include
ALL_LDFLAGS += -L/usr/local/opt/libzip/lib
endif
ifneq (,$(wildcard /opt/homebrew/opt/libzip/.))
ALL_CPPFLAGS += -I/opt/homebrew/opt/libzip/include
ALL_LDFLAGS += -L/opt/homebrew/opt/libzip/lib
endif
# Source, Binaries, Dependencies
SRC := $(shell find $(SRCDIR) -type f -name '*.c')
OBJ := $(patsubst $(SRCDIR)/%,$(OBJDIR)/%,$(SRC:.c=.o))
DEP := $(OBJ:.o=.d)
BIN := $(BINDIR)/$(TARGET)
-include $(DEP)
# Man Pages
MANSRC := $(shell find $(MANDIR) -type f -name '*.1')
MANPATH := $(PREFIX)/share/man/man1
# Verbosity Control, ala automake
V = 0
# Verbosity for CC
REAL_CC := $(CC)
CC_0 = @echo "CC $<"; $(REAL_CC)
CC_1 = $(REAL_CC)
CC = $(CC_$(V))
# Verbosity for LD
REAL_LD := $(LD)
LD_0 = @echo "LD $@"; $(REAL_LD)
LD_1 = $(REAL_LD)
LD = $(LD_$(V))
# Verbosity for RM
REAL_RM := $(RM)
RM_0 = @echo "Cleaning..."; $(REAL_RM)
RM_1 = $(REAL_RM)
RM = $(RM_$(V))
# Verbosity for RMDIR
REAL_RMDIR := $(RMDIR)
RMDIR_0 = @$(REAL_RMDIR)
RMDIR_1 = $(REAL_RMDIR)
RMDIR = $(RMDIR_$(V))
# Build Rules
.PHONY: clean format lint infer
.DEFAULT_GOAL := all
all: setup $(BIN)
setup: dir
remake: clean all
dir:
@mkdir -p $(OBJDIR)
@mkdir -p $(BINDIR)
$(BIN): $(OBJ)
$(LD) $(ALL_LDFLAGS) $^ $(ALL_LDLIBS) -o $@
$(OBJDIR)/%.o: $(SRCDIR)/%.c
$(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) -c -MMD -MP -o $@ $<
install: all $(MANSRC)
$(INSTALL) -d $(PREFIX)/bin
$(INSTALL) $(BIN) $(PREFIX)/bin
$(INSTALL) -d $(MANPATH)
$(INSTALL) $(MANSRC) $(MANPATH)
uninstall:
$(RM) $(PREFIX)/bin/$(TARGET)
$(RM) $(MANPATH)/$(TARGET).1
clean:
$(RM) $(OBJ) $(DEP) $(BIN)
$(RMDIR) $(OBJDIR) $(BINDIR) 2> /dev/null; true
format:
astyle --options=.astylerc $(SRCDIR)/*.c
astyle --options=.astylerc $(SRCDIR)/*.h
lint:
oclint -report-type html -o report.html \
-enable-clang-static-analyzer \
-enable-global-analysis \
-disable-rule=GotoStatement \
-max-priority-1 1000 \
-max-priority-2 1000 \
-max-priority-3 1000 \
src/*.c src/*.h -- $(ALL_CPPFLAGS) -c
cppcheck --enable=all \
-I/usr/local/include \
-I/usr/local/opt/curl/include \
-I/usr/local/opt/libzip/include \
--language=c \
--std=c89 \
--inconclusive \
src/*.c src/*.h
splint +posixlib +gnuextensions \
-Du_int64_t=unsigned\ long\ long \
-Du_int32_t=unsigned\ int \
-D__int64_t=long\ long \
-D__uint64_t=unsigned\ long\ long \
-D__int32_t=int \
-D__uint32_t=unsigned\ int \
-D__int16_t=short \
-D__uint16_t=unsigned\ short \
-D__darwin_natural_t=long \
-D__darwin_time_t=long \
-D__darwin_size_t=unsigned\ long \
-D__darwin_ssize_t=long \
-D__darwin_intptr_t=unsigned\ long \
-D__darwin_clock_t=unsigned\ long \
-I/usr/local/include \
-I/usr/local/opt/curl/include \
-I/usr/local/opt/libzip/include \
-I/usr/local/Cellar/libzip/1.1/lib/libzip/include \
src/*.c src/*.h
infer: clean
infer -- make