diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e0feeab --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +files +native-gcc +.repos \ No newline at end of file diff --git a/.env10 b/.env10 new file mode 100644 index 0000000..917ea31 --- /dev/null +++ b/.env10 @@ -0,0 +1,2 @@ +GCC_VER=10 +BINUTILS_VER=2.23.2 \ No newline at end of file diff --git a/.env11 b/.env11 new file mode 100644 index 0000000..b7b97f6 --- /dev/null +++ b/.env11 @@ -0,0 +1,2 @@ +GCC_VER=11 +BINUTILS_VER=2.23.2 \ No newline at end of file diff --git a/.env6 b/.env6 new file mode 100644 index 0000000..65f5223 --- /dev/null +++ b/.env6 @@ -0,0 +1,2 @@ +GCC_VER=6 +BINUTILS_VER=2.23.2 \ No newline at end of file diff --git a/.env8 b/.env8 new file mode 100644 index 0000000..bd550f1 --- /dev/null +++ b/.env8 @@ -0,0 +1,2 @@ +GCC_VER=8 +BINUTILS_VER=2.23.2 \ No newline at end of file diff --git a/.env9 b/.env9 new file mode 100644 index 0000000..548c215 --- /dev/null +++ b/.env9 @@ -0,0 +1,2 @@ +GCC_VER=9 +BINUTILS_VER=2.23.2 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2aa7c25 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,98 @@ +# The ubuntu:latest tag points to the "latest LTS", since that's the version recommended for general use. +FROM ubuntu:bionic + +LABEL maintainer="Georgios Sokianos " + +ARG DEBIAN_FRONTEND=noninteractive +ARG REPOS_PATH + +WORKDIR /tmp + +RUN dpkg --add-architecture i386 && apt-get update && apt-get -y --no-install-recommends install \ + ca-certificates \ + curl \ + python2.7; + +RUN ln -s /usr/bin/python2.7 /usr/bin/python; \ + curl -fsSL https://bootstrap.pypa.io/pip/2.7/get-pip.py -o /tmp/get-pip.py && \ + python get-pip.py && \ + pip2 install --no-cache-dir argcomplete==1.12.3 mako; \ + rm -rf /tmp/* /var/tmp/*; + + + # libc6:i386 libncurses5:i386 libstdc++6:i386 + # multiarch-support binutils-multiarch \ +RUN apt-get -y --no-install-recommends install \ + autoconf \ + automake \ + autopoint \ + bison \ + dh-autoreconf \ + flex \ + g++-8 \ + gettext \ + git \ + gperf \ + libgmp-dev \ + libmpc3 \ + libmpc-dev \ + libtool \ + make \ + mc \ + nano \ + patch \ + rsync \ + texinfo \ + wget \ + xz-utils; \ + ln -s /usr/bin/g++-8 /usr/bin/g++; \ + rm /usr/bin/gcc; \ + ln -s /usr/bin/gcc-8 /usr/bin/gcc; \ + git config --global user.email "walkero@gmail.com"; \ + git config --global user.name "Georgios Sokianos"; + + # libfl2 \ +# Install latest lha from git repo +RUN git clone https://github.com/jca02266/lha.git && \ + mkdir build && \ + cd lha && \ + autoreconf -vfi && \ + cd ../build && \ + ../lha/configure --prefix=/usr && \ + make && \ + make install && \ + apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*; + +# Add necessary repos +ADD ${REPOS_PATH}/adtools /opt/adtools +ADD ${REPOS_PATH}/binutils-gdb /opt/adtools/binutils/repo +ADD ${REPOS_PATH}/coreutils /opt/adtools/coreutils/repo +# ADD ${REPOS_PATH}/gcc-releases-gcc-8.4.0.tar.gz /opt/adtools/gcc/repo +# ADD ${REPOS_PATH}/gcc /opt/adtools/gcc/repo +ADD ${REPOS_PATH}/gnulib /opt/adtools/gnulib/repo +ADD build-gcc.sh /opt/adtools + +ADD ${REPOS_PATH}/execsg_private_sdk /tmp/execsg_private_sdk + +WORKDIR /opt/adtools + +RUN git submodule init && \ + git submodule update && \ + chmod +x build-gcc.sh + + + + + + + +# && \ +# gild/bin/gild checkout binutils ${BINUTILS_VER} && \ +# gild/bin/gild checkout gcc ${GCC_VER} && \ +# make -C native-build -j4; + +# RUN cd /opt/adtools/native-build && \ +# make native-install && \ +# make native-dist && \ +# make clib2-dist; + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f2b1ad4 --- /dev/null +++ b/Makefile @@ -0,0 +1,92 @@ +REPOSPATH ?= ./repos +REPO ?= walkero/adtoolsbuilder +TAG ?= adtools-build +WORKSPACE ?= -w /opt/adtools +NAME ?= adtools-build +VOLUMES ?= -v "${PWD}/native-gcc":/gcc + +.PHONY: help build buildnc shell gcc6 gcc8 gcc10 gcc11 clonerepos pullrepos clean + +default: help + +help: + @echo "This make file helps on building the Docker image and starting containers" + @echo "where adtools can get build." + @echo "The available parameters can be seen below:" + @echo "" + @echo "build - Build the Docker image" + @echo "buildnc - Pull the latest repos' code and build the Docker image without" + @echo " using caching" + @echo "shell - Create a container with the latest Docker image and get into it." + @echo " Not suitable to compile adtools" + @echo "gcc6 - Create a container with the latest Docker image and get into it" + @echo " to compile adtools with GCC 6." + @echo "gcc8 - Create a container with the latest Docker image and get into it" + @echo " to compile adtools with GCC 8." + @echo "gcc10 - Create a container with the latest Docker image and get into it" + @echo " to compile adtools with GCC 10." + @echo "gcc11 - Create a container with the latest Docker image and get into it" + @echo " to compile adtools with GCC 11." + @echo "clonerepos - Clone the necessary repositories under repos folder." + @echo "pullrepos - Pull the latest code for the projects under repos folder." + @echo "clean - Remove the docker container, if this still exists." + @echo "" + @echo "Since the SDK 53.34 is used, there is a need of the latest ExecSG private SDK" + @echo "which should be placed manually under repos folder. So the path should be:" + @echo "repos/execsg_private_sdk/SDK/..." + @echo "" + +# TODO: Add a check for the execsg_private_sdk folder +build: + docker build -t $(REPO):$(TAG) \ + --build-arg REPOS_PATH=$(REPOSPATH) . + +buildnc: pullrepos + docker build --no-cache -t $(REPO):$(TAG) \ + --build-arg REPOS_PATH=$(REPOSPATH) . + +shell: + docker run -it --rm --name $(NAME) $(WORKSPACE) $(VOLUMES) $(REPO):$(TAG) /bin/bash + +gcc6: + docker run -it --rm --name $(NAME)-6 $(WORKSPACE) \ + -v "${PWD}/native-gcc/6":/gcc \ + -v "${PWD}/files/native-build/makefile-SDK53.34":/opt/adtools/native-build/makefile \ + -v "${PWD}/files/gcc-build":/opt/adtools/gcc-build \ + --env-file .env6 $(REPO):$(TAG) /bin/bash + +gcc8: + docker run -it --rm --name $(NAME)-8 $(WORKSPACE) \ + -v "${PWD}/native-gcc/8":/gcc \ + -v "${PWD}/files/native-build/makefile-SDK53.34":/opt/adtools/native-build/makefile \ + -v "${PWD}/files/gcc-build":/opt/adtools/gcc-build \ + --env-file .env8 $(REPO):$(TAG) /bin/bash + +gcc10: + docker run -it --rm --name $(NAME)-10 $(WORKSPACE) \ + -v "${PWD}/native-gcc/10":/gcc \ + -v "${PWD}/files/native-build/makefile-SDK53.34":/opt/adtools/native-build/makefile \ + -v "${PWD}/files/gcc-build":/opt/adtools/gcc-build \ + --env-file .env10 $(REPO):$(TAG) /bin/bash + +gcc11: + docker run -it --rm --name $(NAME)-11 $(WORKSPACE) \ + -v "${PWD}/native-gcc/11":/gcc \ + -v "${PWD}/files/native-build/makefile-SDK53.34":/opt/adtools/native-build/makefile \ + -v "${PWD}/files/gcc-build":/opt/adtools/gcc-build \ + --env-file .env11 $(REPO):$(TAG) /bin/bash + +clonerepos: + git clone https://github.com/sba1/adtools $(REPOSPATH)/adtools + git clone https://github.com/bminor/binutils-gdb $(REPOSPATH)/binutils-gdb + git clone https://github.com/coreutils/coreutils $(REPOSPATH)/coreutils + git clone https://github.com/coreutils/gnulib $(REPOSPATH)/gnulib + +pullrepos: + git -C $(REPOSPATH)/adtools pull + git -C $(REPOSPATH)/binutils-gdb pull + git -C $(REPOSPATH)/coreutils pull + git -C $(REPOSPATH)/gnulib pull + +clean: + -docker rm -f $(NAME) diff --git a/build-gcc.sh b/build-gcc.sh new file mode 100644 index 0000000..169f259 --- /dev/null +++ b/build-gcc.sh @@ -0,0 +1,26 @@ +#!/bin/bash +# This script compiles the native GCC environment + +gild/bin/gild checkout binutils ${BINUTILS_VER} && \ +gild/bin/gild checkout gcc ${GCC_VER} && \ +make -C native-build -j4 + +# Prepare coreutils 5.2 (disabled) +gild/bin/gild checkout coreutils 5.2 + + +# Prepare coreutils 8.27 +# gild/bin/gild checkout coreutils 8.27 && \ +# gild/bin/gild checkout gnulib for-coreutils-8.27 && \ +# cd coreutils/repo && \ +# ./bootstrap + + +# create the release packages +cd /opt/adtools/native-build +# The following might fail on [ and need to run twice +make native-install + +make native-dist && \ +make clib2-dist && \ +mv adtools-os4-*.lha /gcc diff --git a/files/gcc-build/Makefile b/files/gcc-build/Makefile new file mode 100644 index 0000000..9e135e1 --- /dev/null +++ b/files/gcc-build/Makefile @@ -0,0 +1,57 @@ +# +# Makefile to compile cross +# +# Use SRC_DIR to alter the path of the source (default ../gcc) +# Use VERSION to specify the version (alters the name of the created drawer) +# +# when compiling 4.4.x or newer. +# +# + +SRC_DIR=../gcc/repo +VERSION:=$(shell cat $(SRC_DIR)/gcc/BASE-VER) +MAJOR_VERSION:=$(word 1, $(subst ., , $(VERSION))) +CROSS_BUILD_DIR=cross-$(VERSION) +NATIVE_BUILD_DIR=native-$(VERSION) +PREFIX=/usr/local/amiga +BUILD=i686-pc-linux-gnu ## for some reasons configure script of gcc 4.2.4 doesn't identify the correct build type +REAL_SRC_DIR=$(realpath $(SRC_DIR)) + +# Defines FEATURES macro according to the actual gcc version +include features.mk + +all: cross + +.PHONY: cross-configure +cross-configure: + mkdir -p $(CROSS_BUILD_DIR) + cd $(CROSS_BUILD_DIR); $(REAL_SRC_DIR)/configure \ + --with-bugurl='https://github.com/sba1/adtools/issues' \ + --with-pkgversion='adtools build $(VERSION)' \ + --target=ppc-amigaos \ + --prefix=$(PREFIX) \ + $(FEATURES) #\ +# --enable-checking=gc + +.PHONY: cross +cross: cross-configure + $(MAKE) -C $(CROSS_BUILD_DIR) + +.PHONY: native +native: + mkdir -p $(NATIVE_BUILD_DIR) + cd $(NATIVE_BUILD_DIR); LDFLAGS="-lunix" $(REAL_SRC_DIR)/configure \ + --with-bugurl='https://github.com/sba1/adtools/issues' \ + --with-pkgversion='adtools build $(VERSION)' \ + --host=ppc-amigaos \ + --target=ppc-amigaos \ + --disable-nls \ + --prefix=/gcc \ + --with-gmp=$(LIB_PATH) \ + --with-mpfr=$(LIB_PATH) \ + --with-mpc=$(LIB_PATH) \ + --program-prefix=ppc-amigaos- \ + --program-suffix=-$(MAJOR_VERSION) \ + --libexecdir=/gcc/libexec \ + $(FEATURES) + $(MAKE) -C $(NATIVE_BUILD_DIR) diff --git a/files/gcc-build/features.mk b/files/gcc-build/features.mk new file mode 100644 index 0000000..49be2d8 --- /dev/null +++ b/files/gcc-build/features.mk @@ -0,0 +1,18 @@ +MAJOR_VERSION:=$(word 1, $(subst ., , $(VERSION))) + +FEATURES=\ + --enable-languages=c,c++ \ + --enable-haifa \ + --enable-sjlj-exceptions \ + --disable-libstdcxx-pch \ + --disable-tls + +# Check, if major version is greater than or equals to 8 +ifeq ($(shell test $(MAJOR_VERSION) -ge 8; echo $$?), 0) +FEATURES+=--enable-threads=amigaos --enable-lto + +# Check, if major version is greater than or equals to 11 +ifeq ($(shell test $(MAJOR_VERSION) -ge 11; echo $$?), 0) +FEATURES+=--disable-c++tools +endif +endif diff --git a/files/native-build/makefile-SDK53.30 b/files/native-build/makefile-SDK53.30 new file mode 100644 index 0000000..4d00e52 --- /dev/null +++ b/files/native-build/makefile-SDK53.30 @@ -0,0 +1,503 @@ +# +# This makefile drives the native build done on a non-native system, i.e., +# before building the native compiler, a cross compiler will be build. +# We then build the native compiler using the freshly-built cross +# compiler. +# +# The user running this script must have write access to /gcc +# +# Define CROSS_IS_PRESENT=1 if a suitable cross compiler is already +# present, in which case the cross compiler build is skipped, e.g.: +# +# make CROSS_IS_PRESENT=1 +# + +ROOT_DIR=$(realpath .) + +# Compiler setup, utilize ccache if available +CCACHE:=$(shell which ccache) +HOST_GCC:=$(strip $(CCACHE) gcc) +HOST_GXX:=$(strip $(CCACHE) g++) + +GMP_ARCHIVE=gmp-5.1.3.tar.bz2 +MPFR_ARCHIVE=mpfr-3.1.6.tar.bz2 +MPC_ARCHIVE=mpc-1.0.3.tar.gz + +BINUTILS_VERSION=2.23.2 +BINUTILS_SRC_DIR=../binutils/repo + +GCC_SRC_DIR=../gcc/repo +GCC_VERSION:=$(shell cat $(GCC_SRC_DIR)/gcc/BASE-VER) +GCC_DEV_PHASE:=$(shell cat ${GCC_SRC_DIR}/gcc/DEV-PHASE) + +ifneq ($(GCC_DEV_PHASE),) +GCC_DEV_PHASE:= ($(GCC_DEV_PHASE)) +endif + +GCC_BRANCH_NAME:=$(word 1, $(subst ., , $(GCC_VERSION))) + +SDK_URL=https://www.hyperion-entertainment.biz/index.php?option=com_registration&view=download&format=raw&file=82&Itemid=82 +SDK_VERSION=53.30 + +# Native tools +COREUTILS_SRC_DIR=../coreutils/repo +COREUTILS_VERSION=5.2.1 + +# Distribution version, used as middle part of a distribution archive +DIST_VERSION=$(shell date +%Y%m%d)-$(shell git rev-list --count HEAD) + +CLIB2_URL=https://github.com/sodero/clib2 +CLIB2_SHA1=3609972cb4c2c8ff60e4d79571d5eaabf5bf97b4 +CLIB2_RELEASE_ARCHIVE_NAME=adtools-os4-clib2-$(DIST_VERSION).lha + +CROSS_PREFIX?=$(ROOT_DIR)/root-cross +# This assumes that cross prefix is absolute +DESTDIR?= + +STRIP=$(CROSS_PREFIX)/bin/ppc-amigaos-strip +STRIPFLAGS=--strip-all --strip-unneeded-rel-relocs -R.comment + +all: gcc-native-done-$(GCC_VERSION) + +# +# Print the dist version that is used as suffix for various +# suffixes. +# +.PHONY: print-dist-version +print-dist-version: + @echo $(DIST_VERSION) + +# +# Downloads clib2 +# +downloads-done-clib2: + mkdir -p downloads + cd downloads && (git clone $(CLIB2_URL) clib2 || true) && cd clib2 && git checkout $(CLIB2_SHA1) + touch $@ + +# +# Downloads the SDK and libraries necesseary to build the cross compiler +# +downloads-done: downloads-done-clib2 + wget "$(SDK_URL)" -O downloads/SDK_$(SDK_VERSION).lha + cd downloads && wget -N http://ftp.gnu.org/gnu/gmp/$(GMP_ARCHIVE) + cd downloads && wget -N http://ftp.gnu.org/gnu/mpfr/$(MPFR_ARCHIVE) + cd downloads && wget -N http://ftp.gnu.org/gnu/mpc/$(MPC_ARCHIVE) + touch $@ + +# +# Builds the cross binutils package (assembler, etc). +# +binutils-cross-build-done-$(BINUTILS_VERSION): + $(MAKE) -C ../binutils-build SRC_DIR=$(BINUTILS_SRC_DIR) PREFIX=$(CROSS_PREFIX) CROSS_BUILD_DIR=$(ROOT_DIR)/binutils-cross-build-$(BINUTILS_VERSION) + touch $@ + +.PHONY: binutils-build +binutils-build: binutils-cross-build-done-$(BINUTILS_VERSION) + +# +# Installs the cross binutils package (assembler, etc). +# +binutils-cross-done-$(BINUTILS_VERSION): binutils-cross-build-done-$(BINUTILS_VERSION) + $(MAKE) -C $(ROOT_DIR)/binutils-cross-build-$(BINUTILS_VERSION) install DESTDIR=$(DESTDIR) + touch $@ + +.PHONY: binutils-install +binutils-install: binutils-cross-done-$(BINUTILS_VERSION) + +# +# Prepares the includes +# +includes-done: downloads-done + mkdir -p $(CROSS_PREFIX)/ppc-amigaos/SDK/include + cd downloads && lha x SDK_$(SDK_VERSION).lha +# We built clib2 inplace +# cd downloads/SDK_Install && lha xf clib2*.lha + cd downloads/SDK_Install && lha xf newlib*.lha + cd downloads/SDK_Install && lha xf base.lha + cd downloads/SDK_Install && rm -Rf *.lha + cd downloads/SDK_Install && mv newlib* $(CROSS_PREFIX)/ppc-amigaos/SDK +# cd downloads/SDK_Install && mv clib2* $(CROSS_PREFIX)/ppc-amigaos/SDK + cd downloads/SDK_Install && mv Include/* $(CROSS_PREFIX)/ppc-amigaos/SDK/include + rm -Rf downloads/SDK_Install downloads/SDK_Install.info + touch $@ + +# +# Path to the initial cross compiler or standard +# cross compiler if a cross compiler is present +# + +ifeq ($(CROSS_IS_PRESENT),1) + +XGCC=ppc-amigaos-gcc +XGCC_CC=ppc-amigaos-gcc +XAR=ppc-amigaos-ar -q +XRANLIB=ppc-amigaos-ranlib + +CLIB2_CROSS_DONE_DEPENDENCY=downloads-done-clib2 + +else + +XGCC_DIR=$(abspath .)/gcc-cross-build-$(GCC_VERSION)/gcc +XGCC=$(XGCC_DIR)/xgcc +XGCC_CC=$(XGCC) -B $(XGCC_DIR) +XAR=$(CROSS_PREFIX)/bin/ppc-amigaos-ar -q +XRANLIB=$(CROSS_PREFIX)/bin/ppc-amigaos-ranlib + +CLIB2_CROSS_DONE_DEPENDENCY=xgcc-done-$(GCC_VERSION) + +endif + +CLIB2_DIR=downloads/clib2/library + +# +# Prints the folder where the basic xg (xgcc or xg++) compilers +# can be round. +# +.PHONY: print-xg-dir +print-xg-dir: + @echo $(XGCC_DIR) + +# +# Build only xgcc, no other stuff like libstdc++ etc. +# +xgcc-done-$(GCC_VERSION): includes-done binutils-cross-done-$(BINUTILS_VERSION) + CC="$(HOST_GCC)" CXX="$(HOST_GXX)" $(MAKE) -C ../gcc-build cross-configure \ + SRC_DIR=$(GCC_SRC_DIR) \ + PREFIX=$(CROSS_PREFIX) \ + CROSS_BUILD_DIR=$(ROOT_DIR)/gcc-cross-build-$(GCC_VERSION) \ + VERSION=$(GCC_VERSION) + $(MAKE) -C $(ROOT_DIR)/gcc-cross-build-$(GCC_VERSION) all-gcc + touch $@ + +# +# Build clib2 via xgcc +# +clib2-cross-done-$(GCC_VERSION): $(CLIB2_CROSS_DONE_DEPENDENCY) +# Build clib2 using xgcc that have just been built + $(MAKE) -C $(CLIB2_DIR) -f GNUmakefile.os4 CC="$(XGCC_CC)" AR="$(XAR)" RANLIB="$(XRANLIB)" +# Copy clib2 libs and includes + rm -Rf $(CROSS_PREFIX)/ppc-amigaos/SDK/clib2/lib $(CROSS_PREFIX)/ppc-amigaos/SDK/clib2/include + mkdir -p $(CROSS_PREFIX)/ppc-amigaos/SDK/clib2/lib + mkdir -p $(CROSS_PREFIX)/ppc-amigaos/SDK/clib2/include + cp -Rp $(CLIB2_DIR)/include/* $(CROSS_PREFIX)/ppc-amigaos/SDK/clib2/include + cp -Rp $(CLIB2_DIR)/lib/* $(CROSS_PREFIX)/ppc-amigaos/SDK/clib2/lib + touch $@ + +# +# Build the cross compiler +# +gcc-cross-done-$(GCC_VERSION): clib2-cross-done-$(GCC_VERSION) +# Compile remaining + $(MAKE) -C $(ROOT_DIR)/gcc-cross-build-$(GCC_VERSION) + $(MAKE) -C $(ROOT_DIR)/gcc-cross-build-$(GCC_VERSION) install + touch $@ + +.PHONY: gcc-cross +gcc-cross: gcc-cross-done-$(GCC_VERSION) + +# +# Optional target for additional libs +# +.PHONY: additionals-libs +additionals-libs: + mkdir -p $(CROSS_PREFIX)/ppc-amigaos/SDK/local/common/include + mkdir -p /tmp/abcd + cd downloads && lha xw=/tmp/abcd SDK_$(SDK_VERSION).lha + cd /tmp/abcd/SDK_Install && lha x pthread.lha && lha x zlib-1.2.3.lha + cp -Rf /tmp/abcd/SDK_Install/Local/* $(CROSS_PREFIX)/ppc-amigaos/SDK/local + rm -Rf /tmp/abcd + + +ifeq ($(CROSS_IS_PRESENT),1) +NATIVE_LIBRARY_DEPENDENCIES=downloads-done +else +NATIVE_LIBRARY_DEPENDENCIES=gcc-cross-done-$(GCC_VERSION) +endif + +# +# Build and install the libraries +# +libraries-done: $(NATIVE_LIBRARY_DEPENDENCIES) + cd downloads && tar -xjf $(notdir $(GMP_ARCHIVE)) + cd downloads && tar -xjf $(notdir $(MPFR_ARCHIVE)) + cd downloads && tar -xzf $(notdir $(MPC_ARCHIVE)) + cd $(basename $(basename downloads/$(notdir $(GMP_ARCHIVE)))) && PATH="$(CROSS_PREFIX)/bin:$(PATH)" ./configure --host=ppc-amigaos --prefix=$(CROSS_PREFIX) && PATH="$(CROSS_PREFIX)/bin:$(PATH)" make install + cd $(basename $(basename downloads/$(notdir $(MPFR_ARCHIVE)))) && PATH="$(CROSS_PREFIX)/bin:$(PATH)" ./configure --host=ppc-amigaos --prefix=$(CROSS_PREFIX) -with-gmp=$(CROSS_PREFIX) && PATH="$(CROSS_PREFIX)/bin:$(PATH)" make install + cd $(basename $(basename downloads/$(notdir $(MPC_ARCHIVE)))) && PATH="$(CROSS_PREFIX)/bin:$(PATH)" ./configure --host=ppc-amigaos --prefix=$(CROSS_PREFIX) --with-gmp=$(CROSS_PREFIX) --with-mpfr=$(CROSS_PREFIX) && PATH="$(CROSS_PREFIX)/bin:$(PATH)" make install + touch $@ + +# +# Build the native binutils +# +binutils-native-done-$(BINUTILS_VERSION): libraries-done + PATH="$(CROSS_PREFIX)/bin:$(PATH)" $(MAKE) -C ../binutils-build native \ + SRC_DIR=$(BINUTILS_SRC_DIR) \ + PREFIX=/gcc \ + NATIVE_BUILD_DIR=$(ROOT_DIR)/binutils-native-build-$(BINUTILS_VERSION) + touch $@ + +# +# Build the native gcc +# +gcc-native-done-$(GCC_VERSION): binutils-native-done-$(BINUTILS_VERSION) + mkdir -p $(ROOT_DIR)/root-native/gcc/include + mkdir -p /gcc/include + PATH="$(CROSS_PREFIX)/bin:$(PATH)" $(MAKE) -C ../gcc-build native \ + SRC_DIR=$(GCC_SRC_DIR) \ + PREFIX=/gcc \ + NATIVE_BUILD_DIR=$(ROOT_DIR)/gcc-native-build-$(GCC_VERSION) \ + VERSION=$(GCC_VERSION) \ + LIB_PATH=$(CROSS_PREFIX) \ + NATIVE_SYS_ROOT=$(ROOT_DIR)/root-native + touch $@ + +ifeq ($(CROSS_IS_PRESENT),1) +coreutils-native-done: +else +coreutils-native-done: gcc-cross-done-$(GCC_VERSION) +endif + mkdir -p coreutils-native-build + @if [ ! -f $(COREUTILS_SRC_DIR)/configure ]; then echo "Please checkout coreutils first!"; false; fi +# Pretend few files to be uptodate + touch $(realpath $(COREUTILS_SRC_DIR))/configure $(realpath $(COREUTILS_SRC_DIR))/config.hin +# cd coreutils-native-build ; PATH="$(CROSS_PREFIX)/bin:$(PATH)" LIBS="-lunix" $(realpath $(COREUTILS_SRC_DIR))/configure --prefix=/gcc --host=ppc-amigaos + cd coreutils-native-build ; PATH="$(CROSS_PREFIX)/bin:$(PATH)" CPPFLAGS="-mcrt=clib2" LDFLAGS="-mcrt=clib2" LIBS="-lunix -lnet" $(realpath $(COREUTILS_SRC_DIR))/configure --prefix=/gcc --host=ppc-amigaos --disable-maintainer-mode + PATH="$(CROSS_PREFIX)/bin:$(PATH)" $(MAKE) -C coreutils-native-build + touch $@ + + +GCC_BASE_BRANCH_NAME=$(GCC_BRANCH_NAME)-base +# +# Build the main docs +# +.PHONY: doc +doc: + rm -Rf $@ + mkdir -p $@/tmp/orig + mkdir -p $@/tmp/patched + + echo "@set version-GCC $(GCC_VERSION)-adtools" >$@/tmp/orig/gcc-vers.texi + echo "@set srcdir $(ROOT_DIR)/$(GCC_BASE_BRANCH_NAME)/gcc" >>$@/tmp/orig/gcc-vers.texi + echo "@set BUGURL https://github.com/sba1/adtools/issues" >>$@/tmp/orig/gcc-vers.texi + + echo "@set version-GCC $(GCC_VERSION)-adtools" >$@/tmp/patched/gcc-vers.texi + echo "@set srcdir $(GCC_SRC_DIR)/gcc" >>$@/tmp/patched/gcc-vers.texi + echo "@set BUGURL https://github.com/sba1/adtools/issues" >>$@/tmp/patched/gcc-vers.texi + + # Checkout base branch as worktree + cd $(GCC_SRC_DIR) && git worktree add -f $(ROOT_DIR)/$(GCC_BASE_BRANCH_NAME) $(GCC_BASE_BRANCH_NAME) || true + cd $(ROOT_DIR)/$(GCC_BASE_BRANCH_NAME) && git checkout --detach $(GCC_BASE_BRANCH_NAME) + + makeinfo --plaintext -I $(GCC_BASE_BRANCH_NAME)/gcc/doc -I $(GCC_BASE_BRANCH_NAME)/gcc/doc/include -I $@/tmp/orig -o $@/tmp/orig/gcc.txt $(GCC_BASE_BRANCH_NAME)/gcc/doc/gcc.texi + makeinfo --plaintext -I $(GCC_BASE_BRANCH_NAME)/gcc/doc -I $(GCC_BASE_BRANCH_NAME)/gcc/doc/include -I $@/tmp/orig -o $@/tmp/orig/cpp.txt $(GCC_BASE_BRANCH_NAME)/gcc/doc/cpp.texi + + makeinfo --plaintext -I $(GCC_SRC_DIR)/gcc/doc -I $(GCC_SRC_DIR)/gcc/doc/include -I $@/tmp/patched -o $@/tmp/patched/gcc.txt $(GCC_SRC_DIR)/gcc/doc/gcc.texi + makeinfo --plaintext -I $(GCC_SRC_DIR)/gcc/doc -I $(GCC_SRC_DIR)/gcc/doc/include -I $@/tmp/patched -o $@/tmp/patched/cpp.txt $(GCC_SRC_DIR)/gcc/doc/cpp.texi + + cd $@/tmp && bash -c "wdiff -n -w $$'\033[30;41m' -x $$'\033[0m' -y $$'\033[30;42m' -z $$'\033[0m' orig/gcc.txt patched/gcc.txt >../gcc.txt" || true + cd $@/tmp && bash -c "wdiff -n -w $$'\033[30;41m' -x $$'\033[0m' -y $$'\033[30;42m' -z $$'\033[0m' orig/cpp.txt patched/cpp.txt >../cpp.txt" || true + + rm -Rf $@/tmp +# +# Target for generating the ReadMe used for Aminet +# +ReadMe: ReadMe.mak + python -c "\ + from mako.template import Template;\ + from mako.lookup import TemplateLookup;\ + print Template(\ + filename='$<',\ + input_encoding='utf-8',\ + output_encoding='utf-8',\ + lookup=TemplateLookup(['./'],input_encoding='utf-8')).render(\ + DIST_VERSION='$(DIST_VERSION)',\ + ADTOOLS_COMMIT_SHA1='$(shell git rev-list HEAD -1)',\ + BINUTILS_VERSION='$(BINUTILS_VERSION)',\ + GCC_VERSION='$(GCC_VERSION)',\ + GCC_DEV_PHASE='$(GCC_DEV_PHASE)',\ + COREUTILS_VERSION='$(COREUTILS_VERSION)',\ + CLIB2_RELEASE_ARCHIVE_NAME='$(CLIB2_RELEASE_ARCHIVE_NAME)'\ + )\ + " >$@.utf8 + iconv --from-code=UTF8 --to-code=ISO-8859-15 $@.utf8 >$@ + +# Function to make a file whose name is prefixed by the target alias +# but which is the same as the given one. +# +# We use cp here until we know that softlinks would work properly. +define MAKE_TARGET_ALIAS + cp /gcc/bin/$(1) /gcc/bin/ppc-amigaos-$(1) +endef + +# A simple macro for inserting a newline +define NL + + +endef + +# +# Lists all executable files that are produced by the binutils steps +# and that also should be reachable via a target alias prefix. +# +BINUTILS_EXES = \ + addr2line \ + ar \ + as \ + c++filt \ + elfedit \ + gprof \ + ld \ + ld.bfd \ + nm \ + objcopy \ + objdump \ + ranlib \ + readelf \ + size \ + strings \ + strip + +# +# Install native compiler into /gcc. Needs write access to this directory +# +native-install: coreutils-native-done gcc-native-done-$(GCC_VERSION) ReadMe doc + rm -Rf /gcc/* + PATH="$(CROSS_PREFIX)/bin:$(PATH)" $(MAKE) -C binutils-native-build-$(BINUTILS_VERSION) install +# Create copies of few files that usually are also accessible via a filename with the target alias prefix + $(foreach EXE, $(BINUTILS_EXES), $(call MAKE_TARGET_ALIAS,$(EXE))$(NL)) + PATH="$(CROSS_PREFIX)/bin:$(PATH)" $(MAKE) -C gcc-native-build-$(GCC_VERSION) install + PATH="$(CROSS_PREFIX)/bin:$(PATH)" $(MAKE) -C coreutils-native-build install +# Disabled SDK as we don't want to distribute it +# cp -R $(CROSS_PREFIX)/ppc-amigaos/SDK /gcc +# Disabled, because we don't want to copy from CROSS_PREFIX here +# cp -Rf $(CROSS_PREFIX)/lib/gcc/ppc-amigaos /gcc/lib/gcc/ + # Delete all but our target gcc libs + find /gcc/lib/gcc/ppc-amigaos -mindepth 1 -maxdepth 1 -not -name $(GCC_VERSION) | xargs rm -Rf +# Disabled, no longer required +# # Move lib archives (e.g., libgcc.a into the proper directory) +# cd /gcc/lib/gcc ; for lib in `find -name *.a -o -name *.so`; do mkdir -p `dirname $$lib`/lib; mv $$lib `dirname $$lib`/lib ; done + cp ReadMe /gcc + mkdir -p /gcc/doc + cp doc/* /gcc/doc + +# +# Similar to native-install but deploys the components in separate directories +# +native-separate-install: + rm -Rf root-native-binutils + rm -Rf root-native-gcc + rm -Rf root-native-coreutils + PATH="$(CROSS_PREFIX)/bin:$(PATH)" $(MAKE) -C binutils-native-build-$(BINUTILS_VERSION) install DESTDIR=$(ROOT_DIR)/root-native-binutils + PATH="$(CROSS_PREFIX)/bin:$(PATH)" $(MAKE) -C gcc-native-build-$(GCC_VERSION) install DESTDIR=$(ROOT_DIR)/root-native-gcc + PATH="$(CROSS_PREFIX)/bin:$(PATH)" $(MAKE) -C coreutils-native-build install DESTDIR=$(ROOT_DIR)/root-native-coreutils + $(MAKE) private-native-separate-dist + +# Private target. Unfinished +private-native-separate-dist: + $(foreach var,$(wildcard $(ROOT_DIR)/root-native-coreutils/gcc/bin/*), $(STRIP) $(STRIPFLAGS) $(var) ; ) true + $(foreach var,$(wildcard $(ROOT_DIR)/root-native-binutils/gcc/bin/*), $(STRIP) $(STRIPFLAGS) $(var) ; ) true + $(foreach var,$(wildcard $(ROOT_DIR)/root-native-gcc/gcc/bin/*), $(STRIP) $(STRIPFLAGS) $(var) ; ) true + $(STRIP) $(STRIPFLAGS) $(ROOT_DIR)/root-native-gcc/gcc/libexec/gcc/ppc-amigaos/$(GCC_VERSION)/cc1 + $(STRIP) $(STRIPFLAGS) $(ROOT_DIR)/root-native-gcc/gcc/libexec/gcc/ppc-amigaos/$(GCC_VERSION)/cc1plus + $(STRIP) $(STRIPFLAGS) $(ROOT_DIR)/root-native-gcc/gcc/libexec/gcc/ppc-amigaos/$(GCC_VERSION)/lto1 + $(STRIP) $(STRIPFLAGS) $(ROOT_DIR)/root-native-gcc/gcc/libexec/gcc/ppc-amigaos/$(GCC_VERSION)/lto-wrapper + rm -Rf dist + mkdir -p dist/coreutils-$(COREUTILS_VERSION)-$(DIST_VERSION) + +# +# Strip native files +# +native-strip: +# Invoke make recursively with another target so that $(wildcard) is properly resolved. + $(MAKE) native-strip-really + +native-strip-really: + $(foreach var,$(wildcard /gcc/bin/*), $(STRIP) --strip-all --strip-unneeded-rel-relocs $(var) ; ) true + $(STRIP) $(STRIPFLAGS) /gcc/libexec/gcc/ppc-amigaos/$(GCC_VERSION)/cc1 + $(STRIP) $(STRIPFLAGS) /gcc/libexec/gcc/ppc-amigaos/$(GCC_VERSION)/cc1plus + $(STRIP) $(STRIPFLAGS) /gcc/libexec/gcc/ppc-amigaos/$(GCC_VERSION)/lto1 + $(STRIP) $(STRIPFLAGS) /gcc/libexec/gcc/ppc-amigaos/$(GCC_VERSION)/lto-wrapper + +# +# Native distribution archive +# +DIST_FOLDER:=adtools-os4-$(GCC_BRANCH_NAME)-$(DIST_VERSION) + +native-dist: native-strip-really + rm -f $(realpath .)/$(DIST_FOLDER).lha + rm -Rf /tmp/$(DIST_FOLDER) + mkdir /tmp/$(DIST_FOLDER) + cp -pR /gcc/* /tmp/$(DIST_FOLDER) + + # Deduplicate + ../bin/dedup /tmp/$(DIST_FOLDER) >.dedup + echo "; Create alternative filenames" >/tmp/$(DIST_FOLDER)/RestoreLinks + ../bin/dedup /tmp/$(DIST_FOLDER) --amigaos --folder-is-pwd >>/tmp/$(DIST_FOLDER)/RestoreLinks +# Disbaled until we find a way to keep softlinks via lha +# sh -x .dedup +# rm .dedup + + cd /tmp && lha ao5 $(realpath .)/$(DIST_FOLDER).lha $(DIST_FOLDER)/* + +# +# Clib2 distribution +# +clib2-dist: clib2-cross-done-$(GCC_VERSION) + cd root-cross/ppc-amigaos/SDK && lha ao5 $(realpath .)/$(CLIB2_RELEASE_ARCHIVE_NAME) clib2 + +# +# Upload the binary archive to the main Aminet server +# +.PHONY: upload-release +upload-release: native-dist + ln -s $(DIST_FOLDER).lha adtools-$(GCC_BRANCH_NAME)-os4.lha + lftp -e "put adtools-$(GCC_BRANCH_NAME)-os4.lha && put ReadMe -o adtools-$(GCC_BRANCH_NAME)-os4.readme && quit" ftp://main.aminet.net/new + +# +# Cleanup clib2 +# + +.PHONY: clean-clib2 +clean-clib2: + $(MAKE) -C $(CLIB2_DIR) -f GNUmakefile.os4 clean + +# +# Cleanup gcc only +# + +.PHONY: clean-gcc +clean-gcc: + rm -Rf \ + xgcc-done-$(GCC_VERSION) \ + gcc-cross-build-$(GCC_VERSION) \ + gcc-cross-done-$(GCC_VERSION) \ + gcc-native-build-$(GCC_VERSION) \ + gcc-native-done-$(GCC_VERSION) + +# +# Cleanup everything +# +.PHONY: clean +clean: clean-clib2 clean-gcc + rm -Rf \ + binutils-cross-build-$(BINUTILS_VERSION) \ + binutils-native-build-$(BINUTILS_VERSION) \ + $(CROSS_PREFIX) \ + build-cross-done \ + binutils-cross-build-done-$(BINUTILS_VERSION) \ + binutils-cross-done-$(BINUTILS_VERSION) \ + binutils-native-done-$(BINUTILS_VERSION) \ + clib2-cross-done-$(GCC_VERSION) \ + includes-done \ + libraries-done \ + root-native \ + coreutils-native-build \ + coreutils-native-done + +# +# Cleanup really everything +# +.PNONY: clean-all +clean-all: clean + rm -Rf downloads-done downloads-done-clib2 downloads diff --git a/files/native-build/makefile-SDK53.34 b/files/native-build/makefile-SDK53.34 new file mode 100644 index 0000000..7a6a7b7 --- /dev/null +++ b/files/native-build/makefile-SDK53.34 @@ -0,0 +1,513 @@ +# +# This makefile drives the native build done on a non-native system, i.e., +# before building the native compiler, a cross compiler will be build. +# We then build the native compiler using the freshly-built cross +# compiler. +# +# The user running this script must have write access to /gcc +# +# Define CROSS_IS_PRESENT=1 if a suitable cross compiler is already +# present, in which case the cross compiler build is skipped, e.g.: +# +# make CROSS_IS_PRESENT=1 +# + +ROOT_DIR=$(realpath .) + +# Compiler setup, utilize ccache if available +CCACHE:=$(shell which ccache) +HOST_GCC:=$(strip $(CCACHE) gcc) +HOST_GXX:=$(strip $(CCACHE) g++) + +GNU_SERVER=http://ftp.gnu.org/gnu +# GNU_SERVER=http://ftp.vim.org/ftp/gnu + +GMP_ARCHIVE=gmp-5.1.3.tar.bz2 +MPFR_ARCHIVE=mpfr-3.1.6.tar.bz2 +MPC_ARCHIVE=mpc-1.0.3.tar.gz + +BINUTILS_VERSION=2.23.2 +BINUTILS_SRC_DIR=../binutils/repo + +GCC_SRC_DIR=../gcc/repo +GCC_VERSION:=$(shell cat $(GCC_SRC_DIR)/gcc/BASE-VER) +GCC_DEV_PHASE:=$(shell cat ${GCC_SRC_DIR}/gcc/DEV-PHASE) + +ifneq ($(GCC_DEV_PHASE),) +GCC_DEV_PHASE:= ($(GCC_DEV_PHASE)) +endif + +GCC_BRANCH_NAME:=$(word 1, $(subst ., , $(GCC_VERSION))) + +SDK_URL=https://www.hyperion-entertainment.biz/index.php?option=com_registration&view=download&format=raw&file=125&Itemid=125 +SDK_VERSION=53.34 + +# Native tools +COREUTILS_SRC_DIR=../coreutils/repo +COREUTILS_VERSION=5.2.1 + +# Distribution version, used as middle part of a distribution archive +DIST_VERSION=$(shell date +%Y%m%d)-$(shell git rev-list --count HEAD) + +CLIB2_URL=https://github.com/sodero/clib2 +CLIB2_SHA1=18ff2b535a59fff8aa5237c08fe32551cb0bfe45 +# CLIB2_URL=https://github.com/sba1/clib2-1 +# CLIB2_SHA1=b874ff71deb55016a20f87483beb1ecbe226c55e +CLIB2_RELEASE_ARCHIVE_NAME=adtools-os4-clib2-$(DIST_VERSION).lha + +CROSS_PREFIX?=$(ROOT_DIR)/root-cross +# This assumes that cross prefix is absolute +DESTDIR?= + +STRIP=$(CROSS_PREFIX)/bin/ppc-amigaos-strip +STRIPFLAGS=--strip-all --strip-unneeded-rel-relocs -R.comment + +all: gcc-native-done-$(GCC_VERSION) + +# +# Print the dist version that is used as suffix for various +# suffixes. +# +.PHONY: print-dist-version +print-dist-version: + @echo $(DIST_VERSION) + +# +# Downloads clib2 +# +downloads-done-clib2: + mkdir -p downloads + cd downloads && (git clone $(CLIB2_URL) clib2 || true) && cd clib2 && git checkout $(CLIB2_SHA1) + touch $@ + +# +# Downloads the SDK and libraries necesseary to build the cross compiler +# +downloads-done: downloads-done-clib2 + wget "$(SDK_URL)" -O downloads/SDK_$(SDK_VERSION).lha + cd downloads && wget -N $(GNU_SERVER)/gmp/$(GMP_ARCHIVE) + cd downloads && wget -N $(GNU_SERVER)/mpfr/$(MPFR_ARCHIVE) + cd downloads && wget -N $(GNU_SERVER)/mpc/$(MPC_ARCHIVE) + touch $@ + +# +# Builds the cross binutils package (assembler, etc). +# +binutils-cross-build-done-$(BINUTILS_VERSION): + $(MAKE) -C ../binutils-build SRC_DIR=$(BINUTILS_SRC_DIR) PREFIX=$(CROSS_PREFIX) CROSS_BUILD_DIR=$(ROOT_DIR)/binutils-cross-build-$(BINUTILS_VERSION) + touch $@ + +.PHONY: binutils-build +binutils-build: binutils-cross-build-done-$(BINUTILS_VERSION) + +# +# Installs the cross binutils package (assembler, etc). +# +binutils-cross-done-$(BINUTILS_VERSION): binutils-cross-build-done-$(BINUTILS_VERSION) + $(MAKE) -C $(ROOT_DIR)/binutils-cross-build-$(BINUTILS_VERSION) install DESTDIR=$(DESTDIR) + touch $@ + +.PHONY: binutils-install +binutils-install: binutils-cross-done-$(BINUTILS_VERSION) + +# +# Prepares the includes +# +includes-done: downloads-done + mkdir -p $(CROSS_PREFIX)/ppc-amigaos/SDK/include + cd downloads && lha x SDK_$(SDK_VERSION).lha +# We built clib2 inplace +# cd downloads/SDK_Install && lha xf clib2*.lha + cd downloads/SDK_Install && lha xf newlib*.lha + cd downloads/SDK_Install && lha xf base.lha + cd downloads/SDK_Install && rm -Rf *.lha + cd downloads/SDK_Install && mv newlib* $(CROSS_PREFIX)/ppc-amigaos/SDK +# cd downloads/SDK_Install && mv clib2* $(CROSS_PREFIX)/ppc-amigaos/SDK + cd downloads/SDK_Install && mv Include/* $(CROSS_PREFIX)/ppc-amigaos/SDK/include +# Copying the latest execsg private sdk header files + cp -r /tmp/execsg_private_sdk/SDK/Include/* $(CROSS_PREFIX)/ppc-amigaos/SDK/include/ + rm -Rf downloads/SDK_Install downloads/SDK_Install.info + touch $@ + +# +# Path to the initial cross compiler or standard +# cross compiler if a cross compiler is present +# + +ifeq ($(CROSS_IS_PRESENT),1) + +XGCC=ppc-amigaos-gcc +XGCC_CC=ppc-amigaos-gcc +XAR=ppc-amigaos-ar -q +XRANLIB=ppc-amigaos-ranlib + +CLIB2_CROSS_DONE_DEPENDENCY=downloads-done-clib2 + +else + +XGCC_DIR=$(abspath .)/gcc-cross-build-$(GCC_VERSION)/gcc +XGCC=$(XGCC_DIR)/xgcc +XGCC_CC=$(XGCC) -B $(XGCC_DIR) +XAR=$(CROSS_PREFIX)/bin/ppc-amigaos-ar -q +XRANLIB=$(CROSS_PREFIX)/bin/ppc-amigaos-ranlib + +CLIB2_CROSS_DONE_DEPENDENCY=xgcc-done-$(GCC_VERSION) + +endif + +CLIB2_DIR=downloads/clib2/library + +# +# Prints the folder where the basic xg (xgcc or xg++) compilers +# can be round. +# +.PHONY: print-xg-dir +print-xg-dir: + @echo $(XGCC_DIR) + +# +# Build only xgcc, no other stuff like libstdc++ etc. +# +xgcc-done-$(GCC_VERSION): includes-done binutils-cross-done-$(BINUTILS_VERSION) + CC="$(HOST_GCC)" CXX="$(HOST_GXX)" $(MAKE) -C ../gcc-build cross-configure \ + SRC_DIR=$(GCC_SRC_DIR) \ + PREFIX=$(CROSS_PREFIX) \ + CROSS_BUILD_DIR=$(ROOT_DIR)/gcc-cross-build-$(GCC_VERSION) \ + VERSION=$(GCC_VERSION) + $(MAKE) -C $(ROOT_DIR)/gcc-cross-build-$(GCC_VERSION) all-gcc + touch $@ + +# +# Build clib2 via xgcc +# +clib2-cross-done-$(GCC_VERSION): $(CLIB2_CROSS_DONE_DEPENDENCY) +# Build clib2 using xgcc that have just been built + $(MAKE) -C $(CLIB2_DIR) -f GNUmakefile.os4 CC="$(XGCC_CC)" AR="$(XAR)" RANLIB="$(XRANLIB)" +# Copy clib2 libs and includes + rm -Rf $(CROSS_PREFIX)/ppc-amigaos/SDK/clib2/lib $(CROSS_PREFIX)/ppc-amigaos/SDK/clib2/include + mkdir -p $(CROSS_PREFIX)/ppc-amigaos/SDK/clib2/lib + mkdir -p $(CROSS_PREFIX)/ppc-amigaos/SDK/clib2/include + cp -Rp $(CLIB2_DIR)/include/* $(CROSS_PREFIX)/ppc-amigaos/SDK/clib2/include + cp -Rp $(CLIB2_DIR)/lib/* $(CROSS_PREFIX)/ppc-amigaos/SDK/clib2/lib + cp $(CLIB2_DIR)/../LICENSE $(CROSS_PREFIX)/ppc-amigaos/SDK/clib2 + touch $@ + +# +# Build the cross compiler +# +gcc-cross-done-$(GCC_VERSION): clib2-cross-done-$(GCC_VERSION) +# Compile remaining + $(MAKE) -C $(ROOT_DIR)/gcc-cross-build-$(GCC_VERSION) + $(MAKE) -C $(ROOT_DIR)/gcc-cross-build-$(GCC_VERSION) install + touch $@ + +.PHONY: gcc-cross +gcc-cross: gcc-cross-done-$(GCC_VERSION) + +# +# Optional target for additional libs +# +.PHONY: additionals-libs +additionals-libs: + mkdir -p $(CROSS_PREFIX)/ppc-amigaos/SDK/local/common/include + mkdir -p /tmp/abcd + cd downloads && lha xw=/tmp/abcd SDK_$(SDK_VERSION).lha + cd /tmp/abcd/SDK_Install && lha x pthread.lha && lha x zlib-1.2.3.lha + cp -Rf /tmp/abcd/SDK_Install/Local/* $(CROSS_PREFIX)/ppc-amigaos/SDK/local + rm -Rf /tmp/abcd + + +ifeq ($(CROSS_IS_PRESENT),1) +NATIVE_LIBRARY_DEPENDENCIES=downloads-done +else +NATIVE_LIBRARY_DEPENDENCIES=gcc-cross-done-$(GCC_VERSION) +endif + +# +# Build and install the libraries +# +libraries-done: $(NATIVE_LIBRARY_DEPENDENCIES) + cd downloads && tar -xjf $(notdir $(GMP_ARCHIVE)) + cd downloads && tar -xjf $(notdir $(MPFR_ARCHIVE)) + cd downloads && tar -xzf $(notdir $(MPC_ARCHIVE)) + cd $(basename $(basename downloads/$(notdir $(GMP_ARCHIVE)))) && PATH="$(CROSS_PREFIX)/bin:$(PATH)" ./configure --host=ppc-amigaos --prefix=$(CROSS_PREFIX) && PATH="$(CROSS_PREFIX)/bin:$(PATH)" make install + cd $(basename $(basename downloads/$(notdir $(MPFR_ARCHIVE)))) && PATH="$(CROSS_PREFIX)/bin:$(PATH)" ./configure --host=ppc-amigaos --prefix=$(CROSS_PREFIX) -with-gmp=$(CROSS_PREFIX) && PATH="$(CROSS_PREFIX)/bin:$(PATH)" make install + cd $(basename $(basename downloads/$(notdir $(MPC_ARCHIVE)))) && PATH="$(CROSS_PREFIX)/bin:$(PATH)" ./configure --host=ppc-amigaos --prefix=$(CROSS_PREFIX) --with-gmp=$(CROSS_PREFIX) --with-mpfr=$(CROSS_PREFIX) && PATH="$(CROSS_PREFIX)/bin:$(PATH)" make install + touch $@ + +# +# Build the native binutils +# +binutils-native-done-$(BINUTILS_VERSION): libraries-done + PATH="$(CROSS_PREFIX)/bin:$(PATH)" $(MAKE) -C ../binutils-build native \ + SRC_DIR=$(BINUTILS_SRC_DIR) \ + PREFIX=/gcc \ + NATIVE_BUILD_DIR=$(ROOT_DIR)/binutils-native-build-$(BINUTILS_VERSION) + touch $@ + +# +# Build the native gcc +# +gcc-native-done-$(GCC_VERSION): binutils-native-done-$(BINUTILS_VERSION) + mkdir -p $(ROOT_DIR)/root-native/gcc/include + mkdir -p /gcc/include + PATH="$(CROSS_PREFIX)/bin:$(PATH)" $(MAKE) -C ../gcc-build native \ + SRC_DIR=$(GCC_SRC_DIR) \ + PREFIX=/gcc \ + NATIVE_BUILD_DIR=$(ROOT_DIR)/gcc-native-build-$(GCC_VERSION) \ + VERSION=$(GCC_VERSION) \ + LIB_PATH=$(CROSS_PREFIX) \ + NATIVE_SYS_ROOT=$(ROOT_DIR)/root-native + touch $@ + +ifeq ($(CROSS_IS_PRESENT),1) +coreutils-native-done: +else +coreutils-native-done: gcc-cross-done-$(GCC_VERSION) +endif + mkdir -p coreutils-native-build + @if [ ! -f $(COREUTILS_SRC_DIR)/configure ]; then echo "Please checkout coreutils first!"; false; fi +# Pretend few files to be uptodate + touch $(realpath $(COREUTILS_SRC_DIR))/configure $(realpath $(COREUTILS_SRC_DIR))/config.hin +# cd coreutils-native-build ; PATH="$(CROSS_PREFIX)/bin:$(PATH)" LIBS="-lunix" $(realpath $(COREUTILS_SRC_DIR))/configure --prefix=/gcc --host=ppc-amigaos + cd coreutils-native-build ; PATH="$(CROSS_PREFIX)/bin:$(PATH)" CPPFLAGS="-mcrt=clib2" LDFLAGS="-mcrt=clib2" LIBS="-lunix -lnet" $(realpath $(COREUTILS_SRC_DIR))/configure --prefix=/gcc --host=ppc-amigaos --disable-maintainer-mode + PATH="$(CROSS_PREFIX)/bin:$(PATH)" $(MAKE) -C coreutils-native-build + touch $@ + + +GCC_BASE_BRANCH_NAME=$(GCC_BRANCH_NAME)-base +# +# Build the main docs +# +.PHONY: doc +doc: + rm -Rf $@ + mkdir -p $@/tmp/orig + mkdir -p $@/tmp/patched + + echo "@set version-GCC $(GCC_VERSION)-adtools" >$@/tmp/orig/gcc-vers.texi + echo "@set srcdir $(ROOT_DIR)/$(GCC_BASE_BRANCH_NAME)/gcc" >>$@/tmp/orig/gcc-vers.texi + echo "@set BUGURL https://github.com/sba1/adtools/issues" >>$@/tmp/orig/gcc-vers.texi + + echo "@set version-GCC $(GCC_VERSION)-adtools" >$@/tmp/patched/gcc-vers.texi + echo "@set srcdir $(GCC_SRC_DIR)/gcc" >>$@/tmp/patched/gcc-vers.texi + echo "@set BUGURL https://github.com/sba1/adtools/issues" >>$@/tmp/patched/gcc-vers.texi + + # Checkout base branch as worktree + cd $(GCC_SRC_DIR) && git worktree add -f $(ROOT_DIR)/$(GCC_BASE_BRANCH_NAME) $(GCC_BASE_BRANCH_NAME) || true + cd $(ROOT_DIR)/$(GCC_BASE_BRANCH_NAME) && git checkout --detach $(GCC_BASE_BRANCH_NAME) + + makeinfo --plaintext -I $(GCC_BASE_BRANCH_NAME)/gcc/doc -I $(GCC_BASE_BRANCH_NAME)/gcc/doc/include -I $@/tmp/orig -o $@/tmp/orig/gcc.txt $(GCC_BASE_BRANCH_NAME)/gcc/doc/gcc.texi + makeinfo --plaintext -I $(GCC_BASE_BRANCH_NAME)/gcc/doc -I $(GCC_BASE_BRANCH_NAME)/gcc/doc/include -I $@/tmp/orig -o $@/tmp/orig/cpp.txt $(GCC_BASE_BRANCH_NAME)/gcc/doc/cpp.texi + + makeinfo --plaintext -I $(GCC_SRC_DIR)/gcc/doc -I $(GCC_SRC_DIR)/gcc/doc/include -I $@/tmp/patched -o $@/tmp/patched/gcc.txt $(GCC_SRC_DIR)/gcc/doc/gcc.texi + makeinfo --plaintext -I $(GCC_SRC_DIR)/gcc/doc -I $(GCC_SRC_DIR)/gcc/doc/include -I $@/tmp/patched -o $@/tmp/patched/cpp.txt $(GCC_SRC_DIR)/gcc/doc/cpp.texi + + cd $@/tmp && bash -c "wdiff -n -w $$'\033[30;41m' -x $$'\033[0m' -y $$'\033[30;42m' -z $$'\033[0m' orig/gcc.txt patched/gcc.txt >../gcc.txt" || true + cd $@/tmp && bash -c "wdiff -n -w $$'\033[30;41m' -x $$'\033[0m' -y $$'\033[30;42m' -z $$'\033[0m' orig/cpp.txt patched/cpp.txt >../cpp.txt" || true + + rm -Rf $@/tmp +# +# Target for generating the ReadMe used for Aminet +# +ReadMe: ReadMe.mak + python -c "\ + from mako.template import Template;\ + from mako.lookup import TemplateLookup;\ + print Template(\ + filename='$<',\ + input_encoding='utf-8',\ + output_encoding='utf-8',\ + lookup=TemplateLookup(['./'],input_encoding='utf-8')).render(\ + DIST_VERSION='$(DIST_VERSION)',\ + ADTOOLS_COMMIT_SHA1='$(shell git rev-list HEAD -1)',\ + BINUTILS_VERSION='$(BINUTILS_VERSION)',\ + GCC_VERSION='$(GCC_VERSION)',\ + GCC_DEV_PHASE='$(GCC_DEV_PHASE)',\ + COREUTILS_VERSION='$(COREUTILS_VERSION)',\ + CLIB2_RELEASE_ARCHIVE_NAME='$(CLIB2_RELEASE_ARCHIVE_NAME)'\ + )\ + " >$@.utf8 + iconv --from-code=UTF8 --to-code=ISO-8859-15 $@.utf8 >$@ + +# Function to make a file whose name is prefixed by the target alias +# but which is the same as the given one. +# +# We use cp here until we know that softlinks would work properly. +define MAKE_TARGET_ALIAS + cp /gcc/bin/$(1) /gcc/bin/ppc-amigaos-$(1) +endef + +# A simple macro for inserting a newline +define NL + + +endef + +# +# Lists all executable files that are produced by the binutils steps +# and that also should be reachable via a target alias prefix. +# +BINUTILS_EXES = \ + addr2line \ + ar \ + as \ + c++filt \ + elfedit \ + gprof \ + ld \ + ld.bfd \ + nm \ + objcopy \ + objdump \ + ranlib \ + readelf \ + size \ + strings \ + strip + +# +# Install native compiler into /gcc. Needs write access to this directory +# +native-install: coreutils-native-done gcc-native-done-$(GCC_VERSION) ReadMe doc + rm -Rf /gcc/* + PATH="$(CROSS_PREFIX)/bin:$(PATH)" $(MAKE) -C binutils-native-build-$(BINUTILS_VERSION) install +# Create copies of few files that usually are also accessible via a filename with the target alias prefix + $(foreach EXE, $(BINUTILS_EXES), $(call MAKE_TARGET_ALIAS,$(EXE))$(NL)) + PATH="$(CROSS_PREFIX)/bin:$(PATH)" $(MAKE) -C gcc-native-build-$(GCC_VERSION) install + PATH="$(CROSS_PREFIX)/bin:$(PATH)" $(MAKE) -C coreutils-native-build install +# Disabled SDK as we don't want to distribute it +# cp -R $(CROSS_PREFIX)/ppc-amigaos/SDK /gcc +# Disabled, because we don't want to copy from CROSS_PREFIX here +# cp -Rf $(CROSS_PREFIX)/lib/gcc/ppc-amigaos /gcc/lib/gcc/ + # Delete all but our target gcc libs + find /gcc/lib/gcc/ppc-amigaos -mindepth 1 -maxdepth 1 -not -name $(GCC_VERSION) | xargs rm -Rf +# Disabled, no longer required +# # Move lib archives (e.g., libgcc.a into the proper directory) +# cd /gcc/lib/gcc ; for lib in `find -name *.a -o -name *.so`; do mkdir -p `dirname $$lib`/lib; mv $$lib `dirname $$lib`/lib ; done + cp ReadMe /gcc + mkdir -p /gcc/doc + cp doc/* /gcc/doc + +# +# Similar to native-install but deploys the components in separate directories +# +native-separate-install: + rm -Rf root-native-binutils + rm -Rf root-native-gcc + rm -Rf root-native-coreutils + PATH="$(CROSS_PREFIX)/bin:$(PATH)" $(MAKE) -C binutils-native-build-$(BINUTILS_VERSION) install DESTDIR=$(ROOT_DIR)/root-native-binutils + PATH="$(CROSS_PREFIX)/bin:$(PATH)" $(MAKE) -C gcc-native-build-$(GCC_VERSION) install DESTDIR=$(ROOT_DIR)/root-native-gcc + PATH="$(CROSS_PREFIX)/bin:$(PATH)" $(MAKE) -C coreutils-native-build install DESTDIR=$(ROOT_DIR)/root-native-coreutils + $(MAKE) private-native-separate-dist + +# Private target. Unfinished +private-native-separate-dist: + $(foreach var,$(wildcard $(ROOT_DIR)/root-native-coreutils/gcc/bin/*), $(STRIP) $(STRIPFLAGS) $(var) ; ) true + $(foreach var,$(wildcard $(ROOT_DIR)/root-native-binutils/gcc/bin/*), $(STRIP) $(STRIPFLAGS) $(var) ; ) true + $(foreach var,$(wildcard $(ROOT_DIR)/root-native-gcc/gcc/bin/*), $(STRIP) $(STRIPFLAGS) $(var) ; ) true + $(STRIP) $(STRIPFLAGS) $(ROOT_DIR)/root-native-gcc/gcc/libexec/gcc/ppc-amigaos/$(GCC_VERSION)/cc1 + $(STRIP) $(STRIPFLAGS) $(ROOT_DIR)/root-native-gcc/gcc/libexec/gcc/ppc-amigaos/$(GCC_VERSION)/cc1plus + $(STRIP) $(STRIPFLAGS) $(ROOT_DIR)/root-native-gcc/gcc/libexec/gcc/ppc-amigaos/$(GCC_VERSION)/lto1 + $(STRIP) $(STRIPFLAGS) $(ROOT_DIR)/root-native-gcc/gcc/libexec/gcc/ppc-amigaos/$(GCC_VERSION)/lto-wrapper + rm -Rf dist + mkdir -p dist/coreutils-$(COREUTILS_VERSION)-$(DIST_VERSION) + +# +# Strip native files +# +native-strip: +# Invoke make recursively with another target so that $(wildcard) is properly resolved. + $(MAKE) native-strip-really + +native-strip-really: + $(foreach var,$(wildcard /gcc/bin/*), $(STRIP) --strip-all --strip-unneeded-rel-relocs $(var) ; ) true + $(STRIP) $(STRIPFLAGS) /gcc/libexec/gcc/ppc-amigaos/$(GCC_VERSION)/cc1 + $(STRIP) $(STRIPFLAGS) /gcc/libexec/gcc/ppc-amigaos/$(GCC_VERSION)/cc1plus + $(STRIP) $(STRIPFLAGS) /gcc/libexec/gcc/ppc-amigaos/$(GCC_VERSION)/lto1 + $(STRIP) $(STRIPFLAGS) /gcc/libexec/gcc/ppc-amigaos/$(GCC_VERSION)/lto-wrapper + +# +# Native distribution archive +# +DIST_FOLDER:=adtools-os4-$(GCC_BRANCH_NAME)-$(DIST_VERSION) + +native-dist: native-strip-really + rm -f $(realpath .)/$(DIST_FOLDER).lha + rm -Rf /tmp/$(DIST_FOLDER) + mkdir /tmp/$(DIST_FOLDER) + cp -pR /gcc/* /tmp/$(DIST_FOLDER) + + # Deduplicate + ../bin/dedup /tmp/$(DIST_FOLDER) >.dedup + echo "; Create alternative filenames" >/tmp/$(DIST_FOLDER)/RestoreLinks + ../bin/dedup /tmp/$(DIST_FOLDER) --amigaos --folder-is-pwd >>/tmp/$(DIST_FOLDER)/RestoreLinks +# Disbaled until we find a way to keep softlinks via lha +# sh -x .dedup +# rm .dedup + + # cd /tmp && lha ao5 $(realpath .)/$(DIST_FOLDER).lha $(DIST_FOLDER)/* + cd /tmp && lha -aq2o6 $(realpath .)/$(DIST_FOLDER).lha $(DIST_FOLDER)/* + +# +# Clib2 distribution +# +clib2-dist: clib2-cross-done-$(GCC_VERSION) + # cd root-cross/ppc-amigaos/SDK && lha ao5 $(realpath .)/$(CLIB2_RELEASE_ARCHIVE_NAME) clib2 + cd root-cross/ppc-amigaos/SDK && lha -aq2o6 $(realpath .)/$(CLIB2_RELEASE_ARCHIVE_NAME) clib2 + +# +# Upload the binary archive to the main Aminet server +# +.PHONY: upload-release +upload-release: native-dist + ln -s $(DIST_FOLDER).lha adtools-$(GCC_BRANCH_NAME)-os4.lha + lftp -e "put adtools-$(GCC_BRANCH_NAME)-os4.lha && put ReadMe -o adtools-$(GCC_BRANCH_NAME)-os4.readme && quit" ftp://main.aminet.net/new + +# +# Cleanup clib2 +# + +.PHONY: clean-clib2 +clean-clib2: + test ! -d $(CLIB2_DIR) && true || $(MAKE) -C $(CLIB2_DIR) -f GNUmakefile.os4 clean + +# +# Cleanup gcc only +# + +.PHONY: clean-gcc +clean-gcc: + rm -Rf \ + xgcc-done-$(GCC_VERSION) \ + gcc-cross-build-$(GCC_VERSION) \ + gcc-cross-done-$(GCC_VERSION) \ + gcc-native-build-$(GCC_VERSION) \ + gcc-native-done-$(GCC_VERSION) + +# +# Cleanup everything +# +.PHONY: clean +clean: clean-clib2 clean-gcc + rm -Rf \ + binutils-cross-build-$(BINUTILS_VERSION) \ + binutils-native-build-$(BINUTILS_VERSION) \ + $(CROSS_PREFIX) \ + build-cross-done \ + binutils-cross-build-done-$(BINUTILS_VERSION) \ + binutils-cross-done-$(BINUTILS_VERSION) \ + binutils-native-done-$(BINUTILS_VERSION) \ + clib2-cross-done-$(GCC_VERSION) \ + includes-done \ + libraries-done \ + root-native \ + coreutils-native-build \ + coreutils-native-done + +# +# Cleanup really everything +# +.PNONY: clean-all +clean-all: clean + rm -Rf downloads-done downloads-done-clib2 downloads