2016-02-18 07:11:59 -08:00
|
|
|
#**************************************************************************
|
|
|
|
#* *
|
|
|
|
#* OCaml *
|
|
|
|
#* *
|
|
|
|
#* Xavier Leroy, projet Cristal, INRIA Rocquencourt *
|
|
|
|
#* *
|
|
|
|
#* Copyright 1999 Institut National de Recherche en Informatique et *
|
|
|
|
#* en Automatique. *
|
|
|
|
#* *
|
|
|
|
#* All rights reserved. This file is distributed under the terms of *
|
|
|
|
#* the GNU Lesser General Public License version 2.1, with the *
|
|
|
|
#* special exception on linking described in the file LICENSE. *
|
|
|
|
#* *
|
|
|
|
#**************************************************************************
|
1999-11-17 10:59:06 -08:00
|
|
|
|
2014-04-02 09:20:38 -07:00
|
|
|
ROOTDIR=../..
|
2016-09-13 08:59:47 -07:00
|
|
|
|
2020-04-17 05:53:49 -07:00
|
|
|
include $(ROOTDIR)/Makefile.common
|
2019-07-28 02:36:38 -07:00
|
|
|
include $(ROOTDIR)/Makefile.best_binaries
|
2016-09-13 08:59:47 -07:00
|
|
|
|
2019-09-11 00:16:15 -07:00
|
|
|
OC_CFLAGS += $(SHAREDLIB_CFLAGS)
|
|
|
|
|
|
|
|
OC_CPPFLAGS += -I$(ROOTDIR)/runtime
|
|
|
|
|
|
|
|
NATIVE_CPPFLAGS = \
|
|
|
|
-DNATIVE_CODE -DTARGET_$(ARCH) -DMODEL_$(MODEL) -DSYS_$(SYSTEM)
|
|
|
|
|
2016-09-13 08:59:47 -07:00
|
|
|
CAMLRUN ?= $(ROOTDIR)/boot/ocamlrun
|
|
|
|
|
|
|
|
LIBS = -nostdlib -I $(ROOTDIR)/stdlib -I $(ROOTDIR)/otherlibs/$(UNIXLIB)
|
|
|
|
|
2019-07-28 02:36:38 -07:00
|
|
|
CAMLC=$(BEST_OCAMLC) $(LIBS)
|
|
|
|
CAMLOPT=$(BEST_OCAMLOPT) $(LIBS)
|
|
|
|
|
2016-09-13 08:59:47 -07:00
|
|
|
MKLIB=$(CAMLRUN) $(ROOTDIR)/tools/ocamlmklib
|
2014-04-29 04:56:17 -07:00
|
|
|
COMPFLAGS=-w +33..39 -warn-error A -g -bin-annot -safe-string
|
1997-05-14 02:43:45 -07:00
|
|
|
|
2016-09-13 08:59:47 -07:00
|
|
|
LIBNAME=threads
|
1997-05-14 02:43:45 -07:00
|
|
|
|
2017-03-06 08:50:26 -08:00
|
|
|
# Note: the header on which object files produced from st_stubs.c
|
|
|
|
# should actually depend is known for sure only at compile-time.
|
|
|
|
# That's why this dependency is handled in the Makefile directly
|
|
|
|
# and removed from the output of the C compiler during make depend
|
|
|
|
|
2020-04-17 06:11:22 -07:00
|
|
|
BYTECODE_C_OBJS=st_stubs.b.$(O)
|
|
|
|
NATIVECODE_C_OBJS=st_stubs.n.$(O)
|
1997-05-14 02:43:45 -07:00
|
|
|
|
2016-09-13 08:59:47 -07:00
|
|
|
THREADS_SOURCES = thread.ml mutex.ml condition.ml event.ml threadUnix.ml
|
1997-05-14 02:43:45 -07:00
|
|
|
|
2016-09-13 08:59:47 -07:00
|
|
|
THREADS_BCOBJS = $(THREADS_SOURCES:.ml=.cmo)
|
|
|
|
THREADS_NCOBJS = $(THREADS_SOURCES:.ml=.cmx)
|
1997-05-14 02:43:45 -07:00
|
|
|
|
2016-09-13 08:59:47 -07:00
|
|
|
MLIFILES=thread.mli mutex.mli condition.mli event.mli threadUnix.mli
|
|
|
|
CMIFILES=$(MLIFILES:.mli=.cmi)
|
1997-05-14 02:43:45 -07:00
|
|
|
|
2016-09-13 08:59:47 -07:00
|
|
|
all: lib$(LIBNAME).$(A) $(LIBNAME).cma $(CMIFILES)
|
1997-05-14 02:43:45 -07:00
|
|
|
|
2016-09-13 08:59:47 -07:00
|
|
|
allopt: lib$(LIBNAME)nat.$(A) $(LIBNAME).cmxa $(CMIFILES)
|
1997-05-14 02:43:45 -07:00
|
|
|
|
2016-09-13 08:59:47 -07:00
|
|
|
lib$(LIBNAME).$(A): $(BYTECODE_C_OBJS)
|
2018-09-06 07:12:42 -07:00
|
|
|
$(MKLIB_CMD) -o $(LIBNAME) $(BYTECODE_C_OBJS) $(PTHREAD_LINK)
|
1997-05-14 02:43:45 -07:00
|
|
|
|
2016-09-13 08:59:47 -07:00
|
|
|
lib$(LIBNAME)nat.$(A): $(NATIVECODE_C_OBJS)
|
2018-09-06 07:12:42 -07:00
|
|
|
$(MKLIB_CMD) -o $(LIBNAME)nat $^
|
2016-09-13 08:59:47 -07:00
|
|
|
|
|
|
|
$(LIBNAME).cma: $(THREADS_BCOBJS)
|
|
|
|
ifeq "$(UNIX_OR_WIN32)" "unix"
|
2017-08-12 13:24:41 -07:00
|
|
|
$(MKLIB) -o $(LIBNAME) -ocamlc '$(CAMLC)' -cclib -lunix -linkall \
|
|
|
|
$(PTHREAD_CAML_LINK) $^
|
2016-09-13 08:59:47 -07:00
|
|
|
# TODO: Figure out why -cclib -lunix is used here.
|
|
|
|
# It may be because of the threadsUnix module which is deprecated.
|
|
|
|
# It may hence be good to figure out whether this module shouldn't be
|
|
|
|
# removed, and then -cclib -lunix arguments.
|
|
|
|
else # Windows
|
2017-08-12 13:24:41 -07:00
|
|
|
$(MKLIB) -o $(LIBNAME) -ocamlc "$(CAMLC)" -linkall \
|
|
|
|
$(PTHREAD_CAML_LINK) $^
|
2016-09-13 08:59:47 -07:00
|
|
|
endif
|
1997-05-14 02:43:45 -07:00
|
|
|
|
2001-10-24 06:08:53 -07:00
|
|
|
# See remark above: force static linking of libthreadsnat.a
|
2016-09-13 08:59:47 -07:00
|
|
|
$(LIBNAME).cmxa: $(THREADS_NCOBJS)
|
|
|
|
$(CAMLOPT) -linkall -a -cclib -lthreadsnat $(PTHREAD_CAML_LINK) -o $@ $^
|
2007-11-06 07:16:56 -08:00
|
|
|
|
2010-01-22 04:48:24 -08:00
|
|
|
# Note: I removed "-cclib -lunix" from the line above.
|
|
|
|
# Indeed, if we link threads.cmxa, then we must also link unix.cmxa,
|
2007-11-06 07:16:56 -08:00
|
|
|
# which itself will pass -lunix to the C linker. It seems more
|
|
|
|
# modular to me this way. -- Alain
|
|
|
|
|
2020-04-17 06:11:22 -07:00
|
|
|
# The following lines produce two object files st_stubs.b.$(O) and
|
|
|
|
# st_stubs.n.$(O) from the same source file st_stubs.c (it is compiled
|
2017-03-06 08:50:26 -08:00
|
|
|
# twice, each time with different options).
|
2016-09-14 15:38:03 -07:00
|
|
|
|
2020-04-17 06:11:22 -07:00
|
|
|
st_stubs.n.$(O): OC_CPPFLAGS += $(NATIVE_CPPFLAGS)
|
2007-11-06 07:16:56 -08:00
|
|
|
|
2020-04-17 06:11:22 -07:00
|
|
|
ifneq "$(COMPUTE_DEPS)" "false"
|
|
|
|
st_stubs.%.$(O): st_stubs.c
|
|
|
|
else
|
|
|
|
st_stubs.%.$(O): st_stubs.c $(RUNTIME_HEADERS) $(wildcard *.h)
|
|
|
|
endif
|
2019-09-11 00:16:15 -07:00
|
|
|
$(CC) -c $(OC_CFLAGS) $(OC_CPPFLAGS) $(OUTPUTOBJ)$@ $<
|
1997-12-19 08:04:40 -08:00
|
|
|
|
1997-05-14 02:43:45 -07:00
|
|
|
partialclean:
|
|
|
|
rm -f *.cm*
|
|
|
|
|
|
|
|
clean: partialclean
|
2019-10-15 03:46:36 -07:00
|
|
|
rm -f dllthreads*.so dllthreads*.dll *.a *.lib *.o *.obj
|
2020-04-17 06:11:22 -07:00
|
|
|
rm -rf $(DEPDIR)
|
1997-05-14 02:43:45 -07:00
|
|
|
|
2018-03-29 05:24:51 -07:00
|
|
|
INSTALL_THREADSLIBDIR=$(INSTALL_LIBDIR)/$(LIBNAME)
|
2014-04-07 00:06:17 -07:00
|
|
|
|
1997-05-14 02:43:45 -07:00
|
|
|
install:
|
2017-01-27 09:48:48 -08:00
|
|
|
if test -f dllthreads$(EXT_DLL); then \
|
2018-03-29 05:24:51 -07:00
|
|
|
$(INSTALL_PROG) \
|
makefiles: use 'install' instead of 'cp' in 'make install' targets
I can observe weird performance bottlenecks on my machine caused by
the use of 'cp' in the 'install' scripts of OCaml. When installing
into a directory that is already populated by an existing
installation, 'make install' can routinely take 10s on my machine¹. After this
change it reliably takes 1.5s, independently of whether the
destination is already populated or not.
¹: a brtfs filesystem on an old-ish SSD
Why I care
----------
An extra 10s delay due to 'make install' can be noticeable in tight
change-build-install-test feedback loops for a compiler change where
we change the compiler, have a fast 'make world.opt' due to
incremental builds, install the change and test it -- possibly after
installing a couple opam packages, which can be fairly quick.
Partial diagnosis
-----------------
The performance issue seems to be caused by the fact that 'cp' (at
least the GNU coreutils version), when the file already exists,
replaces it by opening it in writeonly+truncate mode and writing the
file content ('strace' shows that the delay is caused within an
'openat' call). In particular, using the --remove-destination option
(which changes 'cp' to just remove the destination file before
copying) removes the performance issue, but this option seems missing
from the BSD/OSX 'cp' so it could cause portability issue.
Change
------
The present commit rewrites the 'install' targets of all Makefiles to
use the 'install' command instead. 'install' by default gives
executable-like permission to the destination file, instead of reusing
the source file's permissions, so we specify manually the permission
modes, depending on whether the installed file is an executable (or
dynamically-linked library) or just data (including other compiled
object files).
Testing
-------
I checked manually that the permissions of the installed files are
identical to the ones of the current 'cp'-using targets, except for
some '.mli' file in middle_end which currently have +x bits enabled
for no good reason.
Remark: To test this, playing with the DESTDIR variable is very useful
(this lets you install to a new directory (or the same as before)
without having to re-run the configure script). I used the following,
fairly slow shell script to collect permissions:
for f in $(find $DESTDIR); do \
echo $(basename $f) $(ls -l $f | cut -d' ' -f1); \
done | sort
Remark: it is important to run `sync` in-between 'make install' runs
to avoid timing effects due to filesystem or disk caching
strategies. I believe that this corresponds to the natural time delay
(and unrelated disk activity) that would occur in realistic
change-install-test feedback loops.
2018-03-28 08:46:34 -07:00
|
|
|
dllthreads$(EXT_DLL) "$(INSTALL_STUBLIBDIR)/dllthreads$(EXT_DLL)"; \
|
|
|
|
fi
|
2018-03-29 05:24:51 -07:00
|
|
|
$(INSTALL_DATA) libthreads.$(A) "$(INSTALL_LIBDIR)"
|
2016-09-13 08:59:47 -07:00
|
|
|
cd "$(INSTALL_LIBDIR)"; $(RANLIB) libthreads.$(A)
|
2018-03-29 05:24:51 -07:00
|
|
|
mkdir -p "$(INSTALL_THREADSLIBDIR)"
|
|
|
|
$(INSTALL_DATA) \
|
2018-05-14 00:15:44 -07:00
|
|
|
$(CMIFILES) threads.cma \
|
|
|
|
"$(INSTALL_THREADSLIBDIR)"
|
|
|
|
ifeq "$(INSTALL_SOURCE_ARTIFACTS)" "true"
|
|
|
|
$(INSTALL_DATA) \
|
|
|
|
$(CMIFILES:.cmi=.cmti) \
|
2018-03-29 05:24:51 -07:00
|
|
|
"$(INSTALL_THREADSLIBDIR)"
|
2018-01-06 21:19:47 -08:00
|
|
|
$(INSTALL_DATA) $(MLIFILES) "$(INSTALL_THREADSLIBDIR)"
|
2018-05-14 00:15:44 -07:00
|
|
|
endif
|
2018-03-29 05:24:51 -07:00
|
|
|
$(INSTALL_DATA) threads.h "$(INSTALL_LIBDIR)/caml"
|
1997-05-14 02:43:45 -07:00
|
|
|
|
|
|
|
installopt:
|
2018-03-29 05:24:51 -07:00
|
|
|
$(INSTALL_DATA) libthreadsnat.$(A) "$(INSTALL_LIBDIR)"
|
2016-09-13 08:59:47 -07:00
|
|
|
cd "$(INSTALL_LIBDIR)"; $(RANLIB) libthreadsnat.$(A)
|
2018-03-29 05:24:51 -07:00
|
|
|
$(INSTALL_DATA) \
|
makefiles: use 'install' instead of 'cp' in 'make install' targets
I can observe weird performance bottlenecks on my machine caused by
the use of 'cp' in the 'install' scripts of OCaml. When installing
into a directory that is already populated by an existing
installation, 'make install' can routinely take 10s on my machine¹. After this
change it reliably takes 1.5s, independently of whether the
destination is already populated or not.
¹: a brtfs filesystem on an old-ish SSD
Why I care
----------
An extra 10s delay due to 'make install' can be noticeable in tight
change-build-install-test feedback loops for a compiler change where
we change the compiler, have a fast 'make world.opt' due to
incremental builds, install the change and test it -- possibly after
installing a couple opam packages, which can be fairly quick.
Partial diagnosis
-----------------
The performance issue seems to be caused by the fact that 'cp' (at
least the GNU coreutils version), when the file already exists,
replaces it by opening it in writeonly+truncate mode and writing the
file content ('strace' shows that the delay is caused within an
'openat' call). In particular, using the --remove-destination option
(which changes 'cp' to just remove the destination file before
copying) removes the performance issue, but this option seems missing
from the BSD/OSX 'cp' so it could cause portability issue.
Change
------
The present commit rewrites the 'install' targets of all Makefiles to
use the 'install' command instead. 'install' by default gives
executable-like permission to the destination file, instead of reusing
the source file's permissions, so we specify manually the permission
modes, depending on whether the installed file is an executable (or
dynamically-linked library) or just data (including other compiled
object files).
Testing
-------
I checked manually that the permissions of the installed files are
identical to the ones of the current 'cp'-using targets, except for
some '.mli' file in middle_end which currently have +x bits enabled
for no good reason.
Remark: To test this, playing with the DESTDIR variable is very useful
(this lets you install to a new directory (or the same as before)
without having to re-run the configure script). I used the following,
fairly slow shell script to collect permissions:
for f in $(find $DESTDIR); do \
echo $(basename $f) $(ls -l $f | cut -d' ' -f1); \
done | sort
Remark: it is important to run `sync` in-between 'make install' runs
to avoid timing effects due to filesystem or disk caching
strategies. I believe that this corresponds to the natural time delay
(and unrelated disk activity) that would occur in realistic
change-install-test feedback loops.
2018-03-28 08:46:34 -07:00
|
|
|
$(THREADS_NCOBJS) threads.cmxa threads.$(A) \
|
2018-03-29 05:24:51 -07:00
|
|
|
"$(INSTALL_THREADSLIBDIR)"
|
|
|
|
cd "$(INSTALL_THREADSLIBDIR)" && $(RANLIB) threads.$(A)
|
1997-05-14 02:43:45 -07:00
|
|
|
|
1997-11-17 05:04:18 -08:00
|
|
|
.SUFFIXES: .ml .mli .cmo .cmi .cmx
|
1997-05-14 02:43:45 -07:00
|
|
|
|
|
|
|
.mli.cmi:
|
|
|
|
$(CAMLC) -c $(COMPFLAGS) $<
|
|
|
|
|
|
|
|
.ml.cmo:
|
2007-01-29 04:11:18 -08:00
|
|
|
$(CAMLC) -c $(COMPFLAGS) $<
|
1997-05-14 02:43:45 -07:00
|
|
|
|
|
|
|
.ml.cmx:
|
2016-02-11 03:16:10 -08:00
|
|
|
$(CAMLOPT) -c $(COMPFLAGS) $(OPTCOMPFLAGS) $<
|
1997-05-14 02:43:45 -07:00
|
|
|
|
2020-04-17 06:11:22 -07:00
|
|
|
DEP_FILES := st_stubs.b.$(D)
|
|
|
|
ifneq "$(NATIVE_COMPILER)" "false"
|
|
|
|
DEP_FILES += st_stubs.n.$(D)
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq "$(COMPUTE_DEPS)" "true"
|
|
|
|
include $(addprefix $(DEPDIR)/, $(DEP_FILES))
|
|
|
|
endif
|
|
|
|
|
|
|
|
%.n.$(O): OC_CPPFLAGS += $(NATIVE_CPPFLAGS)
|
2020-05-03 08:00:28 -07:00
|
|
|
%.n.$(D): OC_CPPFLAGS += $(NATIVE_CPPFLAGS)
|
2020-04-17 06:11:22 -07:00
|
|
|
|
2020-05-03 08:00:28 -07:00
|
|
|
define GEN_RULE
|
|
|
|
$(DEPDIR)/%.$(1).$(D): %.c | $(DEPDIR)
|
|
|
|
$$(DEP_CC) $$(OC_CPPFLAGS) $$< -MT '$$*.$(1).$(O)' -MF $$@
|
|
|
|
endef
|
2020-04-17 06:11:22 -07:00
|
|
|
|
2020-05-03 08:00:28 -07:00
|
|
|
$(foreach object_type, b n, $(eval $(call GEN_RULE,$(object_type))))
|
2020-04-17 06:11:22 -07:00
|
|
|
|
2017-03-06 05:30:40 -08:00
|
|
|
.PHONY: depend
|
2017-03-06 08:50:26 -08:00
|
|
|
depend:
|
2020-04-17 06:11:22 -07:00
|
|
|
$(CAMLRUN) $(ROOTDIR)/boot/ocamlc -depend -slash *.mli *.ml > .depend
|
1997-05-14 02:43:45 -07:00
|
|
|
|
|
|
|
include .depend
|