summaryrefslogtreecommitdiff
path: root/tools/ocaml-objcopy-macosx
blob: 3b8dcc2af3a276197248c88c92105b6a9e8f85be (plain)
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
#!/bin/bash

#**************************************************************************
#*                                                                        *
#*                                 OCaml                                  *
#*                                                                        *
#*           Damien Doligez, projet Cristal, INRIA Rocquencourt           *
#*                                                                        *
#*   Copyright 2005 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.          *
#*                                                                        *
#**************************************************************************

TMP="${TMPDIR=/tmp}"
TEMP="${TMP}"/ocaml-objcopy-$$.o
UNDEF="${TMP}"/ocaml-objcopy-$$.sym

usage () {
  echo "usage: objcopy {--redefine-sym <old>=<new>} file.o" >&2
  exit 2
}

: > "$UNDEF"

while : ; do
  case $# in
    0) break;;
    *) case $1 in
         --redefine-sym)
           case $2 in
             *=*) ALIAS="$ALIAS -i${2#*=}:${2%%=*}"
                  echo ${2%%=*} >>"$UNDEF"
                  ;;
             *) usage;;
           esac
           shift 2
           ;;
         -*) usage;;
         *) case $FILE in
              "") FILE=$1; shift;;
              *) usage;;
            esac;;
       esac;;
  esac
done

ld -o "$TEMP" -r $ALIAS "$FILE"
ld -o "$FILE" -r -unexported_symbols_list "$UNDEF" "$TEMP"

rm -f "$TEMP" "$UNDEF"