diff --git a/test/Makefile b/test/Makefile index 65a3646d..d343fbc2 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,7 +1,9 @@ ARCH ?= x86_64 -busybox-ver = 1.31.0 -busybox-bin = busybox-$(ARCH) +finit_bin = ../src/finit + +busybox_ver = 1.31.0 +busybox_bin = busybox-$(ARCH) testroot = test_root testroot_bin = $(testroot)/bin @@ -22,52 +24,57 @@ binaries = $(testroot_bin)/cat \ $(testroot_bin)/sleep \ $(testroot_bin)/top \ $(testroot_bin)/touch -dirs = $(testroot)/dev \ - $(testroot)/etc \ - $(testroot)/lib \ - $(testroot)/proc \ - $(testroot)/sbin \ - $(testroot)/sys \ - $(testroot)/tmp \ - $(testroot)/usr/local/lib +dirs = $(testroot)/bin \ + $(testroot)/dev \ + $(testroot)/etc \ + $(testroot)/lib \ + $(testroot)/lib64 \ + $(testroot)/proc \ + $(testroot)/sbin \ + $(testroot)/sys \ + $(testroot)/tmp \ + $(testroot)/usr/lib -$(testroot)/%: $(testroot) +$(dirs): mkdir -p $@ -$(busybox-bin): - wget 'https://www.busybox.net/downloads/binaries/$(busybox-ver)-defconfig-multiarch-musl/$(busybox-bin)' - md5sum -c $(busybox-bin).md5 +$(busybox_bin): + wget 'https://www.busybox.net/downloads/binaries/$(busybox_ver)-defconfig-multiarch-musl/$(busybox_bin)' + md5sum -c $(busybox_bin).md5 $(testroot): mkdir $(testroot) -$(testroot_bin)/$(busybox-bin): $(testroot_bin) $(busybox-bin) - cp $(busybox-bin) $(testroot_bin)/ - chmod +x $(testroot_bin)/$(busybox-bin) +$(testroot_bin)/$(busybox_bin): $(busybox_bin) + mkdir -p $(testroot_bin) + cp $(busybox_bin) $(testroot_bin)/ + chmod +x $(testroot_bin)/$(busybox_bin) -$(testroot_bin)/%: $(testroot_bin)/$(busybox-bin) +$(binaries): $(testroot_bin)/$(busybox_bin) cd $(testroot_bin); \ - ln -s $(busybox-bin) $(notdir $@) + ln -s $(busybox_bin) $(notdir $@) $(testroot_bin)/chrootsetup.sh: chrootsetup.sh cp $< $@ -$(testroot)/sbin/finit: ../src/finit $(testroot)/lib/ld-musl-x86_64.so.1 $(testroot)/usr/local/lib/libite.so.5 $(testroot)/usr/local/lib/libuev.so.2 +libs_src = $(shell ldd $(finit_bin) | grep -v lib64 | grep '=>' | cut -d' ' -f3) +libs = $(foreach path,$(libs_src),$(testroot)/usr/lib/$(shell basename $(path))) +libs64_src = $(shell ldd $(finit_bin) | grep lib64 | grep '=>' | cut -d' ' -f3) +libs64 = $(foreach path,$(libs64_src),$(testroot)/lib64/$(shell basename $(path))) + +$(testroot)/sbin/finit: $(finit_bin) $(libs) $(libs64) cp $< $@ -$(testroot)/lib/ld-musl-x86_64.so.1: - cp test_root.backup/lib/ld-musl-x86_64.so.1 $@ - -$(testroot)/usr/local/lib/libite.so.5: - cp test_root.backup/usr/local/lib/libite.so.5 $@ - -$(testroot)/usr/local/lib/libuev.so.2: - cp test_root.backup/usr/local/lib/libuev.so.2 $@ - .PHONY: test test: $(binaries) $(testroot_bin)/chrootsetup.sh $(dirs) $(testroot)/sbin/finit ./runtest.sh test_start_stop_service/test.sh +$(libs): $@ + cp $(shell ldd $(finit_bin) | cut -d' ' -f3 | grep $(notdir $@)) $@ + +$(libs64): $@ + cp $(shell ldd $(finit_bin) | cut -d' ' -f3 | grep $(notdir $@)) $@ + .PHONY: lint lint: shellcheck $(shell find . -name '*.sh') @@ -75,4 +82,4 @@ lint: .PHONY: clean clean: rm -rf $(testroot) - rm -f $(busybox-bin) + rm -f $(busybox_bin)