From b7b4efcdf1dcaa999a246f03ee52b16b57c8b1d5 Mon Sep 17 00:00:00 2001
From: Zachary T Welch <zw@superlucidity.net>
Date: Tue, 10 Nov 2009 04:27:02 -0800
Subject: [PATCH] makefiles: improve build order

Separates various groups of files to be built in logical succession.
In each layer, the core module (target.c, nand.c, etc.) is built _after_
their helper modules (e.g. image.c, nand_ecc.c) but _before_ any of
their drivers (e.g. arm966e.c, mx3_nand.c).

This allows problems introduced at the bottom of the stack to result
in build failures as soon as possible, as the helpers and core should
wrap portions of them.
---
 src/flash/Makefile.am  |  81 +++++++++++++++-----------
 src/target/Makefile.am | 127 ++++++++++++++++++++++++-----------------
 2 files changed, 123 insertions(+), 85 deletions(-)

diff --git a/src/flash/Makefile.am b/src/flash/Makefile.am
index d448197a9..e1224519b 100644
--- a/src/flash/Makefile.am
+++ b/src/flash/Makefile.am
@@ -6,65 +6,78 @@ AM_CPPFLAGS = \
 METASOURCES = AUTO
 noinst_LTLIBRARIES = libflash.la
 libflash_la_SOURCES = \
-	arm_nandio.c \
-	flash.c \
-	lpc2000.c \
-	lpc288x.c \
-	lpc2900.c \
+	$(FLASH_SRCS) \
+	$(NAND_SRCS) \
+	mflash.c
+
+FLASH_SRCS = \
 	cfi.c \
 	non_cfi.c \
-	at91sam7.c \
+	faux.c \
+	$(FLASH_DEVICES_SRCS) \
+	flash.c
+
+FLASH_DEVICES_SRCS = \
+	aduc702x.c \
 	at91sam3.c \
-	davinci_nand.c \
+	at91sam7.c \
+	avrf.c \
+	ecos.c \
+	lpc2000.c \
+	lpc288x.c \
+	lpc2900.c \
+	ocl.c \
+	pic32mx.c \
+	stellaris.c \
+	stm32x.c \
 	str7x.c \
 	str9x.c \
-	aduc702x.c \
-	nand.c \
+	str9xpec.c \
+	tms470.c
+
+NAND_SRCS = \
+	arm_nandio.c \
 	nand_ecc.c \
 	nand_ecc_kw.c \
+	$(NAND_DEVICES_SRCS) \
+	nand.c
+
+NAND_DEVICES_SRCS = \
+	davinci_nand.c \
 	lpc3180_nand_controller.c \
-	stellaris.c \
-	str9xpec.c \
-	stm32x.c \
-	tms470.c \
-	ecos.c \
+	mx3_nand.c \
 	orion_nand.c \
 	s3c24xx_nand.c \
 	s3c2410_nand.c \
 	s3c2412_nand.c \
 	s3c2440_nand.c \
-	s3c2443_nand.c \
-	ocl.c \
-	mflash.c \
-	pic32mx.c \
-	avrf.c \
-	faux.c \
-	mx3_nand.c
+	s3c2443_nand.c
+
 
 noinst_HEADERS = \
 	arm_nandio.h \
+	at91sam7.h \
+	at91sam3.h \
+	avrf.h \
+	cfi.h \
 	flash.h \
 	lpc2000.h \
 	lpc288x.h \
 	lpc2900.h \
-	cfi.h \
+	lpc3180_nand_controller.h \
+	mflash.h \
+	mx3_nand.h \
 	non_cfi.h \
-	at91sam7.h \
-	at91sam3.h \
-	str7x.h \
-	str9x.h \
 	nand.h \
-	lpc3180_nand_controller.h \
+	ocl.h \
+	pic32mx.h \
 	stellaris.h \
-	str9xpec.h \
 	stm32x.h \
+	str7x.h \
+	str9x.h \
+	str9xpec.h \
 	tms470.h \
 	s3c24xx_nand.h \
-	s3c24xx_regs_nand.h \
-	mflash.h \
-	ocl.h \
-	pic32mx.h \
-	avrf.h \
-	mx3_nand.h
+	s3c24xx_regs_nand.h
 
 MAINTAINERCLEANFILES = $(srcdir)/Makefile.in
diff --git a/src/target/Makefile.am b/src/target/Makefile.am
index f62ba1d87..9dd0bdc91 100644
--- a/src/target/Makefile.am
+++ b/src/target/Makefile.am
@@ -25,90 +25,115 @@ $(DEBUG_HEADER): $(BIN2C) $(DEBUG_HANDLER)
 METASOURCES = AUTO
 noinst_LTLIBRARIES = libtarget.la
 libtarget_la_SOURCES = \
