Debian Codegraph @

test/lib/sysroot.mk

raw symbols SCIP
1 # Root file system for test environment.
2 #
3 # Copyright (c) 2021 Jacques de Laval <[email protected]>
4 #
5 # Permission is hereby granted, free of charge, to any person obtaining a copy
6 # of this software and associated documentation files (the "Software"), to deal
7 # in the Software without restriction, including without limitation the rights
8 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 # copies of the Software, and to permit persons to whom the Software is
10 # furnished to do so, subject to the following conditions:
11 #
12 # The above copyright notice and this permission notice shall be included in
13 # all copies or substantial portions of the Software.
14 #
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 # THE SOFTWARE.
22
23 srcdir ?= ../
24 SKEL ?= $(srcdir)/skel
25 DEST ?= ../sysroot
26
27 CACHE ?= ~/.cache
28 ARCH ?= x86_64
29
30 FINITBIN ?= ./sbin/finit
31
32 BBVER ?= 1_35_0
33 BBBIN = busybox-$(ARCH)
34 BBHOME ?= https://github.com/troglobit/busybox-builder/releases/download
35 BBURL ?= $(BBHOME)/$(BBVER)/$(BBBIN)
36
37 _libs_src = $(shell ldd $(FINITBIN) | grep -Eo '/[^ ]+')
38 libs = $(foreach path,$(_libs_src),$(abspath $(DEST))$(path))
39
40 all: $(libs) $(DEST)/bin/$(BBBIN)
41 @(cd $(DEST); \
42 for prg in `./bin/$(BBBIN) --list-full`; do \
43 case $$prg in \
44 usr/bin/* | usr/sbin/*) \
45 ln -sf ../../bin/$(BBBIN) $$prg;; \
46 bin/* | sbin/*) \
47 ln -sf ../bin/$(BBBIN) $$prg;; \
48 *) \
49 ln -sf bin/$(BBBIN) $$prg;; \
50 esac; \
51 done)
52
53 $(DEST)/bin/$(BBBIN).sha256:
54 @mkdir -p $(DEST)
55 @cp -a $(SKEL)/* $(DEST)/
56 @chmod -R u+w $(DEST)/
57 @find $(DEST) -name .empty -delete
58
59 $(DEST)/bin/$(BBBIN): $(DEST)/bin/$(BBBIN).sha256
60 @(cd $(dir $@); \
61 if ! sha256sum --status -c $(BBBIN).sha256 2>/dev/null; then \
62 if [ -d $(CACHE) ]; then \
63 echo "Cannot find $(BBBIN), checking $(CACHE) ..."; \
64 cd $(CACHE); \
65 cp -v $(DEST)/bin/$(BBBIN).sha256 .; \
66 if ! sha256sum --status -c $(BBBIN).sha256; then \
67 echo "No $(BBBIN), downloading $(BBURL) ..."; \
68 wget -O $(BBBIN) $(BBURL); \
69 else \
70 echo "Found valid $(BBBIN) in cache!"; \
71 fi; \
72 cp $(BBBIN) $@; \
73 cd $(dir $@); \
74 else \
75 echo "Cannot find $(BBBIN), downloading ..."; \
76 wget -O $@ $(BBURL); \
77 fi; \
78 sha256sum -c $(BBBIN).sha256 || (rm $@; false); \
79 fi)
80 @chmod +x $@
81
82 $(libs): $(DEST)/bin/$(BBBIN).sha256
83 mkdir -p $(dir $@)
84 cp $(patsubst $(abspath $(DEST))%,%,$@) $@