Skip to content

Instantly share code, notes, and snippets.

@nlgranger
Created October 17, 2024 21:48
Show Gist options
  • Select an option

  • Save nlgranger/9ecc0b4f0a9e1c0079860bdc7cfb11f7 to your computer and use it in GitHub Desktop.

Select an option

Save nlgranger/9ecc0b4f0a9e1c0079860bdc7cfb11f7 to your computer and use it in GitHub Desktop.
PKGBUILD skeleton genetator for projects with git submodules
# example of generate output using https://github.com/tianocore/edk2
sources=(
"berkeley-softfloat-3::git+file:///home/ngranger/Downloads/edk2/src/berkeley-softfloat-3"
"brotli::git+file:///home/ngranger/Downloads/edk2/src/brotli"
"cmocka::git+file:///home/ngranger/Downloads/edk2/src/cmocka"
"cryptography::git+file:///home/ngranger/Downloads/edk2/src/cryptography"
"edk2-cmocka::git+file:///home/ngranger/Downloads/edk2/src/edk2-cmocka"
"engine::git+file:///home/ngranger/Downloads/edk2/src/engine"
"googletest::git+file:///home/ngranger/Downloads/edk2/src/googletest"
"jansson::git+file:///home/ngranger/Downloads/edk2/src/jansson"
"krb5::git+file:///home/ngranger/Downloads/edk2/src/krb5"
"libprov::git+file:///home/ngranger/Downloads/edk2/src/libprov"
"libspdm::git+file:///home/ngranger/Downloads/edk2/src/libspdm"
"mbedtls::git+file:///home/ngranger/Downloads/edk2/src/mbedtls"
"oniguruma::git+file:///home/ngranger/Downloads/edk2/src/oniguruma"
"openssl::git+file:///home/ngranger/Downloads/edk2/src/openssl"
"public-mipi-sys-t::git+file:///home/ngranger/Downloads/edk2/src/public-mipi-sys-t"
"pugixml::git+file:///home/ngranger/Downloads/edk2/src/pugixml"
"pylibfdt::git+file:///home/ngranger/Downloads/edk2/src/pylibfdt"
"subhook::git+file:///home/ngranger/Downloads/edk2/src/subhook"
"wycheproof::git+file:///home/ngranger/Downloads/edk2/src/wycheproof"
)
checksums=(
"SKIP"
"SKIP"
"SKIP"
"SKIP"
"SKIP"
"SKIP"
"SKIP"
"SKIP"
"SKIP"
"SKIP"
"SKIP"
"SKIP"
"SKIP"
"SKIP"
"SKIP"
"SKIP"
"SKIP"
"SKIP"
"SKIP"
"SKIP"
"SKIP"
"SKIP"
"SKIP"
"SKIP"
"SKIP"
"SKIP"
"SKIP"
"SKIP"
"SKIP"
)
prepare() {
repo="."
git -C $repo submodule init
git -C $repo config submodule.SoftFloat.url "file://$srcdir/berkeley-softfloat-3"
git -C $repo config submodule.BaseTools/Source/C/BrotliCompress/brotli.url "file://$srcdir/brotli"
git -C $repo config submodule.CryptoPkg/Library/MbedTlsLib/mbedtls.url "file://$srcdir/mbedtls"
git -C $repo config submodule.CryptoPkg/Library/OpensslLib/openssl.url "file://$srcdir/openssl"
git -C $repo config submodule.MdeModulePkg/Library/BrotliCustomDecompressLib/brotli.url "file://$srcdir/brotli"
git -C $repo config submodule.MdeModulePkg/Universal/RegularExpressionDxe/oniguruma.url "file://$srcdir/oniguruma"
git -C $repo config submodule.MdePkg/Library/BaseFdtLib/libfdt.url "file://$srcdir/pylibfdt"
git -C $repo config submodule.MdePkg/Library/MipiSysTLib/mipisyst.url "file://$srcdir/public-mipi-sys-t"
git -C $repo config submodule.RedfishPkg/Library/JsonLib/jansson.url "file://$srcdir/jansson"
git -C $repo config submodule.SecurityPkg/DeviceSecurity/SpdmLib/libspdm.url "file://$srcdir/libspdm"
git -C $repo config submodule.UnitTestFrameworkPkg/Library/CmockaLib/cmocka.url "file://$srcdir/edk2-cmocka"
git -C $repo config submodule.UnitTestFrameworkPkg/Library/GoogleTestLib/googletest.url "file://$srcdir/googletest"
git -C $repo config submodule.UnitTestFrameworkPkg/Library/SubhookLib/subhook.url "file://$srcdir/subhook"
git -C $repo -c protocol.file.allow=always submodule update
repo="./CryptoPkg/Library/OpensslLib/openssl"
git -C $repo submodule init
git -C $repo config submodule.gost-engine.url "file://$srcdir/engine"
git -C $repo config submodule.krb5.url "file://$srcdir/krb5"
git -C $repo config submodule.pyca.cryptography.url "file://$srcdir/cryptography"
git -C $repo config submodule.wycheproof.url "file://$srcdir/wycheproof"
git -C $repo -c protocol.file.allow=always submodule update
repo="./CryptoPkg/Library/OpensslLib/openssl/gost-engine"
git -C $repo submodule init
git -C $repo config submodule.libprov.url "file://$srcdir/libprov"
git -C $repo -c protocol.file.allow=always submodule update
repo="./MdePkg/Library/MipiSysTLib/mipisyst"
git -C $repo submodule init
git -C $repo config submodule.external/googletest.url "file://$srcdir/googletest"
git -C $repo config submodule.external/pugixml.url "file://$srcdir/pugixml"
git -C $repo -c protocol.file.allow=always submodule update
repo="./SecurityPkg/DeviceSecurity/SpdmLib/libspdm"
git -C $repo submodule init
git -C $repo config submodule.os_stub/mbedtlslib/mbedtls.url "file://$srcdir/mbedtls"
git -C $repo config submodule.os_stub/openssllib/openssl.url "file://$srcdir/openssl"
git -C $repo config submodule.unit_test/cmockalib/cmocka.url "file://$srcdir/cmocka"
git -C $repo -c protocol.file.allow=always submodule update
repo="./SecurityPkg/DeviceSecurity/SpdmLib/libspdm/os_stub/openssllib/openssl"
git -C $repo submodule init
git -C $repo config submodule.gost-engine.url "file://$srcdir/engine"
git -C $repo config submodule.krb5.url "file://$srcdir/krb5"
git -C $repo config submodule.pyca.cryptography.url "file://$srcdir/cryptography"
git -C $repo config submodule.wycheproof.url "file://$srcdir/wycheproof"
git -C $repo -c protocol.file.allow=always submodule update
repo="./SecurityPkg/DeviceSecurity/SpdmLib/libspdm/os_stub/openssllib/openssl/gost-engine"
git -C $repo submodule init
git -C $repo config submodule.libprov.url "file://$srcdir/libprov"
git -C $repo -c protocol.file.allow=always submodule update
}
#!/usr/bin/env sh
# To be run inside the desired repo (cloned recursively)
# propose a repo name based on the url (filename without .git)
function repo_name {
git config --get remote.origin.url | sed 's|.*/\([^/.]*\)\(.git\)*$|\1|g'
}
# print commands to update submodules urls to $srcdir (recursive)
function configure_repo {
[ -f "$1/.gitmodules" ] || return
echo " repo=\"$1\""
echo " git -C \$repo submodule init"
git -C $1 submodule foreach -q 'echo $name $sm_path' | while read -r sm_name sm_path; do
name=$(git -C $1/$sm_path config --get remote.origin.url | sed 's|.*/\([^/.]*\)\(.git\)*$|\1|g')
echo " git -C \$repo config submodule.$sm_name.url \"file://\$srcdir/$name\""
done
echo " git -C \$repo -c protocol.file.allow=always submodule update"
echo ""
git -C $1 submodule foreach -q 'echo $sm_path' | while read -r sm_path; do
configure_repo $1/$sm_path
done
}
# -- sources --
echo "sources=("
# parent repo
git config get remote.origin.url
# submodules
git submodule foreach --recursive -q 'git -C $toplevel config get submodule.$name.url' | sort -u | sed 's|.*/\([^/.]*\)\(.git\)*$| "\1::git+\0"|g'
echo ")"
echo ""
# -- checksums --
echo "checksums=("
# parent repo
echo ' "SKIP"'
# submodules
git submodule foreach --recursive -q 'echo " \"SKIP\""'
echo ")"
echo ""
# -- prepare --
echo "prepare() {"
echo ""
configure_repo .
echo "}"
@mirh
Copy link
Copy Markdown

mirh commented Apr 2, 2026

I just used your script to revive wine-mono-git, and I found it has problems (at every step) when the repos have dots in their names

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment