Initial commit.
[todo.git] / ocaml-link.sh
1 #!/bin/bash -
2 # (C) Copyright 2015-2016 Red Hat Inc.
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 # See guestfs-hacking(1) section "HOW OCAML PROGRAMS ARE COMPILED AND LINKED"
19
20 # Hack automake to link OCaml-based binaries properly.
21 # There is no other way to add the -cclib parameter to the end of
22 # the command line.
23
24 # Usage:
25 #   ./ocaml-link.sh -cclib '...' -- ARGS
26 # Pass the cclib argument separately, and the rest as separated
27 # arguments.
28
29 TEMP=`getopt -a -o '' --long 'cclib:' \
30   -n "$(basename $0)" -- "$@"`
31 if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
32 eval set -- "$TEMP"
33
34 cclib=
35
36 while true ; do
37   case "$1" in
38     -cclib|--cclib) cclib="$2" ; shift 2 ;;
39     --) shift ; break ;;
40     *) echo "Internal error!" ; exit 1 ;;
41   esac
42 done
43
44 exec "$@" -linkpkg -cclib "${cclib}"