build system: use full (in-tree) paths

So far we assumed that all files in *-srcs are below src/
which wasn't really true actually and will be less true with
future changes.

Fix up crt0.S handling on x86, which is covered by default rules
due to this change.

This is inspired by the commit listed below, but rewritten to match
upstream, and split in smaller pieces to keep intent clear.

Change-Id: Icae563c2d545b1aea809406e73faf3b417796a1b
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Based-On-Change-Id: I50af7dacf616e0f8ff4c43f4acc679089ad7022b
Based-On-Signed-off-by: Julius Werner <jwerner@chromium.org>
Based-On-Reviewed-on: https://chromium-review.googlesource.com/219170
Reviewed-on: http://review.coreboot.org/9288
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@google.com>
diff --git a/Makefile b/Makefile
index f6f9a60..3ad19df 100644
--- a/Makefile
+++ b/Makefile
@@ -230,7 +230,7 @@
 # $4 additional dependencies
 ifn$(EMPTY)def $(1)-objs_$(2)_template
 de$(EMPTY)fine $(1)-objs_$(2)_template
-$(obj)/$$(1).$(1).o: src/$$(1).$(2) $(obj)/config.h $(4)
+$$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $(obj)/config.h $(4)
 	@printf "    CC         $$$$(subst $$$$(obj)/,,$$$$(@))\n"
 	$(CC_$(1)) -MMD $$$$(CPPFLAGS_$(1)) $$$$(CFLAGS_$(1)) -MT $$$$(@) $(3) -c -o $$$$@ $$$$<
 en$(EMPTY)def
@@ -244,7 +244,7 @@
 		$(if $(generic-objs_$(type)_template_gen),$(eval $(call generic-objs_$(type)_template_gen,$(class))),\
 		$(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps))))))
 
-foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(subst src/,,$(basename $(file))))))
+foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file)))))
 $(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
 
 DEPENDENCIES = $(addsuffix .d,$(basename $(allobjs)))
diff --git a/Makefile.inc b/Makefile.inc
index d18acfc..0e34577 100644
--- a/Makefile.inc
+++ b/Makefile.inc
@@ -147,7 +147,7 @@
 #######################################################################
 # Add handler to compile ACPI's ASL
 define ramstage-objs_asl_template
-$(obj)/$(1).ramstage.asl: src/$(1).asl $(obj)/config.h
+$$(call src-to-obj,ramstage,$(1).asl): $(1).asl $(obj)/config.h
 	@printf "    IASL       $$(subst $(top)/,,$$(@))\n"
 	$(CC_ramstage) -x assembler-with-cpp -E -MMD -MT $$(@) -D__ACPI__ -P -include $(src)/include/kconfig.h -I$(obj) -I$(src) -I$(src)/include -I$(src)/arch/$(ARCHDIR-$(ARCH-ramstage-y))/include -I$(src)/mainboard/$(MAINBOARDDIR) $$< -o $$@
 	cd $$(dir $$@); $(IASL) -p $$(notdir $$@) -tc $$(notdir $$@)
diff --git a/src/arch/x86/Makefile.inc b/src/arch/x86/Makefile.inc
index fe92a22..e2170f5 100644
--- a/src/arch/x86/Makefile.inc
+++ b/src/arch/x86/Makefile.inc
@@ -233,17 +233,12 @@
 	 || { echo "The romstage is larger than XIP size. Please expand the CONFIG_XIP_ROM_SIZE" ; exit 1; }
 	mv $@.tmp $@
 
-$(objgenerated)/crt0.romstage.S: $$(crt0s)
+$(objgenerated)/crt0.S: $$(crt0s)
 	@printf "    GEN        $(subst $(obj)/,,$(@))\n"
-	printf '$(foreach crt0,$(crt0s),#include "$(crt0:$(obj)/%=%)"\n)' > $@
+	printf '$(foreach crt0,$(crt0s),#include "$(crt0)"\n)' > $@
 
-$(objgenerated)/crt0.romstage.o: $(objgenerated)/crt0.S
-	@printf "    CC         $(subst $(obj)/,,$(@))\n"
-	$(CC_romstage) $(CFLAGS_x86_32) $(DISASSEMBLY) -c -o $@ $<  > $(basename $@).disasm
-
-$(objgenerated)/crt0.S: $(objgenerated)/crt0.romstage.S $(obj)/config.h $(obj)/build.h
-	@printf "    CC         $(subst $(obj)/,,$(@))\n"
-	$(CC_romstage) $(CPPFLAGS_romstage) -MMD -x assembler-with-cpp -E -I$(src)/include -I$(src)/arch/x86/include -I$(obj) -include $(obj)/config.h -include $(obj)/build.h -I. -I$(src) $< -o $@
+# Compiling crt0 with -g seems to trigger https://sourceware.org/bugzilla/show_bug.cgi?id=6428
+romstage-S-ccopts += -I. -g0
 
 endif # CONFIG_ARCH_ROMSTAGE_X86_32