bootstrap (6930B)
1 #!/bin/sh 2 3 if command -v "command" >/dev/null 2>&1; then 4 have_cmd() 5 { 6 command -v "$1" >/dev/null 2>&1 7 } 8 elif type "type" >/dev/null 2>&1; then 9 have_cmd() 10 { 11 type "$1" >/dev/null 2>&1 12 } 13 else 14 have_cmd() 15 { 16 : # dummy fallback 17 } 18 fi 19 20 # Extract the dotted version string from stdin and write it to stdout 21 ver_filter() 22 { 23 ${SED-sed} -n 's/^\(.*[^0-9.]\)\{0,1\}\([0-9][0-9]*\(\.[0-9][0-9]*\)\{0,4\}\).*$/\2/p' 24 } 25 26 # Compare two version strings 27 # Return codes: 28 # * 11 if the first version is greater than the second version 29 # * 10 if versions are equal 30 # * 9 if the first version is less than the second version 31 __helper_ver_cmp() 32 { 33 _verA=$1 34 _verB=$2 35 _save_IFS="$IFS" 36 IFS=. 37 set dummy ${_verA} 38 _verA1=${2:-0}; _verA2=${3:-0}; _verA3=${4:-0}; _verA4=${5:-0}; _verA5=${6:-0} 39 set dummy ${_verB} 40 _verB1=${2:-0}; _verB2=${3:-0}; _verB3=${4:-0}; _verB4=${5:-0}; _verB5=${6:-0} 41 IFS="${_save_IFS}" 42 [ "${_verA1}" -gt "${_verB1}" ] && return 11 43 [ "${_verA1}" -lt "${_verB1}" ] && return 9 44 [ "${_verA2}" -gt "${_verB2}" ] && return 11 45 [ "${_verA2}" -lt "${_verB2}" ] && return 9 46 [ "${_verA3}" -gt "${_verB3}" ] && return 11 47 [ "${_verA3}" -lt "${_verB3}" ] && return 9 48 [ "${_verA4}" -gt "${_verB4}" ] && return 11 49 [ "${_verA4}" -lt "${_verB4}" ] && return 9 50 [ "${_verA5}" -gt "${_verB5}" ] && return 11 51 [ "${_verA5}" -lt "${_verB5}" ] && return 9 52 return 10 53 } 54 55 # Usage: ver_cmp VER1 -gt|-lt|-ge|-le|-eq|-ne VER2 56 # For example: ver_cmp 5.10.1 -gt 5.9.1 57 ver_cmp() 58 { 59 __helper_ver_cmp "$1" "$3" 60 [ $? $2 10 ] 61 } 62 63 # Locate the bootstrap source directory 64 bs_srcdir='' || exit 1 65 if have_cmd 'dirname' && test X"`dirname / 2>/dev/null`" = X"/"; then 66 bs_srcdir=`dirname $0` || exit 2 67 else 68 case $0 in 69 */*) bs_srcdir=`echo $0 | ${SED-sed} -n 's|/[^/]*$||p'` || exit 2;; 70 *) bs_srcdir='.' ;; 71 esac 72 fi 73 74 test -n "$bs_srcdir" && cd "$bs_srcdir" || echo "Warning: cannot detect the source directory" 1>&2 75 76 if test ! -f './configure.ac'; then 77 echo "Error: 'configure.ac' not found. Wrong source directory?" 1>&2 78 exit 2 79 fi 80 if test ! -f './src/include/microhttpd2.h'; then 81 echo "Error: 'src/include/microhttpd2.h' not found. Wrong source directory?" 1>&2 82 exit 2 83 fi 84 85 : "${UNCRUSTIFY=uncrustify}" 86 UNCRUSTIFY_VER_NEEDED="0.78.0" 87 88 if have_cmd ${UNCRUSTIFY}; then 89 UNCRUSTIFY_VER=`${UNCRUSTIFY} --version | ver_filter` 90 if ver_cmp "$UNCRUSTIFY_VER" -ge "$UNCRUSTIFY_VER_NEEDED"; then 91 if test -f uncrustify.cfg; then 92 echo "Uncrustify configuration already exists; skipping installation of the configuration from the upstream file." 93 else 94 echo "Installing the libmicrohttpd Uncrustify configuration" 95 rm -f ./uncrustify.cfg 96 ln -s contrib/uncrustify.cfg uncrustify.cfg || \ 97 cp contrib/uncrustify.cfg uncrustify.cfg || \ 98 echo "Failed to install Uncrustify configuration file" 1>&2 99 fi 100 else 101 echo "Uncrustify version $UNCRUSTIFY_VER detected -- hook not installed. Please install Uncrustify $UNCRUSTIFY_VER_NEEDED or newer if you plan to contribute to development." 102 fi 103 else 104 echo "Uncrustify not detected -- hook not installed. Please install Uncrustify $UNCRUSTIFY_VER_NEEDED or newer if you plan to contribute to development." 105 fi 106 107 test -n "$GIT" || GIT="$GIT_CMD" 108 test -n "$GIT" || GIT="$GIT_BINARY" 109 test -n "$GIT" || GIT="git" 110 111 if test -d "${GIT_DIR-.git}"; then 112 if have_cmd "$GIT"; then 113 ver_GIT=`"$GIT" --version 2>/dev/null | ver_filter` 114 if ver_cmp "$ver_GIT" -lt "1.7"; then 115 echo "Git version $ver_GIT detected. If you plan to contribute to development, consider installing a modern Git version." 116 else 117 if test -f "${GIT_DIR-.git}/mhd2_special_config"; then :; else 118 git_settings_modified='no' 119 if ver_cmp "$ver_GIT" -ge "1.7.9"; then 120 if git_set_VAL=`"$GIT" config --get --local --bool 'pull.rebase' 2>/dev/null` && test "$git_set_VAL" = "true"; then :; else 121 echo "Setting 'pull.rebase' to 'true' for this repository." 122 "$GIT" config --local 'pull.rebase' 'true' && git_settings_modified='yes' 123 fi 124 else 125 if git_set_VAL=`"$GIT" config --get --local 'branch.autoSetupRebase' 2>/dev/null` && test "$git_set_VAL" = "always"; then :; else 126 echo "Setting 'branch.autoSetupRebase' to 'always' for this repository." 127 "$GIT" config --local 'branch.autoSetupRebase' 'always' && git_settings_modified='yes' 128 fi 129 fi 130 if ver_cmp "$ver_GIT" -ge "2.6"; then 131 if git_set_VAL=`"$GIT" config --get --local --bool 'rebase.autoStash' 2>/dev/null` && test "$git_set_VAL" = "true"; then :; else 132 echo "Setting 'rebase.autoStash' to 'true' for this repository." 133 "$GIT" config --local 'rebase.autoStash' 'true' && git_settings_modified='yes' 134 fi 135 fi 136 if test "$git_settings_modified" != "no"; then 137 echo "Some Git repository settings have been modified." 138 echo "Use the following command to prevent such modifications in the future:" 139 echo " touch '${GIT_DIR-.git}/mhd2_special_config'" 140 fi 141 fi 142 if test -f uncrustify.cfg && have_cmd ${UNCRUSTIFY}; then 143 if test -f "${GIT_DIR-.git}/hooks/pre-commit"; then 144 echo "Pre-commit Git hook already exists; skipping installation of the upstream file." 145 else 146 echo "Installing Uncrustify pre-commit Git hook" 147 rm -f "${GIT_DIR-.git}/hooks/pre-commit" 148 if test ${GIT_DIR+y}; then 149 ln -s "`pwd`/contrib/precommit_hook.sh" "${GIT_DIR}/hooks/pre-commit" 150 else 151 ln -s ../../contrib/precommit_hook.sh .git/hooks/pre-commit 152 fi 153 test $? -eq 0 || cp contrib/precommit_hook.sh "${GIT_DIR-.git}/hooks/pre-commit" || \ 154 echo "Failed to install pre-commit Git hook" 1>&2 155 if test -f "${GIT_DIR-.git}/hooks/pre-commit"; then 156 if chmod +x "${GIT_DIR-.git}/hooks/pre-commit"; then :; else 157 echo "Failed to mark the pre-commit Git hook as executable" 1>&2 158 fi 159 if dir_GIT_HOOKS=`"$GIT" config --get core.hooksPath 2>/dev/null` && test "X$dir_GIT_HOOKS" != "X${GIT_DIR-.git}/hooks"; then 160 echo "The installed hook will not be used due to the current Git configuration." 161 echo "Consider updating the Git configuration by running the following command:" 162 echo " '$GIT' config --local core.hooksPath '${GIT_DIR-.git}/hooks'" 163 fi 164 fi 165 fi 166 fi 167 fi 168 else 169 echo "No 'git' command detected; skipping installation of the pre-commit Git hook and Git configuration." 170 fi 171 else 172 echo "No '${GIT_DIR-.git}' directory found; skipping installation of the pre-commit Git hook and Git configuration." 173 fi 174 175 WANT_AUTOCONF=latest 176 WANT_AUTOMAKE=latest 177 export WANT_AUTOCONF 178 export WANT_AUTOMAKE 179 180 autoreconf -vi ${1+"$@"} || \ 181 echo "*** Failed to build Autoconf output files ***" >&2