From 7846eb2e2fed44be05f068bc34cdb35330021d39 Mon Sep 17 00:00:00 2001
From: Adam Dunkels <adam@thingsquare.com>
Date: Tue, 10 Dec 2013 08:42:10 +0100
Subject: [PATCH] Split the cc2430 custom rules into its own file

---
 cpu/cc2430/Makefile.cc2430                    | 63 -------------------
 cpu/cc2430/Makefile.customrules-cc2430        | 63 +++++++++++++++++++
 .../sensinode/Makefile.customrules-sensinode  |  1 +
 3 files changed, 64 insertions(+), 63 deletions(-)
 create mode 100644 cpu/cc2430/Makefile.customrules-cc2430
 create mode 100644 platform/sensinode/Makefile.customrules-sensinode

diff --git a/cpu/cc2430/Makefile.cc2430 b/cpu/cc2430/Makefile.cc2430
index 2a8209129..1cd207356 100644
--- a/cpu/cc2430/Makefile.cc2430
+++ b/cpu/cc2430/Makefile.cc2430
@@ -114,66 +114,3 @@ CONTIKI_OBJECTFILES = $(addprefix $(OBJECTDIR)/, \
 PROJECT_OBJECTFILES = $(addprefix $(OBJECTDIR)/, \
 	$(call oname, $(PROJECT_SOURCEFILES)))
 
-### Compilation rules
-
-SEGMENT_RULE_FILES = $(foreach dir, . $(CONTIKI_PLATFORM_DIRS) \
-	$(CONTIKI_CPU_DIRS_LIST), $(wildcard $(dir)/segment.rules) )
-
-# NB: Assumes SEGMENT_RULES was not overridden and is in $(OBJECTDIR)
-$(SEGMENT_RULES): $(SEGMENT_RULE_FILES) | $(OBJECTDIR)
-	cat $(SEGMENT_RULE_FILES) | \
-	   sed -e 's/#.*$$//' -e 's/^\s*//' -e '/^$$/d' > $@
-
-CUSTOM_RULE_LINK=1
-CUSTOM_RULE_C_TO_OBJECTDIR_O=1
-CUSTOM_RULE_ALLOBJS_TO_TARGETLIB=1
-
-$(OBJECTDIR)/%.rel: %.c $(SEGMENT_RULES) | $(OBJECTDIR)
-	$(TRACE_CC)
-	$(Q)$(CC) $(call c_seg,$<,$@) $(CFLAGS) -c $< -o $@ -Wp,-MMD,$(@:.rel=.d),-MQ,$@
-	@$(FINALIZE_SDCC_DEPENDENCY)
-
-contiki-$(TARGET).lib: $(CONTIKI_OBJECTFILES) $(PROJECT_OBJECTFILES) \
-	$(CONTIKI_ASMOBJECTFILES) $(CONTIKI_CASMOBJECTFILES)
-	rm -f $@
-	for target in $^; do echo $$target >> $@; done
-
-.PRECIOUS: %.$(TARGET) %.hex
-
-# build app/example local object files. We need a separate rule so that we can
-# pass -DAUTOSTART_ENABLE for those files only
-$(OBJECTDIR)/%.app.rel: %.c $(SEGMENT_RULES) | $(OBJECTDIR)
-	$(TRACE_CC)
-	$(Q)$(CC) $(call c_seg,$<,$@) -DAUTOSTART_ENABLE $(CFLAGS) -c $< -o $@
-
-# .ihx is the sdcc binary output file
-%.ihx: $(OBJECTDIR)/%.app.rel $(CONTIKI_TARGET_MAIN) contiki-$(TARGET).lib
-# Automatic bank relocation when building banked code
-ifeq ($(HAVE_BANKING),1)
-	@echo "\nFirst Link"
-	@echo "==============="
-	$(TRACE_LD)
-	$(Q)$(LD) $(LDFLAGS) -o $@ $(CONTIKI_TARGET_MAIN) $(OBJECTDIR)/$*.app.rel -llibsdcc.lib -lcontiki-$(TARGET).lib
-	@echo "\nBank Allocation"
-	@echo "==============="
-	python $(BANK_ALLOC) $(basename $(@F)) $(SEGMENT_RULES) $(OFFSET_FIRMWARE)
-	@echo "\nFinal Link"
-	@echo "==============="
-endif
-	$(TRACE_LD)
-	$(Q)$(LD) $(LDFLAGS) $(LD_POST_FLAGS) -o $@ $(CONTIKI_TARGET_MAIN) $(OBJECTDIR)/$*.app.rel -llibsdcc.lib -lcontiki-$(TARGET).lib
-
-# Pack the hex file for programmers which dislike SDCC output hex format
-%.hex: %.ihx
-	@echo "\nPack hex file"
-	@echo "==============="
-ifeq ($(HAVE_BANKING),1)
-	srec_cat -disable_sequence_warnings $< -intel -crop 0x10000 0x1FFFF -offset -0x10000 -o bank1.hex -intel
-	srec_cat -disable_sequence_warnings $< -intel -crop 0x20000 0x2FFFF -offset -0x18000 -o bank2.hex -intel
-	srec_cat -disable_sequence_warnings $< -intel -crop 0x30000 0x3FFFF -offset -0x20000 -o bank3.hex -intel
-	srec_cat -disable_sequence_warnings $< -intel -crop 0x00000 0x0FFFF -o home.ihx -intel
-	srec_cat home.ihx -intel bank1.hex -intel bank2.hex -intel bank3.hex -intel -o $@ -intel
-	rm -f home.ihx bank1.hex bank2.hex bank3.hex
-else
-	$(PACKIHX) $< > $@
-endif
diff --git a/cpu/cc2430/Makefile.customrules-cc2430 b/cpu/cc2430/Makefile.customrules-cc2430
new file mode 100644
index 000000000..68ed21c60
--- /dev/null
+++ b/cpu/cc2430/Makefile.customrules-cc2430
@@ -0,0 +1,63 @@
+### Compilation rules
+
+SEGMENT_RULE_FILES = $(foreach dir, . $(CONTIKI_PLATFORM_DIRS) \
+	$(CONTIKI_CPU_DIRS_LIST), $(wildcard $(dir)/segment.rules) )
+
+# NB: Assumes SEGMENT_RULES was not overridden and is in $(OBJECTDIR)
+$(SEGMENT_RULES): $(SEGMENT_RULE_FILES) | $(OBJECTDIR)
+	cat $(SEGMENT_RULE_FILES) | \
+	   sed -e 's/#.*$$//' -e 's/^\s*//' -e '/^$$/d' > $@
+
+CUSTOM_RULE_LINK=1
+CUSTOM_RULE_C_TO_OBJECTDIR_O=1
+CUSTOM_RULE_ALLOBJS_TO_TARGETLIB=1
+
+$(OBJECTDIR)/%.rel: %.c $(SEGMENT_RULES) | $(OBJECTDIR)
+	$(TRACE_CC)
+	$(Q)$(CC) $(call c_seg,$<,$@) $(CFLAGS) -c $< -o $@ -Wp,-MMD,$(@:.rel=.d),-MQ,$@
+	@$(FINALIZE_SDCC_DEPENDENCY)
+
+contiki-$(TARGET).lib: $(CONTIKI_OBJECTFILES) $(PROJECT_OBJECTFILES) \
+	$(CONTIKI_ASMOBJECTFILES) $(CONTIKI_CASMOBJECTFILES)
+	rm -f $@
+	for target in $^; do echo $$target >> $@; done
+
+.PRECIOUS: %.$(TARGET) %.hex
+
+# build app/example local object files. We need a separate rule so that we can
+# pass -DAUTOSTART_ENABLE for those files only
+$(OBJECTDIR)/%.app.rel: %.c $(SEGMENT_RULES) | $(OBJECTDIR)
+	$(TRACE_CC)
+	$(Q)$(CC) $(call c_seg,$<,$@) -DAUTOSTART_ENABLE $(CFLAGS) -c $< -o $@
+
+# .ihx is the sdcc binary output file
+%.ihx: $(OBJECTDIR)/%.app.rel $(CONTIKI_TARGET_MAIN) contiki-$(TARGET).lib
+# Automatic bank relocation when building banked code
+ifeq ($(HAVE_BANKING),1)
+	@echo "\nFirst Link"
+	@echo "==============="
+	$(TRACE_LD)
+	$(Q)$(LD) $(LDFLAGS) -o $@ $(CONTIKI_TARGET_MAIN) $(OBJECTDIR)/$*.app.rel -llibsdcc.lib -lcontiki-$(TARGET).lib
+	@echo "\nBank Allocation"
+	@echo "==============="
+	python $(BANK_ALLOC) $(basename $(@F)) $(SEGMENT_RULES) $(OFFSET_FIRMWARE)
+	@echo "\nFinal Link"
+	@echo "==============="
+endif
+	$(TRACE_LD)
+	$(Q)$(LD) $(LDFLAGS) $(LD_POST_FLAGS) -o $@ $(CONTIKI_TARGET_MAIN) $(OBJECTDIR)/$*.app.rel -llibsdcc.lib -lcontiki-$(TARGET).lib
+
+# Pack the hex file for programmers which dislike SDCC output hex format
+%.hex: %.ihx
+	@echo "\nPack hex file"
+	@echo "==============="
+ifeq ($(HAVE_BANKING),1)
+	srec_cat -disable_sequence_warnings $< -intel -crop 0x10000 0x1FFFF -offset -0x10000 -o bank1.hex -intel
+	srec_cat -disable_sequence_warnings $< -intel -crop 0x20000 0x2FFFF -offset -0x18000 -o bank2.hex -intel
+	srec_cat -disable_sequence_warnings $< -intel -crop 0x30000 0x3FFFF -offset -0x20000 -o bank3.hex -intel
+	srec_cat -disable_sequence_warnings $< -intel -crop 0x00000 0x0FFFF -o home.ihx -intel
+	srec_cat home.ihx -intel bank1.hex -intel bank2.hex -intel bank3.hex -intel -o $@ -intel
+	rm -f home.ihx bank1.hex bank2.hex bank3.hex
+else
+	$(PACKIHX) $< > $@
+endif
diff --git a/platform/sensinode/Makefile.customrules-sensinode b/platform/sensinode/Makefile.customrules-sensinode
new file mode 100644
index 000000000..13ec8cf5e
--- /dev/null
+++ b/platform/sensinode/Makefile.customrules-sensinode
@@ -0,0 +1 @@
+include $(CONTIKI)/cpu/cc2430/Makefile.customrules-cc2430