Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync Makefile and common syms #676

Merged
merged 3 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 50 additions & 56 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,20 @@ ifneq (,$(MAKECMDGOALS))
endif
endif

.SHELLSTATUS ?= 0

ifeq ($(SETUP_PREREQS),1)
# If set on: Default target or a rule requiring a scan
# Forcibly execute `make tools` since we need them for what we are doing.
$(call infoshell, $(MAKE) -f make_tools.mk)
$(foreach line, $(shell $(MAKE) -f make_tools.mk | sed "s/ /__SPACE__/g"), $(info $(subst __SPACE__, ,$(line))))
ifneq ($(.SHELLSTATUS),0)
$(error Errors occurred while building tools. See error messages above for more details)
endif
# Oh and also generate mapjson sources before we use `SCANINC`.
$(call infoshell, $(MAKE) generated)
$(foreach line, $(shell $(MAKE) generated | sed "s/ /__SPACE__/g"), $(info $(subst __SPACE__, ,$(line))))
ifneq ($(.SHELLSTATUS),0)
$(error Errors occurred while generating map-related sources. See error messages above for more details)
endif
endif

# Collect sources
Expand Down Expand Up @@ -237,7 +245,10 @@ include spritesheet_rules.mk
include json_data_rules.mk
include audio_rules.mk

# NOTE: Tools must have been built prior (FIXME)
# so you can't really call this rule directly
generated: $(AUTO_GEN_TARGETS)
@: # Silence the "Nothing to be done for `generated'" message, which some people were confusing for an error.

%.s: ;
%.png: ;
Expand All @@ -252,8 +263,6 @@ generated: $(AUTO_GEN_TARGETS)
%.lz: % ; $(GFX) $< $@
%.rl: % ; $(GFX) $< $@

# NOTE: Tools must have been built prior (FIXME)
generated: tools $(AUTO_GEN_TARGETS)
clean-generated:
-rm -f $(AUTO_GEN_TARGETS)

Expand Down Expand Up @@ -287,69 +296,52 @@ endif
# As a side effect, they're evaluated immediately instead of when the rule is invoked.
# It doesn't look like $(shell) can be deferred so there might not be a better way (Icedude_907: there is soon).

# For C dependencies.
# Args: $1 = Output file without extension (build/assets/src/data), $2 = Input file (src/data.c)
define C_DEP
$(call C_DEP_IMPL,$1,$2,$1)
endef
# Internal implementation details.
# $1: Output file without extension, $2 input file, $3 temp path (if keeping)
define C_DEP_IMPL
$1.o: $2
$(C_BUILDDIR)/%.o: $(C_SUBDIR)/%.c
ifneq ($(KEEP_TEMPS),1)
@echo "$$(CC1) <flags> -o $$@ $$<"
@$$(CPP) $$(CPPFLAGS) $$< | $$(PREPROC) -i $$< charmap.txt | $$(CC1) $$(CFLAGS) -o - - | cat - <(echo -e ".text\n\t.align\t2, 0") | $$(AS) $$(ASFLAGS) -o $$@ -
@echo "$(CC1) <flags> -o $@ $<"
@$(CPP) $(CPPFLAGS) $< | $(PREPROC) -i $< charmap.txt | $(CC1) $(CFLAGS) -o - - | cat - <(echo -e ".text\n\t.align\t2, 0") | $(AS) $(ASFLAGS) -o $@ -
else
@$$(CPP) $$(CPPFLAGS) $$< -o $3.i
@$$(PREPROC) $3.i charmap.txt | $$(CC1) $$(CFLAGS) -o $3.s
@echo -e ".text\n\t.align\t2, 0 @ Don't pad with nop\n" >> $3.s
$$(AS) $$(ASFLAGS) -o $$@ $3.s
@$(CPP) $(CPPFLAGS) $< -o $*.i
@$(PREPROC) $*.i charmap.txt | $(CC1) $(CFLAGS) -o $*.s
@echo -e ".text\n\t.align\t2, 0\n" >> $*.s
$(AS) $(ASFLAGS) -o $@ $*.s
endif

$(C_BUILDDIR)/%.d: $(C_SUBDIR)/%.c
$(SCANINC) -M $@ $(INCLUDE_SCANINC_ARGS) -I tools/agbcc/include $<

ifneq ($(NODEP),1)
$1.d: $2
$(SCANINC) -M $1.d $(INCLUDE_SCANINC_ARGS) -I tools/agbcc/include $2
-include $1.d
-include $(addprefix $(OBJ_DIR)/,$(C_SRCS:.c=.d))
endif
endef

