#!/bin/sh # A camlp4o/ocamlfind combo # Public Domain. Use at your own risk. # Please report bugs and fixes to Martin Jambon # Thanks to Gerd Stolpmann src='' pkg='' syntax='camlp4o' libfiles='' usage(){ echo 'camlp4find is a preprocessing command which can be used instead of camlp4o or camlp4r in order to use ocamlfind packages. Usage: camlp4find [camlp4o|camlp4r] [packages] [files to parse] camlp4find -echo camlp4find -help A "file to parse" can be specified as follows: somefile.ml somefile.mli -impl anyfile -intf anyfile -echo displays the command which should be executed and exits -help displays this message Example: The following command assumes that the packages pa_tryfinally, pa_openin and micmatch_pcre are installed. pr_o.cmo is the standard module which will generate a human-readable output for the preprocessed OCaml code. The file to process does not end in .ml, so we have to use the -impl option exactly like with camlp4o: camlp4find pa_tryfinally pa_openin micmatch_pcre pr_o.cmo -impl somefile.mml ' 1>&2 exit 2 } while : ; do case "$1" in "") break;; camlp4o) syntax=camlp4o;; camlp4r) syntax=camlp4r;; -impl) shift; src="$src -impl $1";; -intf) shift; src="$src -intf $1";; *.ml) src="$src $1";; *.cmo|*.cma) libfiles="$libfiles $1";; -echo) echo=true;; -*) usage;; *) pkg="$pkg $1";; esac shift done i_options=`ocamlfind query -predicates "syntax,preprocessor,$syntax" \ $pkg -i-format` a_options=`ocamlfind query -predicates "syntax,preprocessor,$syntax" \ $pkg -a-format` cmd="$syntax $i_options $a_options -I +camlp4 $libfiles $src" if [ -z "$echo" ] then exec $cmd else echo $cmd fi