bootstrap 6.75 KB
Newer Older
1
#! /bin/sh
2
3
4
5
6
7
8

fatal ()
{
  echo >&2 "$0: $@"
  exit 1
}

Guillaume Lazzara's avatar
Guillaume Lazzara committed
9
10
11
12
13
stderr ()
{
    echo >&2 "$0: $@"
}

Roland Levillain's avatar
Roland Levillain committed
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
usage ()
{
  cat <<EOF
Usage: $0 [OPTION]

Options:
  -h, --help              display this message
  -r, --regen             regenerate files stored in the repository

Report bugs to <olena-bugs@lrde.epita.fr>
EOF
}

# Regenerate files stored in the repository?
regen_p=false

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
awk_strverscmp='
  # Use only awk features that work with 7th edition Unix awk (1978).
  # My, what an old awk you have, Mr. Solaris!
  END {
    while (length(v1) || length(v2)) {
      # Set d1 to be the next thing to compare from v1, and likewise for d2.
      # Normally this is a single character, but if v1 and v2 contain digits,
      # compare them as integers and fractions as strverscmp does.
      if (v1 ~ /^[0-9]/ && v2 ~ /^[0-9]/) {
	# Split v1 and v2 into their leading digit string components d1 and d2,
	# and advance v1 and v2 past the leading digit strings.
	for (len1 = 1; substr(v1, len1 + 1) ~ /^[0-9]/; len1++) continue
	for (len2 = 1; substr(v2, len2 + 1) ~ /^[0-9]/; len2++) continue
	d1 = substr(v1, 1, len1); v1 = substr(v1, len1 + 1)
	d2 = substr(v2, 1, len2); v2 = substr(v2, len2 + 1)
	if (d1 ~ /^0/) {
	  if (d2 ~ /^0/) {
	    # Compare two fractions.
	    while (d1 ~ /^0/ && d2 ~ /^0/) {
	      d1 = substr(d1, 2); len1--
	      d2 = substr(d2, 2); len2--
	    }
	    if (len1 != len2 && ! (len1 && len2 && substr(d1, 1, 1) == substr(d2, 1, 1))) {
	      # The two components differ in length, and the common prefix
	      # contains only leading zeros.  Consider the longer to be less.
	      d1 = -len1
	      d2 = -len2
	    } else {
	      # Otherwise, compare as strings.
	      d1 = "x" d1
	      d2 = "x" d2
	    }
	  } else {
	    # A fraction is less than an integer.
	    exit 1
	  }
	} else {
	  if (d2 ~ /^0/) {
	    # An integer is greater than a fraction.
	    exit 2
	  } else {
	    # Compare two integers.
	    d1 += 0
	    d2 += 0
	  }
	}
      } else {
	# The normal case, without worrying about digits.
	if (v1 == "") d1 = v1; else { d1 = substr(v1, 1, 1); v1 = substr(v1,2) }
	if (v2 == "") d2 = v2; else { d2 = substr(v2, 1, 1); v2 = substr(v2,2) }
      }
      if (d1 < d2) exit 1
      if (d1 > d2) exit 2
    }
  }
'

version_compare ()
{
  awk "$awk_strverscmp" v1="$1" v2="$2" /dev/null
  case $? in
    1)  echo '<';;
    0)  echo '=';;
    2)  echo '>';;
  esac
}

97
98
# require TOOL REQUIREMENT [OPTION]
# ---------------------------------
99
# Test that TOOL exists, and its version is at least REQUIREMENT.
100
# If given, use OPTION to query TOOL; use `--version' otherwise.
101
102
require ()
{
103
104
  local option
  if test $# -eq 3; then option=$3; else option=--version; fi
105
106
  local version=$(eval "$1 $option" \
                  | sed -n 's/[^0-9.]*\([0-9][0-9.]*\).*/\1/p;q')
107
  test x"$version" != x ||
108
    fatal "$1 (version $2 or better) is required"
109
  case $(version_compare "$2" "$version") in
110
    '>') fatal "$1 $2 or better is required: this is $1 $version";;
111
112
113
  esac
}

Guillaume Lazzara's avatar
Guillaume Lazzara committed
114
115
116
117
118
# run DIRECTORY COMMAND-LINE
# --------------------------
run ()
{
    (
119
        set -e
Guillaume Lazzara's avatar
Guillaume Lazzara committed
120
121
122
123
124
125
126
127
128
129
130
        stderr "$@"
        cd "$1"
        shift
        if ! "$@"; then
            fatal "unexpected failure: $@"
            exit 1
        fi
    )
}


131
132
133
# Failures do matter.
set -e

Roland Levillain's avatar
Roland Levillain committed
134
135
136
137
138
139
140
141
142
# Process arguments.
for arg in "$@"; do
  case "$arg" in
    -h|--help) usage; exit 0 ;;
    -r|--regen) regen_p=true ;;
    *) fatal "error: unrecognized option: $1" ;;
  esac
done

