package / ocaml-base-compiler.4.10.0 / tools / ocaml-objcopy-macosx
1 #!/usr/bin/env bash
2
3 #**************************************************************************
4 #* *
5 #* OCaml *
6 #* *
7 #* Damien Doligez, projet Cristal, INRIA Rocquencourt *
8 #* *
9 #* Copyright 2005 Institut National de Recherche en Informatique et *
10 #* en Automatique. *
11 #* *
12 #* All rights reserved. This file is distributed under the terms of *
13 #* the GNU Lesser General Public License version 2.1, with the *
14 #* special exception on linking described in the file LICENSE. *
15 #* *
16 #**************************************************************************
17
18 TMP="${TMPDIR=/tmp}"
19 TEMP="${TMP}"/ocaml-objcopy-$$.o
20 UNDEF="${TMP}"/ocaml-objcopy-$$.sym
21
22 usage () {
23 echo "usage: objcopy {--redefine-sym <old>=<new>} file.o" >&2
24 exit 2
25 }
26
27 : > "$UNDEF"
28
29 while : ; do
30 case $# in
31 0) break;;
32 *) case $1 in
33 --redefine-sym)
34 case $2 in
35 *=*) ALIAS="$ALIAS -i${2#*=}:${2%%=*}"
36 echo ${2%%=*} >>"$UNDEF"
37 ;;
38 *) usage;;
39 esac
40 shift 2
41 ;;
42 -*) usage;;
43 *) case $FILE in
44 "") FILE=$1; shift;;
45 *) usage;;
46 esac;;
47 esac;;
48 esac
49 done
50
51 ld -o "$TEMP" -r $ALIAS "$FILE"
52 ld -o "$FILE" -r -unexported_symbols_list "$UNDEF" "$TEMP"
53
54 rm -f "$TEMP" "$UNDEF"
55