forked from suve/vrms-rpm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
180 lines (137 loc) · 5.75 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
#
# Makefile for vrms-rpm
# Copyright (C) 2017 Marcin "dextero" Radomski
# Copyright (C) 2018-2021 Artur "suve" Iwicki
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 3,
# as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program (LICENCE.txt). If not, see <http://www.gnu.org/licenses/>.
#
DEFAULT_LICENCE_LIST ?= tweaked
DESTDIR ?=
PREFIX ?= /usr/local
WITH_LIBRPM ?= 1
CFLAGS += -std=c11 -iquote ./ -Wall -Wextra -D_POSIX_C_SOURCE=200112L
CWARNS := -Wfloat-equal -Wparentheses
CERRORS := -Werror=incompatible-pointer-types -Werror=discarded-qualifiers -Werror=int-conversion -Werror=div-by-zero -Werror=sequence-point -Werror=uninitialized -Werror=duplicated-cond
ifeq "$(WITH_LIBRPM)" "1"
CFLAGS += -DWITH_LIBRPM
LDFLAGS += -lrpm -lrpmio
else ifneq "$(WITH_LIBRPM)" "0"
# The following line must *NOT* be indented, otherwise it's a syntax error
$(error "WITH_LIBRPM" must be "0" or "1", found "$(WITH_LIBRPM)")
endif
LICENCE_FILENAMES := $(basename $(notdir $(shell ls licences/*.txt)))
LICENCE_FILES := $(addprefix build/, $(shell ls licences/*.txt))
PO_FILES := $(shell ls lang/*.po)
MO_FILES := $(PO_FILES:lang/%.po=build/locale/%/LC_MESSAGES/vrms-rpm.mo)
MANS := $(shell ls man/*.man)
MAN_LANGS := $(MANS:man/%.man=%)
NON_EN_MAN_LANGS := $(filter-out en, $(MAN_LANGS))
MAN_FILES := $(MANS:man/%.man=build/man/%.man)
IMAGES := $(shell ls images/*)
SOURCES := $(shell ls src/*.c)
OBJECTS := $(SOURCES:src/%.c=build/%.o)
TEST_SOURCES := $(shell ls test/*.c)
TEST_OBJECTS := $(TEST_SOURCES:test/%.c=build/test/%.o)
# -- variables end
.PHONY: all build executable lang-files man-pages install install/prepare remove test
all: build
build: executable lang-files man-pages $(LICENCE_FILES) build/bash-completion.sh
executable: build/vrms-rpm
lang-files: $(MO_FILES)
man-pages: $(MAN_FILES)
clean:
rm -rf build/ src/config.h
install: install/prepare
mkdir -p "$(DESTDIR)$(PREFIX)"
cp -a install/* "$(DESTDIR)$(PREFIX)"
rm -rf install
remove: install/prepare
find install -type f | sed -e 's|^install|$(DESTDIR)$(PREFIX)|' | xargs rm -vf
find install -depth -type d | sed -e 's|^install|$(DESTDIR)$(PREFIX)|' | xargs rmdir -v --ignore-fail-on-non-empty
rm -rf install
test: build/run-tests
./build/run-tests
help:
@echo "TARGETS:"
@echo " all - build whole project (excluding tests)"
@echo " executable - compile C code and build the executable"
@echo " lang-files - compile translation files"
@echo " man-pages - compile man pages"
@echo ""
@echo " clean - remove compiled artifacts"
@echo " install - install project"
@echo " remove - uninstall project"
@echo ""
@echo " test - compile and run the test suite (requires cmocka)"
@echo ""
@echo "VARIABLES:"
@echo " DEFAULT_LICENCE_LIST"
@echo " default list of good licences to use (default: tweaked)"
@echo " changed at run-time using --licence-list"
@echo " possible values: $(LICENCE_FILENAMES)"
@echo " DESTDIR"
@echo " installation destination (default: empty)"
@echo " helpful when packaging the application"
@echo " PREFIX"
@echo " installation prefix (default: /usr/local)"
@echo " used to set up file paths"
@echo " WITH_LIBRPM"
@echo " when set to \"0\", disables linking against librpm"
# -- PHONY targets end
src/config.h: src/generate-config.sh
src/generate-config.sh -d '$(DEFAULT_LICENCE_LIST)' -l '$(LICENCE_FILENAMES)' -p '$(PREFIX)' > "$@"
build/bash-completion.sh: src/bash-completion.sh
mkdir -p "$(dir $@)"
sed -e 's|__LICENCE_LIST__|$(LICENCE_FILENAMES)|' < "$<" > "$@"
build/man/%.man: man/%.man
mkdir -p "$(dir $@)"
cp "$<" "$@"
src/convert-man.sh -d '$(DEFAULT_LICENCE_LIST)' -l '$(LICENCE_FILENAMES)' -p '$(PREFIX)' -f "$@"
build/locale/%/LC_MESSAGES/vrms-rpm.mo: lang/%.po
mkdir -p "$(dir $@)"
msgfmt --check -o "$@" "$<"
build/licences/%.txt: licences/%.txt
mkdir -p "$(dir $@)"
cat "$<" | LC_COLLATE=C sort --ignore-case | uniq > "$@"
build/%.o: src/%.c src/config.h
mkdir -p "$(dir $@)"
$(CC) $(CFLAGS) $(CWARNS) $(CERRORS) -c -o "$@" "$<"
build/test/%.o: test/%.c
mkdir -p "$(dir $@)"
$(CC) $(CFLAGS) $(CWARNS) $(CERRORS) -c -o "$@" "$<"
build/vrms-rpm: $(OBJECTS)
$(CC) $(CFLAGS) $(CWARNS) $(CERRORS) $(LDFLAGS) -o "$@" $^
build/run-tests: $(filter-out build/vrms-rpm.o, $(OBJECTS)) $(TEST_OBJECTS)
$(CC) $(CFLAGS) $(CWARNS) $(CERRORS) $(LDFLAGS) -lcmocka -o "$@" $^
install/bin/vrms-rpm: build/vrms-rpm
install -vD -p -m 755 "$<" "$@"
install/share/bash-completion/completions/vrms-rpm: build/bash-completion.sh
install -vD -m 644 "$<" "$@"
install/share/suve/vrms-rpm/images/%: images/%
install -vD -m 644 "$<" "$@"
install/share/suve/vrms-rpm/licences/%.txt: build/licences/%.txt
install -vD -m 644 "$<" "$@"
install/share/man/man1/vrms-rpm.1: build/man/en.man
install -vD -p -m 644 "$<" "$@"
install/share/man/%/man1/vrms-rpm.1: build/man/%.man
install -vD -p -m 644 "$<" "$@"
install/share/locale/%: build/locale/%
install -vD -p -m 644 "$<" "$@"
install/prepare: build
install/prepare: install/bin/vrms-rpm
install/prepare: install/share/bash-completion/completions/vrms-rpm
install/prepare: install/share/man/man1/vrms-rpm.1
install/prepare: $(NON_EN_MAN_LANGS:%=install/share/man/%/man1/vrms-rpm.1)
install/prepare: $(MO_FILES:build/%=install/share/%)
install/prepare: $(LICENCE_FILES:build/%=install/share/suve/vrms-rpm/%)
install/prepare: $(IMAGES:%=install/share/suve/vrms-rpm/%)