Refactoring the script by encapsulating related operations into functions for readability and maintainability
Replace set -e
with set -euo pipefail
at the beginning of the script. This will cause the script to exit if any variable is unset (due to the -u option) and also if any command in a pipeline fails (due to the -o pipefail
option). This may make the script more robust and easier to debug
In the run_autoreconf
function, I’ve added an error message to be displayed if the autoreconf
command fails.
check_libtoolize
function using parameter substitution
check if autoreconf
is executable
Also using the copy_if_newer
function which is being called 4 times.
-
The first time, it’s checking if
'depends/config.guess'
is newer than'build-aux/config.guess'
. If it is, it copies the former over the latter. -
The second time, it’s doing the same check and potential copy, but this time between
'depends/config.guess'
and'src/secp256k1/build-aux/config.guess'
. -
The third and fourth calls are doing similar checks and potential copies, but with
'depends/config.sub'
and the destination files.
The 'config.guess'
and 'config.sub'
scripts are used by GNU Autotools, and they help determine the type of system your software is building on. The 'config.guess'
script guesses the build type for your system, and 'config.sub'
validates and canonicalizes that guess.
The copy_if_newer
calls ensure that the most recent versions of 'config.guess'
and 'config.sub'
are used in the directories where they are needed. Could be useful ie, when the scripts in those directories are not updated as frequently or need to be isolated from changes in other parts of someone’s system.
Currently #!/bin/sh
is used, which is the system’s default shell. I’m not sure if that will be ever problematic.
If we know that this script should run in bash, maybe it’s better to specify #!/usr/bin/env bash
?