Debian Codegraph @

GNUmakefile

raw ◀ ▶
3 Debian patches touch this file
1 # spell-checker:ignore (misc) testsuite runtest findstring (targets) busytest toybox distclean pkgs nextest ; (vars/env) BINDIR BUILDDIR CARGOFLAGS CFLAGS DESTDIR DOCSDIR INSTALLDIR INSTALLEES MULTICALL DATAROOTDIR TESTDIR manpages
2
3 # Config options
4 ifneq (,$(filter install, $(MAKECMDGOALS)))
5 PROFILE?=release
6 endif
7 PROFILE ?= debug
8 MULTICALL ?= n
9 COMPLETIONS ?= y
10 MANPAGES ?= y
11 LOCALES ?= y
12 # allow bootstrapping by our install. mkdir, chmod and cp should be avoided
13 INSTALL ?= install
14
15 # Needed for the foreach loops to split each loop into a separate command
16 define newline
17
18
19 endef
20
21 PROFILE_CMD := --profile=${PROFILE}
22 ifeq ($(PROFILE),debug)
23 PROFILE_CMD =
24 endif
25
26 # Binaries
27 CARGO ?= cargo
28 CARGOFLAGS ?=
29
30 #prefix prepended to all binaries and library dir
•31 PROG_PREFIX ?= rust-
32
33 # Install directories
•34 PREFIX ?= /usr
35 DESTDIR ?=
36 BINDIR ?= $(PREFIX)/bin
37 DATAROOTDIR ?= $(PREFIX)/share
•38 LOCALEDIR ?= $(DATAROOTDIR)/coreutils/locales
39 LIBSTDBUF_DIR ?= $(PREFIX)/libexec/$(PROG_PREFIX)coreutils
40 # Export variable so that it is used during the build
41 export LIBSTDBUF_DIR
42
43 INSTALLDIR_BIN=$(DESTDIR)$(BINDIR)
44
45 # This won't support any directory with spaces in its name, but you can just
46 # make a symlink without spaces that points to the directory.
47 BASEDIR ?= $(shell pwd)
48 ifdef CARGO_TARGET_DIR
49 BUILDDIR := $(CARGO_TARGET_DIR)/${PROFILE}
50 BUILDDIR_UUDOC := $(CARGO_TARGET_DIR)/${PROFILE}
51 else
52 BUILDDIR := $(BASEDIR)/target/$(CARGO_BUILD_TARGET)/${PROFILE}
53 # uudoc should not be cross build
54 BUILDDIR_UUDOC := $(BASEDIR)/target/$(PROFILE)
55 endif
56 PKG_BUILDDIR := $(BUILDDIR)/deps
57 DOCSDIR := $(BASEDIR)/docs
58
59 BUSYBOX_ROOT := $(BASEDIR)/tmp
60 BUSYBOX_VER := 1.36.1
61 BUSYBOX_SRC := $(BUSYBOX_ROOT)/busybox-$(BUSYBOX_VER)
62
63 TOYBOX_ROOT := $(BASEDIR)/tmp
64 TOYBOX_VER := 0.8.12
65 TOYBOX_SRC := $(TOYBOX_ROOT)/toybox-$(TOYBOX_VER)
66
67 # Detect the target system
68 # See https://doc.rust-lang.org/beta/rustc/platform-support.html
69 # todo: support building wasm
70 OS := $(or $(CARGO_BUILD_TARGET),$(shell rustc --print host-tuple))
71
72 # hardlinks are better default since
73 # - Windows(cygwin) does not allow symlink by default
74 # - std::env:current_exe resolves symlink
75 LN ?= ln -f
76
77 SELINUX_PROGS := \
78 chcon \
79 runcon
80
81 $(info Detected OS = $(OS))
82
83 ifeq (,$(findstring windows,$(OS)))
84 FEATURE_EXTRACT_UTILS := feat_os_unix
85 else
86 FEATURE_EXTRACT_UTILS := windows
87 endif
88 PROGS := $(shell cargo tree --depth 1 --features $(FEATURE_EXTRACT_UTILS) --format "{p}" --prefix none | sed -E -n 's/^uu_([^ ]+).*/\1/p')
89
90 ifeq ($(SELINUX_ENABLED),1)
91 PROGS += $(SELINUX_PROGS)
92 endif
93
94 UTILS ?= $(filter-out $(SKIP_UTILS),$(PROGS))
95
96 ifneq ($(findstring stdbuf,$(UTILS)),)
97 # Use external libstdbuf per default. It is more robust than embedding libstdbuf.
98 CARGOFLAGS += --features feat_external_libstdbuf
99 endif
100
101 # Programs with usable tests
102
103 TESTS := \
104 $(sort $(filter $(UTILS),$(PROGS) $(SELINUX_PROGS)))
105
106 TEST_NO_FAIL_FAST :=
107 TEST_SPEC_FEATURE :=
108 ifneq ($(SPEC),)
109 TEST_NO_FAIL_FAST :=--no-fail-fast
110 TEST_SPEC_FEATURE := test_unimplemented
111 else ifeq ($(SELINUX_ENABLED),1)
112 TEST_NO_FAIL_FAST :=
113 TEST_SPEC_FEATURE := selinux
114 BUILD_SPEC_FEATURE := selinux
115 endif
116
117 define TEST_BUSYBOX
118 test_busybox_$(1):
119 -(cd $(BUSYBOX_SRC)/testsuite && bindir=$(BUILDDIR) ./runtest $(RUNTEST_ARGS) $(1))
120 endef
121
122 # Output names
123 EXES := \
124 $(sort $(UTILS))
125
126 INSTALLEES := ${EXES}
127 ifeq (${MULTICALL}, y)
128 INSTALLEES := ${INSTALLEES} coreutils
129 endif
130
131 all: build
132
133 build-pkgs:
134 ifneq (${MULTICALL}, y)
135 ifdef BUILD_SPEC_FEATURE
136 ${CARGO} build ${CARGOFLAGS} --features "$(BUILD_SPEC_FEATURE)" ${PROFILE_CMD} $(foreach pkg,$(EXES),-p uu_$(pkg))
137 else
138 ${CARGO} build ${CARGOFLAGS} ${PROFILE_CMD} $(foreach pkg,$(EXES),-p uu_$(pkg))
139 endif
140 endif
141
142 build-coreutils:
143 ${CARGO} build ${CARGOFLAGS} --features "${EXES} $(BUILD_SPEC_FEATURE)" ${PROFILE_CMD} --no-default-features
144
145 ifeq (${MULTICALL}, y)
146 build: build-coreutils locales
147 else
148 build: build-pkgs locales
149 endif
150
151 $(foreach test,$(UTILS),$(eval $(call TEST_BUSYBOX,$(test))))
152
153 test:
154 ${CARGO} test ${CARGOFLAGS} --features "$(TESTS) $(TEST_SPEC_FEATURE)" $(PROFILE_CMD) --no-default-features $(TEST_NO_FAIL_FAST)
155
156 nextest:
157 ${CARGO} nextest run ${CARGOFLAGS} --features "$(TESTS) $(TEST_SPEC_FEATURE)" $(PROFILE_CMD) --no-default-features $(TEST_NO_FAIL_FAST)
158
159 test_toybox:
160 -(cd $(TOYBOX_SRC)/ && CFLAGS="-pipe -O0 -s" make tests)
161
162 toybox-src:
163 if [ ! -e "$(TOYBOX_SRC)" ] ; then \
164 $(INSTALL) -d "$(TOYBOX_ROOT)" ; \
165 curl -Ls "https://github.com/landley/toybox/archive/refs/tags/$(TOYBOX_VER).tar.gz" -o "$(TOYBOX_ROOT)/$(TOYBOX_VER).tar.gz" ; \
166 tar -C "$(TOYBOX_ROOT)" -xf "$(TOYBOX_ROOT)/$(TOYBOX_VER).tar.gz" ; \
167 sed -i -e "s|TESTDIR=\".*\"|TESTDIR=\"$(BUILDDIR)\"|g" $(TOYBOX_SRC)/scripts/test.sh; \
168 sed -i -e "s/ || exit 1//g" $(TOYBOX_SRC)/scripts/test.sh; \
169 fi ;
170
171 busybox-src:
172 if [ ! -e "$(BUSYBOX_SRC)" ] ; then \
173 $(INSTALL) -d "$(BUSYBOX_ROOT)" ; \
174 curl -Ls "https://github.com/mirror/busybox/archive/refs/tags/$(subst .,_,$(BUSYBOX_VER)).tar.gz" -o "$(BUSYBOX_ROOT)/busybox-$(BUSYBOX_VER).tar.gz" ; \
175 tar -C "$(BUSYBOX_ROOT)" -xf "$(BUSYBOX_ROOT)/busybox-$(BUSYBOX_VER).tar.gz" ; \
176 fi ;
177
178 # This is a busybox-specific config file their test suite wants to parse.
179 $(BUILDDIR)/.config: $(BASEDIR)/.busybox-config
180 $(INSTALL) -m 644 $< $@
181
182 # Test under the busybox test suite
183 $(BUILDDIR)/busybox: busybox-src build-coreutils $(BUILDDIR)/.config
184 $(INSTALL) -m 755 "$(BUILDDIR)/coreutils" "$(BUILDDIR)/busybox"
185
186 prepare-busytest: $(BUILDDIR)/busybox
187 # disable inapplicable tests
188 -( cd "$(BUSYBOX_SRC)/testsuite" ; if [ -e "busybox.tests" ] ; then mv busybox.tests busybox.tests- ; fi ; )
189
190 ifeq ($(EXES),)
191 busytest:
192 else
193 busytest: $(BUILDDIR)/busybox $(addprefix test_busybox_,$(filter-out $(SKIP_UTILS),$(EXES)))
194 endif
195
196 clean:
197 cargo clean
198 cd $(DOCSDIR) && $(MAKE) clean
199
200 distclean: clean
201 $(CARGO) clean $(CARGOFLAGS) && $(CARGO) update $(CARGOFLAGS)
202
203 ifeq ($(MANPAGES),y)
204 # Do not cross-build uudoc
205 build-uudoc:
206 @unset CARGO_BUILD_TARGET && ${CARGO} build ${CARGOFLAGS} --bin uudoc --features "uudoc ${EXES}" ${PROFILE_CMD} --no-default-features
207
208 install-manpages: build-uudoc
209 $(INSTALL) -d $(DESTDIR)$(DATAROOTDIR)/man/man1
210 $(foreach prog, $(INSTALLEES), \
211 $(BUILDDIR_UUDOC)/uudoc manpage $(prog) > $(DESTDIR)$(DATAROOTDIR)/man/man1/$(PROG_PREFIX)$(prog).1 $(newline) \
212 )
213 else
214 install-manpages:
215 endif
216
217 ifeq ($(COMPLETIONS),y)
218
219 install-completions: build-uudoc
220 $(INSTALL) -d $(DESTDIR)$(DATAROOTDIR)/zsh/site-functions
221 $(INSTALL) -d $(DESTDIR)$(DATAROOTDIR)/bash-completion/completions
222 $(INSTALL) -d $(DESTDIR)$(DATAROOTDIR)/fish/vendor_completions.d
223 $(foreach prog, $(INSTALLEES), \
224 $(BUILDDIR_UUDOC)/uudoc completion $(prog) zsh > $(DESTDIR)$(DATAROOTDIR)/zsh/site-functions/_$(PROG_PREFIX)$(prog) $(newline) \
225 $(BUILDDIR_UUDOC)/uudoc completion $(prog) bash > $(DESTDIR)$(DATAROOTDIR)/bash-completion/completions/$(PROG_PREFIX)$(prog).bash $(newline) \
226 $(BUILDDIR_UUDOC)/uudoc completion $(prog) fish > $(DESTDIR)$(DATAROOTDIR)/fish/vendor_completions.d/$(PROG_PREFIX)$(prog).fish $(newline) \
227 )
228 else
229 install-completions:
230 endif
231
232 ifeq ($(LOCALES),y)
233 locales:
•234 # Copy uucore common locales
235 @if [ -d "$(BASEDIR)/src/uucore/locales" ]; then \
236 $(INSTALL) -d "$(BUILDDIR)/locales/uucore"; \
237 for locale_file in "$(BASEDIR)"/src/uucore/locales/*.ftl; do \
238 $(INSTALL) -m 644 "$$locale_file" "$(BUILDDIR)/locales/uucore/"; \
239 done; \
240 if [ -d "$(BASEDIR)/src/uucore/locales/errors" ]; then \
241 $(INSTALL) -d "$(BUILDDIR)/locales/uucore/errors"; \
242 for locale_file in "$(BASEDIR)"/src/uucore/locales/errors/*.ftl; do \
243 $(INSTALL) -m 644 "$$locale_file" "$(BUILDDIR)/locales/uucore/errors/"; \
244 done; \
245 fi; \
246 fi; \
247 # Copy utility-specific locales
248 @for prog in $(INSTALLEES); do \
249 if [ -d "$(BASEDIR)/src/uu/$$prog/locales" ]; then \
250 $(INSTALL) -d "$(BUILDDIR)/locales/$$prog"; \
251 for locale_file in "$(BASEDIR)"/src/uu/$$prog/locales/*.ftl; do \
252 if [ "$$(basename "$$locale_file")" != "en-US.ftl" ]; then \
253 $(INSTALL) -m 644 "$$locale_file" "$(BUILDDIR)/locales/$$prog/"; \
254 fi; \
255 done; \
256 fi; \
257 done
258
259 # Some utils require extra locale files outside of their package:
260 # - *sum binaries need the files from checksum_common
261 INSTALLEES_WITH_EXTRA_LOCALE = \
262 $(INSTALLEES) \
•263 $(if $(findstring sum,$(INSTALLEES)),checksum_common,)
264
265 UU_LOCALES := $(wildcard $(BASEDIR)/l10n/src/uu/*/locales/*.ftl)
266 UUC_CORE_LOCALES := $(wildcard $(BASEDIR)/l10n/src/uucore/locales/*)
267
268 UU_LOCALES_NO_EN := $(filter-out %/en-US.ftl,$(UU_LOCALES))
269
270 define uu_install_locale
271 $(eval prog := $(notdir $(patsubst %/locales/,%,$(dir $(dir $(1))))))
272 mkdir -p $(DESTDIR)$(LOCALEDIR)/$(prog)
273 $(INSTALL) -m 644 $(1) $(DESTDIR)$(LOCALEDIR)/$(prog)/
274 endef
•275
276 install-locales:
•277 @mkdir -p $(DESTDIR)$(LOCALEDIR)
278 @# Install lazy error locales shared by all utilities
279 @if [ -d "$(BASEDIR)/src/uucore/locales/errors" ]; then \
•280 $(INSTALL) -d "$(DESTDIR)$(LOCALEDIR)/uucore/errors"; \
281 for locale_file in "$(BASEDIR)"/src/uucore/locales/errors/*.ftl; do \
282 if [ "$$(basename "$$locale_file")" != "en-US.ftl" ]; then \
•283 $(INSTALL) -m 644 "$$locale_file" "$(DESTDIR)$(LOCALEDIR)/uucore/errors/"; \
•284 fi; \
285 done; \
286 fi
•287 @$(foreach f,$(UU_LOCALES_NO_EN),$(call uu_install_locale,$(f));)
288 @if [ -d "$(BASEDIR)/l10n/src/uucore/locales" ]; then \
289 mkdir -p "$(DESTDIR)$(LOCALEDIR)/uucore"; \
290 for f in $(UUC_CORE_LOCALES); do \
291 [ -e "$$f" ] || continue; \
292 $(INSTALL) -m 644 "$$f" "$(DESTDIR)$(LOCALEDIR)/uucore/"; \
293 done \
294 fi
295 else
296 locales:
297 install-locales:
298 endif
299
300 install: build install-manpages install-completions install-locales
301 $(INSTALL) -d $(INSTALLDIR_BIN)
302 ifneq (,$(and $(findstring stdbuf,$(UTILS)),$(findstring feat_external_libstdbuf,$(CARGOFLAGS))))
303 ifneq (,$(findstring cygwin,$(OS)))
304 $(INSTALL) -d $(DESTDIR)$(LIBSTDBUF_DIR)
305 $(INSTALL) -m 755 $(BUILDDIR)/deps/stdbuf.dll $(DESTDIR)$(LIBSTDBUF_DIR)/libstdbuf.dll
306 else ifneq (,$(findstring windows,$(OS)))
307 @echo "NOTE: Windows stdbuf depends on Cygwin's libstdbuf.dll"
308 else
309 $(INSTALL) -d $(DESTDIR)$(LIBSTDBUF_DIR)
310 $(INSTALL) -m 755 $(BUILDDIR)/deps/libstdbuf.* $(DESTDIR)$(LIBSTDBUF_DIR)/
311 endif
312 endif
313 ifeq (${MULTICALL}, y)
314 $(INSTALL) -m 755 $(BUILDDIR)/coreutils $(INSTALLDIR_BIN)/$(PROG_PREFIX)coreutils
315 $(foreach prog, $(filter-out coreutils, $(INSTALLEES)), \
316 cd $(INSTALLDIR_BIN) && $(LN) $(PROG_PREFIX)coreutils $(PROG_PREFIX)$(prog) $(newline) \
317 )
318 $(if $(findstring test,$(INSTALLEES)), cd $(INSTALLDIR_BIN) && $(LN) $(PROG_PREFIX)coreutils $(PROG_PREFIX)[)
319 else
320 $(foreach prog, $(INSTALLEES), \
321 $(INSTALL) -m 755 $(BUILDDIR)/$(prog) $(INSTALLDIR_BIN)/$(PROG_PREFIX)$(prog) $(newline) \
322 )
323 $(if $(findstring test,$(INSTALLEES)), $(INSTALL) -m 755 $(BUILDDIR)/test $(INSTALLDIR_BIN)/$(PROG_PREFIX)[)
324 endif
325
326 uninstall:
327 ifeq (,$(findstring windows,$(OS)))
328 rm -f $(DESTDIR)$(LIBSTDBUF_DIR)/libstdbuf.*
329 -rm -d $(DESTDIR)$(LIBSTDBUF_DIR) 2>/dev/null || true
330 endif
331 ifeq (${MULTICALL}, y)
332 rm -f $(addprefix $(INSTALLDIR_BIN)/,$(PROG_PREFIX)coreutils)
333 endif
334 rm -f $(addprefix $(INSTALLDIR_BIN)/$(PROG_PREFIX),$(PROGS))
335 rm -f $(INSTALLDIR_BIN)/$(PROG_PREFIX)[
336 rm -f $(addprefix $(DESTDIR)$(DATAROOTDIR)/zsh/site-functions/_$(PROG_PREFIX),$(PROGS))
337 rm -f $(addprefix $(DESTDIR)$(DATAROOTDIR)/bash-completion/completions/$(PROG_PREFIX),$(PROGS).bash)
338 rm -f $(addprefix $(DESTDIR)$(DATAROOTDIR)/fish/vendor_completions.d/$(PROG_PREFIX),$(addsuffix .fish,$(PROGS)))
339 rm -f $(addprefix $(DESTDIR)$(DATAROOTDIR)/man/man1/$(PROG_PREFIX),$(addsuffix .1,$(PROGS)))
340
341 .PHONY: all build build-coreutils build-pkgs build-uudoc test distclean clean busytest install uninstall