~ubuntu-branches/ubuntu/wily/swi-prolog/wily

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
#!/usr/bin/env bash
#
# ./prepare
#
# Prepare sources obtained from GIT for   compilation. Runs GNU autoconf
# to generate all configure  files   and  optionally downloads generated
# documentation  files.  On  first  run  the  desired  handling  of  the
# documentation is stored in the  file   .doc-action.  This  file can be
# deleted to make this script ask again.
#
# This script must be run each time after updating your version from the
# master repository. It is  normally  executed   from  configure  in the
# toplevel directory.
#
# On Windows installations, this script may be run from the MsysGit bash
# shell to initialise the submodules and download the documentation.

# default submodules to pull.  Use --all to get all registered submodule
# You can also create a file modules in this directory, listing the
# desired modules one-per-line

COREMODULES="bench packages/chr packages/clpqr packages/inclpr packages/jpl"
COREMODULES+=" packages/xpce packages/odbc packages/protobufs"
COREMODULES+=" packages/sgml packages/clib packages/http packages/plunit"
COREMODULES+=" packages/pldoc packages/RDF packages/semweb packages/ssl"
COREMODULES+=" packages/R packages/zlib packages/tipc packages/table"
COREMODULES+=" packages/nlp packages/cpp packages/windows packages/PDT"
COREMODULES+=" packages/utf8proc packages/archive"

version="`cat VERSION`"
server="http://www.swi-prolog.org"
serverpath="/download"
serverurl="$server$serverpath"
yes=ask
man=auto
tar=tar

usage()
{
cat << _EOM_
Usage: $0 [--yes] [--all] [--man]
_EOM_
  exit 1
}


while [ ! -z "$1" ]; do
  case "$1" in
    --yes)
	yes=yes
	shift
	;;
    --all)
	COREMODULES=
	shift
	;;
    --man)
	man=download
	shift
	;;
    *)
	usage
	;;
  esac
done


findexe()
{ oldifs="$IFS"
  IFS=:
  for d in $PATH; do
    if [ -x $d/$1 ]; then
       IFS="$oldifs"
       return 0
    fi
  done
  IFS="$oldifs"
  return 1
}


confirm ()
{ if [ "$yes" = yes ]; then
    return 0
  fi

  while true; do
    printf "$1"
    read answer
    case "$answer" in
          y*)   return 0
                ;;
          n*)   return 1
                ;;
          *)
                echo "Please answer yes or no"
                ;;
    esac
  done
}


################################################################
# Fix programs
################################################################

if findexe gtar; then tar=gtar; fi;

################################################################
# Sub-modules
################################################################

nothere=`git submodule status $COREMODULES | awk '/^[-]/ {print $2}'`
if [ ! -z "$nothere" ]; then
  echo "The following submodules are not yet initialised"
  for m in $nothere; do
    echo "   $m"
  done
  if confirm "Do you want me to run git submodule update --init? "; then
    git submodule update --init $nothere
  fi
fi

outofdate=`git submodule | awk '/^[+]/ {print $2}'`
if [ -z "$outofdate" ]; then
  echo "All submodules are up-to-date"
else
  echo "The following submodules are not up-to-date"
  for m in $outofdate; do
    echo "   $m"
  done
  if confirm "Do you want me to run git submodule update? "; then
    git submodule update $outofdate
  fi
fi


################################################################
# Documentation check and download
################################################################

download_docs()
{ doc=pl-doc-$version.tar.gz

  if ! findexe curl; then
    echo "ERROR: downloading documentation requires the curl program"
    exit 1
  fi

  printf "Downloading documentation for SWI-Prolog $version from $server ..."
  curl $serverurl/generated/$doc > $doc
  ls -l $doc
  printf "Unpacking $doc ..."
  if $tar zxf $doc; then
     rm $doc
     echo "ok"
  else
     rm $doc
     echo "Unpack failed."
  fi
  eval_doc
}

eval_doc()
{ doc=unknown
  if [ ! -r man/Manual/index.html ]; then
    doc=absent
  else
    if [ -f doc-version ]; then
      docversion="`cat doc-version`"
      if [ "$docversion" != $version ]; then
	doc=out-of-date
      else
	doc=ok
      fi
    else
      doc=build
    fi
  fi
}

