Last active
August 27, 2021 23:49
-
-
Save marcastel/90b211f83751877c9939a61f29e376bf to your computer and use it in GitHub Desktop.
Bootstrap ISLE make(1)-based build system
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/ksh | |
#! @brief Bootstrap ISLE make(1)-based build system | |
# Construct the man(1) page for this utility | |
typeset usage=$'[-][+NAME?\bgh-bootstrap\b - boostrapping utility for the first time cloning of ISLE GitHub repositories.] | |
[+DESCRIPTION?This is a small KornShell utility to automatically clone ISLE GitHub repositories that use our \bmake(1)\b-bassed | |
build system. Its operations are pretty straightforward: first the repository is cloned locally into the specified \bdirectory\b; | |
then the repository is cloned again within the new directory to create the special \bMakefiles\b folder and to link the master | |
\bMakefile\b file; finally it launches the first time configuration of the repository (\bmake first-insteall\b).] | |
[+?Simple. No magic. It avoids the hassle of typing all those commands!] | |
[+?The provided \brepo\b repository name should follow the GitHub naming convention and should have the form \b{owner}/{repo}\n | |
or \b{org}/{repo}\b. If the \bowner\b or \borg\b is not supplied, it will be assumed to be \bISLEcode\b. The \bdirectory\b name | |
is optional. If ommited, the default \bGit\b behaviour is enacted and the name defaults to the \brepo\b name; if one minor, | |
difference: the repository name will be forced to lowercase.] | |
[s:ssh?Rather than using an HTTP URL, this option allows to specify a \bNAME\b defined in the current user\'s SSH config file. | |
See the SSH CONFIG section below for further details.]:[NAME] | |
[+SSH CONFIG?Rather than using regular HTTP URLs, it is recommended to configure your GitHub account with an SSH key and then | |
configure your local SSH configuration (\b~/.ssh/config\b) to use that key -- cf \bssh_config(5)\b for further details. A typical | |
setup looks like this:][+\ | |
Host marcastel.github | |
Hostname github.com | |
User git | |
IdentityFile ~/.ssh/k-marcastel-github.pem] | |
[+?Where \bk-marcastel-github.pem\b is the SSH key registered with GitHub. Assuming we want to clone the \bISLEcode/KAML\b | |
repository, the conventional HTTP URL will be constructed as:][+\ | |
https:://github.com/ISLEcode/KAML] | |
[+?By passing the option \b--ssh marcastel.github\b, the URL will be constructed as:][+\ | |
git@marcastel.github::/ISLEcode/KAML.git] | |
[+?which allows to use the Git protocol over a secured SSH connection.] | |
\brepo\b [ \bdirectory\b ]' | |
# Collect command line arguments and assign defaults | |
typeset clone='git clone --depth=1' dir=$2 repo=$1 ssh url; whence -q git-dupe && clone='git dupe' | |
# Collect the command line arguments; otherwise automatically display this utility's man page | |
[[ -n $1 ]] || set -- --man; while getopts "$usage" opt; do case $opt in s) ssh=$OPTARG ;; | |
esac; done; (( OPTIND > 1 )) && shift $(( OPTIND - 1 )) | |
# Configuration step, adjust variables and assert that we can continue | |
[[ $repo == */* ]] || { repo=ISLEcode/$repo; print -u2 "No owner or organisation specified; assuming: $repo"; } | |
typeset -l dir; [[ -n $dir ]] || dir=${repo#*/}; [[ -n $ssh ]] && url="git@$ssh:$repo.git" || url="https://github.com/$repo" | |
# First we clone the master branch to build the *regular* repository | |
$clone --branch master $url $dir || { print -u2 "$repo: failed to clone repository's master branch."; exit 1; } | |
# Next we clone the repository's `makefiile` branch; we abort on errors assuming this is a *foreign* repository | |
$clone --branch makefiles $url $dir/Makefiles || { print -u2 "$repo: failed to clone the repository's build system."; exit 1; } | |
# Sanity check: make sure our Makefiles subdirectory exists and that we have our *universal* Makefile | |
cd $dir; [[ -d Makefiles && -f Makefiles/Makefile.in ]] || { print -u2 "$dir: things appear corrupted here!"; exit 1; } | |
# Bind the master Makefile file and launch the first install target to further the installation | |
ln -s Makefiles/Makefile.in Makefile && make first-install || { print -u2 "$dir: failed to install Makefile!"; exit 1; } | |
# __END__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment