# BusyBox for aarch64: the same source and configuration (its licence and source tarball are /linux's).
build/linux-a64/busybox: linux/busybox.config linux/musl-cc $(MUSL_A64)/lib/libc.a
	rm -rf build/busybox-a64 && mkdir -p build/busybox-a64 build/linux-a64
	$(MAKE) -C linux/busybox O=$(CURDIR)/build/busybox-a64 HOSTCC=cc allnoconfig >build/busybox-a64/config.log 2>&1
	for o in $$(grep -v '^#' linux/busybox.config); do case $$o in \
	    *=*) sed -i.bak "s/^CONFIG_$${o%%=*}=.*/CONFIG_$$o/; s/^# CONFIG_$${o%%=*} is not set$$/CONFIG_$$o/" build/busybox-a64/.config;; \
	    *) sed -i.bak "s/^# CONFIG_$$o is not set$$/CONFIG_$$o=y/" build/busybox-a64/.config;; esac; done
	yes "" | $(MAKE) -C linux/busybox O=$(CURDIR)/build/busybox-a64 HOSTCC=cc oldconfig >>build/busybox-a64/config.log 2>&1
	MUSL_SYSROOT=$(CURDIR)/$(MUSL_A64) MUSL_TARGET=aarch64-linux-musl MUSL_LIBCC=$(CURDIR)/$(CCRT_A64) \
	    $(MAKE) -C linux/busybox O=$(CURDIR)/build/busybox-a64 CC=$(CURDIR)/linux/musl-cc HOSTCC=cc \
	    LD=$(LD) AR=$(LLVM_AR) NM=$(LLVM_NM) STRIP=$(LLVM_STRIP) OBJCOPY=$(OBJCOPY) >build/busybox-a64/make.log 2>&1 \
	    || { tail -30 build/busybox-a64/make.log; exit 1; }
	cp build/busybox-a64/busybox $@
