From d38cc9314a6fa911cb83052d093328605d0b71df Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 16 Nov 2023 20:04:05 +0800 Subject: [PATCH] Init --- .drone.yml | 22 ++++++++++++++++ .gitignore | 3 +++ build.sh | 56 ++++++++++++++++++++++++++++++++++++++++ patches/gcc-13.2.0.patch | 34 ++++++++++++++++++++++++ 4 files changed, 115 insertions(+) create mode 100644 .drone.yml create mode 100644 .gitignore create mode 100644 build.sh create mode 100644 patches/gcc-13.2.0.patch diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..6efda05 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,22 @@ + +--- +kind: pipeline +type: docker +name: Build + +trigger: + event: + - push + - custom + +steps: + - name: Build & Upload + image: ubuntu:22.04 + commands: + - sudo apt update && sudo apt install libgmp-dev libmpfr-dev libmpc-dev gcc-multilib + - bash build.sh + environment: + GITEA_ENDPOINT: https://git.m.ac + GITEA_USER: baoshuo + GITEA_TOKEN: + from_secret: GITEA_TOKEN diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4bb0003 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +build/ +deb/ +*.deb diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..c2af291 --- /dev/null +++ b/build.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +CURRENT_DIR=$(pwd) +GCC_VERSION="13.2.0" +# GCC_GIT="git://gcc.gnu.org/git/gcc.git" +GCC_GIT="https://git.m.ac/mirrors/gcc.git" +GCC_SRC="${CURRENT_DIR}/../src" +BUILD_DIR="build" + +# Clone GCC +echo "===> Cloning GCC..." +git clone -b "releases/gcc-$GCC_VERSION" --depth 1 "${GCC_GIT}" "${GCC_SRC}" + +# Apply patches +echo "===> Applying patches..." +cd ${GCC_SRC} +patch -p1 < ../patches/gcc-$GCC_VERSION.patch +cd ${CURRENT_DIR} + +# Configure GCC +echo "===> Configuring GCC..." +cd ${CURRENT_DIR}/${BUILD_DIR} +${GCC_SRC}/configure -v \ + --enable-languages=c,c++ \ + --prefix=/usr \ + --build=x86_64-linux-gnu \ + --host=x86_64-linux-gnu \ + --target=x86_64-linux-gnu \ + --with-pkgversion="s2oj-gcc-$GCC_VERSION~1baoshuo1" + +# Build GCC +echo "===> Building GCC..." +make -j$(nproc) + +# Make .deb package +echo "===> Making .deb package \"s2oj-gcc-$GCC_VERSION~1baoshuo1.deb\" ..." +make -j$(nproc) DESTDIR=${CURRENT_DIR}/deb install +cd ${CURRENT_DIR}/deb +mkdir -p DEBIAN +cat << EOF > DEBIAN/control +Package: s2oj-gcc +Version: $GCC_VERSION~1baoshuo1 +Section: base +Priority: optional +Architecture: amd64 +Maintainer: Baoshuo +Description: GCC $GCC_VERSION for S2OJ +EOF +cd ${CURRENT_DIR} +dpkg-deb --build deb s2oj-gcc-$GCC_VERSION~1baoshuo1.deb + +# Upload package to Gitea +echo "===> Uploading package to Gitea..." +curl --user "${GITEA_USER}:${GITEA_TOKEN}" \ + --upload-file s2oj-gcc-$GCC_VERSION~1baoshuo1.deb \ + ${GITEA_ENDPOINT}/api/packages/${GITEA_USER}/debian/pool/all/main/upload diff --git a/patches/gcc-13.2.0.patch b/patches/gcc-13.2.0.patch new file mode 100644 index 0000000..2414f7c --- /dev/null +++ b/patches/gcc-13.2.0.patch @@ -0,0 +1,34 @@ +diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc +index 072cfb691..0c1a26b21 100644 +--- a/gcc/c-family/c-attribs.cc ++++ b/gcc/c-family/c-attribs.cc +@@ -5626,6 +5626,12 @@ static tree + handle_optimize_attribute (tree *node, tree name, tree args, + int ARG_UNUSED (flags), bool *no_add_attrs) + { ++ if (getenv("ONLINE_JUDGE")) ++ { ++ error_at (DECL_SOURCE_LOCATION (*node), "%qE attribute is disallowed in online judge mode", name); ++ return NULL_TREE; ++ } ++ + /* Ensure we have a function type. */ + if (TREE_CODE (*node) != FUNCTION_DECL) + { +diff --git a/gcc/c-family/c-pragma.cc b/gcc/c-family/c-pragma.cc +index 0d2b333ce..091c0edc9 100644 +--- a/gcc/c-family/c-pragma.cc ++++ b/gcc/c-family/c-pragma.cc +@@ -1163,6 +1163,12 @@ handle_pragma_optimize (cpp_reader *) + bool close_paren_needed_p = false; + tree optimization_previous_node = optimization_current_node; + ++ if (getenv("ONLINE_JUDGE")) ++ { ++ error ("%<#pragma GCC optimize%> is not allowed in online judge mode"); ++ return; ++ } ++ + if (cfun) + { + error ("%<#pragma GCC optimize%> is not allowed inside functions");