introduce scripting engine

This commit is contained in:
nakst 2022-01-28 09:47:26 +00:00
parent 50060594c2
commit b6e8b8f17f
14 changed files with 4891 additions and 141 deletions

View File

@ -3,7 +3,7 @@ set -e
SYSROOT=`realpath root`
VERSION=2.6.9
bin/build get-source-checked ee5b677fd9b1b9f484b5aeb4614f43df21993088c0c0571187f93acb0866e98c bochs-$VERSION https://netix.dl.sourceforge.net/project/bochs/bochs/$VERSION/bochs-$VERSION.tar.gz
bin/script util/get_source.script checksum=ee5b677fd9b1b9f484b5aeb4614f43df21993088c0c0571187f93acb0866e98c directoryName=bochs-$VERSION url=https://netix.dl.sourceforge.net/project/bochs/bochs/$VERSION/bochs-$VERSION.tar.gz
cd bin/source
cp ../../ports/bochs/config.cc .

View File

@ -5,7 +5,7 @@ VERSION=1.33.1
uname -a | grep Darwin && PATH="/usr/local/opt/gnu-sed/libexec/gnubin:$PATH"
bin/build get-source-checked 12cec6bd2b16d8a9446dd16130f2b92982f1819f6e1c5f5887b6db03f5660d28 busybox-$VERSION https://www.busybox.net/downloads/busybox-$VERSION.tar.bz2
bin/script util/get_source.script checksum=12cec6bd2b16d8a9446dd16130f2b92982f1819f6e1c5f5887b6db03f5660d28 directoryName=busybox-$VERSION url=https://www.busybox.net/downloads/busybox-$VERSION.tar.bz2
cd bin/source
cp ../../ports/busybox/config .config
sed -i "51 i CONFIG_SYSROOT=\"$SYSROOT\"" .config

View File

@ -1,7 +1,7 @@
set -e
SYSROOT=`realpath root`
VERSION=4.3.1
bin/build get-source-checked ad009240d46e307b4e03a213a0f49c11b650e445b1f8be0dda2a9212b34d2ffb ffmpeg-$VERSION https://ffmpeg.org/releases/ffmpeg-$VERSION.tar.xz
bin/script util/get_source.script checksum=ad009240d46e307b4e03a213a0f49c11b650e445b1f8be0dda2a9212b34d2ffb directoryName=ffmpeg-$VERSION url=https://ffmpeg.org/releases/ffmpeg-$VERSION.tar.xz
mkdir bin/build-ffmpeg
cd bin/build-ffmpeg
../source/configure --disable-all --cc=x86_64-essence-gcc --cxx=x86_64-essence-g++ --enable-cross-compile --enable-avcodec --enable-avformat --enable-swscale --enable-decoder=h264 --enable-parser=h264 --enable-decoder=aac --enable-parser=aac --enable-demuxer=mov --enable-protocol=file --disable-pthreads --prefix=/Applications/POSIX

View File

@ -3,7 +3,7 @@ set -e
if [ ! -d "bin/freetype" ]; then
echo "Downloading FreeType..."
bin/build get-source-checked bf380e4d7c4f3b5b1c1a7b2bf3abb967bda5e9ab480d0df656e0e08c5019c5e6 freetype-2.9 https://download.savannah.gnu.org/releases/freetype/freetype-2.9.tar.gz
bin/script util/get_source.script checksum=bf380e4d7c4f3b5b1c1a7b2bf3abb967bda5e9ab480d0df656e0e08c5019c5e6 directoryName=freetype-2.9 url=https://download.savannah.gnu.org/releases/freetype/freetype-2.9.tar.gz
mv bin/source bin/freetype
cp ports/freetype/patch-ftoption.h bin/freetype/include/freetype/config/ftoption.h

View File