143
# Requirements over bootstrap tools.
144
require autoconf 2.61
Roland Levillain's avatar
Roland Levillain committed
145
require automake 1.11
146
147
148
149
150
151
152
153
154
155
libtoolize=libtoolize
for l in "$LIBTOOLIZE" glibtoolize libtoolize;
do
  if ($l --version) >/dev/null 2>&1; then
    libtoolize=$l
    break
  fi
done
export LIBTOOLIZE=$libtoolize
require $libtoolize 1.5.22
156

157
require doxygen 1.5.6
158
159
160
161
162
# We used to require `convert' from ImageMagick 6.3.7, but `convert'
# from GraphicsMagick 1.3.12 is also fine.  Use that later revision
# number even if ImageMagick is actually used so as to be compatible
# with both implementations.
require convert 1.3.12 -version
163
require hevea 1.10 -version
164
165
166
167
168
# Admittedly a bit hacky, but these tools
# 1. display their version numbers on stderr, not stdout; and
# 2. contain a digit ("2") in their name, which disturbs `require'.
require bibtex2html 1.95 "--version 2>&1 | sed 's/bibtex2html//'"
require bib2bib 1.95 "--version 2>&1 | sed 's/bib2bib//'"
169

170

Roland Levillain's avatar
Roland Levillain committed
171
172
# Regen files stored in the repository if asked so.
if $regen_p; then
173
174
175
176
177
  # Generate `milena/headers.mk'.
  (cd milena && ../build-aux/generate_dist_headers.sh mln headers.mk)
  # Generate `scribo/headers.mk'.
  (cd scribo && ../build-aux/generate_dist_headers.sh scribo headers.mk)

Roland Levillain's avatar
Roland Levillain committed
178
179
180
181
182
183
184
185
186
187
188
  # Generate files of Milena's documentation.
  # * Figures.
  (
    cd milena/doc
    rm -f figures.mk.tmp
    ./gen-figures-mk >figures.mk.tmp
    mv -f figures.mk.tmp figures.mk
    chmod -w figures.mk
  )
  # * Examples.
  rm -f milena/doc/examples.mk.tmp
189
  milena/doc/gen-make-variable EXAMPLES					      \
Roland Levillain's avatar
Roland Levillain committed
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
    `find milena/doc/examples -name '*.cc' | sed 's,^milena/doc,\$(srcdir),'` \
    >milena/doc/examples.mk.tmp
  mv -f milena/doc/examples.mk.tmp milena/doc/examples.mk
  chmod -w milena/doc/examples.mk
  # * Split examples.
  (
    cd milena/doc
    rm -f split-examples.mk.tmp
    ./gen-split-examples-mk >split-examples.mk.tmp
    mv -f split-examples.mk.tmp split-examples.mk
    chmod -w split-examples.mk
  )
  # * Outputs.
  rm -f milena/doc/outputs.mk.tmp
  milena/doc/gen-make-variable OUTPUTS				\
    `find milena/doc/examples					\
         -name \*.cc -a \! -path milena/doc/examples/trash/\*	\
       | sed -e 's,milena/doc/examples/,,'			\
208
             -e 'y,/,_,'					\
Roland Levillain's avatar
Roland Levillain committed
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
             -e 's,\(.*\)\.cc$,$(srcdir)/outputs/\1.txt,'`	\
    >milena/doc/outputs.mk.tmp
  mv -f milena/doc/outputs.mk.tmp milena/doc/outputs.mk
  chmod -w milena/doc/outputs.mk
  # * Outputs rules and timestamps.
  (
    cd milena/doc
    rm -f examples-outputs.mk.tmp
    ./gen-examples-outputs-mk					\
      `find examples -name \*.cc -a \! -path examples/trash/\*	\
         | env LC_ALL=C sort`					\
      >examples-outputs.mk.tmp
    mv -f examples-outputs.mk.tmp examples-outputs.mk
    chmod -w examples-outputs.mk
  )
  # * Split outputs.
  (
    cd milena/doc
    rm -f split-outputs.mk.tmp
    ./gen-split-outputs-mk >split-outputs.mk.tmp
    mv -f split-outputs.mk.tmp split-outputs.mk
    chmod -w split-outputs.mk
  )
232
fi
Roland Levillain's avatar
Roland Levillain committed
233

234
235
236
237
238
239
240
241
242
243
# Generate unit tests files.  These actions are not part of the `-r'
# option, since unit tests files are not stored in the repository.
#
# * Milena unit tests files.
run . ./build-aux/build_unit_test.sh		\
  milena/mln					\
  milena/tests/unit_test			\
  milena/tests/unit_test/disabled_tests		\
  mln
# *Scribo unit tests files.
244
245
246
247
248
run . ./build-aux/build_unit_test.sh    \
  scribo/scribo				\
  scribo/tests/unit_test		\
  scribo/tests/unit_test/disabled_tests \
  scribo
249

250
251
# Install the GNU Build System.
autoreconf -f -v -i