Skip to content

Commit

Permalink
Merge pull request #321 from iratahack/master
Browse files Browse the repository at this point in the history
Use crosstool-ng to build latest m68k version of gcc for repo workflow
  • Loading branch information
Stephane-D authored Apr 3, 2024
2 parents f81c54b + 73e098d commit 10b4131
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 158 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/sgdk-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: 'true'

# TODO: arm64 images are currently disabled because they keep hanging in
# the GitHub Actions environment.
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "tools/sjasm"]
path = tools/sjasm
url = https://github.com/Konamiman/Sjasm.git
[submodule "tools/musicg"]
path = tools/musicg
url = https://github.com/loisaidasam/musicg
45 changes: 20 additions & 25 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,14 @@ RUN jlink \

# Stage One - build all tools and libs for SGDK
FROM jre-minimal as build
RUN apk add --no-cache build-base git
RUN apk add --no-cache build-base git cmake ninja

# Set-up environment and folders
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/

# Get SGDK sources
COPY . /sgdk

# 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
COPY . $SGDK_PATH

# Building apj.jar
WORKDIR $SGDK_PATH/tools/apj/src
Expand All @@ -72,19 +57,29 @@ 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 .

# Building xgm2tool.jar
WORKDIR $SGDK_PATH/tools/xgm2tool/src
ENV CLASSPATH="$SGDK_PATH/bin/apj.jar:$SGDK_PATH/bin/lz4w.jar:$SGDK_PATH/tools/xgm2tool/src"
RUN cp -r $SGDK_PATH/tools/commons/src/sgdk .
RUN cp -r $SGDK_PATH/tools/musicg/src/com .
RUN cp -r $SGDK_PATH/tools/musicg/graphic .
RUN find . -name "*.java" | xargs javac
RUN echo -e "Main-Class: sgdk.xgm2tool.Launcher\nClass-Path: apj.jar lz4w.jar" > Manifest.txt
RUN jar cfm $SGDK_PATH/bin/xgm2tool.jar Manifest.txt .

# Copy m68k compiler from base image
COPY --from=m68k-files /m68k/ /usr/
ENV PATH="$SGDK_PATH/bin:${PATH}"

# Build SGDK libraries
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
# 32-bit not supported on Alpine, this may have side-effects
RUN sed -i /-m32/d $SGDK_PATH/tools/xgmtool/src/CMakeLists.txt
ENV PREFIX=m68k-elf-
RUN cmake -G Ninja -S $SGDK_PATH -B $SGDK_PATH/build_release -DCMAKE_BUILD_TYPE=Release && cmake --build $SGDK_PATH/build_release
RUN cmake -G Ninja -S $SGDK_PATH -B $SGDK_PATH/build_debug -DCMAKE_BUILD_TYPE=Debug && cmake --build $SGDK_PATH/build_debug

RUN rm -rf $SGDK_PATH/tools
RUN rm -rf $SGDK_PATH/build_release
RUN rm -rf $SGDK_PATH/build_debug

# Stage Two - copy tools into a clean image
FROM alpine:$ALPINE_VERSION
Expand Down
154 changes: 21 additions & 133 deletions deps/gcc.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,151 +1,39 @@
ARG ALPINE_VERSION=3.18.3

ARG CROSSTOOL_VERSION=1.26.0
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
ARG CROSSTOOL_VERSION

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 ##########################
########################## Install required packages ######################
#################################################################################
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 apk update && apk upgrade && apk add cmake alpine-sdk wget xz git bash autoconf automake bison flex texinfo help2man gawk libtool ncurses-dev gettext-dev python3-dev rsync openjdk11 ninja

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 #############################
############################ Building crosstool-ng ########################
#################################################################################
WORKDIR $BUILDDIR/$NEWLIB
ENV CFLAGS_FOR_TARGET="-Os -g -ffunction-sections -fdata-sections -fomit-frame-pointer -ffast-math"
WORKDIR /root
RUN git clone --branch crosstool-ng-$CROSSTOOL_VERSION --depth=1 https://github.com/crosstool-ng/crosstool-ng.git
WORKDIR /root/crosstool-ng
RUN ./bootstrap && ./configure --enable-local
RUN make
ENV PATH=/root/crosstool-ng:$PATH
COPY samples/m68k-elf ./samples/m68k-elf

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 ###########################
############################### Building 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"

WORKDIR $BASEDIR
ENV CT_EXPERIMENTAL=y
ENV CT_ALLOW_BUILD_AS_ROOT=y
ENV CT_ALLOW_BUILD_AS_ROOT_SURE=y
# Configure and build the tools
RUN ct-ng m68k-elf
RUN ct-ng build

# Second stage, just copy the built files
FROM scratch
ARG BASEDIR
WORKDIR /m68k
COPY --from=build $BASEDIR/staging/usr/ ./
COPY --from=build /root/x-tools/m68k-elf/ .
10 changes: 10 additions & 0 deletions deps/samples/m68k-elf/crosstool.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CT_CONFIG_VERSION="4"
CT_STRIP_TARGET_TOOLCHAIN_EXECUTABLES=y
CT_ARCH_M68K=y
CT_ARCH_CPU="68000"
CT_OMIT_TARGET_VENDOR=y
CT_BINUTILS_PLUGINS=y
CT_LIBC_NONE=y
CT_COMP_TOOLS_AUTOCONF=y
CT_COMP_TOOLS_AUTOMAKE=y
CT_COMP_TOOLS_LIBTOOL=y
3 changes: 3 additions & 0 deletions deps/samples/m68k-elf/reported.by
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
reporter_name="IrataHack"
reporter_url=""
reporter_comment="m68k bare-metal tools for SGDK."
1 change: 1 addition & 0 deletions tools/musicg
Submodule musicg added at f04681

0 comments on commit 10b4131

Please sign in to comment.