Skip to content
This repository has been archived by the owner on Nov 27, 2021. It is now read-only.

Commit

Permalink
Execute ocamlbuild only once per make invocation
Browse files Browse the repository at this point in the history
This fixes in particular parallel make execution (even
if it does not lead to any speed-up).
  • Loading branch information
kerneis committed Aug 20, 2013
1 parent bd92c2f commit 9576f47
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 33 deletions.
80 changes: 48 additions & 32 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# authors: George Necula, Gabriel Kerneis

CILLY = cilly
CIL_VERSION = @CIL_VERSION@

.PHONY: all
all: cillib $(CILLY)
Expand Down Expand Up @@ -52,53 +53,67 @@ OBJDIR = _build
BINDIR = bin
CILLYDIR = lib

OCAMLBEST = @OCAMLBEST@
CILLIB_FILES = $(OBJDIR)/src/cil.cma
ifeq ($(OCAMLBEST),opt)
CILLIB_FILES += $(OBJDIR)/src/cil.cmxa $(OBJDIR)/src/cil.a
EXEMODE = .native
else
EXEMODE = .byte
# Ocaml tools
OCAMLC = @OCAMLC@
OCAMLOPT = @OCAMLOPT@
OCAMLFIND = @OCAMLFIND@
OCAMLBUILD = @OCAMLBUILD@

PERL = @PERL@

# Build the list of files for cillib
CILLIB_TARGETS=
CILLY_EXE_FILES=

ifneq ($(OCAMLC),"no")
CILLIB_TARGETS += $(OBJDIR)/src/cil.cma
CILLY_EXE_FILES += $(OBJDIR)/src/cilly.byte
endif
ifneq ($(OCAMLOPT),"no")
CILLIB_TARGETS += $(OBJDIR)/src/cil.cmxa $(OBJDIR)/src/cil.a
CILLY_EXE_FILES += $(OBJDIR)/src/cilly.native
endif

EXE = $(EXEMODE)$(EXEEXT)
CILLIB_FILES = $(OBJDIR)/src/cil.libfiles
CILDOC_INDEX = $(OBJDIR)/cil.docdir/index.html

OCAMLBUILD = @OCAMLBUILD@
OCAMLBUILD += -build-dir $(OBJDIR) -no-links -classic-display

OCAMLFIND = @OCAMLFIND@
# Force a single invocation of ocamlbuild per make execution

PERL = @PERL@
OCAMLBUILD += -build-dir $(OBJDIR) -no-links -classic-display

# Force to always rebuild a target (for ocamlbuild targets)
.PHONY: .FORCE
.FORCE:
OCAMLBUILD_TARGETS = \
$(CILLIB_TARGETS) \
$(CILLIB_FILES) \
$(CILLY_EXE_FILES) \
$(CILDOC_INDEX)

$(OBJDIR)/src/%: .FORCE
$(OCAMLBUILD) src/$*
# Trick: this no-op rule is executed for each target, but
# its PHONY dependency is built exactly once.
$(OCAMLBUILD_TARGETS): ocamlbuild
@:

$(OBJDIR)/doc/%: .FORCE
CIL_VERSION=@CIL_VERSION@ $(OCAMLBUILD) doc/$*
.PHONY: ocamlbuild
ocamlbuild:
export CIL_VERSION
$(OCAMLBUILD) $(patsubst $(OBJDIR)/%,%,$(OCAMLBUILD_TARGETS))

# OCaml CIL library
.PHONY: cillib
cillib: $(CILLIB_FILES) $(OBJDIR)/src/cil.libfiles

# cilly main executable
$(BINDIR)/$(CILLY)$(EXE): $(OBJDIR)/src/main$(EXEMODE)
cp $< $@
cillib: $(CILLIB_TARGETS)

# cilly perl wrapper
prefix = @prefix@
INSTALL_BASE = $(prefix)

CILLYMOD := Cilly

$(CILLYDIR)/Makefile: Makefile $(CILLYDIR)/Makefile.PL $(CILLYDIR)/App/$(CILLYMOD).pm
$(CILLYDIR)/Makefile: $(CILLYDIR)/Makefile.PL $(CILLYDIR)/App/$(CILLYMOD).pm
cd $(CILLYDIR); $(PERL) Makefile.PL INSTALL_BASE="$(INSTALL_BASE)"

.PHONY: $(CILLY)
$(CILLY): $(BINDIR)/$(CILLY)$(EXE) $(CILLYDIR)/Makefile
$(CILLY): $(CILLY_EXE_FILES) $(CILLYDIR)/Makefile
cp $(CILLY_EXE_FILES) bin/
$(MAKE) -C $(CILLYDIR)