# Create generic rules if no dependency scanning, else create the real rules
ifeq ($(NODEP),1)
$(eval $(call C_DEP,$(C_BUILDDIR)/%,$(C_SUBDIR)/%.c))
else
$(foreach src,$(C_SRCS),$(eval $(call C_DEP,$(OBJ_DIR)/$(basename $(src)),$(src))))
$(ASM_BUILDDIR)/%.o: $(ASM_SUBDIR)/%.s
$(AS) $(ASFLAGS) -o $@ $<

$(ASM_BUILDDIR)/%.d: $(ASM_SUBDIR)/%.s
$(SCANINC) -M $@ $(INCLUDE_SCANINC_ARGS) -I "" $<

ifneq ($(NODEP),1)
-include $(addprefix $(OBJ_DIR)/,$(ASM_SRCS:.s=.d))
endif

# Similar methodology for Assembly files
# $1: Output path without extension, $2: Input file (`*.s`)
define ASM_DEP
$1.o: $2
$$(AS) $$(ASFLAGS) -o $$@ $$<
$(call ASM_SCANINC,$1,$2)
endef
# As above but first doing a preprocessor pass
define ASM_DEP_PREPROC
$1.o: $2
$$(PREPROC) $$< charmap.txt | $$(CPP) $(INCLUDE_SCANINC_ARGS) - | $$(PREPROC) -ie $$< charmap.txt | $$(AS) $$(ASFLAGS) -o $$@
$(call ASM_SCANINC,$1,$2)
endef

define ASM_SCANINC
$(C_BUILDDIR)/%.o: $(C_SUBDIR)/%.s
$(PREPROC) $< charmap.txt | $(CPP) $(INCLUDE_SCANINC_ARGS) - | $(PREPROC) -ie $< charmap.txt | $(AS) $(ASFLAGS) -o $@

$(C_BUILDDIR)/%.d: $(C_SUBDIR)/%.s
$(SCANINC) -M $@ $(INCLUDE_SCANINC_ARGS) -I "" $<

ifneq ($(NODEP),1)
$1.d: $2
$(SCANINC) -M $1.d $(INCLUDE_SCANINC_ARGS) -I "" $2
-include $1.d
-include $(addprefix $(OBJ_DIR)/,$(C_ASM_SRCS:.s=.d))
endif
endef

# Dummy rules or real rules
ifeq ($(NODEP),1)
$(eval $(call ASM_DEP,$(ASM_BUILDDIR)/%,$(ASM_SUBDIR)/%.s))
$(eval $(call ASM_DEP_PREPROC,$(C_BUILDDIR)/%,$(C_SUBDIR)/%.s))
$(eval $(call ASM_DEP_PREPROC,$(DATA_ASM_BUILDDIR)/%,$(DATA_ASM_SUBDIR)/%.s))
else
$(foreach src, $(ASM_SRCS), $(eval $(call ASM_DEP,$(src:%.s=$(OBJ_DIR)/%),$(src))))
$(foreach src, $(C_ASM_SRCS), $(eval $(call ASM_DEP_PREPROC,$(src:%.s=$(OBJ_DIR)/%),$(src))))
$(foreach src, $(REGULAR_DATA_ASM_SRCS), $(eval $(call ASM_DEP_PREPROC,$(src:%.s=$(OBJ_DIR)/%),$(src))))
$(DATA_ASM_BUILDDIR)/%.o: $(DATA_ASM_SUBDIR)/%.s
$(PREPROC) $< charmap.txt | $(CPP) $(INCLUDE_SCANINC_ARGS) - | $(PREPROC) -ie $< charmap.txt | $(AS) $(ASFLAGS) -o $@

$(DATA_ASM_BUILDDIR)/%.d: $(DATA_ASM_SUBDIR)/%.s
$(SCANINC) -M $@ $(INCLUDE_SCANINC_ARGS) -I "" $<

ifneq ($(NODEP),1)
-include $(addprefix $(OBJ_DIR)/,$(REGULAR_DATA_ASM_SRCS:.s=.d))
endif

$(OBJ_DIR)/sym_bss.ld: sym_bss.txt
Expand All @@ -373,8 +365,10 @@ endif
# Final rules

# Elf from object files
LDFLAGS = -Map ../../$(MAP)
$(ELF): $(LD_SCRIPT) $(LD_SCRIPT_DEPS) $(OBJS)
@cd $(OBJ_DIR) && $(LD) $(LDFLAGS) -T ../../$< --print-memory-usage -o ../../$@ $(OBJS_REL) $(LIB) | cat
@echo "cd $(OBJ_DIR) && $(LD) $(LDFLAGS) -T ../../$< --print-memory-usage -o ../../$@ <objs> <libs> | cat"
$(FIX) $@ -t"$(TITLE)" -c$(GAME_CODE) -m$(MAKER_CODE) -r$(GAME_REVISION) --silent

# Builds the rom from the elf file
Expand Down
1 change: 0 additions & 1 deletion common_syms/AgbRfu_LinkManager.txt

