| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 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))%,%,$@) $@ |