summaryrefslogtreecommitdiff
path: root/gnu.ocaml.obj.mk
diff options
context:
space:
mode:
authorGrégoire Duchêne <gduchene@awhk.org>2014-09-11 17:31:37 +0200
committerGrégoire Duchêne <gduchene@awhk.org>2014-09-24 16:06:04 +0200
commit1ff288efb8ae94291e6ee7deb7cb066d85c1c450 (patch)
treeecb84de38fec7b1683ba775a4590117bb9c127ff /gnu.ocaml.obj.mk
parentfce67653347965627bc3adc3575078635e28f519 (diff)
Added subdirectory support
By default, ostumake will look for OCaml code into every subdirectory available. It is possible to exclude files and/or directories by adding them to the EXCL variable. The previous behavior is also available by setting the NOSUBDIR variable. Most of the code has been moved to the gnu.ocaml.obj.mk file. This allows the user to choose between building a whole binary or just the object files. This commit closes #3.
Diffstat (limited to 'gnu.ocaml.obj.mk')
-rw-r--r--gnu.ocaml.obj.mk107
1 files changed, 107 insertions, 0 deletions
diff --git a/gnu.ocaml.obj.mk b/gnu.ocaml.obj.mk
new file mode 100644
index 0000000..2ec4735
--- /dev/null
+++ b/gnu.ocaml.obj.mk
@@ -0,0 +1,107 @@
+# Copyright (c) 2014, Grégoire Duchêne <gduchene@awhk.org>
+#
+# Permission to use, copy, modify, and/or distribute this software for
+# any purpose with or without fee is hereby granted, provided that the
+# above copyright notice and this permission notice appear in all
+# copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
+# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
+# AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+# PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+# PERFORMANCE OF THIS SOFTWARE.
+
+include $(dir $(lastword $(MAKEFILE_LIST)))gnu.ocaml.rules.mk
+
+_FNDFLAGS= . $(_MAXDEPTH) -type f -regex $(_PAT) $(_EXL)
+
+ifdef NOSUBDIR
+_MAXDEPTH= -maxdepth 1
+endif
+
+ifdef EXCL
+_EXL= $(foreach e, $(EXCL), -not -regex '.*$e.*')
+endif
+
+DEPFILE?= .Makefile.dep
+MENHIR?= menhir
+OCAMLDEP?= ocamldep
+OCAMLLEX?= ocamllex
+
+.DEFAULT_GOAL:= obj
+
+_FND= find
+_PAT= '.*ml[ily]*.*'
+_SRC= $(shell $(_FND) $(_FNDFLAGS))
+_ORD= $(CSRC) $(shell $(OCAMLDEP) $(_INC) -sort $(_SRC))
+_INC= $(foreach e, $(sort $(foreach e, $(_SRC), $(dir $e))), -I '$e')
+
+ifdef CSRC
+ifndef OCAMLNATIVE
+OCAMLFLAGS+= -custom
+endif
+endif
+
+ifndef OCAMLC
+ifdef OCAMLNATIVE
+OCAMLC= ocamlfind ocamlopt
+else
+OCAMLC= ocamlfind ocamlc
+endif
+endif
+
+ifdef PKG
+OCAMLFLAGS+= -linkpkg -package '$(PKG)'
+endif
+
+OCAMLFLAGS+= $(DEBUG)
+
+ifndef NOSUBDIR
+OCAMLFLAGS+= $(_INC)
+endif
+
+_OBJ= $(patsubst %.c, %.o, $(filter %.c, $(_ORD)))
+
+ifdef OCAMLNATIVE
+_OBJ+= $(patsubst %.ml, %.cmx, $(filter %.ml, $(_ORD)))
+_CLN+= $(patsubst %.cmx, %.o, $(_OBJ))
+_CLN+= $(patsubst %.cmx, %.cmi, $(_OBJ))
+else
+_OBJ+= $(patsubst %.ml, %.cmo, $(filter %.ml, $(_ORD)))
+_CLN+= $(patsubst %.cmo, %.cmi, $(_OBJ))
+endif
+
+_INT= $(patsubst %.mly, %.ml, $(filter %.mly, $(_SRC)))
+_INT+= $(patsubst %.mll, %.ml, $(filter %.mll, $(_SRC)))
+_CLN+= $(patsubst %.ml, %.mli, $(_INT))
+
+-include $(DEPFILE)
+
+$(_OBJ): $(DEPFILE)
+
+$(DEPFILE): $(_SRC) $(_INT)
+ $(OCAMLDEP) $(_INC) $(_SRC) > $(DEPFILE)
+
+all: $(_OBJ)
+
+clean:
+ $(RM) $(_CLN) $(_INT) $(_OBJ) $(PROG)
+
+dep:
+ $(OCAMLDEP) $(_INC) $(_SRC) > $(DEPFILE)
+
+dist-clean: clean
+ $(RM) $(DEPFILE)
+
+obj: $(_OBJ)
+
+.PHONY: dep
+
+ifndef OSTUMAKE_DEBUG
+.SILENT: $(DEPFILE) dep
+endif
+
+.SUFFIXES: