|
| 1 | +#!/bin/bash |
| 2 | +# create a metamath executable from scratch |
| 3 | + |
| 4 | +# Change to the top folder of metamath-exe before |
| 5 | +# running this script, unless you provide the -m option. |
| 6 | + |
| 7 | +# Draft version, proof of concept. |
| 8 | + |
| 9 | +help_text=\ |
| 10 | +'Builds all artefacts in the metamath-exe/build subfolder (if not directed |
| 11 | +otherwise). Change to the metamath-exe top folder first before running |
| 12 | +this script, or issue the -m option. |
| 13 | +
|
| 14 | +Possible options are: |
| 15 | +
|
| 16 | +-a Used by autotools. Put hyphens in the version string when used with -v |
| 17 | +-b build binary only, no reconfigure. Faster, but should not be used on first run. |
| 18 | +-c Clean the build directory. |
| 19 | +-d build documentation using Doxygen, in addition to building the executable. |
| 20 | +-h print this help and exit. |
| 21 | +-m followed by a directory: top folder of metamath-exe. |
| 22 | + Relative paths are relative to the current directory. |
| 23 | +-o followed by a directory: optionally clean directory and build all artefacts there. |
| 24 | + Relative paths are relative to the destination'"'"'s top metamath-exe directory. |
| 25 | +-v extract the version from metamath sources, print it and exit' |
| 26 | + |
| 27 | +#============ evaluate command line parameters ========== |
| 28 | + |
| 29 | +do_autoconf=1 |
| 30 | +do_clean=0 |
| 31 | +do_doc=0 |
| 32 | +print_help=0 |
| 33 | +version_only=0 |
| 34 | +version_for_autoconf=0 |
| 35 | +unset dest_dir |
| 36 | +top_dir="$(pwd)" |
| 37 | + |
| 38 | +while getopts abcdhm:o:v flag |
| 39 | +do |
| 40 | + case "${flag}" in |
| 41 | + a) version_for_autoconf=1;; |
| 42 | + b) do_autoconf=0;; |
| 43 | + c) do_clean=1;; |
| 44 | + d) do_doc=1;; |
| 45 | + h) print_help=1;; |
| 46 | + m) cd "${OPTARG}" && top_dir=$(pwd);; |
| 47 | + o) dest_dir=${OPTARG};; |
| 48 | + v) version_only=1;; |
| 49 | + esac |
| 50 | +done |
| 51 | + |
| 52 | +if [ $print_help -gt 0 ] |
| 53 | +then |
| 54 | + echo "$help_text" |
| 55 | + exit |
| 56 | +fi |
| 57 | + |
| 58 | +#=========== setup environment ===================== |
| 59 | + |
| 60 | +src_dir="$top_dir/src" |
| 61 | +build_dir=${dest_dir:-"$top_dir/build"} |
| 62 | + |
| 63 | +# verify we can navigate to the sources |
| 64 | +if [ ! -f "$src_dir/metamath.c" ] |
| 65 | +then |
| 66 | + echo 'This script must be run from the top folder of the metamath-exe directory.' |
| 67 | + echo 'Run ./build.sh -h for more information' |
| 68 | + exit |
| 69 | +fi |
| 70 | + |
| 71 | +cd "$top_dir" |
| 72 | + |
| 73 | +#========= extract the version from metamath.c ============= |
| 74 | + |
| 75 | +# look in metamath.c for a line matching the pattern ' #define MVERSION "<version>" ' |
| 76 | +# and save the line in VERSION |
| 77 | +version=`grep '[[:space:]]*#[[:space:]]*define[[:space:]][[:space:]]*MVERSION[[:space:]][[:space:]]*"[^"]*"' "$src_dir/metamath.c"` |
| 78 | + |
| 79 | +# extract the version (without quotes) from the saved line |
| 80 | + |
| 81 | +# strip everything up to and including the first quote character |
| 82 | +version=${version#*\"} |
| 83 | +# strip everything from the first remaining quote character on |
| 84 | +version=${version%%\"*} |
| 85 | + |
| 86 | +if [ $version_only -eq 1 ] |
| 87 | +then |
| 88 | + if [ $version_for_autoconf -eq 1 ]; then |
| 89 | + echo "$version" | tr ' ' - |
| 90 | + else |
| 91 | + echo "$version" |
| 92 | + fi |
| 93 | + exit |
| 94 | +fi |
| 95 | + |
| 96 | +# clear the build directory |
| 97 | +if [ $do_clean -eq 1 ] |
| 98 | +then |
| 99 | + rm -rf "$build_dir" |
| 100 | + if [ $do_autoconf -eq 0 ]; then exit; fi |
| 101 | +fi |
| 102 | + |
| 103 | +# Enter the build directory |
| 104 | +mkdir -p "$build_dir" |
| 105 | +cd "$build_dir" |
| 106 | + |
| 107 | +# allow external programs easy access to the metamath version extracted from |
| 108 | +# the sources |
| 109 | +echo "$version" > metamath_version |
| 110 | + |
| 111 | +#=========== run the configure.ac ===================== |
| 112 | + |
| 113 | +if [ $do_autoconf -eq 1 ] |
| 114 | +then |
| 115 | + cd "$top_dir" |
| 116 | + autoreconf -i |
| 117 | + |
| 118 | + cd "$build_dir" |
| 119 | + "$top_dir/configure" -q |
| 120 | +fi |
| 121 | + |
| 122 | +#=========== do the build ===================== |
| 123 | + |
| 124 | +make |
| 125 | +mv src/metamath "$top_dir" |
| 126 | + |
| 127 | +#=========== run Doxygen documentation generator ===================== |
| 128 | + |
| 129 | +if [ $do_doc -eq 1 ] |
| 130 | +then |
| 131 | + if ! command doxygen -v &> /dev/null; then |
| 132 | + echo >&2 'doxygen not found. Cannot build documentation.' |
| 133 | + exit 1 |
| 134 | + fi |
| 135 | + |
| 136 | + cd "$build_dir/src" |
| 137 | + |
| 138 | + # create a Doxyfile.local and use it for creation of documentation locally |
| 139 | + |
| 140 | + # start with the settings given by the distribution |
| 141 | + cp "$top_dir/Doxyfile.diff" Doxyfile.local |
| 142 | + |
| 143 | + # add the project version number |
| 144 | + echo "PROJECT_NUMBER = \"$version\"" >> Doxyfile.local |
| 145 | + |
| 146 | + # let the users preferences always override... |
| 147 | + if [ -f "$top_dir/Doxyfile" ] |
| 148 | + then |
| 149 | + cat "$top_dir/Doxyfile" >> Doxyfile.local |
| 150 | + fi |
| 151 | + |
| 152 | + # ... except for the destination directory. Force this to the build folder. |
| 153 | + echo "OUTPUT_DIRECTORY = \"$build_dir\"" >> Doxyfile.local |
| 154 | + |
| 155 | + # make sure the logo is in the build directory |
| 156 | + cp --force --symbolic-link "$top_dir/doc/Metamath.png" . |
| 157 | + |
| 158 | + doxygen Doxyfile.local |
| 159 | + echo "Documentation has been generated at $build_dir/html/index.html" |
| 160 | +fi |
0 commit comments