Skip to content

Commit

Permalink
clenup makefiles and move tool building (including java) to docker
Browse files Browse the repository at this point in the history
  • Loading branch information
justgook committed Aug 15, 2023
1 parent fef762e commit 60c4689
Show file tree
Hide file tree
Showing 6 changed files with 336 additions and 278 deletions.
8 changes: 2 additions & 6 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
# Ignore non-build related directories
/.git/
/doc/
/sample/
/vstudio/
/.*/

#prebuilds
**.exe
**.dll
/lib/
/out/
/bin/
# Ignore non-build related files
.*
.DS_Store
/build_adv.bat
/build_lib.bat
/*.bat
/changelog.txt
/COPYING.RUNTIME
/Dockerfile
/Dockerfile-m1
/license.txt
/readme.md
11 changes: 4 additions & 7 deletions .github/workflows/sgdk-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ env:
on:
workflow_dispatch:
workflow_run:
workflows: ["gcc-docker"]
workflows: [ "gcc-docker" ]
branches:
- 'master'
- '*'
types:
- completed
push:
Expand All @@ -27,12 +27,9 @@ on:
- 'sample/**'
- '**.md'
branches:
- 'master'
- '*'
tags:
- 'v*'
pull_request:
branches:
- 'master'


jobs:
Expand Down Expand Up @@ -105,7 +102,7 @@ jobs:
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1

merge:
if: ${{ github.event_name != 'pull_request' }}
runs-on: ubuntu-latest
Expand Down
98 changes: 76 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,48 +1,102 @@
ARG ALPINE_VERSION=3.18.3
ARG JDK_VER=11

ARG BASE_IMAGE=ghcr.io/Stephane-D/sgdk-m68k-gcc
FROM $BASE_IMAGE as build
ARG BASE_IMAGE=ghcr.io/Stephane-D/sgdk-m68k-gcc:v1.90

# Stage Zero - just init image to download files in other stages
FROM $BASE_IMAGE as m68k-files


FROM alpine:$ALPINE_VERSION as jdk-base
ARG JDK_VER
RUN apk add --no-cache openjdk${JDK_VER}

RUN apk add --no-cache build-base git openjdk${JDK_VER}-jre-headless
WORKDIR /tmp
RUN git clone https://github.com/istvan-v/sjasmep.git
WORKDIR sjasmep
RUN make


# 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
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
RUN cd /sgdk/tools/bintos \
&& gcc -O2 -s src/bintos.c -o $SGDK_PATH/bin/bintos
WORKDIR $SGDK_PATH/tools/bintos
RUN gcc -O2 -s src/bintos.c -o $SGDK_PATH/bin/bintos

# Building xgmtool
RUN cd /sgdk/tools/xgmtool \
&& gcc -fexpensive-optimizations -Os -s src/*.c -o $SGDK_PATH/bin/xgmtool

RUN mv /tmp/sjasmep/sjasm ./bin/

ENV PATH="/$SGDK_PATH/bin:${PATH}"

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}"

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=build /m68k/ /usr/
COPY --from=m68k-files /m68k/ /usr/

#RUN apt-get install -y build-essential openjdk-17-jre-headless
ARG JDK_VER
RUN apk add --no-cache build-base openjdk${JDK_VER}-jre-headless
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
Expand All @@ -52,11 +106,11 @@ 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}"
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_PATH/makefile.gen
ENTRYPOINT ["/bin/sh","-c","make -f $SGDK_PATH/makefile.gen $@", "--"]
78 changes: 29 additions & 49 deletions deps/gcc.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ ENV BUILDDIR="$BASEDIR/build"
ENV INSTALLDIR="$BASEDIR/install"
ENV STAGINGDIR="$BASEDIR/staging"

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
Expand All @@ -34,23 +39,11 @@ 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




# TODO DELETE THOSE
RUN mkdir -p "$SRCDIR"
RUN mkdir -p "$BUILDDIR"
RUN mkdir -p "$INSTALLDIR"
RUN mkdir -p "$STAGINGDIR"





### Building binutils ###
#################################################################################
########################## Building binutils ##############################
#################################################################################
WORKDIR $BUILDDIR/$BINUTILS
RUN $SRCDIR/$BINUTILS/configure \
--prefix=/usr \
Expand All @@ -59,28 +52,24 @@ RUN $SRCDIR/$BINUTILS/configure \
--with-cpu=$TARGET_CPU \
--disable-nls

RUN make -j$(nproc)
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 ###"
#################################################################################
######################### 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 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 \
Expand All @@ -93,15 +82,13 @@ RUN $SRCDIR/$GCC/configure \
--disable-shared \
--disable-nls

RUN make -j$(nproc) all-gcc
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 NewLib #############################
#################################################################################
WORKDIR $BUILDDIR/$NEWLIB
ENV CFLAGS_FOR_TARGET="-Os -g -ffunction-sections -fdata-sections -fomit-frame-pointer -ffast-math"

Expand All @@ -114,17 +101,15 @@ RUN "$SRCDIR/$NEWLIB/configure" \
--with-cpu=$TARGET_CPU \
--disable-nls

RUN make -j$(nproc)
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"
ENV CFLAGS_FOR_TARGET=""
#################################################################################
############################ Building final GCC ###########################
#################################################################################
WORKDIR $BUILDDIR/$GCC

RUN "$SRCDIR/$GCC/configure" \
--prefix=/usr \
Expand All @@ -138,23 +123,18 @@ RUN "$SRCDIR/$GCC/configure" \
--disable-shared \
--disable-nls

RUN make -j$(nproc)
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
# COPY build_toolchain .
# RUN ./build_toolchain

# Second stage, just create the m68k user and copy the built files
FROM alpine:$ALPINE_VERSION
ARG BASEDIR

COPY --from=build $BASEDIR/staging/usr/ /usr/
WORKDIR m68k
COPY --from=build $BASEDIR/staging/usr/ .

# Second stage, just copy the built files
FROM scratch
ARG BASEDIR
WORKDIR /m68k
COPY --from=build $BASEDIR/staging/usr/ ./
Loading

0 comments on commit 60c4689

Please sign in to comment.