Merge pull request #212 from riscv/hartsel
[riscv-isa-sim.git] / debug_rom / Makefile
index a6da5a82db6b4327d9ea658cacfb0304ad55aae9..c5f2205de3bbf38baba4d600342f2277d409d098 100644 (file)
@@ -4,14 +4,21 @@
 CC = $(RISCV)/bin/riscv64-unknown-elf-gcc
 OBJCOPY = $(RISCV)/bin/riscv64-unknown-elf-objcopy
 
-%.o:   %.S
-       $(CC) -c $<
+COMPILE = $(CC) -nostdlib -nostartfiles -I.. -Tlink.ld
 
-debug_rom:     debug_rom.o
-       $(CC) -nostdlib -nostartfiles -Tlink.ld -o $@ $^
+ELFS = debug_rom
+DEPS = debug_rom.S link.ld ../riscv/debug_rom_defines.h ../riscv/encoding.h
 
-debug_rom.raw: debug_rom
-       $(OBJCOPY) -O binary --only-section .text debug_rom debug_rom.raw
+all: $(patsubst %,%.h,$(ELFS))
+
+%.h:   %.raw
+       xxd -i $^ | sed "s/^unsigned/static const unsigned/" > $@
+
+%.raw: %
+       $(OBJCOPY) -O binary --only-section .text $^ $@
+
+debug_rom:     $(DEPS)
+       $(COMPILE) -o $@ $^
 
 clean:
-       rm -f debug_rom debug_rom.o debug_rom.raw
+       rm -f $(ELFS) debug_rom*.raw debug_rom.h