@ -9,15 +9,15 @@ MPFR_VERSION=4.1.0
MPC_VERSION=1.2.1
rm -rf bin/gcc-src bin/binutils-src bin/mpc-src bin/gmp-src bin/mpfr-src
bin/build get-source-checked e81d9edf373f193af428a0f256674aea62a9d74dfe93f65192d4eae030b0f3b0 binutils-$BINUTILS_VERSION ftp://ftp.gnu.org/gnu/binutils/binutils-$BINUTILS_VERSION.tar.xz
bin/script util/get_source.script checksum=e81d9edf373f193af428a0f256674aea62a9d74dfe93f65192d4eae030b0f3b0 directoryName=binutils-$BINUTILS_VERSION url=ftp://ftp.gnu.org/gnu/binutils/binutils-$BINUTILS_VERSION.tar.xz
mv bin/source bin/binutils-src
bin/build get-source-checked 4c4a6fb8a8396059241c2e674b85b351c26a5d678274007f076957afa1cc9ddf gcc-$GCC_VERSION ftp://ftp.gnu.org/gnu/gcc/gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.xz
bin/script util/get_source.script checksum=4c4a6fb8a8396059241c2e674b85b351c26a5d678274007f076957afa1cc9ddf directoryName=gcc-$GCC_VERSION url=ftp://ftp.gnu.org/gnu/gcc/gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.xz
mv bin/source bin/gcc-src
bin/build get-source-checked fd4829912cddd12f84181c3451cc752be224643e87fac497b69edddadc49b4f2 gmp-$GMP_VERSION ftp://ftp.gnu.org/gnu/gmp/gmp-$GMP_VERSION.tar.xz
bin/script util/get_source.script checksum=fd4829912cddd12f84181c3451cc752be224643e87fac497b69edddadc49b4f2 directoryName=gmp-$GMP_VERSION url=ftp://ftp.gnu.org/gnu/gmp/gmp-$GMP_VERSION.tar.xz
mv bin/source bin/gmp-src
bin/build get-source-checked 0c98a3f1732ff6ca4ea690552079da9c597872d30e96ec28414ee23c95558a7f mpfr-$MPFR_VERSION ftp://ftp.gnu.org/gnu/mpfr/mpfr-$MPFR_VERSION.tar.xz
bin/script util/get_source.script checksum=0c98a3f1732ff6ca4ea690552079da9c597872d30e96ec28414ee23c95558a7f directoryName=mpfr-$MPFR_VERSION url=ftp://ftp.gnu.org/gnu/mpfr/mpfr-$MPFR_VERSION.tar.xz
mv bin/source bin/mpfr-src
bin/build get-source-checked 17503d2c395dfcf106b622dc142683c1199431d095367c6aacba6eec30340459 mpc-$MPC_VERSION ftp://ftp.gnu.org/gnu/mpc/mpc-$MPC_VERSION.tar.gz
bin/script util/get_source.script checksum=17503d2c395dfcf106b622dc142683c1199431d095367c6aacba6eec30340459 directoryName=mpc-$MPC_VERSION url=ftp://ftp.gnu.org/gnu/mpc/mpc-$MPC_VERSION.tar.gz
mv bin/source bin/mpc-src
cp ports/gcc/changes/binutils_bfd_config.bfd bin/binutils-src/bfd/config.bfd

View File

@ -58,7 +58,7 @@ CFLAGS="-DHAVE_CONFIG_H -I. -I.. -ffreestanding -fno-rtti -g -O3 -DHB_TINY -fno-
if [ ! -d "bin/harfbuzz" ]; then
echo "Downloading Harfbuzz..."
bin/build get-source-checked 9413b8d96132d699687ef914ebb8c50440efc87b3f775d25856d7ec347c03c12 harfbuzz-2.6.4 https://www.freedesktop.org/software/harfbuzz/release/harfbuzz-2.6.4.tar.xz
bin/script util/get_source.script checksum=9413b8d96132d699687ef914ebb8c50440efc87b3f775d25856d7ec347c03c12 directoryName=harfbuzz-2.6.4 url=https://www.freedesktop.org/software/harfbuzz/release/harfbuzz-2.6.4.tar.xz
mv bin/source bin/harfbuzz
cd bin/harfbuzz

View File

