cpu/test/Makefile

33 lines
980 B
Makefile
Raw Normal View History

2021-07-02 01:28:23 -06:00
BUILD_DIR = build
2020-09-27 18:04:08 -06:00
CC = riscv64-linux-gnu-gcc
# CFLAGS = -march=rv32i -mabi=ilp32
2021-07-02 01:28:23 -06:00
CFLAGS = -march=rv64i -mabi=lp64
2020-09-27 18:04:08 -06:00
AS = riscv64-linux-gnu-as
ASFLAGS = $(CFLAGS)
LD = riscv64-linux-gnu-ld
LDFLAGS = -T test.ld
2021-07-02 01:28:23 -06:00
all: $(BUILD_DIR)/text.hex $(BUILD_DIR)/data.hex
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
$(BUILD_DIR)/%.o: %.S | $(BUILD_DIR)
2020-09-27 18:04:08 -06:00
$(AS) $(ASFLAGS) $^ -o $@
2021-07-02 01:28:23 -06:00
$(BUILD_DIR)/%.o: %.c | $(BUILD_DIR)
$(CC) $(CFLAGS) $^ -o $@
2021-07-02 01:28:23 -06:00
$(BUILD_DIR)/%.elf: $(BUILD_DIR)/%.o %.ld
2020-11-14 23:04:24 -07:00
$(LD) $(LDFLAGS) $< -o $@
2020-09-27 18:04:08 -06:00
2021-07-02 01:28:23 -06:00
$(BUILD_DIR)/text.hex: $(BUILD_DIR)/test.elf
riscv64-linux-gnu-objdump -s $^ | sed -n '/.text/,$$p' | tail -n+2 | sed -n '/.data/,$$!p' | cut -f3-6 -d ' ' | sed -e 's/ /\n/g' | sed 's/^\(..\)\(..\)\(..\)\(..\)/\4\3\2\1/' > $@
2021-07-02 01:28:23 -06:00
$(BUILD_DIR)/data.hex: $(BUILD_DIR)/test.elf
riscv64-linux-gnu-objdump -s $^ | sed -n '/.data/,$$p' | tail -n+2 | sed -n '/.bss/,$$!p' | cut -f3-6 -d ' ' | sed -e 's/ /\n/g' | sed 's/^\(..\)\(..\)\(..\)\(..\)/\4\3\2\1/' > $@
clean:
2021-07-02 01:28:23 -06:00
rm -rf $(BUILD_DIR)