3 # Copyright (C) 2013 Red Hat Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 TEMP=`getopt -o 'gI:o:' --long 'help,pkgdir:' -n goaljobs -- "$@"`
23 echo "goaljobs: could not parse command line arguments"
32 echo "Usage: goaljobs [-o output] source.ml"
33 echo "See goaljobs(1) man page for more information."
61 echo "Internal error!"
71 # Bytecode or native code?
72 if ocamlopt --help >/dev/null 2>&1; then
80 # Get name of final source file.
83 # Get module names of all source files, and check them.
87 # Module name of source file.
88 module=`basename "$src" .ml`
89 module="$(tr '[:lower:]' '[:upper:]' <<< ${module:0:1})${module:1}"
91 # Check module name is a valid OCaml name.
92 if [[ ! ( "$module" =~ ^[A-Z][a-zA-Z0-9_]*$ ) ]]; then
93 echo "$0: module name '$module' is not a valid OCaml module name."
94 echo "You have to use a file that contains only letters, numbers and"
95 echo "underscore, and starts with a letter."
99 modules[i++]="$module"
102 # Choose an output filename if the user didn't select one.
103 if [ "$output" = "" ]; then
104 output=`basename "$final" .ml`
107 # Create a temporary 'main' file to handle command line args.
108 main=$(mktemp --suffix=.ml /tmp/goaljobsmainXXXXXX)
109 echo "let modules = [" > $main
110 for module in "${modules[@]}"; do
111 echo " \"$module\";" >> $main
114 echo "Goaljobs.init ()" >> $main
116 # Either use installed package or if user selected --pkgdir then
117 # use goaljobs from that directory.
119 if [ "$pkgdir" = "" ]; then
121 pkg[1]="goaljobs,goaljobs.syntax"
123 # Get the dependencies manually. Note that calendar requires
125 pkgdir="$(cd $pkgdir; pwd)"
128 pkg[2]="unix.$libext"
132 pkg[6]="calendarLib.$libext"
133 pkg[7]="goaljobs.$libext"
135 pkg[9]="camlp4o $pkgdir/pa_goal.cmo"
138 # Compile the input file(s).
140 ocamlfind $best "${passthru[@]}" "${pkg[@]}" "$@" $main -o "$output"
141 ocamlfind $best "${passthru[@]}" "${pkg[@]}" "$@" $main -o "$output"
143 mainbase="$(echo $main | sed s,\.ml$,,)"