On 6/14/19 3:29 PM, Eric Blake wrote: > On 6/14/19 5:16 AM, Philippe Mathieu-Daudé wrote: >> Cc'ing Eric :) >> > >>> When running this script out of 'make', we get: >>> >>> $ cd roms >>> $ ./edk2-build.sh aarch64 --arch=AARCH64 >>> --platform=ArmVirtPkg/ArmVirtQemu.dsc > /dev/null >>> ./edk2-build.sh: line 46: MAKEFLAGS: unbound variable >>> >>> Fix this by checking the variable is defined before using it, >>> else use a default value. >>> >>> Signed-off-by: Philippe Mathieu-Daudé <phi...@redhat.com> >>> --- >>> roms/edk2-build.sh | 8 +++++++- >>> 1 file changed, 7 insertions(+), 1 deletion(-) >>> >>> diff --git a/roms/edk2-build.sh b/roms/edk2-build.sh >>> index 4f46f8a6a2..5390228b4e 100755 >>> --- a/roms/edk2-build.sh >>> +++ b/roms/edk2-build.sh > > This is running under /bin/bash (hmm - not '/bin/env bash' like other > scripts in qemu?), so... > >>> @@ -43,7 +43,13 @@ fi >>> # any), for the edk2 "build" utility. >>> source ../edk2-funcs.sh >>> edk2_toolchain=$(qemu_edk2_get_toolchain "$emulation_target") >>> -edk2_thread_count=$(qemu_edk2_get_thread_count "$MAKEFLAGS") >>> +if [ -v MAKEFLAGS ]; then > > the non-portable bashism '[ -v' works. However, it's just as easy to
Ah, OK. > work around this problem portably for all POSIX shells without needing 'if': > >>> + edk2_thread_count=$(qemu_edk2_get_thread_count "$MAKEFLAGS") >>> +else >>> + # We are not running within 'make', let the edk2 "build" utility to fetch >>> + # the logical CPU count with Python's multiprocessing.cpu_count() method. >>> + edk2_thread_count=0 >>> +fi > > edk2_thread_count=$(qemu_edk2_get_thread_count "${MAKEFLAGS:-0}") Argh I'm confuse, this is what I wanted to do first but I couldn't get it working, maybe I forget the '-'. Thanks a lot for your help, the result is way more elegant :) > > at which point the really long comment needs a bit of a tweak. >