This file was deleted.

10 changes: 0 additions & 10 deletions common_syms/agb_flash.txt

This file was deleted.

3 changes: 0 additions & 3 deletions common_syms/battle_anim_special.txt

This file was deleted.

1 change: 0 additions & 1 deletion common_syms/battle_controller_pokedude.txt

This file was deleted.

9 changes: 0 additions & 9 deletions common_syms/battle_main.txt

This file was deleted.

4 changes: 0 additions & 4 deletions common_syms/berry_fix_program.txt

This file was deleted.

1 change: 0 additions & 1 deletion common_syms/bg.txt

This file was deleted.

1 change: 0 additions & 1 deletion common_syms/cable_club.txt

This file was deleted.

1 change: 0 additions & 1 deletion common_syms/ereader_screen.txt

This file was deleted.

1 change: 0 additions & 1 deletion common_syms/event_data.txt

This file was deleted.

1 change: 0 additions & 1 deletion common_syms/evolution_scene.txt

This file was deleted.

2 changes: 0 additions & 2 deletions common_syms/fame_checker.txt

This file was deleted.

3 changes: 0 additions & 3 deletions common_syms/field_camera.txt

This file was deleted.

1 change: 0 additions & 1 deletion common_syms/field_control_avatar.txt

This file was deleted.

2 changes: 0 additions & 2 deletions common_syms/field_specials.txt

This file was deleted.

1 change: 0 additions & 1 deletion common_syms/fieldmap.txt

This file was deleted.

2 changes: 0 additions & 2 deletions common_syms/help_system.txt

This file was deleted.

1 change: 0 additions & 1 deletion common_syms/help_system_util.txt

This file was deleted.

10 changes: 0 additions & 10 deletions common_syms/image_processing_effects.txt

This file was deleted.

5 changes: 0 additions & 5 deletions common_syms/librfu_rfu.txt

This file was deleted.

1 change: 0 additions & 1 deletion common_syms/librfu_sio32id.txt

This file was deleted.

1 change: 0 additions & 1 deletion common_syms/librfu_stwi.txt

This file was deleted.

35 changes: 0 additions & 35 deletions common_syms/link.txt

This file was deleted.

3 changes: 0 additions & 3 deletions common_syms/link_rfu_2.txt

This file was deleted.

2 changes: 0 additions & 2 deletions common_syms/list_menu.txt

This file was deleted.

4 changes: 0 additions & 4 deletions common_syms/load_save.txt

This file was deleted.

12 changes: 0 additions & 12 deletions common_syms/m4a.txt

This file was deleted.

12 changes: 0 additions & 12 deletions common_syms/main.txt

This file was deleted.

8 changes: 0 additions & 8 deletions common_syms/overworld.txt

This file was deleted.

1 change: 0 additions & 1 deletion common_syms/party_menu.txt

This file was deleted.

4 changes: 0 additions & 4 deletions common_syms/quest_log.txt

This file was deleted.

1 change: 0 additions & 1 deletion common_syms/random.txt

This file was deleted.

12 changes: 0 additions & 12 deletions common_syms/save.txt

This file was deleted.

1 change: 0 additions & 1 deletion common_syms/save_failed_screen.txt

This file was deleted.

2 changes: 0 additions & 2 deletions common_syms/scrcmd.txt

This file was deleted.

1 change: 0 additions & 1 deletion common_syms/sound.txt

This file was deleted.

2 changes: 0 additions & 2 deletions common_syms/sprite.txt

This file was deleted.

1 change: 0 additions & 1 deletion common_syms/task.txt

This file was deleted.

1 change: 0 additions & 1 deletion common_syms/text.txt

This file was deleted.

2 changes: 0 additions & 2 deletions common_syms/text_printer.txt

This file was deleted.

2 changes: 0 additions & 2 deletions common_syms/window.txt

This file was deleted.

1 change: 1 addition & 0 deletions include/gba/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#define IWRAM_DATA __attribute__((section("iwram_data")))
#define EWRAM_DATA __attribute__((section("ewram_data")))
#endif
#define COMMON_DATA __attribute__((section("common_data")))

#if MODERN
#define NOINLINE __attribute__((noinline))
Expand Down
1 change: 1 addition & 0 deletions ld_script.ld
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ SECTIONS {

/* COMMON starts at 0x30030E0 */
INCLUDE "sym_common.ld"
src/*.o(COMMON);

*libc.a:sbrkr.o(COMMON);
end = .;
Expand Down
1 change: 1 addition & 0 deletions ld_script_modern.ld
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ SECTIONS {

/* COMMON starts at 0x30022A8 */
*(COMMON);
*(common_data);
end = .;
__end__ = .;
} > IWRAM
Expand Down
Loading