From 8410abb3d9e16bdc9331c5a4842a5de0210bd9f6 Mon Sep 17 00:00:00 2001 From: mintsuki Date: Fri, 18 Sep 2020 21:38:59 +0200 Subject: [PATCH] Build gzip and nasm as part of the toolchain to ensure reproducibility --- Makefile | 2 +- decompressor/Makefile | 6 ++--- stage2/Makefile | 6 ++--- toolchain/make_toolchain.sh | 51 ++++++++++++++++++++++++------------- 4 files changed, 40 insertions(+), 25 deletions(-) diff --git a/Makefile b/Makefile index 669c8c89..f6a1301b 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ CC = cc CFLAGS = -O2 -pipe -Wall -Wextra +PATH := $(shell pwd)/toolchain/bin:$(PATH) .PHONY: all clean stage2 stage2-clean decompressor decompressor-clean toolchain test.img echfs-test ext2-test fat32-test @@ -10,7 +11,6 @@ all: stage2 decompressor clean: stage2-clean decompressor-clean rm -f stage2/stage2.bin.gz rm -f limine-install - # We don't remove limine.bin because not everyone wants to build the bootloader themselves. stage2: $(MAKE) -C stage2 all diff --git a/decompressor/Makefile b/decompressor/Makefile index 734a309b..4fd006c5 100644 --- a/decompressor/Makefile +++ b/decompressor/Makefile @@ -1,6 +1,6 @@ -CC = ../toolchain/bin/i386-elf-gcc -LD = ../toolchain/bin/i386-elf-gcc -OBJCOPY = ../toolchain/bin/i386-elf-objcopy +CC = i386-elf-gcc +LD = i386-elf-gcc +OBJCOPY = i386-elf-objcopy CFLAGS = -flto -Os -pipe -Wall -Wextra diff --git a/stage2/Makefile b/stage2/Makefile index e54cf336..1e998921 100644 --- a/stage2/Makefile +++ b/stage2/Makefile @@ -1,6 +1,6 @@ -CC = ../toolchain/bin/i386-elf-gcc -LD = ../toolchain/bin/i386-elf-gcc -OBJCOPY = ../toolchain/bin/i386-elf-objcopy +CC = i386-elf-gcc +LD = i386-elf-gcc +OBJCOPY = i386-elf-objcopy CFLAGS = -flto -Os -pipe -Wall -Wextra diff --git a/toolchain/make_toolchain.sh b/toolchain/make_toolchain.sh index 00eb5230..f743d282 100755 --- a/toolchain/make_toolchain.sh +++ b/toolchain/make_toolchain.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/bin/sh set -e set -x @@ -7,6 +7,8 @@ PREFIX="$(pwd)" TARGET=i386-elf BINUTILSVERSION=2.35 GCCVERSION=10.2.0 +NASMVERSION=2.15.05 +GZIPVERSION=1.10 if [ -z "$MAKEFLAGS" ]; then MAKEFLAGS="$1" @@ -15,29 +17,27 @@ export MAKEFLAGS export PATH="$PREFIX/bin:$PATH" -if [ -x "$(command -v gmake)" ]; then - mkdir -p "$PREFIX/bin" - cat <"$PREFIX/bin/make" -#!/usr/bin/env sh -gmake "\$@" -EOF - chmod +x "$PREFIX/bin/make" -fi - -mkdir -p build -cd build - if [ ! -f binutils-$BINUTILSVERSION.tar.gz ]; then - wget -4 https://ftp.gnu.org/gnu/binutils/binutils-$BINUTILSVERSION.tar.gz # Force IPv4 otherwise wget hangs + wget https://ftp.gnu.org/gnu/binutils/binutils-$BINUTILSVERSION.tar.gz fi if [ ! -f gcc-$GCCVERSION.tar.gz ]; then - wget -4 https://ftp.gnu.org/gnu/gcc/gcc-$GCCVERSION/gcc-$GCCVERSION.tar.gz # Same as above + wget https://ftp.gnu.org/gnu/gcc/gcc-$GCCVERSION/gcc-$GCCVERSION.tar.gz +fi +if [ ! -f nasm-$NASMVERSION.tar.gz ]; then + wget https://www.nasm.us/pub/nasm/releasebuilds/$NASMVERSION/nasm-$NASMVERSION.tar.gz +fi +if [ ! -f gzip-$GZIPVERSION.tar.gz ]; then + wget https://ftp.gnu.org/gnu/gzip/gzip-$GZIPVERSION.tar.gz fi -tar -xf binutils-$BINUTILSVERSION.tar.gz -tar -xf gcc-$GCCVERSION.tar.gz +rm -rf build +mkdir build +cd build -rm -rf build-gcc build-binutils +tar -xf ../binutils-$BINUTILSVERSION.tar.gz +tar -xf ../gcc-$GCCVERSION.tar.gz +tar -xf ../nasm-$NASMVERSION.tar.gz +tar -xf ../gzip-$GZIPVERSION.tar.gz mkdir build-binutils cd build-binutils @@ -56,3 +56,18 @@ make all-gcc make all-target-libgcc make install-gcc make install-target-libgcc +cd .. + +mkdir build-nasm +cd build-nasm +../nasm-$NASMVERSION/configure --prefix="$PREFIX" +make +make install +cd .. + +mkdir build-gzip +cd build-gzip +../gzip-$GZIPVERSION/configure --prefix="$PREFIX" +make +make install +cd ..