Advertisement
doragasu

SGDK Makefile for GNU/Linux

Aug 3rd, 2013
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Make 5.30 KB | None | 0 0
  1. # Makefile for building SEGA Genesis/Megadrive ROMs using the toolchain built
  2. # by kubilus1 scripts. This Makefile is a modified version of the one supplied
  3. # with SGDK by Stef.
  4. # http://gendev.spritesmind.net/forum/viewtopic.php?t=1248
  5. # Modified by doragasu
  6.  
  7. GDK?=/opt/toolchains/gen
  8. TOOLS= $(GDK)/bin
  9. BIN= $(GDK)/m68k-elf/bin/
  10. LIB= $(GDK)/m68k-elf/lib
  11.  
  12. PREFIX=m68k-elf-
  13.  
  14. LIBSRC= $(GDK)/m68k-elf/src
  15. LIBINCLUDE= $(GDK)/m68k-elf/include
  16. LINKSCRIPT= $(GDK)/ldscripts/md.ld
  17.  
  18. SRC= src
  19. RES= res
  20. INCLUDE= include
  21.  
  22. SHELL=sh
  23. RM= rm
  24. AR= $(BIN)$(PREFIX)ar
  25. CC= $(BIN)$(PREFIX)gcc
  26. LD= $(BIN)$(PREFIX)ld
  27. ECHO=echo
  28. OBJCPY= $(BIN)$(PREFIX)objcopy
  29. ASMZ80= $(TOOLS)/sjasm
  30. #MACCER= $(TOOLS)/mac68k
  31. SIZEBND= $(TOOLS)/sizebnd
  32. BINTOS= $(TOOLS)/bintos
  33. WAVTORAW= $(TOOLS)/wavtoraw
  34. PCMTORAW= $(TOOLS)/pcmtoraw
  35. #GENRES= $(TOOLS)/genres
  36. #TFMCOM= $(TOOLS)/tfmcom
  37. NM= $(BIN)$(PREFIX)nm
  38. MKDIR= mkdir
  39. #NM2WCH= $(TOOLS)/nm2wch
  40. ADDR2LINE= $(BIN)$(PREFIX)addr2line
  41. #OUT2GSRC=$(TOOLS)/out2gsrc
  42.  
  43. OPTION=
  44.  
  45. SRC_C= $(wildcard *.c)
  46. SRC_C+= $(wildcard $(SRC)/*.c)
  47. SRC_S= $(wildcard *.s)
  48. SRC_S+= $(wildcard $(SRC)/*.s)
  49. SRC_SZ80= $(wildcard *.s80)
  50. SRC_SZ80+= $(wildcard $(SRC)/*.s80)
  51.  
  52. RES_C= $(wildcard $(RES)/*.c)
  53. RES_S= $(wildcard $(RES)/*.s)
  54. RES_BMP= $(wildcard *.bmp)
  55. RES_BMP+= $(wildcard $(RES)/*.bmp)
  56. RES_WAV= $(wildcard *.wav)
  57. RES_WAV+= $(wildcard $(RES)/*.wav)
  58. RES_WAVPCM= $(wildcard *.wavpcm)
  59. RES_WAVPCM+= $(wildcard $(RES)/*.wavpcm)
  60. RES_DAT= $(wildcard *.dat)
  61. RES_DAT+= $(wildcard $(RES)/*.dat)
  62. RES_RAW= $(wildcard *.raw)
  63. RES_RAW+= $(wildcard $(RES)/*.raw)
  64. RES_PCM= $(wildcard *.pcm)
  65. RES_PCM+= $(wildcard $(RES)/*.pcm)
  66. #RES_TFD= $(wildcard *.tfd)
  67. #RES_TFD+= $(wildcard $(RES)/*.tfd)
  68. RES_TFC= $(wildcard *.tfc)
  69. RES_TFC+= $(wildcard $(RES)/*.tfc)
  70. RES_MVS= $(wildcard *.mvs)
  71. RES_MVS+= $(wildcard $(RES)/*.mvs)
  72. RES_EIF= $(wildcard *.eif)
  73. RES_EIF+= $(wildcard $(RES)/*.eif)
  74. RES_ESF= $(wildcard *.esf)
  75. RES_ESF+= $(wildcard $(RES)/*.esf)
  76. RES_VGM= $(wildcard *.vgm)
  77. RES_VGM+= $(wildcard $(RES)/*.vgm)
  78. #RES_RC= $(wildcard *.rc)
  79. #RES_RC+= $(wildcard $(RES)/*.rc)
  80. #RES_ASM= $(wildcard *.asm)
  81. #RES_ASM+= $(wildcard $(RES)/*.asm)
  82.  
  83. OBJ= $(RES_BMP:.bmp=.o)
  84. OBJ+= $(RES_WAV:.wav=.o)
  85. OBJ+= $(RES_WAVPCM:.wavpcm=.o)
  86. OBJ+= $(RES_RC:.rc=.o)
  87. OBJ+= $(RES_ASM:.asm=.o)
  88. OBJ+= $(RES_DAT:.dat=.o)
  89. OBJ+= $(RES_RAW:.raw=.o)
  90. OBJ+= $(RES_PCM:.pcm=.o)
  91. OBJ+= $(RES_TFD:.tfd=.o)
  92. OBJ+= $(RES_TFC:.tfc=.o)
  93. OBJ+= $(RES_MVS:.mvs=.o)
  94. OBJ+= $(RES_VGM:.vgm=.o)
  95. OBJ+= $(RES_EIF:.eif=.o)
  96. OBJ+= $(RES_ESF:.esf=.o)
  97. OBJ+= $(RES_S:.s=.o)
  98. OBJ+= $(RES_C:.c=.o)
  99. OBJ+= $(SRC_SZ80:.s80=.o)
  100. OBJ+= $(SRC_S:.s=.o)
  101. OBJ+= $(SRC_C:.c=.o)
  102.  
  103. OBJS = $(addprefix out/, $(OBJ))
  104.  
  105. INCS= -I$(LIBINCLUDE) -I$(INCLUDE) -I$(SRC) -I$(RES)
  106. #FLAGS= $(OPTION) -g3 -m68000 -Wall -O1 -fomit-frame-pointer -fno-builtin-memset -fno-builtin-memcpy $(INCS)
  107. FLAGS= $(OPTION) -m68000 -Wall -O1 -fomit-frame-pointer -fno-builtin-memset -fno-builtin-memcpy $(INCS)
  108. #FLAGS= $(OPTION) -m68000 -Wall -O3 -fno-web -fno-gcse -fno-unit-at-a-time -fomit-frame-pointer -fno-builtin-memset -fno-builtin-memcpy $(INCS)
  109. FLAGSZ80= -i$(LIBSRC) -i$(LIBINCLUDE) -i$(SRC) -i$(INCLUDE) -i$(RES)
  110.  
  111.  
  112. release: out/rom.bin
  113. #debug: out/rom.bin out/rom.wch
  114. #debugall: out/rom.bin out/rom.wch out/rom.gsrc
  115.  
  116. all: release
  117. default: release
  118.  
  119. .PHONY: clean
  120.  
  121. clean:
  122.     $(RM) -f $(OBJS) out.lst out/cmd_ out/sega.o out/rom_head.bin out/rom_head.o out/rom.nm out/rom.wch out/rom.out out/rom.bin
  123.  
  124. cleanobj:
  125.     $(RM) -f $(OBJS) out/sega.o out/rom_head.bin out/rom_head.o out/rom.out
  126.  
  127. out/rom.bin: out/rom.out
  128.     $(OBJCPY) -O binary out/rom.out out/romtmp.bin
  129.     dd if=out/romtmp.bin of=$@ bs=128K conv=sync
  130.     $(RM) -f out/romtmp.bin
  131.  
  132. #out/rom.wch: out/rom.out
  133. #   $(NM) -n -S -t x out/rom.out >out/rom.nm
  134. #   $(NM2WCH) out/rom.nm out/rom.wch
  135.  
  136. #out/rom.gsrc: out/rom.bin
  137. #   $(OUT2GSRC) i out/rom.bin out/rom.addr
  138. #   $(ADDR2LINE) -e out/rom.out < out/rom.addr > out/rom.gsrc
  139.  
  140. out/rom.out: out/sega.o out/cmd_ $(LIB)/libmd.a
  141.     $(CC) -n -T $(LINKSCRIPT) -nostdlib out/sega.o @out/cmd_ -L$(LIB) -lmd -lgcc -o out/rom.out
  142.     $(RM) out/cmd_
  143.  
  144. out/cmd_: $(OBJS)
  145.     $(ECHO) "$(OBJS)" > out/cmd_
  146.  
  147. out/sega.o: $(LIBSRC)/boot/sega.s out/rom_head.bin
  148.     $(MKDIR) -p out
  149.     $(CC) $(FLAGS) -c $(LIBSRC)/boot/sega.s -o $@
  150.  
  151. out/rom_head.bin: out/rom_head.o
  152.     $(LD) -T $(LINKSCRIPT) -nostdlib --oformat binary -o $@ $<
  153.  
  154. out/rom_head.o: $(LIBSRC)/boot/rom_head.c
  155.     $(MKDIR) -p out
  156.     $(CC) $(FLAGS) -c $< -o $@
  157.  
  158.  
  159. out/%.o: %.c
  160.     $(MKDIR) -p out
  161.     $(MKDIR) -p out/src
  162.     $(MKDIR) -p out/res
  163.     $(CC) $(FLAGS) -c $< -o $@
  164.  
  165. out/%.o: %.s
  166.     $(MKDIR) -p out
  167.     $(MKDIR) -p out/src
  168.     $(MKDIR) -p out/res
  169.     $(CC) $(FLAGS) -c $< -o $@
  170.  
  171.  
  172. #%.asm: %.rc
  173. #   $(GENRES) $< $@
  174.  
  175. #%.s: %.asm
  176. #   $(MACCER) -o $@ $<
  177.  
  178. %.s: %.bmp
  179.     $(BINTOS) -bmp $<
  180.  
  181. %.raw: %.wav
  182.     $(WAVTORAW) $< $@ 16000
  183.  
  184. %.pcm: %.wavpcm
  185.     $(WAVTORAW) $< $@ 22050
  186.  
  187. %.rawpcm: %.pcm
  188.     $(PCMTORAW) $< $@
  189.  
  190. #%.tfc: %.tfd
  191. #   $(TFMCOM) $<
  192.  
  193. %.o80: %.s80
  194.     $(ASMZ80) $(FLAGSZ80) $< $@ out.lst
  195.  
  196. %.s: %.tfc
  197.     $(BINTOS) -align 32768 $<
  198.  
  199. %.s: %.mvs
  200.     $(BINTOS) -align 256 $<
  201.  
  202. %.s: %.esf
  203.     $(BINTOS) -align 32768 $<
  204.  
  205. %.s: %.eif
  206.     $(BINTOS) -align 256 $<
  207.  
  208. %.s: %.vgm
  209.     $(BINTOS) -align 256 $<
  210.  
  211. %.s: %.raw
  212.     $(BINTOS) -align 256 -sizealign 256 $<
  213.  
  214. %.s: %.rawpcm
  215.     $(BINTOS) -align 128 -sizealign 128 -nullfill 136 $<
  216.  
  217. %.s: %.dat
  218.     $(BINTOS) -align 256 -sizealign 256 $<
  219.  
  220. %.s: %.o80
  221.     $(BINTOS) $<
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement