diff --git a/.circleci/config.yml b/.circleci/config.yml index d628102..67afbf9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -23,7 +23,9 @@ jobs: command: make tools_build - run: name: build SGDK - command: make sgdk_build + command: | + export GENDEV=`pwd`/build + make sgdk_build sgdk_install - run: name: build samples command: | diff --git a/Dockerfile b/Dockerfile index 487bf90..277b0b0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -42,4 +42,4 @@ ENV PATH $GENDEV/bin:$PATH WORKDIR /src -ENTRYPOINT make -f $GENDEV/sgdk/mkfiles/makefile.gen +ENTRYPOINT make -f $GENDEV/sgdk/mkfiles/Makefile.rom diff --git a/Makefile b/Makefile index 324be8f..e9600ea 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,9 @@ PATH := $(BUILDDIR)/bin:$(PATH) build: toolchain_build tools_build sgdk_build echo "Done" +docker_build: + docker build -t gendev . + $(BUILDDIR): mkdir -p $@ @@ -44,9 +47,6 @@ tools_build: tools_clean: cd tools && $(MAKE) tools_clean -sgdk_samples: - cd sgdk && $(MAKE) sample_clean samples - $(GENDEV): if [ -w /opt ]; then \ mkdir -p $(GENDEV); \ @@ -82,11 +82,17 @@ dist/gendev_$(VER)_all.deb: pkg_build cd dist && dpkg-deb -Zxz -z9 --build $(TOPDIR)/pkg_build . sgdk_build: - cd sgdk && GENDEV=$(BUILDDIR) $(MAKE) install + cd sgdk && GENDEV=$(BUILDDIR) $(MAKE) + +sgdk_install: $(GENDEV) + cd sgdk && $(MAKE) install sgdk_clean: - cd sgdk && $(MAKE) clean +sgdk_samples: + cd sgdk && $(MAKE) sample_clean samples + clean: tools_clean toolchain_clean sgdk_clean -rm -rf $(BUILDDIR) -rm -rf pkg_build diff --git a/sgdk/Makefile b/sgdk/Makefile index c5149eb..380319b 100644 --- a/sgdk/Makefile +++ b/sgdk/Makefile @@ -1,59 +1,97 @@ + +# Locatin of gendev install GENDEV?=/opt/gendev/ GENBIN=$(GENDEV)/bin -GENGCC_BIN=$(GENDEV)/bin -SGDKDIR=$(CURDIR)/SGDK + +# Location of build and source +BUILDDIR?=$(CURDIR)/build +SGDKDIR=$(BUILDDIR)/sgdk SAMPLESDIR=$(SGDKDIR)/sample -SGDKVER=v1.51 +# Version of SGDK to build +SGDKVER=v1.62 + +# SGDK install location SGDKINSTALLDIR=$(GENDEV)/sgdk$(SGDKVER) -all: tools $(SGDKDIR) $(SGDKDIR)/libmd.a +all: $(SGDKDIR) $(SGDKDIR)/lib/libmd.a tools -tools: $(SGDKDIR) +# Various tools needed to use SGDK +tools: $(SGDKDIR) $(SGDKINSTALLDIR) + cd $(SGDKDIR)/tools/bintos/src && \ + gcc -o bintos bintos.c + cd $(SGDKDIR)/tools/sizebnd/src && \ + gcc -o sizebnd sizebnd.c + cd $(SGDKDIR)/tools/xgmtool && \ + $(MAKE) -f $(CURDIR)/mkfiles/Makefile.xgmtool cd $(SGDKDIR)/tools/bintos/src && \ - gcc -o bintos bintos.c && cp bintos $(GENDEV)/bin/. + cp bintos $(SGDKINSTALLDIR)/bin/. cd $(SGDKDIR)/tools/sizebnd/src && \ - gcc -o sizebnd sizebnd.c && cp sizebnd $(GENDEV)/bin/. + cp sizebnd $(SGDKINSTALLDIR)/bin/. cd $(SGDKDIR)/tools/xgmtool && \ - $(MAKE) -f ../../../files/Makefile.xgmtool && cp out/xgmtool $(GENDEV)/bin/. - cp $(SGDKDIR)/bin/*.jar $(GENDEV)/bin/. + cp out/xgmtool $(SGDKINSTALLDIR)/bin/. + cp $(SGDKDIR)/bin/*.jar $(SGDKINSTALLDIR)/bin/. + +# Create a new patchfile based on the current SGDK checkout patch: $(SGDKDIR) - cd $(SGDKDIR) && git diff . > ../files/sgdk_$(SGDKVER).diff + cd $(SGDKDIR) && git diff . > $(CURDIR)/patches/sgdk_$(SGDKVER).diff +# Update an SGDK checkout with the current versions patchfile prep: $(SGDKDIR) - cd $(SGDKDIR) && patch -u -p1 -l < ../files/sgdk_$(SGDKVER).diff + cd $(SGDKDIR) && patch -u -p1 -l < $(CURDIR)/patches/sgdk_$(SGDKVER).diff + +$(BUILDDIR): + mkdir -p $@ +# Checkout and prep SGDK for building SGDK: $(SGDKDIR) -$(SGDKDIR): - git clone -b '$(SGDKVER)' --single-branch --depth 1 https://github.com/Stephane-D/SGDK.git +$(SGDKDIR): $(BUILDDIR) + cd $(BUILDDIR) && git clone -b '$(SGDKVER)' --single-branch --depth 1 https://github.com/Stephane-D/SGDK.git sgdk + cd $(SGDKDIR) && patch -u -p1 -l < $(CURDIR)/patches/sgdk_$(SGDKVER).diff + rm -f $(SGDKDIR)/lib/*.a + rm -f $(SGDKDIR)/bin/*.exe -$(SGDKDIR)/libmd.a: prep - cp -rf ../tools/files/applib/lib $(SGDKDIR)/tools/appack - cd $(SGDKDIR) && ln -sf ../files/Makefile.sgdk_lib . - cd $(SGDKDIR) && $(MAKE) -f Makefile.sgdk_lib +$(SGDKDIR)/mkfiles: $(SGDKDIR) + mkdir -p $(SGDKDIR)/mkfiles + cp -f $(CURDIR)/mkfiles/makefile.vars $@/. + cp -f $(CURDIR)/mkfiles/Makefile.sgdk_lib $@/. + cp -f $(CURDIR)/mkfiles/Makefile.rom $@/. + +$(SGDKDIR)/lib/libmd.a: $(SGDKDIR) $(SGDKDIR)/mkfiles tools + cd $(SGDKDIR) && SGDKDIR=$(SGDKDIR) $(MAKE) -f $(CURDIR)/mkfiles/Makefile.sgdk_lib + cp $(GENDEV)/lib/libgcc.a $(SGDKDIR)/lib/libgcc.a + mv $(SGDKDIR)/libmd.a $(SGDKDIR)/lib/libmd.a + @echo "Done building sgdk library" $(SGDKINSTALLDIR): mkdir -p $@ rm -f $(GENDEV)/sgdk cd $(GENDEV) && ln -sf sgdk$(SGDKVER) sgdk + mkdir -p $@/src + mkdir -p $@/bin + mkdir -p $@/inc + mkdir -p $@/res + mkdir -p $@/lib + mkdir -p $@/mkfiles -install: tools $(SGDKDIR)/libmd.a $(SGDKINSTALLDIR) +install: $(SGDKDIR)/lib/libmd.a $(SGDKINSTALLDIR) echo "Install" - mkdir -p $(GENDEV)/sgdk/src - mkdir -p $(GENDEV)/sgdk/inc - mkdir -p $(GENDEV)/sgdk/lib - mkdir -p $(GENDEV)/sgdk/res - mkdir -p $(GENDEV)/sgdk/mkfiles - cp $(SGDKDIR)/md.ld $(GENDEV)/sgdk/. - cp $(SGDKDIR)/inc/* $(GENDEV)/sgdk/inc/. - cp -r $(SGDKDIR)/src/boot $(GENDEV)/sgdk/src/. - cp -r $(SGDKDIR)/res/* $(GENDEV)/sgdk/res/. - cp $(GENDEV)/lib/libgcc.a $(GENDEV)/sgdk/lib/. - cp $(SGDKDIR)/libmd.a $(GENDEV)/sgdk/lib/. - cp $(SGDKDIR)/makefile.gen $(GENDEV)/sgdk/mkfiles/. - cp files/makefile.vars $(GENDEV)/sgdk/mkfiles/. - cp $(SGDKDIR)/tools/sizebnd/src/sizebnd $(GENDEV)/bin/ + cp $(SGDKDIR)/md.ld $(SGDKINSTALLDIR)/. + cp $(SGDKDIR)/inc/* $(SGDKINSTALLDIR)/inc/. + cp -r $(SGDKDIR)/src/boot $(SGDKINSTALLDIR)/src/. + cp -r $(SGDKDIR)/res/* $(SGDKINSTALLDIR)/res/. + cp $(GENDEV)/lib/libgcc.a $(SGDKINSTALLDIR)/lib/. + cp $(SGDKDIR)/lib/libmd.a $(SGDKINSTALLDIR)/lib/. + cp $(SGDKDIR)/makefile.gen $(SGDKINSTALLDIR)/mkfiles/. + cp $(SGDKDIR)/mkfiles/* $(SGDKINSTALLDIR)/mkfiles/. + cp $(SGDKDIR)/tools/sizebnd/src/sizebnd $(SGDKINSTALLDIR)/bin/ + cd $(SGDKINSTALLDIR)/bin && ln -sf ../../bin/m68k-elf-gcc gcc + cd $(SGDKINSTALLDIR)/bin && ln -sf ../../bin/m68k-elf-nm nm + cd $(SGDKINSTALLDIR)/bin && ln -sf ../../bin/m68k-elf-ld ld + cd $(SGDKINSTALLDIR)/bin && ln -sf ../../bin/m68k-elf-objcopy objcopy + cd $(SGDKINSTALLDIR)/bin && ln -sf ../../bin/sjasm sjasm + SAMPLES=$(wildcard $(SAMPLESDIR)/*/out) SAMPLEROMS=$(addsuffix /rom.bin,$(SAMPLES)) @@ -64,15 +102,16 @@ sample_clean: $(CLEANSAMPLES) @echo "Done cleaning samples" $(CLEANSAMPLES): - cd $@/.. && $(MAKE) -f $(SGDKDIR)/makefile.gen clean + cd $@/.. && $(MAKE) -f $(CURDIR)/mkfiles/Makefile.rom clean samples: $(SAMPLEROMS) @echo "All samples built" -$(SAMPLEDIR)/%/out/rom.bin: +$(SAMPLESDIR)/%/out/rom.bin: echo "ROM $@" - cd $@/../../ && $(MAKE) -f $(GENDEV)/sgdk/mkfiles/makefile.gen + cd $@/../../ && GENDEV=$(GENDEV) $(MAKE) -f $(SGDKINSTALLDIR)/mkfiles/Makefile.rom clean: echo "Clean" -rm -rf $(SGDKDIR) + -rm -rf $(BUILDDIR) diff --git a/sgdk/files/sgdk.ld b/sgdk/files/sgdk.ld deleted file mode 100644 index 13c81f8..0000000 --- a/sgdk/files/sgdk.ld +++ /dev/null @@ -1,116 +0,0 @@ -OUTPUT_ARCH(m68k) -SEARCH_DIR(.) -/*GROUP(-lbcc -lc -lgcc)*/ -__DYNAMIC = 0; - -/* - * Setup the memory map of the SEGA Genesis. - * stack grows down from high memory. - * - * The memory map look like this: - * +--------------------+ <- low memory - * | .text | - * | _etext | - * | ctor list | the ctor and dtor lists are for - * | dtor list | C++ support - * +--------------------+ - * . . - * . . - * . . - * +--------------------+ <- 0x00FF0000 - * | .data | initialized data goes here - * | _data | - * | _edata | - * +--------------------+ - * | .bss | - * | _bstart | start of bss, cleared by crt0 - * | _bend | start of heap, used by sbrk() - * +--------------------+ - * . . - * . . - * . . - * | __stack | top of stack - * +--------------------+ <- 0x01000000 - */ -MEMORY -{ - rom : ORIGIN = 0x00000000, LENGTH = 0x00400000 - ram : ORIGIN = 0x00FF0000, LENGTH = 0x00010000 -} - -/* - * allocate the stack to be at the top of memory, since the stack - * grows down - */ - -PROVIDE (__stack = 0x01000000); - - -SECTIONS -{ - .text 0x00000000: - { - *(.text .text.*) - . = ALIGN(0x4); - __CTOR_LIST__ = .; - LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2) - *(.ctors) - LONG(0) - __CTOR_END__ = .; - __DTOR_LIST__ = .; - LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2) - *(.dtors) - LONG(0) - __DTOR_END__ = .; - *(.rodata .rodata.*) - *(.gcc_except_table .gcc_except_table.*) - - . = ALIGN(0x4); - __INIT_SECTION__ = . ; - *(.init) - SHORT (0x4E75) /* rts */ - - __FINI_SECTION__ = . ; - *(.fini) - SHORT (0x4E75) /* rts */ - - _etext = .; - *(.lit) - } > rom - _stext = SIZEOF (.text); - - .data 0xFF0000 : - AT ( ADDR (.text) + SIZEOF (.text) ) - { - *(.got.plt) *(.got) - *(.shdata) - *(.data .data.*) - _edata = .; - } > ram - _sdata = SIZEOF (.data); - - .bss 0xFF0000 + SIZEOF (.data) : - { - _start = . ; - *(.shbss) - *(.bss .bss.*) - *(COMMON) - _bend = . ; - end = . ; - } > ram - - .stab 0 (NOLOAD) : - { - *(.stab) - } - - .stabstr 0 (NOLOAD) : - { - *(.stabstr) - } - - .eh_frame 0 (NOLOAD) : - { - *(.eh_frame) - } -} diff --git a/sgdk/mkfiles/Makefile.rom b/sgdk/mkfiles/Makefile.rom new file mode 100644 index 0000000..cba3a59 --- /dev/null +++ b/sgdk/mkfiles/Makefile.rom @@ -0,0 +1,17 @@ +# +# Use this Makefile for most SGDK projects +# + +GENDEV?=/opt/gendev +SGDKDIR?=$(GENDEV)/sgdk + +# Set GDK before including default SGDK makefile +GDK=$(SGDKDIR) + +include $(SGDKDIR)/mkfiles/makefile.gen + +# Override shell variables +MKDIR=/bin/mkdir +RM=/bin/rm +CP=/bin/cp +SHELL=/bin/bash diff --git a/sgdk/files/Makefile.sgdk_lib b/sgdk/mkfiles/Makefile.sgdk_lib similarity index 76% rename from sgdk/files/Makefile.sgdk_lib rename to sgdk/mkfiles/Makefile.sgdk_lib index 031fec2..2745694 100644 --- a/sgdk/files/Makefile.sgdk_lib +++ b/sgdk/mkfiles/Makefile.sgdk_lib @@ -1,7 +1,9 @@ -GENDEV?=/opt/toolchains/gen/ +GENDEV?=/opt/gendev/ MAKE?=make GENGCC_BIN=$(GENDEV)/bin GENBIN=$(GENDEV)/bin +SGDKBIN=$(GENDEV)/sgdk/bin + CC = $(GENGCC_BIN)/m68k-elf-gcc AR = $(GENGCC_BIN)/m68k-elf-ar @@ -9,7 +11,7 @@ RANLIB = $(GENGCC_BIN)/m68k-elf-ranlib OBJC = $(GENGCC_BIN)/m68k-elf-objcopy RM = rm -f ASMZ80 = $(GENBIN)/sjasm -BINTOS = $(GENBIN)/bintos +BINTOS = $(SGDKBIN)/bintos RESCOMP= java -jar ./bin/rescomp.jar OPTION= -Dnologo_ @@ -30,13 +32,7 @@ INCS = -Iinc -Ires FLAGS = $(OPTION) -m68000 -Wall -O1 -c -fomit-frame-pointer $(INCS) FLAGSZ80 = -isrc -iinc -all: appack $(libmd.a_OBJS) libmd.a - -appack: - echo -n "osBits="> tools/appack/makefile.vars - getconf LONG_BIT >> tools/appack/makefile.vars - cd tools/appack/ && make -f makefile.elf - cp tools/appack/appack bin/ +all: $(libmd.a_OBJS) libmd.a %.a: $(libmd.a_OBJS) $(RM) $@ @@ -53,10 +49,13 @@ appack: $(CC) $(FLAGS) -c $< -o $@ %.o: %.s - $(CC) $(FLAGS) -c $< -o $@ + $(CC) -x assembler-with-cpp -MMD $(FLAGS) -c $< -o $@ + +%.o: %.rs + $(CC) -x assembler-with-cpp $(FLAGS_LIB) -c $*.rs -o $@ -%.s: %.res - $(RESCOMP) $< $@ +%.rs: %.res + $(RESCOMP) $*.res $*.rs -dep $*.o clean: #$(RM) -f z80_drv1.c z80_drv2.c diff --git a/sgdk/files/Makefile.xgmtool b/sgdk/mkfiles/Makefile.xgmtool similarity index 100% rename from sgdk/files/Makefile.xgmtool rename to sgdk/mkfiles/Makefile.xgmtool diff --git a/sgdk/files/makefile.vars b/sgdk/mkfiles/makefile.vars similarity index 92% rename from sgdk/files/makefile.vars rename to sgdk/mkfiles/makefile.vars index 65a3383..84ab181 100644 --- a/sgdk/files/makefile.vars +++ b/sgdk/mkfiles/makefile.vars @@ -3,6 +3,7 @@ PATH := $(GENDEV)/bin:$(PATH) GENGCC_BIN= $(GENDEV)/bin GENBIN= $(GENDEV)/bin +BIN= $(GENDEV)/bin GDK= $(GENDEV)/sgdk @@ -33,7 +34,8 @@ NM = nm #JAVA= java ECHO= echo OBJCPY = $(GENGCC_BIN)/m68k-elf-objcopy -ASMZ80 = $(GENBIN)/zasm +ASMZ80 = $(GENBIN)/sjasm +#ASMZ80 = $(GENBIN)/zasm #MACCER= $(BIN)/mac68k SIZEBND= $(GENGCC_BIN)/sizebnd BINTOS = $(GENBIN)/bintos diff --git a/sgdk/files/rescomp.diff b/sgdk/patches/rescomp.diff similarity index 100% rename from sgdk/files/rescomp.diff rename to sgdk/patches/rescomp.diff diff --git a/sgdk/files/sgdk_1.34.diff b/sgdk/patches/sgdk_1.34.diff similarity index 100% rename from sgdk/files/sgdk_1.34.diff rename to sgdk/patches/sgdk_1.34.diff diff --git a/sgdk/files/sgdk_v1.40.diff b/sgdk/patches/sgdk_v1.40.diff similarity index 100% rename from sgdk/files/sgdk_v1.40.diff rename to sgdk/patches/sgdk_v1.40.diff diff --git a/sgdk/files/sgdk_v1.41.diff b/sgdk/patches/sgdk_v1.41.diff similarity index 100% rename from sgdk/files/sgdk_v1.41.diff rename to sgdk/patches/sgdk_v1.41.diff diff --git a/sgdk/files/sgdk_v1.51.diff b/sgdk/patches/sgdk_v1.51.diff similarity index 100% rename from sgdk/files/sgdk_v1.51.diff rename to sgdk/patches/sgdk_v1.51.diff diff --git a/sgdk/patches/sgdk_v1.62.diff b/sgdk/patches/sgdk_v1.62.diff new file mode 100644 index 0000000..e69de29 diff --git a/sgdk/files/z80_drvrs.diff b/sgdk/patches/z80_drvrs.diff similarity index 100% rename from sgdk/files/z80_drvrs.diff rename to sgdk/patches/z80_drvrs.diff