summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile11
-rw-r--r--ld_script_modern.txt79
2 files changed, 87 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index fd753b982..dc5129729 100644
--- a/Makefile
+++ b/Makefile
@@ -68,6 +68,7 @@ ASM_SOURCES := $(wildcard src/*.s src/*/*.s asm/*.s data/*.s sound/*.s sound/*/
C_OBJECTS := $(addprefix $(BUILD_DIR)/, $(C_SOURCES:%.c=%.o))
ASM_OBJECTS := $(addprefix $(BUILD_DIR)/, $(ASM_SOURCES:%.s=%.o))
ALL_OBJECTS := $(C_OBJECTS) $(ASM_OBJECTS)
+OBJS_REL := $(ALL_OBJECTS:$(BUILD_DIR)/%=%)
SUBDIRS := $(sort $(dir $(ALL_OBJECTS)))
DATA_SRC_SUBDIR = src/data
@@ -83,7 +84,11 @@ LIBDIRS := \
endif
LDFLAGS := $(LIBDIRS:%=-L %) -lgcc -lc
+ifeq ($(MODERN),0)
LD_SCRIPT := $(BUILD_DIR)/ld_script.ld
+else
+LD_SCRIPT := $(BUILD_DIR)/ld_script_modern.ld
+endif
# Special configurations required for lib files
ifeq ($(MODERN),0)
@@ -189,11 +194,11 @@ $(ROM): %.gba: %.elf
$(OBJCOPY) -O binary --gap-fill 0xFF --pad-to 0x9000000 $< $@
%.elf: $(LD_SCRIPT) $(ALL_OBJECTS)
- cd $(BUILD_DIR) && $(LD) -T ld_script.ld -Map ../../$(MAP) -o ../../$@ $(LDFLAGS)
+ cd $(BUILD_DIR) && $(LD) -T $(LD_SCRIPT:$(BUILD_DIR)/%=%) -Map ../../$(MAP) -o ../../$@ $(OBJS_REL) $(LDFLAGS)
$(GBAFIX) $@ -p -t"$(TITLE)" -c$(GAME_CODE) -m$(MAKER_CODE) -r$(GAME_REVISION) --silent
-$(LD_SCRIPT): ld_script.txt $(BUILD_DIR)/sym_common.ld $(BUILD_DIR)/sym_ewram.ld $(BUILD_DIR)/sym_bss.ld
- cd $(BUILD_DIR) && sed -e "s#tools/#../../tools/#g" ../../ld_script.txt >ld_script.ld
+$(LD_SCRIPT): $(LD_SCRIPT:$(BUILD_DIR)/%.ld=%.txt) $(BUILD_DIR)/sym_common.ld $(BUILD_DIR)/sym_ewram.ld $(BUILD_DIR)/sym_bss.ld
+ sed -e "s#tools/#../../tools/#g" $< >$@
$(BUILD_DIR)/sym_%.ld: sym_%.txt
$(CPP) -P $(CPPFLAGS) $< | sed -e "s#tools/#../../tools/#g" > $@
diff --git a/ld_script_modern.txt b/ld_script_modern.txt
new file mode 100644
index 000000000..09f5060ff
--- /dev/null
+++ b/ld_script_modern.txt
@@ -0,0 +1,79 @@
+ENTRY(Start)
+
+gNumMusicPlayers = 4;
+gMaxLines = 60;
+
+SECTIONS {
+ . = 0x2000000;
+
+ ewram (NOLOAD) :
+ ALIGN(4)
+ {
+ INCLUDE "sym_ewram.ld"
+ *(ewram_data);
+
+ . = 0x40000;
+ }
+
+ . = 0x3000000;
+
+ iwram (NOLOAD) :
+ ALIGN(4)
+ {
+ /* .bss starts at 0x3000000 */
+ *(.bss);
+
+ /* .bss.code starts at 0x3000F60 */
+ src/libs/m4a.o(.bss.code);
+
+ /* COMMON starts at 0x3001760 */
+ INCLUDE "sym_common.ld"
+ *(COMMON);
+ end = .;
+ . = 0x8000;
+ }
+
+ . = 0x8000000;
+
+ .text :
+ ALIGN(4)
+ {
+ src/crt0.o(.text);
+ *(.text*);
+ } =0
+
+ script_data :
+ ALIGN(4)
+ {
+ *(script_data);
+ } =0
+
+ .data :
+ ALIGN(4)
+ {
+ *(.data*);
+ } =0
+
+ .rodata :
+ ALIGN(4)
+ {
+ *(.rodata*);
+ } =0
+
+ /* DWARF 2 sections */
+ .debug_aranges 0 : { *(.debug_aranges) }
+ .debug_pubnames 0 : { *(.debug_pubnames) }
+ .debug_info 0 : { *(.debug_info) }
+ .debug_abbrev 0 : { *(.debug_abbrev) }
+ .debug_line 0 : { *(.debug_line) }
+ .debug_frame 0 : { *(.debug_frame) }
+ .debug_str 0 : { *(.debug_str) }
+ .debug_loc 0 : { *(.debug_loc) }
+ .debug_macinfo 0 : { *(.debug_macinfo) }
+
+ /* Discard everything not specifically mentioned above. */
+ /DISCARD/ :
+ {
+ *(*);
+ }
+}