@ -1,7 +1,7 @@
set -ex
rm -rf bin/mesa
bin/build get-source-checked df21351494f7caaec5a3ccc16f14f15512e98d2ecde178bba1d134edc899b961 mesa-20.1.8 https://archive.mesa3d.org//mesa-20.1.8.tar.xz
bin/script util/get_source.script checksum=df21351494f7caaec5a3ccc16f14f15512e98d2ecde178bba1d134edc899b961 directoryName=mesa-20.1.8 url=https://archive.mesa3d.org//mesa-20.1.8.tar.xz
mv bin/source bin/mesa
echo "" > bin/meson_cross.txt

View File

@ -3,7 +3,7 @@ set -e
if [ ! -d "bin/musl" ]; then
echo "Downloading Musl..."
bin/build get-source-checked 68af6e18539f646f9c41a3a2bb25be4a5cfa5a8f65f0bb647fd2bbfdf877e84b musl-1.2.1 https://musl.libc.org/releases/musl-1.2.1.tar.gz
bin/script util/get_source.script checksum=68af6e18539f646f9c41a3a2bb25be4a5cfa5a8f65f0bb647fd2bbfdf877e84b directoryName=musl-1.2.1 url=https://musl.libc.org/releases/musl-1.2.1.tar.gz
mv bin/source bin/musl
cp ports/musl/changes/config.mak bin/musl/config.mak

View File

@ -1,7 +1,7 @@
set -e
SYSROOT=`realpath root`
VERSION=2.15.05
bin/build get-source-checked 3caf6729c1073bf96629b57cee31eeb54f4f8129b01902c73428836550b30a3f nasm-$VERSION https://www.nasm.us/pub/nasm/releasebuilds/$VERSION/nasm-$VERSION.tar.xz
bin/script util/get_source.script checksum=3caf6729c1073bf96629b57cee31eeb54f4f8129b01902c73428836550b30a3f directoryName=nasm-$VERSION url=https://www.nasm.us/pub/nasm/releasebuilds/$VERSION/nasm-$VERSION.tar.xz
cd bin/source
./configure --host=x86_64-essence CC=x86_64-essence-gcc CXX=x86_64-essence-g++ --prefix=/Applications/POSIX
make -j `nproc`

View File

@ -68,6 +68,9 @@ if [ $? -ne 0 ]; then
exit
fi
# Compile the scripting engine.
gcc -o bin/script util/script.c -g -Wall -Wextra -fsanitize=address
# Compile and run Build.
gcc -o bin/build -g util/build.c -pthread -DPARALLEL_BUILD -D${ES_TARGET-TARGET_X86_64} \
-Wall -Wextra -Wno-format-security -Wno-format-overflow -Wno-missing-field-initializers -Wno-unused-function -Wno-format-truncation \

View File

