summaryrefslogtreecommitdiff
path: root/tools/Makefile.shared
diff options
context:
space:
mode:
authorDemi Obenour <demetriobenour@gmail.com>2016-05-13 16:39:19 -0400
committerDemi Obenour <demiobenour@gmail.com>2016-06-06 14:44:10 -0400
commitd89af40f640fcc2a879d48b1152b73736fddf16a (patch)
tree7b652484f80e58884274834ad843c9be65546d9a /tools/Makefile.shared
parent240fde10ac9dce8278707f0cb557856bf6b9ef54 (diff)
downloadocaml-d89af40f640fcc2a879d48b1152b73736fddf16a.tar.gz
Install native versions of tools by default.
Previously, `ocamlc`, `ocamlopt`, `ocamllex`, and `ocamldep` defaulted to the bytecode versions of the tools. However, there is normally no advantage to the bytecode versions if the native-code versions are available, except in unusual circumstances. Instead, install the native-code versions without the `.opt` suffix. They are still installed with the `.opt` suffix for backwards compatibility. Finally, install the bytecode versions with the `.byte` suffix, and build native-code versions of tools that are not currently built in native code. Also, remove some duplication in tools/Makefile.shared. Supersedes GPR #512.
Diffstat (limited to 'tools/Makefile.shared')
-rw-r--r--tools/Makefile.shared233
1 files changed, 116 insertions, 117 deletions
diff --git a/tools/Makefile.shared b/tools/Makefile.shared
index a979be121d..3db6c155ef 100644
--- a/tools/Makefile.shared
+++ b/tools/Makefile.shared
@@ -12,10 +12,67 @@
#* special exception on linking described in the file LICENSE. *
#* *
#**************************************************************************
-
+MAKEFLAGS := -r -R
include ../config/Makefile
+INSTALL_BINDIR:=$(DESTDIR)$(BINDIR)
+INSTALL_LIBDIR:=$(DESTDIR)$(LIBDIR)
+INSTALL_COMPLIBDIR:=$(DESTDIR)$(COMPLIBDIR)
+INSTALL_STUBLIBDIR:=$(DESTDIR)$(STUBLIBDIR)
+INSTALL_MANDIR:=$(DESTDIR)$(MANDIR)
+
+ifeq ($(SYSTEM),unix)
+override define shellquote
+$i := $$(subst ",\",$$(subst $$$$,\$$$$,$$(subst `,\`,$i)))#")#
+endef
+$(foreach i,BINDIR LIBDIR COMPLIBDIR STUBLIBDIR MANDIR,$(eval $(shellquote)))
+endif
+
CAMLRUN ?= ../boot/ocamlrun
CAMLYACC ?= ../boot/ocamlyacc
+DESTDIR ?=
+# Setup GNU make variables storing per-target source and target,
+# a list of installed tools, and a function to quote a filename for
+# the shell.
+override installed_tools := ocamldep ocamlprof ocamlcp ocamloptp \
+ ocamlmktop ocamlmklib ocamlobjinfo
+
+install_files :=
+define byte2native
+$(patsubst %.cmo,%.cmx,$(patsubst %.cma,%.cmxa,$1))
+endef
+
+# $1 = target, $2 = OCaml object dependencies, $3 = other dependencies
+# There is a lot of subtle code here. The multiple layers of expansion
+# are due to `make`'s eval() function, which evaluates the string
+# passed to it as a makefile fragment. So it is crucial that variables
+# not get expanded too many times.
+define byte_and_opt_
+# This check is defensive programming
+$(and $(filter-out 1,$(words $1)),$(error \
+ cannot build file with whitespace in name))
+$1: $3 $2
+ $$(CAMLC) $$(LINKFLAGS) -I .. -o $$@ $2
+
+$1.opt: $3 $$(call byte2native,$2)
+ $$(CAMLOPT) $$(LINKFLAGS) -I .. -o $$@ $$(call byte2native,$2)
+
+all: $1
+
+opt.opt: $1.opt
+
+ifeq '$(filter $(installed_tools),$1)' '$1'
+install_files += $1
+endif
+clean::
+ rm -f -- $1 $1.opt
+
+endef
+
+# Escape any $ characters in the arguments and eval the result.
+define byte_and_opt
+$(eval $(call \
+ byte_and_opt_,$(subst $$,$$$$,$1),$(subst $$,$$$$,$2),$(subst $$,$$$$,$3)))
+endef
ROOTDIR=..
@@ -25,24 +82,20 @@ else
export OCAML_FLEXLINK:=$(ROOTDIR)/boot/ocamlrun $(ROOTDIR)/flexdll/flexlink.exe
endif
-CAMLC=$(CAMLRUN) ../boot/ocamlc -nostdlib -I ../boot -use-prims ../byterun/primitives
+CAMLC=$(CAMLRUN) ../boot/ocamlc -nostdlib -I ../boot -use-prims ../byterun/primitives -I ..
CAMLOPT=$(CAMLRUN) ../ocamlopt -nostdlib -I ../stdlib
CAMLLEX=$(CAMLRUN) ../boot/ocamllex
INCLUDES=-I ../utils -I ../parsing -I ../typing -I ../bytecomp -I ../asmcomp \
-I ../middle_end -I ../middle_end/base_types -I ../driver \
-I ../toplevel
-COMPFLAGS= -absname -w +a-4-9-41-42-44-45-48 -strict-sequence -warn-error A -safe-string -strict-formats $(INCLUDES)
+COMPFLAGS= -absname -w +a-4-9-41-42-44-45-48 -strict-sequence -warn-error A \
+ -safe-string -strict-formats $(INCLUDES)
LINKFLAGS=$(INCLUDES)
-
-all: ocamldep ocamlprof ocamlcp ocamloptp ocamlmktop ocamlmklib dumpobj \
- objinfo read_cmt stripdebug cmpbyt
+VPATH := $(filter-out -I,$(INCLUDES))
# scrapelabels addlabels
-.PHONY: all
-
-opt.opt: ocamldep.opt read_cmt.opt
-.PHONY: opt.opt
+.PHONY: all opt.opt
# The dependency generator
@@ -55,13 +108,10 @@ CAMLDEP_IMPORTS=timings.cmo misc.cmo config.cmo identifiable.cmo numbers.cmo \
builtin_attributes.cmo ast_invariants.cmo \
pparse.cmo compenv.cmo depend.cmo
-ocamldep: $(CAMLDEP_OBJ)
- $(CAMLC) $(LINKFLAGS) -compat-32 -o ocamldep $(CAMLDEP_IMPORTS) \
- $(CAMLDEP_OBJ)
-
-ocamldep.opt: $(CAMLDEP_OBJ:.cmo=.cmx)
- $(CAMLOPT) $(LINKFLAGS) -o ocamldep.opt $(CAMLDEP_IMPORTS:.cmo=.cmx) \
- $(CAMLDEP_OBJ:.cmo=.cmx)
+ocamldep: LINKFLAGS += -compat-32
+$(call byte_and_opt,ocamldep,$(CAMLDEP_IMPORTS) $(CAMLDEP_OBJ),)
+ocamldep: depend.cmi
+ocamldep.opt: depend.cmi
# ocamldep is precious: sometimes we are stuck in the middle of a
# bootstrap and we need to remake the dependencies
@@ -70,14 +120,6 @@ clean::
rm -f ocamldep.opt
-INSTALL_BINDIR=$(DESTDIR)$(BINDIR)
-INSTALL_LIBDIR=$(DESTDIR)$(LIBDIR)
-
-install::
- cp ocamldep "$(INSTALL_BINDIR)/ocamldep$(EXE)"
- if test -f ocamldep.opt; then \
- cp ocamldep.opt "$(INSTALL_BINDIR)/ocamldep.opt$(EXE)"; else :; fi
-
# The profiler
CSLPROF=ocamlprof.cmo
@@ -86,46 +128,27 @@ CSLPROF_IMPORTS=misc.cmo config.cmo identifiable.cmo numbers.cmo \
warnings.cmo location.cmo longident.cmo docstrings.cmo \
syntaxerr.cmo ast_helper.cmo parser.cmo lexer.cmo parse.cmo
-ocamlprof: $(CSLPROF) profiling.cmo
- $(CAMLC) $(LINKFLAGS) -o ocamlprof $(CSLPROF_IMPORTS) $(CSLPROF)
+$(call byte_and_opt,ocamlprof,$(CSLPROF_IMPORTS) profiling.cmo $(CSLPROF),)
-ocamlcp: ocamlcp.cmo
- $(CAMLC) $(LINKFLAGS) -o ocamlcp misc.cmo warnings.cmo config.cmo \
- identifiable.cmo numbers.cmo arg_helper.cmo clflags.cmo \
- main_args.cmo ocamlcp.cmo
+ocamlcp_cmos = misc.cmo warnings.cmo config.cmo identifiable.cmo numbers.cmo \
+ arg_helper.cmo clflags.cmo main_args.cmo
-ocamloptp: ocamloptp.cmo
- $(CAMLC) $(LINKFLAGS) -o ocamloptp misc.cmo warnings.cmo config.cmo \
- identifiable.cmo numbers.cmo arg_helper.cmo clflags.cmo \
- main_args.cmo \
- ocamloptp.cmo
+$(call byte_and_opt,ocamlcp,$(ocamlcp_cmos) ocamlcp.cmo,)
+$(call byte_and_opt,ocamloptp,$(ocamlcp_cmos) ocamloptp.cmo,)
opt:: profiling.cmx
install::
- cp ocamlprof "$(INSTALL_BINDIR)/ocamlprof$(EXE)"
- cp ocamlcp "$(INSTALL_BINDIR)/ocamlcp$(EXE)"
- cp ocamloptp "$(INSTALL_BINDIR)/ocamloptp$(EXE)"
- cp profiling.cmi profiling.cmo "$(INSTALL_LIBDIR)"
+ cp -- profiling.cmi profiling.cmo "$(INSTALL_LIBDIR)"
installopt::
- cp profiling.cmx profiling.$(O) "$(INSTALL_LIBDIR)"
-
-clean::
- rm -f ocamlprof ocamlcp ocamloptp
-
+ cp -- profiling.cmx profiling.$(O) "$(INSTALL_LIBDIR)"
# To help building mixed-mode libraries (OCaml + C)
-ocamlmklib: ocamlmklibconfig.cmo ocamlmklib.cmo
- $(CAMLC) $(LINKFLAGS) -o ocamlmklib ocamlmklibconfig.cmo config.cmo \
- ocamlmklib.cmo
-
-install::
- cp ocamlmklib "$(INSTALL_BINDIR)/ocamlmklib$(EXE)"
+$(call byte_and_opt,ocamlmklib,ocamlmklibconfig.cmo config.cmo \
+ ocamlmklib.cmo,)
-clean::
- rm -f ocamlmklib
ocamlmklibconfig.ml: ../config/Makefile Makefile
(echo 'let bindir = "$(BINDIR)"'; \
@@ -146,16 +169,9 @@ clean::
OCAMLMKTOP=ocamlmktop.cmo
OCAMLMKTOP_IMPORTS=misc.cmo identifiable.cmo numbers.cmo config.cmo \
- arg_helper.cmo clflags.cmo ccomp.cmo
-
-ocamlmktop: $(OCAMLMKTOP)
- $(CAMLC) $(LINKFLAGS) -o ocamlmktop $(OCAMLMKTOP_IMPORTS) $(OCAMLMKTOP)
-
-install::
- cp ocamlmktop "$(INSTALL_BINDIR)/ocamlmktop$(EXE)"
+ arg_helper.cmo clflags.cmo ccomp.cmo
-clean::
- rm -f ocamlmktop
+$(call byte_and_opt,ocamlmktop,$(OCAMLMKTOP_IMPORTS) $(OCAMLMKTOP),)
# Converter olabl/ocaml 2.99 to ocaml 3
@@ -204,6 +220,24 @@ addlabels: addlabels.cmo
#install::
# cp addlabels "$(INSTALL_LIBDIR)"
+ifeq ($(UNIX_OR_WIN32),unix)
+LN := ln -sf
+else
+LN := cp -pf
+endif
+
+install::
+ for i in $(install_files); \
+ do \
+ cp -- "$$i" "$(INSTALL_BINDIR)/$$i.byte$(EXE)" && \
+ if test -f "$$i".opt; then \
+ cp -- "$$i.opt" "$(INSTALL_BINDIR)/$$i.opt$(EXE)" && \
+ (cd "$(INSTALL_BINDIR)/" && $(LN) "$$i.opt$(EXE)" "$$i$(EXE)"); \
+ else \
+ (cd "$(INSTALL_BINDIR)/" && $(LN) "$$i.byte$(EXE)" "$$i$(EXE)"); \
+ fi; \
+ done
+
clean::
rm -f addlabels
@@ -216,6 +250,7 @@ cvt_emit: $(CVT_EMIT)
# cvt_emit is precious: sometimes we are stuck in the middle of a
# bootstrap and we need to remake the dependencies
+.PRECIOUS: cvt_emit
clean::
if test -f cvt_emit; then mv -f cvt_emit cvt_emit.bak; else :; fi
@@ -227,7 +262,6 @@ clean::
beforedepend:: cvt_emit.ml
-
# Reading cmt files
READ_CMT= \
@@ -236,32 +270,17 @@ READ_CMT= \
\
cmt2annot.cmo read_cmt.cmo
-READ_CMT_OPT1 = $(READ_CMT:.cmo=.cmx)
-READ_CMT_OPT = $(READ_CMT_OPT1:.cma=.cmxa)
-
-read_cmt: $(READ_CMT)
- $(CAMLC) $(LINKFLAGS) -o read_cmt $(READ_CMT)
-
-read_cmt.opt: $(READ_CMT_OPT)
- $(CAMLOPT) $(LINKFLAGS) -o read_cmt.opt $(READ_CMT_OPT)
-
-clean::
- rm -f read_cmt read_cmt.opt
+# Reading cmt files
+$(call byte_and_opt,read_cmt,$(READ_CMT),)
-beforedepend::
# The bytecode disassembler
DUMPOBJ=opnames.cmo dumpobj.cmo
-dumpobj: $(DUMPOBJ)
- $(CAMLC) $(LINKFLAGS) -o dumpobj \
- misc.cmo identifiable.cmo numbers.cmo \
- tbl.cmo config.cmo ident.cmo \
- opcodes.cmo bytesections.cmo $(DUMPOBJ)
-
-clean::
- rm -f dumpobj
+$(call byte_and_opt,dumpobj,misc.cmo identifiable.cmo numbers.cmo tbl.cmo \
+ config.cmo ident.cmo opcodes.cmo bytesections.cmo \
+ $(DUMPOBJ),)
opnames.ml: ../byterun/caml/instruct.h
unset LC_ALL || : ; \
@@ -306,37 +325,22 @@ OBJINFO=../compilerlibs/ocamlcommon.cma \
../asmcomp/export_info.cmo \
objinfo.cmo
-objinfo: objinfo_helper$(EXE) $(OBJINFO)
- $(CAMLC) -o objinfo $(OBJINFO)
-
-install::
- cp objinfo "$(INSTALL_BINDIR)/ocamlobjinfo$(EXE)"
- cp objinfo_helper$(EXE) "$(INSTALL_LIBDIR)/objinfo_helper$(EXE)"
-
-clean::
- rm -f objinfo objinfo_helper$(EXE)
+$(call byte_and_opt,ocamlobjinfo,$(OBJINFO),objinfo_helper$(EXE))
# Scan object files for required primitives
-
-PRIMREQ=primreq.cmo
-
-primreq: $(PRIMREQ)
- $(CAMLC) $(LINKFLAGS) -o primreq config.cmo $(PRIMREQ)
+$(call byte_and_opt,primreq,config.cmo primreq.cmo,)
clean::
- rm -f primreq
+ rm -f "objinfo_helper$(EXE)"
+
# Copy a bytecode executable, stripping debug info
-STRIPDEBUG=../compilerlibs/ocamlcommon.cma \
+stripdebug=../compilerlibs/ocamlcommon.cma \
../compilerlibs/ocamlbytecomp.cma \
stripdebug.cmo
-stripdebug: $(STRIPDEBUG)
- $(CAMLC) $(LINKFLAGS) -o stripdebug $(STRIPDEBUG)
-
-clean::
- rm -f stripdebug
+$(call byte_and_opt,stripdebug,$(stripdebug),)
# Compare two bytecode executables
@@ -344,30 +348,25 @@ CMPBYT=../compilerlibs/ocamlcommon.cma \
../compilerlibs/ocamlbytecomp.cma \
cmpbyt.cmo
-cmpbyt: $(CMPBYT)
- $(CAMLC) $(LINKFLAGS) -o cmpbyt $(CMPBYT)
-
-clean::
- rm -f cmpbyt
+$(call byte_and_opt,cmpbyt,$(CMPBYT),)
ifeq "$(RUNTIMEI)" "true"
install::
- cp ocaml-instr-graph ocaml-instr-report $(INSTALL_BINDIR)/
+ cp ocaml-instr-graph ocaml-instr-report "$(INSTALL_BINDIR)/"
endif
# Common stuff
.SUFFIXES:
-.SUFFIXES: .ml .cmo .mli .cmi .cmx
-.ml.cmo:
- $(CAMLC) -c $(COMPFLAGS) $<
+%.cmo: %.ml
+ $(CAMLC) -c $(COMPFLAGS) - $<
-.mli.cmi:
- $(CAMLC) -c $(COMPFLAGS) $<
+%.cmi: %.mli
+ $(CAMLC) -c $(COMPFLAGS) - $<
-.ml.cmx:
- $(CAMLOPT) $(COMPFLAGS) -c $<
+%.cmx: %.ml
+ $(CAMLOPT) $(COMPFLAGS) -c - $<
clean::
rm -f *.cmo *.cmi *.cma *.dll *.so *.lib *.a