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
|
#!/bin/sh
#**************************************************************************
#* *
#* OCaml *
#* *
#* Xavier Leroy, projet Cristal, INRIA Rocquencourt *
#* *
#* Copyright 1999 Institut National de Recherche en Informatique et *
#* en Automatique. *
#* *
#* All rights reserved. This file is distributed under the terms of *
#* the GNU Lesser General Public License version 2.1, with the *
#* special exception on linking described in the file LICENSE. *
#* *
#**************************************************************************
# If primitives contain duplicated lines (e.g. because the code is defined
# like
# #ifdef X
# CAMLprim value caml_foo() ...
# #else
# CAMLprim value caml_foo() ...
# #endif), horrible things will happen: duplicated entries in Runtimedef ->
# double registration in Symtable -> empty entry in the PRIM table ->
# the bytecode interpreter is confused.
# We sort the primitive file and remove duplicates to avoid this problem.
# Warning: we use "sort | uniq" instead of "sort -u" because in the MSVC
# port, the "sort" program in the path is Microsoft's and not cygwin's
# Warning: POSIX sort is locale dependent, that's why we set LC_ALL explicitly.
# Sort is unstable for "is_directory" and "isatty"
# see http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sort.html:
# "using sort to process pathnames, it is recommended that LC_ALL .. set to C"
# #8985: in sed, the meaning of character range a-z depends on the locale,
# so force C locale throughout.
export LC_ALL=C
case $# in
0) echo "Usage: gen_primitives.sh <primitives file> <.c files>" 1>&2
exit 2;;
*) primitives="$1"; shift;;
esac
tmp_primitives="$primitives.tmp$$"
# The tr -d '\r' is _after_ the call to sort just in case sort happens to be the
# Windows version.
sed -n -e 's/^CAMLprim value \([a-z][a-z0-9_]*\).*$/\1/p' "$@" | \
sort | tr -d '\r' | uniq > "$tmp_primitives"
# To speed up builds, we avoid changing "primitives" when files
# containing primitives change but the primitives table does not
if test -f "$primitives" && cmp -s "$tmp_primitives" "$primitives"
then rm "$tmp_primitives"
else mv "$tmp_primitives" "$primitives"
fi
|