Set BUILDING_WITH_NINJA flag when parsing makefiles for ninja build

Distinguish between parsing makefiles in make for a pre-ninja build,
parsing makefiles in kati for a ninja build, and parsing makefiles in
make for a non-ninja build by leaving USE_NINJA=true enabled for the
kati pass but also setting BUILDING_WITH_NINJA.

Change-Id: I63f1ce1efe08cd86fdf41f8051901f720b38cfaf
diff --git a/core/main.mk b/core/main.mk
index 760a054..c2c234c 100644
--- a/core/main.mk
+++ b/core/main.mk
@@ -95,12 +95,19 @@
 # and host information.
 include $(BUILD_SYSTEM)/config.mk
 
+relaunch_with_ninja :=
 ifneq ($(USE_NINJA),false)
+ifndef BUILDING_WITH_NINJA
+relaunch_with_ninja := true
+endif
+endif
+
+ifeq ($(relaunch_with_ninja),true)
 # Mark this is a ninja build.
 $(shell mkdir -p $(OUT_DIR) && touch $(OUT_DIR)/ninja_build)
 include build/core/ninja.mk
-else # !USE_NINJA
-ifeq ($(MAKELEVEL),0)
+else # !relaunch_with_ninja
+ifndef BUILDING_WITH_NINJA
 # Remove ninja build mark if it exists.
 $(shell rm -f $(OUT_DIR)/ninja_build)
 endif
@@ -1066,4 +1073,4 @@
 .PHONY: nothing
 nothing:
 	@echo Successfully read the makefiles.
-endif # !USE_NINJA
+endif # !relaunch_with_ninja