if [ "$man" = download ]; then
  doc=out-of-date
else
  eval_doc
fi

done=false
while [ "$done" = false ]; do
  case "$doc" in
    absent|out-of-date)
      if [ "$yes" = yes -o "$man" = download ]; then
        download_docs
      elif [ -f .doc-action ]; then
	done=true
	case "`cat .doc-action`" in
	  download)
	    download_docs
	    ;;
	  ask)
	    if confirm "Download documentation for $version from $server? "; then
		download_docs
	    fi
	    ;;
	  warn)
	    ;;
	esac
      else
	echo ""
	echo "Could not find documentation.  What do you want to do?"
	echo ""
	echo "    1) Download and unpack documentation from $server"
	echo "       and do this again automatically next time"
	echo "    2) Download and unpack documentation from $server"
	echo "       and ask next time"
	echo "    3) Warn only"
	echo ""
	printf "Option? "
	read answer
	case "$answer" in
	  1) echo download > .doc-action
	     download_docs
	     done=true
	     ;;
	  2) echo ask > .doc-action
	     download_docs
	     done=true
	     ;;
	  3) echo warn > .doc-action
	     done=true
	     ;;
	  *) goto doc_again
	     ;;
	esac
      fi
      ;;
    *)
      done=true
      ;;
  esac
done

case "$doc" in
  absent)
    cat << _EOM_
WARNING: Cannot find documentation in man/Manual.  See README.git
WARNING: and README.doc for further information.
_EOM_
    ;;
  out-of-date)
    cat << _EOM_
WARNING: Documentation version ($docversion) does not match version ($version)
_EOM_
    ;;
esac

################################################################
# Configuration
################################################################

confdir()
{ if grep AC_INIT configure.in 2>&1 >/dev/null; then
    for dep in "$2/ac_swi_c.m4" "$2/ac_swi_noc.m4"; do
      if [ -f configure -a -f "$dep" -a "$dep" -nt configure ]; then
        rm configure;
      fi
    done
    if [ -f configure -a ! configure.in -nt configure ]; then
      return
    fi
    printf "Generating configure in $1 ... "
    if grep AC_CONFIG_HEADER configure.in 2>&1 >/dev/null; then
      autoheader
    fi
    autoconf
    echo done
  fi
}


is_mingw()
{ case `uname` in
    MINGW*)
       return 0
       ;;
    *)
       return 1
       ;;
  esac
}


if findexe autoconf; then
  for f in `find . -name configure.in`; do
    pkgdir="$(cd packages && pwd)"
    d=`dirname $f`
    (cd $d && confdir $d $pkgdir)
  done
  echo "Your kit is prepared."
  echo "Please consult INSTALL for further instructions."
else
  if is_mingw; then
    cat << _EOM_
Detected MinGW but could not find GNU autoconf.

  - If you wish to use MinGW for building SWI-Prolog, please install
    autoconf and re-run this script.
  - If you plan to use Microsoft MSVC for building SWI-Prolog, GNU
    autoconf is not required and you may proceed with building.
_EOM_
  else
    echo 'WARNING: Cannot find GNU autoconf in $PATH.'
    echo 'WARNING: configure scripts cannot be created.'
    echo 'WARNING: Please install autoconf and re-run this script.'
  fi
fi

gettarget()
{ while true; do
    printf "$1"
    read answer
    case "$answer" in
          [xX]64)
		echo "X64"
		return 0
                ;;
	  [xX]86)
		echo "X86"
		return 0;
                ;;
          *)
                echo "Please answer X64 (for 64-bits) or X86 (for 32-bits)"
                ;;
    esac
  done
}

if is_mingw; then
  if [ -d "X64/lib" ]; then
    echo
    echo "Found prerequisites for X64 (64-bit) version"
  elif [ -d "X86/lib" ]; then
    echo
    echo "Found prerequisites for X86 (32-bit) version"
  else
    target=`gettarget "What is your target OS (x64 or X86)? "`
    if [ ! -z "$target" ]; then
      echo "Running git submodule init $target ..."
      git submodule init $target
      echo "ok"
    fi
  fi
fi