TARGET ?= sh4-unknown-linux-gnu- AS=$(TARGET)as LD=$(TARGET)ld CC=$(TARGET)gcc OBJCOPY=$(TARGET)objcopy ENDIAN ?= little ifeq ($(ENDIAN),little) AS_ENDIAN = --little LD_ENDIAN = -EL CC_ENDIAN = -ml OBJ_ENDIAN = -O elf32-sh-linux else AS_ENDIAN = --big LD_ENDIAN = -EB CC_ENDIAN = -mb OBJ_ENDIAN = -O elf32-sh endif OPT = -Og DEBUG = -g -gdwarf-4 AARCH = --isa=sh4 CARCH = -m4-single-only OBJARCH = -B sh4 CFLAGS += -Wall -Werror -Wfatal-errors CFLAGS += -falign-functions=4 -ffunction-sections -fdata-sections -fshort-enums CFLAGS += -ffreestanding -nostdlib DEPFLAGS = -MMD -MP LDFLAGS += --no-warn-execstack ALL_ELF = all: %.o: %.c $(CC) $(CARCH) $(CC_ENDIAN) $(CFLAGS) $(OPT) $(DEBUG) $(DEPFLAGS) -MF ${<}.d -c $< -o $@ %.o: %.s $(AS) $(AARCH) $(AS_ENDIAN) $(DEBUG) $< -o $@ define DEFAULT_LINK $(LD) $(LD_ENDIAN) $(LDFLAGS) \ --section-start=.text=0x0 \ --entry=_start $^ -o $@ endef define BUILD_BINARY_O $(OBJCOPY) \ -I binary $(OBJARCH) $(OBJ_ENDIAN) \ $< $@ endef %.txt.o: %.txt $(BUILD_BINARY_O) %.elf: %.o $(DEFAULT_LINK) %.bin: %.elf $(OBJCOPY) -O binary --remove-section=.stack $< $@ clean: find -P \ -regextype posix-egrep \ -regex '.*\.(o|bin|elf|d)$$' \ -exec rm {} \; .SUFFIXES: .INTERMEDIATE: .SECONDARY: .PHONY: all clean %: RCS/%,v %: RCS/% %: %,v %: s.% %: SCCS/s.% MAKEFLAGS += --no-builtin-rules include 2019/deps.mk include 2020/deps.mk all: $(subst .elf,.bin,$(ALL_ELF))