-	target.c \
+	$(TARGET_CORE_SRC) \
+	$(ARM_DEBUG_SRC) \
+	$(ARMV4_5_SRC) \
+	$(ARMV6_SRC) \
+	$(ARMV7_SRC) \
+	$(ARM_MISC_SRC) \
+	$(MIPS32_SRC) \
+	avrt.c
+
+TARGET_CORE_SRC = \
+	algorithm.c \
 	register.c \
+	image.c \
 	breakpoints.c \
+	target.c \
+	target_request.c
+
+ARMV4_5_SRC = \
 	armv4_5.c \
-	embeddedice.c \
-	etm.c \
+	armv4_5_mmu.c \
+	armv4_5_cache.c \
+	$(ARM7_9_SRC)
+
+ARM7_9_SRC = \
+	arm7_9_common.c \
 	arm7tdmi.c \
+	arm720t.c \
 	arm9tdmi.c \
-	arm_jtag.c \
-	arm7_9_common.c \
-	algorithm.c \
 	arm920t.c \
-	arm720t.c \
-	armv4_5_mmu.c \
-	armv4_5_cache.c \
-	arm_disassembler.c \
 	arm966e.c \
-	arm926ejs.c \
+	arm926ejs.c
+
+ARM_MISC_SRC = \
 	fa526.c \
 	feroceon.c \
-	etb.c \
-	xscale.c \
-	arm_simulator.c \
-	image.c \
+	xscale.c
+
+ARMV6_SRC = \
+	arm11.c \
+	arm11_dbgtap.c
+
+ARMV7_SRC = \
 	armv7m.c \
-	armv7a.c \
 	cortex_m3.c \
-	cortex_a8.c \
+	armv7a.c \
+	cortex_a8.c
+
+ARM_DEBUG_SRC = \
+	arm_jtag.c \
+	arm_disassembler.c \
+	arm_simulator.c \
 	arm_adi_v5.c \
-	etm_dummy.c \
-	$(OOCD_TRACE_FILES) \
-	target_request.c \
+	embeddedice.c \
 	trace.c \
-	arm11.c \
-	arm11_dbgtap.c \
+	etb.c \
+	etm.c \
+	$(OOCD_TRACE_FILES) \
+	etm_dummy.c
+
+MIPS32_SRC = \
 	mips32.c \
 	mips_m4k.c \
 	mips32_pracc.c \
 	mips32_dmaacc.c \
-	mips_ejtag.c \
-	avrt.c
+	mips_ejtag.c
+
 
 noinst_HEADERS = \
-	target.h \
-	target_type.h \
-	trace.h \
-	register.h \
-	armv4_5.h \
-	embeddedice.h \
-	etm.h \
-	arm7tdmi.h \
-	arm9tdmi.h \
+	algorithm.h \
 	arm_jtag.h \
+	arm_adi_v5.h \
+	arm_disassembler.h \
+	arm_simulator.h \
 	arm7_9_common.h \
-	arm920t.h \
+	arm7tdmi.h \
 	arm720t.h \
+	arm9tdmi.h \
+	arm920t.h \
+	arm926ejs.h \
+	arm966e.h \
+	arm11.h \
+	armv4_5.h \
 	armv4_5_mmu.h \
 	armv4_5_cache.h \
-	breakpoints.h \
-	algorithm.h \
-	arm_disassembler.h \
-	arm966e.h \
-	arm926ejs.h \
-	etb.h \
-	xscale.h \
-	xscale_debug.h \
-	arm_simulator.h \
-	image.h \
-	armv7m.h \
 	armv7a.h \
+	armv7m.h \
+	avrt.h \
+	breakpoints.h \
 	cortex_m3.h \
 	cortex_a8.h \
-	arm_adi_v5.h \
+	embeddedice.h \
+	etb.h \
+	etm.h \
 	etm_dummy.h \
-	oocd_trace.h \
-	target_request.h \
-	trace.h \
-	arm11.h \
+	image.h \
 	mips32.h \
 	mips_m4k.h \
 	mips_ejtag.h \
 	mips32_pracc.h \
 	mips32_dmaacc.h \
-	avrt.h
+	oocd_trace.h \
+	register.h \
+	target.h \
+	target_type.h \
+	trace.h \
+	target_request.h \
+	trace.h \
+	xscale.h \
+	xscale_debug.h
 
 nobase_dist_pkglib_DATA =
 nobase_dist_pkglib_DATA += ecos/at91eb40a.elf
-- 
GitLab