# Create the machine dependency module
Expand Down Expand Up @@ -167,7 +182,7 @@ $(OBJDIR)/machdep.ml : src/machdep-ml.c configure.ac Makefile.in

$(CILLYDIR)/App/$(CILLYMOD).pm: $(CILLYDIR)/App/$(CILLYMOD).pm.in src/machdep-ml.c configure.ac Makefile.in
cp $(CILLYDIR)/App/$(CILLYMOD).pm.in $(CILLYDIR)/App/$(CILLYMOD).pm
sed -e "s|CIL_VERSION|@CIL_VERSION@|" $(CILLYDIR)/App/$(CILLYMOD).pm > $(CILLYDIR)/App/$(CILLYMOD).pm.tmp; \
sed -e "s|CIL_VERSION|$(CIL_VERSION)|" $(CILLYDIR)/App/$(CILLYMOD).pm > $(CILLYDIR)/App/$(CILLYMOD).pm.tmp; \
mv $(CILLYDIR)/App/$(CILLYMOD).pm.tmp $(CILLYDIR)/App/$(CILLYMOD).pm; \
if $(MACHDEPCC) -m32 src/machdep-ml.c -o $(OBJDIR)/machdep-ml32.exe ;then \
sed -e "s|nogcc32model|`$(EMUL) $(OBJDIR)/machdep-ml32.exe --env`|" $(CILLYDIR)/App/$(CILLYMOD).pm > $(CILLYDIR)/App/$(CILLYMOD).pm.tmp; \
Expand Down Expand Up @@ -223,7 +238,7 @@ doc: texdoc pdfdoc odoc
.PHONY: odoc texdoc pdfdoc

# Documentation generated by "ocamldoc"
odoc: $(OBJDIR)/doc/cil.docdir/index.html
odoc: $(CILDOC_INDEX)
-rm -rf doc/html/cil/api
-mkdir -p doc/html/cil/
-cp -r $(dir $<) doc/html/cil/api
Expand All @@ -237,7 +252,7 @@ doc/cilpp.tex: doc/cilcode.pl doc/cil.tex $(CILLY)

# Documentation generated from latex files using "hevea"
texdoc: doc/cilpp.tex
cd doc/html/cil; printf '\\def\\cilversion{@CIL_VERSION@}\n' >cil.version.tex
cd doc/html/cil; printf '\\def\\cilversion{$(CIL_VERSION)}\n' >cil.version.tex
cd doc/html/cil; hevea -exec xxdate.exe ../../cilpp
cd doc/html/cil; hevea -exec xxdate.exe ../../cilpp
cd doc/html/cil; mv cilpp.html cil.html
Expand All @@ -246,7 +261,7 @@ texdoc: doc/cilpp.tex
cp -f doc/header.html doc/html/cil

pdfdoc: doc/cilpp.tex
cd doc; printf '\\def\\cilversion{@CIL_VERSION@}\n' >cil.version.tex
cd doc; printf '\\def\\cilversion{$(CIL_VERSION)}\n' >cil.version.tex
cd doc; pdflatex cilpp.tex; pdflatex cilpp.tex
cd doc; mv cilpp.pdf html/cil/CIL.pdf

Expand Down Expand Up @@ -311,11 +326,12 @@ ifneq ($(DESTDIR),)
endif
export OCAMLFIND_DESTDIR

install-findlib: cillib
install-findlib: $(CILLIB_FILES) $(CILLIB_TARGETS)
ifneq ($(OCAMLFIND_DESTDIR),)
mkdir -p $(OCAMLFIND_DESTDIR)
endif
$(OCAMLFIND) install -patch-version @CIL_VERSION@ cil META $(CILLIB_FILES) `cat $(OBJDIR)/src/cil.libfiles`
$(OCAMLFIND) install -patch-version $(CIL_VERSION) cil META \
$(CILLIB_TARGETS) `cat $(CILLIB_FILES)`

uninstall-findlib:
$(OCAMLFIND) remove cil
File renamed without changes.
1 change: 1 addition & 0 deletions doc/_tags
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
<cilcode.tmp>: not_hygienic
<..>: include
2 changes: 1 addition & 1 deletion src/_tags
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"ext": include
"frontc": include

<main.{byte,native}>: use_unix, use_str, use_nums, use_cil
<cilly.{byte,native}>: use_unix, use_str, use_nums, use_cil
File renamed without changes.

0 comments on commit 9576f47

Please sign in to comment.