@ -1243,113 +1243,6 @@ void BuildAndRun(int optimise, bool compile, int debug, int emulator, int log) {
}
}
void GetSource(const char *parameters, const char *checksum) {
if (CallSystem("mkdir -p bin/cache && rm -rf bin/source")) {
exit(1);
}
const char *folder = parameters;
const char *url = NULL;
for (int i = 0; folder[i]; i++) {
if (folder[i] == ' ') {
url = folder + i + 1;
break;
}
}
assert(url);
char name[1024];
strcpy(name, "bin/cache/");
char *nameWithoutDirectory = name + 10;
const char *extension = url;
for (int i = 0; url[i]; i++) {
name[i + 10] = isalnum(url[i]) ? url[i] : '_';
name[i + 11] = 0;
if (url[i] == '.') extension = url + i;
}
char decompressFlag;
if (0 == strcmp(extension, ".bz2")) {
decompressFlag = 'j';
} else if (0 == strcmp(extension, ".xz")) {
decompressFlag = 'J';
} else if (0 == strcmp(extension, ".gz")) {
decompressFlag = 'z';
} else {
fprintf(stderr, "Unknown archive format.\n");
exit(1);
}
char *alternateURL = NULL;
if (checksum) {
// If we're verifying the checksum of the file, then it should be okay to try downloading it from a non-official mirror.
const char *alternateURLPrefix = "https://github.com/nakst/cdn/raw/main/cache/";
alternateURL = (char *) malloc(strlen(alternateURLPrefix) + strlen(nameWithoutDirectory) + 1);
strcpy(alternateURL, alternateURLPrefix);
strcat(alternateURL, nameWithoutDirectory);
}
FILE *f = fopen(name, "rb");
if (f) {
// The file is cached.
fclose(f);
} else {
if (alternateURL) {
fprintf(stderr, "Attempting to download from '%s' with fallback '%s'...\n", alternateURL, url);
} else {
fprintf(stderr, "Attempting to download from '%s'...\n", url);
}
if (!alternateURL || CallSystemF("curl -f -L %s > %s", alternateURL, name)) {
if (CallSystemF("curl -L %s > %s", url, name)) {
CallSystemF("rm %s", name); // Remove partially downloaded file.
fprintf(stderr, "Error: Could not download the file at '%s'. Exiting.\n", url);
exit(1);
}
}
}
free(alternateURL);
#ifdef __APPLE__
#define SHA256SUM "shasum -a 256"
#else
#define SHA256SUM "sha256sum"
#endif
if (checksum) {
fprintf(stderr, "Checking validity of downloaded file...\n");
int checksumLength = strlen(checksum);
for (int i = 0; checksum[i]; i++) {
if (checksum[i] == ' ') {
checksumLength = i;
break;
}
}
if (CallSystemF(SHA256SUM " %s | grep %.*s > /dev/null", name, checksumLength, checksum)) {
fprintf(stderr, "Checksum mismatch for file '%s' downloaded from '%s'.\n", name, url);
CallSystemF("rm %s", name);
exit(1);
}
}
fprintf(stderr, "Decompressing...\n");
if (CallSystemF("tar -x%cf %s", decompressFlag, name)) exit(1);
fprintf(stderr, "Moving...\n");
if (CallSystemF("mv %.*s bin/source", (int) (url - folder), folder)) exit(1);
fprintf(stderr, "Done.\n");
}
void RunTests(int singleTest) {
// TODO Capture emulator memory dump if a test causes a EsPanic.
// TODO Using SMP/KVM if available in the optimised test runs.
@ -1800,25 +1693,6 @@ void DoCommand(const char *l) {
if (automatedBuild) {
exit(status);
}
} else if (0 == memcmp(l, "get-source ", 11)) {
GetSource(l + 11, NULL);
} else if (0 == memcmp(l, "get-source-checked ", 19)) {
const char *checksum = l + 19;
const char *rest = NULL;
for (int i = 0; checksum[i]; i++) {
if (checksum[i] == ' ') {
rest = checksum + i + 1;
break;
}
}
if (!checksum) {
fprintf(stderr, "Invalid usage; expected checksum before other arguments.\n");
exit(1);
}
GetSource(rest, checksum);
} else if (0 == strcmp(l, "make-crash-report")) {
system("rm crash-report.tar.gz");
system("mkdir crash-report");
@ -1871,8 +1745,8 @@ void DoCommand(const char *l) {
} else if (0 == strcmp(l, "get-toolchain")) {
#if defined(__linux__) && defined(__x86_64__)
fprintf(stderr, "Downloading the compiler toolchain...\n");
DoCommand("get-source-checked 700205f81c7a5ca3279ae7b1fdb24e025d33b36a9716b81a71125bf0fec0de50 "
"prefix https://github.com/nakst/build-gcc/releases/download/gcc-11.1.0/gcc-x86_64-essence.tar.xz");
CallSystem("bin/script util/get_source.script checksum=700205f81c7a5ca3279ae7b1fdb24e025d33b36a9716b81a71125bf0fec0de50 "
"directoryName=prefix url=https://github.com/nakst/build-gcc/releases/download/gcc-11.1.0/gcc-x86_64-essence.tar.xz");
DoCommand("setup-pre-built-toolchain");
AddCompilerToPath();
#else

186
util/build_gcc.script Normal file
View File

@ -0,0 +1,186 @@
#import "util/get_source.script" get_source;
// Persistent variables:
bool runningMakefiles #persist;
// Options:
str gccVersion #option;
str binutilsVersion #option;
str targetName #option;
str toolchainPrefix #option;
int processorCount #option;
bool skipYesChecks #option;
bool ConsoleGetYes() {
if skipYesChecks { return true; }
str input = ConsoleGetLine();
return input == "yes" || input == "y";
}
void Start() {
// Set default values for options.
if gccVersion == "" gccVersion = "11.1.0";
if binutilsVersion == "" binutilsVersion = "2.36.1";
if targetName == "" targetName = "x86_64";
if toolchainPrefix == "" toolchainPrefix = "x86_64-essence";
// Get the number of processors to compile with.
if processorCount == 0 {
processorCount = SystemGetProcessorCount();
if processorCount < 1 processorCount = 1;
if processorCount > 16 processorCount = 16;
}
// Print instructions.
PrintStdErr("To build Essence, you need a cross compiler. This will be built for you automatically.\n");
PrintStdErr("- You need to be connected to the internet. ~100MB will be downloaded.\n");
PrintStdErr("- You need ~3GB of drive space available.\n");
PrintStdErr("- You need ~8GB of RAM available.\n");
PrintStdErr("- This should take ~20 minutes on a modern computer.\n");
PrintStdErr("- This does *not* require root permissions.\n");
PrintStdErr("- You must fully update your system before building.\n");
PrintStdErr("Enter 'yes' to continue.\n");
assert ConsoleGetYes();
// Create folders.
assert PathCreateDirectory("bin");
assert PathCreateDirectory("root");
assert PathCreateDirectory("root/Essence");
assert PathCreateDirectory("root/Applications");
assert PathCreateDirectory("root/Applications/POSIX");
assert PathCreateDirectory("root/Applications/POSIX/bin");
assert PathCreateDirectory("root/Applications/POSIX/include");
assert PathCreateDirectory("root/Applications/POSIX/lib");
// Load the persistent variables.
assert PersistRead("bin/build_gcc_state.dat");
// Get the directories.
str sourceTree = PathGetDefaultPrefix();
str crossDirectory = sourceTree + "/cross";
str rootDirectory = sourceTree + "/root";
str compilerPath = crossDirectory + "/bin";
// Modify the path.
str path = compilerPath + ":" + SystemGetEnvironmentVariable("PATH");
SystemSetEnvironmentVariable("PATH", path);
assert !StringContains(path, "::");
assert SystemGetEnvironmentVariable("PATH") == path;
// Get the brew library path if we're running on Darwin.
str hostPlatform = StringTrim(SystemShellEvaluate("uname"));
str libraryPath = "";
if hostPlatform == "Darwin" libraryPath = SystemShellEvaluate("brew --prefix") + "/lib";
// Make sure we're not running as root.
assert StringTrim(SystemShellEvaluate("whoami")) != "root";
// Check all the needed tools are available.
assert SystemShellExecute("which g++");
assert SystemShellExecute("which make");
assert SystemShellExecute("which bison");
assert SystemShellExecute("which flex");
assert SystemShellExecute("which curl");
assert SystemShellExecute("which nasm");
assert SystemShellExecute("which ctags");
assert SystemShellExecute("which xz");
assert SystemShellExecute("which gzip");
assert SystemShellExecute("which tar");
assert SystemShellExecute("which grep");
assert SystemShellExecute("which sed");
assert SystemShellExecute("which awk");
// Check all the needed libraries are available.
assert FileWriteAll("bin/test.c", "void main() {}");
assert !SystemShellExecute("gcc %libraryPath% -lmpc bin/test.c 2>&1 | grep -i undefined"); // libmpc-dev
assert !SystemShellExecute("gcc %libraryPath% -lmpfr bin/test.c 2>&1 | grep -i undefined"); // libmpfr-dev
assert !SystemShellExecute("gcc %libraryPath% -lgmp bin/test.c 2>&1 | grep -i undefined"); // libgmp-dev
// Ask the user if they want to resume an incomplete build.
bool resumeBuild = false;
if runningMakefiles {
PrintStdErr("The build system has detected a build was started, but was not completed.\n");
PrintStdErr("Enter 'yes' to attempt to resume this build.\n");
resumeBuild = ConsoleGetYes();
runningMakefiles = false;
}
if !resumeBuild {
// Cleanup.
assert PathDeleteRecursively("cross");
assert PathDeleteRecursively("bin/build-binutils");
assert PathDeleteRecursively("bin/build-gcc");
assert PathDeleteRecursively("bin/binutils-src");
assert PathDeleteRecursively("bin/gcc-src");
// Create folders.
assert PathCreateDirectory("bin/build-binutils");
assert PathCreateDirectory("bin/build-gcc");
// Copy the C standard library headers to their destination.
assert SystemShellExecute("ports/musl/build.sh %targetName%");
// Download the sources.
get_source.Get("ftp://ftp.gnu.org/gnu/binutils/binutils-%binutilsVersion%.tar.xz", "binutils-%binutilsVersion%",
"e81d9edf373f193af428a0f256674aea62a9d74dfe93f65192d4eae030b0f3b0");
assert PathMove("bin/source", "bin/binutils-src");
get_source.Get("ftp://ftp.gnu.org/gnu/gcc/gcc-%gccVersion%/gcc-%gccVersion%.tar.xz", "gcc-%gccVersion%",
"4c4a6fb8a8396059241c2e674b85b351c26a5d678274007f076957afa1cc9ddf");
assert PathMove("bin/source", "bin/gcc-src");
// Patch the sources.
assert FileCopy("ports/gcc/changes/binutils_bfd_config.bfd", "bin/binutils-src/bfd/config.bfd");
assert FileCopy("ports/gcc/changes/binutils_config.sub", "bin/binutils-src/config.sub");
assert FileCopy("ports/gcc/changes/binutils_gas_configure.tgt", "bin/binutils-src/gas/configure.tgt");
assert FileCopy("ports/gcc/changes/binutils_ld_configure.tgt", "bin/binutils-src/ld/configure.tgt");
assert FileCopy("ports/gcc/changes/gcc_config.sub", "bin/gcc-src/config.sub");
assert FileCopy("ports/gcc/changes/gcc_fixincludes_mkfixinc.sh", "bin/gcc-src/fixincludes/mkfixinc.sh");
assert FileCopy("ports/gcc/changes/gcc_gcc_config_essence.h", "bin/gcc-src/gcc/config/essence.h");
assert FileCopy("ports/gcc/changes/gcc_gcc_config_i386_t-x86_64-essence", "bin/gcc-src/gcc/config/i386/t-x86_64-essence");
assert FileCopy("ports/gcc/changes/gcc_gcc_config.gcc", "bin/gcc-src/gcc/config.gcc");
assert FileCopy("ports/gcc/changes/gcc_gcc_config_host_darwin.c", "bin/gcc-src/gcc/config/host-darwin.c");
assert FileCopy("ports/gcc/changes/gcc_libgcc_config.host", "bin/gcc-src/libgcc/config.host");
assert FileCopy("ports/gcc/changes/gcc_libstdc++-v3_configure", "bin/gcc-src/libstdc++-v3/configure");
// Run configure.
assert SystemShellExecuteWithWorkingDirectory("bin/build-binutils",
"../binutils-src/configure --target=%toolchainPrefix% --prefix=\"%crossDirectory%\" "
+ "--with-sysroot=\"%rootDirectory%\" --disable-nls --disable-werror");
assert SystemShellExecuteWithWorkingDirectory("bin/build-gcc",
"../gcc-src/configure --target=%toolchainPrefix% --prefix=\"%crossDirectory%\" "
+ "--enable-languages=c,c++ --with-sysroot=\"%rootDirectory%\" --disable-nls");
// Add --without-headers for a x86_64-elf build.
}
// Run makefiles.
runningMakefiles = true;
assert SystemShellExecuteWithWorkingDirectory("bin/build-binutils", "make -j %processorCount%");
assert SystemShellExecuteWithWorkingDirectory("bin/build-binutils", "make install");
assert SystemShellExecuteWithWorkingDirectory("bin/build-gcc", "make all-gcc -j %processorCount%");
assert SystemShellExecuteWithWorkingDirectory("bin/build-gcc", "make all-target-libgcc -j %processorCount%");
assert SystemShellExecuteWithWorkingDirectory("bin/build-gcc", "make install-gcc");
assert SystemShellExecuteWithWorkingDirectory("bin/build-gcc", "make install-target-libgcc");
// Remove debugging symbols.
SystemShellExecute("strip %crossDirectory%/bin/*");
SystemShellExecute("strip %crossDirectory%/libexec/gcc/%toolchainPrefix%/%gccVersion%/*");
// Modify the mm_malloc.h header.
assert FileWriteAll("%crossDirectory%/lib/gcc/%toolchainPrefix%/%gccVersion%/include/mm_malloc.h", "/* removed */\n");
// Update the build configuration and compile the system.
FileWriteAll("bin/build_config.ini", "accepted_license=1\ncompiler_path=%compilerPath%\ncross_compiler_index=11\n");
SystemShellExecute("./start.sh c");
// Build libstdc++.
assert SystemShellExecuteWithWorkingDirectory("bin/build-gcc", "make all-target-libstdc++-v3 -j %processorCount%");
assert SystemShellExecuteWithWorkingDirectory("bin/build-gcc", "make install-target-libstdc++-v3");
// Cleanup.
runningMakefiles = false;
assert PathDeleteRecursively("bin/build-binutils");
assert PathDeleteRecursively("bin/build-gcc");
assert PathDeleteRecursively("bin/binutils-src");
assert PathDeleteRecursively("bin/gcc-src");
PrintStdErrHighlight("Build succeeded.\n");
}

63
util/get_source.script Normal file
View File

@ -0,0 +1,63 @@
str url #option;
str directoryName #option;
str checksum #option;
void Get(str url, str directoryName, str checksum) {
assert url != "";
assert directoryName != "";
assert PathCreateDirectory("bin");
assert PathCreateDirectory("bin/cache");
assert PathDeleteRecursively("bin/source");
str url2 = "";
for int i = 0; i < url:len(); i += 1 {
if CharacterIsAlnum(url[i]) {
url2 += url[i];
} else {
url2 += "_";
}
}
str cachePath = "bin/cache/" + url2;
str alternateURL = "";
if checksum != "" {
// If we're verifying the checksum of the file, then it should be okay to try downloading it from a non-official mirror.
alternateURL = "https://github.com/nakst/cdn/raw/main/cache/" + url2;
PrintStdErr("Attempting to download from '%alternateURL%' with fallback '%url%'...\n");
} else {
PrintStdErr("Attempting to download from '%url%'...\n");
}
bool got = PathExists(cachePath);
if !got && alternateURL != "" got = SystemShellExecute("curl -f -L %alternateURL% > %cachePath%");
if !got got = SystemShellExecute("curl -f -L %url% > %cachePath%");
if !got {
PathDelete(cachePath);
PrintStdErrWarning("Error: Could not download the file at '%url%'. Exiting.\n");
assert false;
}
if checksum != "" {
if SystemShellEvaluate("shasum -a 256 %cachePath%") != "%checksum% %cachePath%\n" {
PrintStdErrWarning("Error: Checksum mismatch for file '%cachePath%'.\n");
PathDelete(cachePath);
assert false;
}
PrintStdErr("Valid checksum.\n");
}
assert SystemShellExecute("tar -xaf %cachePath%");
assert PathMove(directoryName, "bin/source");
PrintStdErr("File successfully downloaded and extracted.\n");
}
void Start() {
Get(url, directoryName, checksum);
}

4624
util/script.c Normal file

File diff suppressed because it is too large Load Diff