diff options
Diffstat (limited to 'ocamlbuild/examples')
-rw-r--r-- | ocamlbuild/examples/example1/hello.ml | 5 | ||||
-rw-r--r-- | ocamlbuild/examples/example2/greet.ml | 6 | ||||
-rw-r--r-- | ocamlbuild/examples/example2/hello.ml | 14 | ||||
-rw-r--r-- | ocamlbuild/examples/example3/epoch.ml | 6 | ||||
-rwxr-xr-x | ocamlbuild/examples/example3/make.sh | 32 |
5 files changed, 63 insertions, 0 deletions
diff --git a/ocamlbuild/examples/example1/hello.ml b/ocamlbuild/examples/example1/hello.ml new file mode 100644 index 000000000..c85cb66b8 --- /dev/null +++ b/ocamlbuild/examples/example1/hello.ml @@ -0,0 +1,5 @@ +let _ = + Printf.printf "Hello, %s ! My name is %s\n" + (if Array.length Sys.argv > 1 then Sys.argv.(1) else "stranger") + Sys.argv.(0) +;; diff --git a/ocamlbuild/examples/example2/greet.ml b/ocamlbuild/examples/example2/greet.ml new file mode 100644 index 000000000..ec8088916 --- /dev/null +++ b/ocamlbuild/examples/example2/greet.ml @@ -0,0 +1,6 @@ +type how = Nicely | Badly;; + +let greet how who = + match how with Nicely -> Printf.printf "Hello, %s !\n" who + | Badly -> Printf.printf "Oh, here is that %s again.\n" who +;; diff --git a/ocamlbuild/examples/example2/hello.ml b/ocamlbuild/examples/example2/hello.ml new file mode 100644 index 000000000..b48806a3d --- /dev/null +++ b/ocamlbuild/examples/example2/hello.ml @@ -0,0 +1,14 @@ +open Greet + +let _ = + let name = + if Array.length Sys.argv > 1 then + Sys.argv.(1) + else + "stranger" + in + greet + (if name = "Caesar" then Nicely else Badly) + name; + Printf.printf "My name is %s\n" Sys.argv.(0) +;; diff --git a/ocamlbuild/examples/example3/epoch.ml b/ocamlbuild/examples/example3/epoch.ml new file mode 100644 index 000000000..ad95a0394 --- /dev/null +++ b/ocamlbuild/examples/example3/epoch.ml @@ -0,0 +1,6 @@ +let _ = + let s = Num.num_of_string (Printf.sprintf "%.0f" (Unix.gettimeofday ())) in + let ps = Num.mult_num (Num.num_of_string "1000000000000") s in + Printf.printf "%s picoseconds have passed since January 1st, 1970.\n" + (Num.string_of_num ps) +;; diff --git a/ocamlbuild/examples/example3/make.sh b/ocamlbuild/examples/example3/make.sh new file mode 100755 index 000000000..3588a713f --- /dev/null +++ b/ocamlbuild/examples/example3/make.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +set -e + +TARGET=epoch +FLAGS="-libs unix,nums" +OCAMLBUILD=ocamlbuild + +ocb() +{ + $OCAMLBUILD $FLAGS $* +} + +rule() { + case $1 in + clean) ocb -clean;; + native) ocb $TARGET.native;; + byte) ocb $TARGET.byte;; + all) ocb $TARGET.native $TARGET.byte;; + depend) echo "Not needed.";; + *) echo "Unknown action $1";; + esac; +} + +if [ $# -eq 0 ]; then + rule all +else + while [ $# -gt 0 ]; do + rule $1; + shift + done +fi |