#!/bin/bash
# SPDX-License-Identifier: MulanPSL-2.0+
# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved.

umask 002

make()
{
	command make -j $cpus "$@"
}

cd /c || exit

git clone -b custom-config  https://gitee.com/wu_fengguang/ipxe.git

cd ipxe/src || exit

cpus=$(nproc)

build_ipxe()
{
	make ARCH=$1 bin-$1-efi/ipxe.efi
	make ARCH=$1 bin-$1-efi/snponly.efi
	make ARCH=$1 bin-$1-efi/snp.efi
	make CONFIG=rpi bin-$1-efi/rpi.efi

	mkdir -p /tftpboot/ipxe/bin-$1-efi/
	cp -a bin-$1-efi/*.efi /tftpboot/ipxe/bin-$1-efi/
	chmod 664 /tftpboot/ipxe/bin-$1-efi/*.efi
}

ARCH=$(arch)

case "$ARCH" in
	"aarch64")
	        build_ipxe arm64
	        ;;
	"x86_64")
		build_ipxe x86_64
		;;
esac
