nvramcui: Update Makefile

* use crossgcc to build nvramcui
* build libpayload dependency

Change-Id: Ife3054aeb03b4da0568ad47f96c633460d6c07ae
Signed-off-by: Iru Cai <mytbk920423@gmail.com>
Reviewed-on: https://review.coreboot.org/14377
Tested-by: build bot (Jenkins)
Reviewed-by: Martin Roth <martinroth@google.com>
diff --git a/payloads/nvramcui/Makefile b/payloads/nvramcui/Makefile
index 10dc362..0f27ff8 100755
--- a/payloads/nvramcui/Makefile
+++ b/payloads/nvramcui/Makefile
@@ -1,12 +1,32 @@
-LPGCC = ../libpayload/install/libpayload/bin/lpgcc
+# build libpayload and put .config file in $(CURDIR) instead of ../libpayload
+# to avoid pollute the libpayload source directory and possible conflicts
 all: nvramcui.elf
+	$(MAKE) -C ../libpayload $(LPOPTS) defconfig
+	$(MAKE) -C ../libpayload $(LPOPTS)
+	$(MAKE) -C ../libpayload $(LPOPTS) install
+ifneq ($(strip $(wildcard libpayload)),)
+include $(XCOMPILE)
+LPGCC = CC="$(GCC_CC_x86_32)" "$(LIBPAYLOAD_DIR)/bin/lpgcc"
+%.elf: %.c
 	$(LPGCC) -o $*.elf $*.c
+# If libpayload is not found, first build libpayload,
+# then do the make, this time it'll find libpayload
+# and generate the nvramcui.elf target
+%.elf: libpayload
+	$(MAKE) all
 	rm -f nvramcui.elf
 distclean: clean
+	rm -rf build libpayload .config