#!/bin/mkpkg
# description: GN meta-build system
# url: https://gn.googlesource.com/gn
# Depends on: python3 ninja clang
name=gn
version=0.2324
_commit=304bbef6c7e9a86630c12986b99c8654eb7fe648
release=1
source=(https://gn.googlesource.com/gn/+archive/${_commit}.tar.gz)
sha256sums=(
    "63785159210399064a164aaabf2adcaf4289e068c68976cd7bffa3aa9fd14e6b"
)

build() {
    cd "$SRC"
    export CC=clang
    export CXX=clang++
    export AR=llvm-ar
    export LDFLAGS="-fuse-ld=lld"

    # Gentoo gn-gen-r8: comment out hardcoded -O3/-g, remove -pipe
    sed -i "/cflags.append('-O3')/s/^/#/;
            /cflags.append('-g')/s/^/#/;
            /ldflags.append('-O3')/s/^/#/;
            /options.no_strip/s/^/#/;
            /'-pipe',/d;
            /'-Wno-format',/d;
            /'-Wno-strict-aliasing',/d" build/gen.py

    # Fix ninja regen loop: the +archive tarball gives all files
    # identical timestamps. Set them all to the past so gen.py
    # outputs (build.ninja) will be strictly newer.
    find . -type f -exec touch -t 200001010000 {} +

    python3 build/gen.py \
        --no-last-commit-position \
        --no-static-libstdc++ \
        --no-strip \
        --allow-warnings
    printf '%s\n' \
        '#ifndef OUT_LAST_COMMIT_POSITION_H_' \
        '#define OUT_LAST_COMMIT_POSITION_H_' \
        '#define LAST_COMMIT_POSITION_NUM 2324' \
        "#define LAST_COMMIT_POSITION \"2324 (${_commit})\"" \
        '#endif' \
        > out/last_commit_position.h

    ninja -C out gn
    install -Dm755 out/gn "$PKG/usr/bin/gn"
}
signify() {
    untrusted comment: public key
    RWTZ9IduCSQ/mL8337TEUinPwT92xFEUpD92hkS7IxcOnzTt9QdpohT3
}

# vim: filetype=sh
