diff --git a/.dockerignore b/.dockerignore index 189900848..4e945137a 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,14 +1,17 @@ # Ignore non-build related directories -/.git/ /doc/ /sample/ /vstudio/ +/.*/ +#prebuilds +/lib/ +/out/ +/bin/ # Ignore non-build related files -/.dockerignore -/.gitignore -/build_adv.bat -/build_lib.bat +.* +.DS_Store +/*.bat /changelog.txt /COPYING.RUNTIME /Dockerfile diff --git a/.github/workflows/sgdk-docker.yml b/.github/workflows/sgdk-docker.yml new file mode 100644 index 000000000..2747e43ca --- /dev/null +++ b/.github/workflows/sgdk-docker.yml @@ -0,0 +1,107 @@ +name: sgdk-docker + +concurrency: + group: ${{ github.ref }}-sgdk-docker + cancel-in-progress: true + +on: + workflow_dispatch: # Allows for manual triggering. + pull_request: # Trigger for pull requests. + types: [opened, synchronize, reopened, ready_for_review] + branches: + - master + push: # Trigger when pushed to master. + branches: + - 'master' + paths-ignore: + - 'vstudio/**' + - 'bin/**' + - 'sample/**' + - '**.md' + +env: + # TODO: arm64 images are currently disabled because they keep hanging in the + # GitHub Actions environment. + #PLATFORMS: linux/amd64,linux/arm64 + PLATFORMS: linux/amd64 + +jobs: + build: + runs-on: ubuntu-latest + + permissions: + packages: write + contents: read + + steps: + - name: Checkout + uses: actions/checkout@v4 + + # TODO: arm64 images are currently disabled because they keep hanging in + # the GitHub Actions environment. + #- name: Set up QEMU + # uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GHCR (only on push event) + if: github.event_name == 'push' + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Check if GCC Dockerfile has changed + id: changed-files + uses: tj-actions/changed-files@v42 + with: + files_yaml: | + gcc: + - deps/gcc.Dockerfile + + - name: Build m68k GCC (only if changed) + if: steps.changed-files.outputs.gcc_any_changed == 'true' + uses: docker/build-push-action@v5 + with: + file: deps/gcc.Dockerfile + context: deps/ + platforms: ${{ env.PLATFORMS }} + tags: ghcr.io/${{ github.actor }}/sgdk-m68k-gcc:latest + push: false + load: true + + # Push is a separate step so the build logs are clearly separate from the + # push logs. + - name: Push m68k GCC (only if changed, only on push event) + if: steps.changed-files.outputs.gcc_any_changed == 'true' && github.event_name == 'push' + run: | + docker image push ghcr.io/${{ github.actor }}/sgdk-m68k-gcc:latest + + # NOTE: If you are seeing failures in this job right after forking SGDK, + # you may need to bootstrap the base image into your fork on ghcr.io. + # This can be done with: + # docker image pull ghcr.io/stephane-d/sgdk-m68k-gcc:latest + # docker image tag ghcr.io/stephane-d/sgdk-m68k-gcc:latest \ + # ghcr.io/YOUR_NAMEE/sgdk-m68k-gcc:latest + # gh auth token | docker login ghcr.io -u YOUR_NAME --password-stdin + # docker image push ghcr.io/YOUR_NAMEE/sgdk-m68k-gcc:latest + - name: Build SGDK + uses: docker/build-push-action@v5 + with: + file: Dockerfile + context: . + platforms: ${{ env.PLATFORMS }} + build-args: | + BASE_IMAGE=ghcr.io/${{ github.actor }}/sgdk-m68k-gcc + tags: ghcr.io/${{ github.actor }}/sgdk:latest + push: false + load: true + + # Push is a separate step so the build logs are clearly separate from the + # push logs. + - name: Push SGDK (only on push event) + if: github.event_name == 'push' + run: | + docker image push ghcr.io/${{ github.actor }}/sgdk:latest diff --git a/.gitignore b/.gitignore index 21fae20c0..d24331a20 100644 --- a/.gitignore +++ b/.gitignore @@ -45,3 +45,5 @@ tools/rescomp/format tools/rescomp/rescomp.jar tools/xgm rom builder/bin src/z80_*.h +/.idea +*.iml diff --git a/Dockerfile b/Dockerfile index 6c2b4e58b..63c46603d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,36 +1,117 @@ -FROM amd64/ubuntu:20.04 - -# Set-up argument defaults +ARG ALPINE_VERSION=3.18.3 ARG JDK_VER=11 -# Install supporting packages -RUN dpkg --add-architecture i386 \ - && apt-get update \ - && DEBIAN_FRONTEND=noninteractive apt-get install -y \ - bash \ - make \ - openjdk-${JDK_VER}-jre-headless \ - wine32 \ - && rm -rf /var/lib/apt/lists/* +ARG BASE_IMAGE=ghcr.io/stephane-d/sgdk-m68k-gcc +ARG BASE_IMAGE_VERSION=latest -# Create sgdk unprivileged user -RUN useradd -ms /bin/sh -d /sgdk sgdk +# Stage Zero - just init image to download files in other stages +FROM $BASE_IMAGE:$BASE_IMAGE_VERSION as m68k-files + + +FROM alpine:$ALPINE_VERSION as jdk-base +ARG JDK_VER +RUN apk add --no-cache openjdk${JDK_VER} + + + +# Stage One - build all tools and libs for SGDK +FROM jdk-base as build +RUN apk add --no-cache build-base git # Set-up SGDK -COPY . /sgdk -ENV GDK=/sgdk -ENV SGDK_DOCKER=y +WORKDIR /sgdk +COPY . . +ENV SGDK_PATH=/sgdk +RUN mkdir -p $SGDK_PATH/bin + +# Building sjasm +ENV SJASMEP_DIR="/tmp/sjasmep" +RUN git clone https://github.com/istvan-v/sjasmep.git $SJASMEP_DIR +WORKDIR $SJASMEP_DIR +RUN make +RUN mv $SJASMEP_DIR/sjasm $SGDK_PATH/bin/ + +# Building bintos +WORKDIR $SGDK_PATH/tools/bintos +RUN gcc -O2 -s src/bintos.c -o $SGDK_PATH/bin/bintos + +# Building xgmtool +WORKDIR $SGDK_PATH/tools/xgmtool +RUN gcc -fexpensive-optimizations -Os -s src/*.c -o $SGDK_PATH/bin/xgmtool + +# Building apj.jar +WORKDIR $SGDK_PATH/tools/apj/src +RUN javac sgdk/aplib/*.java +RUN jar cfe $SGDK_PATH/bin/apj.jar sgdk.aplib.Launcher sgdk/aplib/*.class + +# Building lz4w.jar +WORKDIR $SGDK_PATH/tools/lz4w/src +RUN javac sgdk/lz4w/*.java +RUN jar cfe $SGDK_PATH/bin/lz4w.jar sgdk.lz4w.Launcher sgdk/lz4w/*.class + +# Building sizebnd.jar +WORKDIR $SGDK_PATH/tools/sizebnd/src +RUN javac sgdk/sizebnd/*.java +RUN jar cfe $SGDK_PATH/bin/sizebnd.jar sgdk.sizebnd.Launcher sgdk/sizebnd/*.class + +# Building rescomp.jar +WORKDIR $SGDK_PATH/tools/rescomp/src +ENV CLASSPATH="$SGDK_PATH/bin/apj.jar:$SGDK_PATH/bin/lz4w.jar:$SGDK_PATH/tools/rescomp/src" +RUN cp -r $SGDK_PATH/tools/commons/src/sgdk . +RUN find . -name "*.java" +RUN find . -name "*.java" | xargs javac +RUN echo -e "Main-Class: sgdk.rescomp.Launcher\nClass-Path: apj.jar lz4w.jar" > Manifest.txt +RUN jar cfm $SGDK_PATH/bin/rescomp.jar Manifest.txt . + +COPY --from=m68k-files /m68k/ /usr/ +ENV PATH="$SGDK_PATH/bin:${PATH}" -# Create wrappers to execute .exe files using wine -RUN sed -i 's/\r$//' sgdk/bin/create-bin-wrappers.sh && \ - chmod +x sgdk/bin/create-bin-wrappers.sh - -RUN sgdk/bin/create-bin-wrappers.sh +WORKDIR $SGDK_PATH +RUN mkdir lib +#build libmd.a +RUN make -f makelib.gen release +#build libmd_debug.a +RUN make -f makelib.gen debug +RUN rm -rf $SGDK_PATH/tools + + + +FROM jdk-base as jre-minimal +ENV JRE_MODULES="java.base,java.desktop,java.xml" +RUN jlink \ + --module-path "$JAVA_HOME/jmods" \ + --add-modules $JRE_MODULES \ + --verbose \ + --strip-debug \ + --compress 2 \ + --no-header-files \ + --no-man-pages \ + --output /opt/jre-minimal + + +### Second Stage - clean image ### +FROM alpine:$ALPINE_VERSION +RUN apk add --no-cache build-base + +COPY --from=m68k-files /m68k/ /usr/ + +COPY --from=jre-minimal /opt/jre-minimal /opt/jre-minimal +ENV JAVA_HOME=/opt/jre-minimal +ENV PATH="$PATH:$JAVA_HOME/bin" + +# Set-up SGDK +ENV SGDK_PATH=/sgdk + +# Create sgdk unprivileged user +RUN addgroup -S sgdk && adduser -S sgdk -G sgdk -h $SGDK_PATH + +COPY --from=build --chown=sgdk:sgdk $SGDK_PATH $SGDK_PATH + +ENV PATH="$SGDK_PATH/bin:${PATH}" # Set-up mount point and make command VOLUME /src WORKDIR /src - # Use sgdk user USER sgdk -ENTRYPOINT [ "make", "-f", "/sgdk/makefile.gen" ] +ENTRYPOINT ["/bin/sh","-c","make -f $SGDK_PATH/makefile.gen $@", "--"] diff --git a/Dockerfile-m1 b/Dockerfile-m1 deleted file mode 100644 index 903d221c4..000000000 --- a/Dockerfile-m1 +++ /dev/null @@ -1,59 +0,0 @@ -FROM ubuntu:latest - -# Set-up argument defaults -ARG JDK_VER=11 - -# Install supporting packages -RUN apt-get update \ - && DEBIAN_FRONTEND=noninteractive apt-get install -y \ - bash \ - make \ - git \ - babeltrace \ - rsync \ - bison gcc g++ lhasa libgmp-dev libmpfr-dev libmpc-dev flex gettext texinfo \ - openjdk-${JDK_VER}-jre-headless \ - && rm -rf /var/lib/apt/lists/* - -# install GCC 6.3 - -RUN cd /opt \ - && curl -O http://barelyconsciousgames.com/m68k-toolchain-rpi.tar.gz \ - && tar xvzf m68k-toolchain-rpi.tar.gz \ - && apt-get update \ - && DEBIAN_FRONTEND=noninteractive apt-get install -y libc6-armhf-cross \ - && ln -s /usr/arm-linux-gnueabihf/lib/ld-linux-armhf.so.3 /lib/ \ - && ln -s /usr/arm-linux-gnueabihf/lib/libm.so.6 /lib \ - && ln -s /usr/arm-linux-gnueabihf/lib/libc.so.6 /lib \ - && ln -s /usr/arm-linux-gnueabihf/lib/libdl.so.2 /lib \ - && rm m68k-toolchain-rpi.tar.gz - -# Create sgdk unprivileged user -RUN useradd -ms /bin/sh -d /sgdk sgdk - -# Set-up SGDK -COPY . /sgdk -ENV GDK=/sgdk -ENV SGDK_DOCKER=n - -RUN cd /tmp \ - && git clone https://github.com/istvan-v/sjasmep.git \ - && cd sjasmep \ - && make \ - && mv sjasm /sgdk/bin - -ENV PATH="/opt/m68k-toolchain/bin:/sgdk/bin:${PATH}" - -RUN cd /sgdk/tools/bintos \ - && gcc -O2 -s src/bintos.c -o ../../bin/bintos - -RUN cd /sgdk/tools/xgmtool \ - && gcc -fexpensive-optimizations -Os -s src/*.c -o ../../bin/xgmtool - -# Set-up mount point and make command -VOLUME /src -WORKDIR /src - -# Use sgdk user -USER sgdk -ENTRYPOINT [ "make", "-f", "/sgdk/makefile.gen" ] diff --git a/bin/create-bin-wrappers.sh b/bin/create-bin-wrappers.sh deleted file mode 100755 index 43677e90d..000000000 --- a/bin/create-bin-wrappers.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -# This script will be executed at docker build. -# See Dockerfile - -BIN_PATH="/sgdk/bin" - -# Create a bash script for each .exe file in BIN_PATH -for binary in $BIN_PATH/*.exe; do - BASENAME=$(basename $binary .exe) - FILENAME=$BIN_PATH/$BASENAME - echo "#!/bin/bash" > $FILENAME - # create a wineconf folder owned by us, otherwise it will refuse to execute for current user - echo "mkdir -p /tmp/wine" >> $FILENAME - echo "WINEARCH=win32 WINEDEBUG=-all WINEPREFIX=/tmp/wine/.wineconf wine /sgdk/bin/$BASENAME.exe \"\$@\"" >> $FILENAME - chmod +x $FILENAME -done diff --git a/common.mk b/common.mk index dcac4b9ca..5e041182a 100644 --- a/common.mk +++ b/common.mk @@ -27,42 +27,23 @@ ifeq ($(OS),Windows_NT) LTO_PLUGIN := --plugin=liblto_plugin-0.dll LIBGCC := $(LIB)/libgcc.a else - ifeq ($(SGDK_DOCKER),y) - # Linux docker - SHELL = sh - RM = rm - CP = cp - MKDIR = mkdir + # Native Linux and Docker + PREFIX ?= m68k-elf- + SHELL = sh + RM = rm + CP = cp + MKDIR = mkdir - AR := $(BIN)/ar - CC := $(BIN)/gcc - LD := $(BIN)/ld - NM := $(BIN)/nm - OBJCPY := $(BIN)/objcopy - ASMZ80 := $(BIN)/sjasm - MACCER := $(BIN)/mac68k - BINTOS := $(BIN)/bintos - LTO_PLUGIN := --plugin=liblto_plugin-0.dll - LIBGCC := $(LIB)/libgcc.a - else - # Native Linux - PREFIX ?= m68k-elf- - SHELL = sh - RM = rm - CP = cp - MKDIR = mkdir - - AR := $(PREFIX)ar - CC := $(PREFIX)gcc - LD := $(PREFIX)ld - NM := $(PREFIX)nm - OBJCPY := $(PREFIX)objcopy - ASMZ80 := sjasm - MACCER := mac68k - BINTOS := bintos - LTO_PLUGIN := - LIBGCC := -lgcc - endif + AR := $(PREFIX)ar + CC := $(PREFIX)gcc + LD := $(PREFIX)ld + NM := $(PREFIX)nm + OBJCPY := $(PREFIX)objcopy + ASMZ80 := sjasm + MACCER := mac68k + BINTOS := bintos + LTO_PLUGIN := + LIBGCC := -lgcc endif JAVA := java diff --git a/deps/gcc.Dockerfile b/deps/gcc.Dockerfile new file mode 100644 index 000000000..28299e772 --- /dev/null +++ b/deps/gcc.Dockerfile @@ -0,0 +1,151 @@ +ARG ALPINE_VERSION=3.18.3 + +ARG BASEDIR=/tmp/work + +FROM alpine:$ALPINE_VERSION as build +ARG BASEDIR +ARG _binu_ver=2.37 +ARG _gcc_ver=6.3.0 +ARG _mpfrver=4.1.0 +ARG _mpcver=1.2.1 +ARG _gmpver=6.2.1 +ARG _newlib_ver=4.1.0 +ARG PARALLEL_BUILD=1 + +ENV TARGET=m68k-elf +ENV TARGET_CPU=m68000 + +ENV BASEDIR=$BASEDIR +ENV BINUTILS=binutils-${_binu_ver} +ENV GCC=gcc-${_gcc_ver} +ENV MPFR=mpfr-${_mpfrver} +ENV MPC=mpc-${_mpcver} +ENV GMP=gmp-${_gmpver} +ENV NEWLIB=newlib-${_newlib_ver} + +ENV SRCDIR="$BASEDIR/src" +ENV BUILDDIR="$BASEDIR/build" +ENV INSTALLDIR="$BASEDIR/install" +ENV STAGINGDIR="$BASEDIR/staging" +ENV PARALLEL_BUILD="$PARALLEL_BUILD" + +# Choose parallel build or not. Parallel builds can cause issues with +# low-memory hosts or emulation. If parallel builds are disabled, replace +# nproc so it always says "1". +RUN echo "nproc = $(nproc)" +RUN echo "PARALLEL_BUILD = $PARALLEL_BUILD" +RUN if [[ "$PARALLEL_BUILD" == 0 ]]; then echo -e "#!/bin/sh\necho 1" > /usr/local/bin/nproc; chmod 755 /usr/local/bin/nproc; fi +RUN echo "which nproc = $(which nproc)" + +RUN mkdir -p "$SRCDIR" +RUN mkdir -p "$BUILDDIR" +RUN mkdir -p "$INSTALLDIR" +RUN mkdir -p "$STAGINGDIR" + +WORKDIR $SRCDIR +RUN wget http://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.xz -O - | tar -xJ +RUN wget http://ftp.gnu.org/gnu/gcc/${GCC}/${GCC}.tar.bz2 -O - | tar -xj +RUN wget http://ftp.gnu.org/gnu/mpfr/${MPFR}.tar.xz -O - | tar -xJ +RUN wget http://ftp.gnu.org/gnu/mpc/${MPC}.tar.gz -O - | tar -xz +RUN wget http://ftp.gnu.org/gnu/gmp/${GMP}.tar.xz -O - | tar -xJ +RUN wget ftp://sourceware.org/pub/newlib/${NEWLIB}.tar.gz -O - | tar -xz + +RUN apk add --no-cache bash build-base zlib-dev + +################################################################################# +########################## Building binutils ############################## +################################################################################# +WORKDIR $BUILDDIR/$BINUTILS +RUN $SRCDIR/$BINUTILS/configure \ + --prefix=/usr \ + --target=$TARGET \ + --disable-multilib \ + --with-cpu=$TARGET_CPU \ + --disable-nls + +RUN make -j"$(nproc)" +RUN make prefix=$INSTALLDIR/$BINUTILS/usr install +RUN rm -rf $INSTALLDIR/$BINUTILS/usr/share +RUN rm $INSTALLDIR/$BINUTILS/usr/lib/bfd-plugins/libdep.so +RUN cp -r $INSTALLDIR/$BINUTILS/usr/ $STAGINGDIR +RUN cp -r $INSTALLDIR/$BINUTILS/usr/* /usr/ +################################################################################# +######################### Building GCC bootstrap ########################## +################################################################################# +WORKDIR $SRCDIR/$GCC +RUN ln -fs ../$MPFR mpfr +RUN ln -fs ../$MPC mpc +RUN ln -fs ../$GMP gmp + +WORKDIR $BUILDDIR/$GCC-bootstrap +# These flags are required to build older versions of GCC +ENV CFLAGS="$CFLAGS -Wno-implicit-fallthrough -Wno-cast-function-type -fpermissive" +ENV CXXFLAGS="$CXXFLAGS -Wno-implicit-fallthrough -Wno-cast-function-type -fpermissive" +RUN $SRCDIR/$GCC/configure \ + --prefix=/usr \ + --target=$TARGET \ + --enable-languages="c" \ + --disable-multilib \ + --with-cpu=$TARGET_CPU \ + --with-system-zlib \ + --with-libgloss \ + --without-headers \ + --disable-shared \ + --disable-nls + +RUN make -j"$(nproc)" all-gcc +RUN make DESTDIR="$INSTALLDIR/$GCC-bootstrap" install-strip-gcc +RUN rm -rf "$INSTALLDIR/$GCC-bootstrap/usr/share" +RUN cp -r "$INSTALLDIR/$GCC-bootstrap/usr/"* /usr/ +################################################################################# +############################# Building NewLib ############################# +################################################################################# +WORKDIR $BUILDDIR/$NEWLIB +ENV CFLAGS_FOR_TARGET="-Os -g -ffunction-sections -fdata-sections -fomit-frame-pointer -ffast-math" + +RUN "$SRCDIR/$NEWLIB/configure" \ + --prefix=/usr \ + --target=$TARGET \ + --enable-languages="c" \ + --disable-newlib-supplied-syscalls \ + --disable-multilib \ + --with-cpu=$TARGET_CPU \ + --disable-nls + +RUN make -j"$(nproc)" +RUN DESTDIR=$INSTALLDIR/$NEWLIB make install +RUN cp -r "$INSTALLDIR/$NEWLIB/usr/" "$STAGINGDIR" +RUN cp -r "$INSTALLDIR/$NEWLIB/usr/"* /usr/ +ENV CFLAGS_FOR_TARGET="" +################################################################################# +############################ Building final GCC ########################### +################################################################################# +WORKDIR $BUILDDIR/$GCC + +RUN "$SRCDIR/$GCC/configure" \ + --prefix=/usr \ + --target=$TARGET \ + --enable-languages="c,c++" \ + --disable-multilib \ + --with-cpu=$TARGET_CPU \ + --with-system-zlib \ + --with-newlib \ + --with-libgloss \ + --disable-shared \ + --disable-nls + +RUN make -j"$(nproc)" +RUN make DESTDIR="$INSTALLDIR/$GCC" install-strip +RUN rm -rf "$INSTALLDIR/$GCC/usr/share" +RUN rm "$INSTALLDIR/$GCC/usr/lib/libcc1.so" +RUN rm "$INSTALLDIR/$GCC/usr/lib/libcc1.so.0" +RUN rm "$INSTALLDIR/$GCC/usr/lib/libcc1.so.0.0.0" + +RUN cp -ar "$INSTALLDIR/$GCC/usr/" "$STAGINGDIR" + + +# Second stage, just copy the built files +FROM scratch +ARG BASEDIR +WORKDIR /m68k +COPY --from=build $BASEDIR/staging/usr/ ./ diff --git a/makefile.gen b/makefile.gen index 1f4bcafe7..051fea54d 100644 --- a/makefile.gen +++ b/makefile.gen @@ -10,18 +10,20 @@ include $(GDK)/common.mk SRC := src RES := res INCLUDE := inc - +OUT := out SRC_C= $(wildcard *.c) SRC_C+= $(wildcard $(SRC)/*.c) SRC_C+= $(wildcard $(SRC)/*/*.c) SRC_C+= $(wildcard $(SRC)/*/*/*.c) SRC_C:= $(filter-out $(SRC)/boot/rom_head.c,$(SRC_C)) +ifeq ($(SRC_C),) +SRC_C=$(SRC)/main.c +endif SRC_S= $(wildcard *.s) SRC_S+= $(wildcard $(SRC)/*.s) SRC_S+= $(wildcard $(SRC)/*/*.s) SRC_S+= $(wildcard $(SRC)/*/*/*.s) -SRC_S:= $(filter-out $(SRC)/boot/sega.s,$(SRC_S)) SRC_ASM= $(wildcard *.asm) SRC_ASM+= $(wildcard $(SRC)/*.asm) SRC_ASM+= $(wildcard $(SRC)/*/*.asm) @@ -39,7 +41,7 @@ RES_RES+= $(wildcard $(RES)/*.res) RES_RS= $(RES_RES:.res=.rs) RES_H= $(RES_RES:.res=.h) RES_DEP= $(RES_RES:.res=.d) -RES_DEPS= $(addprefix out/, $(RES_DEP)) +RES_DEPS= $(addprefix $(OUT)/, $(RES_DEP)) OBJ= $(RES_RES:.res=.o) OBJ+= $(RES_S:.s=.o) @@ -48,14 +50,14 @@ OBJ+= $(SRC_S80:.s80=.o) OBJ+= $(SRC_ASM:.asm=.o) OBJ+= $(SRC_S:.s=.o) OBJ+= $(SRC_C:.c=.o) -OBJS:= $(addprefix out/, $(OBJ)) +OBJS:= $(addprefix $(OUT)/, $(OBJ)) DEPS:= $(OBJS:.o=.d) #-include $(DEPS) LST:= $(SRC_C:.c=.lst) -LSTS:= $(addprefix out/, $(LST)) +LSTS:= $(addprefix $(OUT)/, $(LST)) INCS:= -I$(INCLUDE) -I$(SRC) -I$(RES) -I$(INCLUDE_LIB) -I$(RES_LIB) DEFAULT_FLAGS= $(EXTRA_FLAGS) -DSGDK_GCC -m68000 -Wall -Wextra -Wno-shift-negative-value -Wno-main -Wno-unused-parameter -fno-builtin -fms-extensions $(INCS) -B$(BIN) @@ -66,20 +68,39 @@ release: FLAGS= $(DEFAULT_FLAGS) -O3 -fuse-linker-plugin -fno-web -fno-gcse -fno release: CFLAGS= $(FLAGS) release: AFLAGS= $(FLAGS) release: LIBMD= $(LIB)/libmd.a -release: pre-build out/rom.bin out/symbol.txt +release: $(OUT)/rom.bin $(OUT)/symbol.txt +.PHONY: release + #release: $(info $$var is [${SRC_C}]) debug: FLAGS= $(DEFAULT_FLAGS) -O1 -DDEBUG=1 debug: CFLAGS= $(FLAGS) -ggdb debug: AFLAGS= $(FLAGS) debug: LIBMD= $(LIB)/libmd_debug.a -debug: pre-build out/rom.bin out/rom.out out/symbol.txt +debug: $(OUT)/rom.bin $(OUT)/rom.out $(OUT)/symbol.txt +.PHONY: debug asm: FLAGS= $(DEFAULT_FLAGS) -O3 -fuse-linker-plugin -fno-web -fno-gcse -fno-unit-at-a-time -fomit-frame-pointer -S asm: CFLAGS= $(FLAGS) asm: AFLAGS= $(FLAGS) asm: LIBMD= $(LIB)/libmd.a -asm: pre-build $(LSTS) +asm: $(LSTS) +.PHONY: asm + +define MAIN_C_CONTENT +#include "genesis.h" + +int main(bool hardReset){ + VDP_drawText("Hello SGDK!", 12, 12); + while(TRUE) { SYS_doVBlankProcess(); } + return 0; +} +endef + +$(SRC)/main.c: export MAIN_C_CONTENT:=$(MAIN_C_CONTENT) +$(SRC)/main.c: + $(MKDIR) -p $(dir $@) + $(ECHO) "$${MAIN_C_CONTENT}" > $@ # include ext.mk if it exists (better to do it after release rule definition) ifneq ("$(wildcard $(GDK)/ext.mk)","") @@ -94,94 +115,104 @@ Debug: debug Release: release Asm: asm -.PHONY: clean - cleantmp: $(RM) -f $(RES_RS) +.PHONY: cleantmp cleandep: $(RM) -f $(DEPS) +.PHONY: cleandep cleanlst: $(RM) -f $(LSTS) +.PHONY: cleanlst cleanres: cleantmp $(RM) -f $(RES_H) $(RES_DEP) $(RES_DEPS) +.PHONY: cleanres cleanobj: - $(RM) -f $(OBJS) out/sega.o out/rom_head.bin out/rom_head.o out/rom.out + $(RM) -f $(OBJS) $(OUT)/sega.o $(OUT)/rom_head.bin $(OUT)/rom_head.o $(OUT)/rom.out +.PHONY: cleanobj clean: cleanobj cleanres cleanlst cleandep - $(RM) -f out.lst out/cmd_ out/symbol.txt out/rom.nm out/rom.wch out/rom.bin + $(RM) -f out.lst $(OUT)/cmd_ $(OUT)/symbol.txt $(OUT)/rom.nm $(OUT)/rom.wch $(OUT)/rom.bin +.PHONY: clean cleanrelease: clean +.PHONY: cleanrelease cleandebug: clean +.PHONY: cleandebug cleanasm: cleanlst +.PHONY: cleanasm cleandefault: clean cleanDefault: clean +.PHONY: cleandefault cleanDefault cleanRelease: cleanrelease cleanDebug: cleandebug cleanAsm: cleanasm - -pre-build: - $(MKDIR) -p $(SRC)/boot - $(MKDIR) -p out +.PHONY: cleanRelease cleanDebug cleanAsm -out/rom.bin: out/rom.out - $(OBJCPY) -O binary out/rom.out out/rom.bin - $(SIZEBND) out/rom.bin -sizealign 131072 -checksum +$(OUT)/rom.bin: $(OUT)/rom.out + $(OBJCPY) -O binary $(OUT)/rom.out $(OUT)/rom.bin + $(SIZEBND) $(OUT)/rom.bin -sizealign 131072 -checksum -out/symbol.txt: out/rom.out - $(NM) $(LTO_PLUGIN) -n out/rom.out > out/symbol.txt +$(OUT)/symbol.txt: $(OUT)/rom.out + $(NM) $(LTO_PLUGIN) -n $(OUT)/rom.out > $(OUT)/symbol.txt -out/rom.out: out/sega.o out/cmd_ $(LIBMD) - $(CC) -m68000 -B$(BIN) -n -T $(GDK)/md.ld -nostdlib out/sega.o @out/cmd_ $(LIBMD) $(LIBGCC) -o out/rom.out -Wl,--gc-sections -flto - $(RM) out/cmd_ +$(OUT)/rom.out: $(OUT)/sega.o $(OUT)/cmd_ $(LIBMD) + $(MKDIR) -p $(dir $@) + $(CC) -m68000 -B$(BIN) -n -T $(GDK)/md.ld -nostdlib $(OUT)/sega.o @$(OUT)/cmd_ $(LIBMD) $(LIBGCC) -o $(OUT)/rom.out -Wl,--gc-sections -flto + $(RM) $(OUT)/cmd_ -out/cmd_: $(OBJS) - $(ECHO) "$(OBJS)" > out/cmd_ +$(OUT)/cmd_: $(OBJS) + $(MKDIR) -p $(dir $@) + $(ECHO) "$(OBJS)" > $(OUT)/cmd_ -out/sega.o: $(SRC)/boot/sega.s out/rom_head.bin - $(CC) -x assembler-with-cpp -Wa,--register-prefix-optional,--bitwise-or $(AFLAGS) -c $(SRC)/boot/sega.s -o $@ +$(OUT)/sega.o: $(OUT)/boot/sega.s $(OUT)/rom_head.bin + $(CC) -x assembler-with-cpp -Wa,--register-prefix-optional,--bitwise-or $(AFLAGS) -c $(OUT)/boot/sega.s -o $@ -out/rom_head.bin: out/rom_head.o +$(OUT)/rom_head.bin: $(OUT)/rom_head.o $(OBJCPY) -O binary $< $@ -out/rom_head.o: $(SRC)/boot/rom_head.c +$(OUT)/rom_head.o: $(SRC)/boot/rom_head.c + $(MKDIR) -p $(dir $@) $(CC) $(DEFAULT_FLAGS) -c $< -o $@ -$(SRC)/boot/sega.s: $(SRC_LIB)/boot/sega.s +$(OUT)/boot/sega.s: $(SRC_LIB)/boot/sega.s + $(ECHO) $@ + $(MKDIR) -p $(dir $@) $(CP) $< $@ $(SRC)/boot/rom_head.c: $(SRC_LIB)/boot/rom_head.c + $(MKDIR) -p $(dir $@) $(CP) $< $@ - -out/%.lst: %.c +$(OUT)/%.lst: %.c $(MKDIR) -p $(dir $@) $(CC) $(CFLAGS) -c $< -o $@ -out/%.o: %.c +$(OUT)/%.o: %.c $(MKDIR) -p $(dir $@) $(CC) $(CFLAGS) -MMD -c $< -o $@ -out/%.o: %.s +$(OUT)/%.o: %.s $(MKDIR) -p $(dir $@) $(CC) -x assembler-with-cpp -Wa,--register-prefix-optional,--bitwise-or $(AFLAGS) -MMD -c $< -o $@ -out/%.o: %.rs +$(OUT)/%.o: %.rs $(MKDIR) -p $(dir $@) $(CC) -x assembler-with-cpp -Wa,--register-prefix-optional,--bitwise-or $(AFLAGS) -c $*.rs -o $@ - $(CP) $*.d out/$*.d + $(CP) $*.d $(OUT)/$*.d $(RM) $*.d %.rs: %.res - $(RESCOMP) $*.res $*.rs -dep out/$*.o + $(RESCOMP) $*.res $*.rs -dep $(OUT)/$*.o %.s: %.asm $(MACCER) -o $@ $< diff --git a/readme.md b/readme.md index 66c0dd501..238715995 100644 --- a/readme.md +++ b/readme.md @@ -113,13 +113,15 @@ https://github.com/SONIC3D/gendev-macos *A modern way to install it on any environement is to use Docker.* -To build the `sgdk` base image: +To download the `sgdk` base image: - docker build -t sgdk . + docker pull ghcr.io/Stephane-D/sgdk + docker tag ghcr.io/Stephane-D/sgdk sgdk -To build the `sgdk` base image on mac with m1 chip: +Or build it: - docker build -t sgdk --file Dockerfile-m1 . + docker build -t ghcr.io/stephane-d/sgdk-m68k-gcc:latest -f deps/gcc.Dockerfile deps/ + docker build -t sgdk . And then to compile the local env, such as `samples` for example: diff --git a/tools/apj/src/sgdk/aplib/Launcher.java b/tools/apj/src/sgdk/aplib/Launcher.java index aae60f9a1..dddf70678 100644 --- a/tools/apj/src/sgdk/aplib/Launcher.java +++ b/tools/apj/src/sgdk/aplib/Launcher.java @@ -1,4 +1,4 @@ -package sgdk.aplib; +package sgdk.aplib; import java.io.File; import java.io.IOException;