-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
260 lines (201 loc) · 9.16 KB
/
makefile
File metadata and controls
260 lines (201 loc) · 9.16 KB
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
################################################################################
# Definition of the project directories.
################################################################################
INCLUDE_DIR = inc
SRC_DIR = src
BUILD_DIR = build
TEST_DIR = tests
################################################################################
# A variable that collects the optional flags.
################################################################################
OPTION_FLAGS=
################################################################################
# A flag to enable / disable ACS borders. If the flag is 'false', ASCII
# characters are used. This may be helpful if, for example putty has an issue
# with ACS and UTF-8.
################################################################################
USE_ACS_BORDERS = true
ifeq ($(USE_ACS_BORDERS),false)
OPTION_FLAGS += -DNO_ACS_BORDER
endif
################################################################################
# A debug flag for the application. If set to 'true' the application has to pipe
# stderr to a file.
################################################################################
DEBUG = false
ifeq ($(DEBUG),true)
OPTION_FLAGS += -DDEBUG -g
#
# The following definitions switch on asan in debug mode.
#
OPTION_FLAGS += -fsanitize=address,undefined -fsanitize-undefined-trap-on-error -static-libasan -fno-omit-frame-pointer
endif
################################################################################
# Ncurses has a major version and that version determines some programs and
# library names, especially the ncurses config program, which contains
# informations for the compiler.
#
# The ncursesw6-config program is currently not part of ubuntu. The parameter
# can be used if ncurses is build from source.
################################################################################
NCURSES_MAJOR = 5
NCURSES_CONFIG = ncursesw$(NCURSES_MAJOR)-config
################################################################################
# Definition of compiler flags. CC is defined by make and CFLAGS can be set by
# the user. The flag _GNU_SOURCE is necessary for qsort_r.
################################################################################
WARN_FLAGS = -Wall -Wextra -Wpedantic -Werror
BUILD_FLAGS = -std=c11 -O2 -D_GNU_SOURCE
FLAGS = $(BUILD_FLAGS) $(OPTION_FLAGS) $(WARN_FLAGS) -I$(INCLUDE_DIR) $(shell $(NCURSES_CONFIG) --cflags)
LIBS = $(shell $(NCURSES_CONFIG) --libs) -lformw -lmenuw -lm
################################################################################
# The list of sources that are used to build the executable. The last one:
# ut_utils.c is only used to build the test programs. Each of the source files
# has a header file with the same name.
################################################################################
SRC_LIBS = \
$(SRC_DIR)/ncv_common.c \
$(SRC_DIR)/ncv_ncurses.c \
$(SRC_DIR)/ncv_parser.c \
$(SRC_DIR)/ncv_table.c \
$(SRC_DIR)/ncv_table_part.c \
$(SRC_DIR)/ncv_table_header.c \
$(SRC_DIR)/ncv_table_sort.c \
$(SRC_DIR)/ncv_corners.c \
$(SRC_DIR)/ncv_field.c \
$(SRC_DIR)/ncv_filter.c \
$(SRC_DIR)/ncv_sort.c \
$(SRC_DIR)/ncv_ui_loop.c \
$(SRC_DIR)/ncv_forms.c \
$(SRC_DIR)/ncv_popup.c \
$(SRC_DIR)/ncv_wbuf.c \
$(SRC_DIR)/ncv_win_header.c \
$(SRC_DIR)/ncv_win_filter.c \
$(SRC_DIR)/ncv_win_table.c \
$(SRC_DIR)/ncv_win_footer.c \
$(SRC_DIR)/ncv_win_help.c \
$(SRC_DIR)/ut_utils.c \
OBJ_LIBS = $(subst $(SRC_DIR),$(BUILD_DIR),$(subst .c,.o,$(SRC_LIBS)))
INC_LIBS = $(subst $(SRC_DIR),$(INCLUDE_DIR),$(subst .c,.h,$(SRC_LIBS)))
################################################################################
# The main program.
################################################################################
EXEC = ccsvv
SRC_EXEC = $(SRC_DIR)/ncv_ccsvv.c
OBJ_EXEC = $(subst $(SRC_DIR),$(BUILD_DIR),$(subst .c,.o,$(SRC_EXEC)))
################################################################################
# The definitions for the test programs.
################################################################################
SRC_TEST = \
$(SRC_DIR)/ut_parser.c \
$(SRC_DIR)/ut_table.c \
$(SRC_DIR)/ut_table_part.c \
$(SRC_DIR)/ut_table_header.c \
$(SRC_DIR)/ut_table_sort.c \
$(SRC_DIR)/ut_sort.c \
$(SRC_DIR)/ut_field.c \
$(SRC_DIR)/ut_common.c \
$(SRC_DIR)/ut_filter.c \
$(SRC_DIR)/ut_wbuf.c \
TESTS = $(subst $(SRC_DIR),$(TEST_DIR),$(subst .c,,$(SRC_TEST)))
OBJ_TEST = $(subst $(SRC_DIR),$(BUILD_DIR),$(subst .c,.o,$(SRC_TEST)))
################################################################################
# Definition of the top-level targets.
#
# A phony target is one that is not the name of a file. If a file 'all' exists,
# nothing will happen.
################################################################################
.PHONY: all
all: $(EXEC) test
################################################################################
# A static pattern, that builds an object file from its source. The automatic
# variable $@ is the target and $< is the first prerequisite, which is the
# corrosponding source file. Example:
#
# build/ncv_common.o: src/ncv_common.c src/ncv_common.h src/ncv_ncurses.h...
# gcc -c -o build/ncv_common.o src/ncv_common.c ...
#
# The complete list of header files is not necessary as a prerequisite, but it
# does not hurt.
################################################################################
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c $(INC_LIBS)
$(CC) -c -o $@ $< $(FLAGS) $(LIBS)
################################################################################
# The goal compiles the executable from the object files. The automatic $^ is
# the list of all prerequisites, which are the object files in this case.
################################################################################
$(EXEC): $(OBJ_LIBS) $(OBJ_EXEC)
$(CC) -o $@ $^ $(FLAGS) $(LIBS)
################################################################################
# The goal compiles the executables of the test programs. The valiable TEST is
# the list of all test programs. The expression:
#
# $(subst $(TEST_DIR),$(BUILD_DIR),$@.o)
#
# creates the corresponding object file from the test program. Example:
#
# tests/ut_parser => build/ut_parser.o
################################################################################
$(TESTS): $(OBJ_LIBS) $(OBJ_TEST)
$(CC) -o $@ $(OBJ_LIBS) $(subst $(TEST_DIR),$(BUILD_DIR),$@.o) $(FLAGS) $(LIBS)
################################################################################
# The test goal invokes all test programs.
################################################################################
.PHONY: test
test: $(TESTS)
@for ut_test in $(TESTS) ; do ./$$ut_test || exit 1 ; done
@echo "Tests: OK"
################################################################################
# Goals to install and uninstall the executable.
# --owner=root --group=root
################################################################################
PREFIX = /usr/local
BINDIR = $(PREFIX)/bin
DOCDIR = $(PREFIX)/share/doc/$(EXEC)
MANDIR = $(PREFIX)/share/man/man1
MANPAGE = ccsvv.1
.PHONY: install uninstall
install: $(EXEC)
gzip -9n -c man/$(MANPAGE) > $(BUILD_DIR)/$(MANPAGE).gz
install -D --mode=644 $(BUILD_DIR)/$(MANPAGE).gz --target-directory=$(MANDIR)
install -D --mode=755 $(EXEC) --target-directory=$(BINDIR) --strip
install -D --mode=644 LICENSE $(DOCDIR)/copyright
gzip -9n -c changelog > $(BUILD_DIR)/changelog.gz
install -D --mode=644 $(BUILD_DIR)/changelog.gz $(DOCDIR)/changelog.gz
uninstall:
rm -f $(DOCDIR)/copyright
if [ -d "$(DOCDIR)" ]; then rmdir $(DOCDIR); fi
rm -f $(BINDIR)/$(EXEC)
rm -f $(MANDIR)/$(MANPAGE).gz
################################################################################
# The cleanup goal deletes the executable, the test programs, all object files
# and some editing remains.
################################################################################
.PHONY: clean
clean:
rm -rf $(BUILD_DIR)/ccsvv*
rm -f $(BUILD_DIR)/*.gz
rm -f $(BUILD_DIR)/*.o
rm -f $(SRC_DIR)/*.c~
rm -f $(INCLUDE_DIR)/*.h~
rm -f $(TEST_DIR)/ut_*
rm -f $(EXEC)
################################################################################
# The goal prints a help message the the ccsvv specific options for the build.
################################################################################
.PHONY: help
help:
@echo "Targets:"
@echo ""
@echo " make | make all : Triggers the build of the executable."
@echo " make test : Triggers unit tests."
@echo " make clean : Removes executables and temporary files from the build."
@echo " make install | uninstall : Installs / uninstalles the program files."
@echo " make help : Prints this message."
@echo ""
@echo "Parameter:"
@echo ""
@echo " DEBUG=[true|false] : A debug flag for the application. (default: false)"
@echo " NCURSES_MAJOR=[5|6] : The major verion of ncurses. (default: 5)"
@echo " USE_ACS_BORDERS=[true|false] : Use ASCII characters as borders. (default: false)"
@echo " PREFIX=<PATH> : Prefix for install / uninstall. (default: /usr/local)"