ocaml/otherlibs/systhreads/Makefile

172 lines
5.5 KiB
Makefile
Raw Normal View History

#**************************************************************************
#* *
#* 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. *
#* *
#**************************************************************************
ROOTDIR=../..
include $(ROOTDIR)/Makefile.common
include $(ROOTDIR)/Makefile.best_binaries
OC_CFLAGS += $(SHAREDLIB_CFLAGS)
OC_CPPFLAGS += -I$(ROOTDIR)/runtime
NATIVE_CPPFLAGS = \
-DNATIVE_CODE -DTARGET_$(ARCH) -DMODEL_$(MODEL) -DSYS_$(SYSTEM)
CAMLRUN ?= $(ROOTDIR)/boot/ocamlrun
LIBS = -nostdlib -I $(ROOTDIR)/stdlib -I $(ROOTDIR)/otherlibs/$(UNIXLIB)
CAMLC=$(BEST_OCAMLC) $(LIBS)
CAMLOPT=$(BEST_OCAMLOPT) $(LIBS)
MKLIB=$(CAMLRUN) $(ROOTDIR)/tools/ocamlmklib
COMPFLAGS=-w +33..39 -warn-error A -g -bin-annot -safe-string
LIBNAME=threads
# 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
BYTECODE_C_OBJS=st_stubs.b.$(O)
NATIVECODE_C_OBJS=st_stubs.n.$(O)
THREADS_SOURCES = thread.ml mutex.ml condition.ml event.ml threadUnix.ml
THREADS_BCOBJS = $(THREADS_SOURCES:.ml=.cmo)
THREADS_NCOBJS = $(THREADS_SOURCES:.ml=.cmx)
MLIFILES=thread.mli mutex.mli condition.mli event.mli threadUnix.mli
CMIFILES=$(MLIFILES:.mli=.cmi)
all: lib$(LIBNAME).$(A) $(LIBNAME).cma $(CMIFILES)
allopt: lib$(LIBNAME)nat.$(A) $(LIBNAME).cmxa $(CMIFILES)
lib$(LIBNAME).$(A): $(BYTECODE_C_OBJS)
2018-09-06 07:12:42 -07:00
$(MKLIB_CMD) -o $(LIBNAME) $(BYTECODE_C_OBJS) $(PTHREAD_LINK)
lib$(LIBNAME)nat.$(A): $(NATIVECODE_C_OBJS)
2018-09-06 07:12:42 -07:00
$(MKLIB_CMD) -o $(LIBNAME)nat $^
$(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) $^
# 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) $^
endif
# See remark above: force static linking of libthreadsnat.a
$(LIBNAME).cmxa: $(THREADS_NCOBJS)
$(CAMLOPT) -linkall -a -cclib -lthreadsnat $(PTHREAD_CAML_LINK) -o $@ $^
# Note: I removed "-cclib -lunix" from the line above.
# Indeed, if we link threads.cmxa, then we must also link unix.cmxa,
# which itself will pass -lunix to the C linker. It seems more
# modular to me this way. -- Alain
# 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
# twice, each time with different options).
st_stubs.n.$(O): OC_CPPFLAGS += $(NATIVE_CPPFLAGS)
ifneq "$(COMPUTE_DEPS)" "false"
st_stubs.%.$(O): st_stubs.c
else
st_stubs.%.$(O): st_stubs.c $(RUNTIME_HEADERS) $(wildcard *.h)
endif
$(CC) -c $(OC_CFLAGS) $(OC_CPPFLAGS) $(OUTPUTOBJ)$@ $<
partialclean:
rm -f *.cm*
clean: partialclean
rm -f dllthreads*.so dllthreads*.dll *.a *.lib *.o *.obj
rm -rf $(DEPDIR)
INSTALL_THREADSLIBDIR=$(INSTALL_LIBDIR)/$(LIBNAME)
install:
if test -f dllthreads$(EXT_DLL); then \
$(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
$(INSTALL_DATA) libthreads.$(A) "$(INSTALL_LIBDIR)"
cd "$(INSTALL_LIBDIR)"; $(RANLIB) libthreads.$(A)
mkdir -p "$(INSTALL_THREADSLIBDIR)"
$(INSTALL_DATA) \
$(CMIFILES) threads.cma \
"$(INSTALL_THREADSLIBDIR)"
ifeq "$(INSTALL_SOURCE_ARTIFACTS)" "true"
$(INSTALL_DATA) \
$(CMIFILES:.cmi=.cmti) \
"$(INSTALL_THREADSLIBDIR)"
install the mli files of the thread library next to its cmi/cmt/etc Here is the diff in the installation directory, limited to the condition module: -./lib/ocaml/condition.mli ./lib/ocaml/threads/condition.cmi ./lib/ocaml/threads/condition.cmti ./lib/ocaml/threads/condition.cmx +./lib/ocaml/threads/condition.mli ./lib/ocaml/vmthreads/condition.cmi ./lib/ocaml/vmthreads/condition.cmti ./lib/ocaml/vmthreads/condition.mli and overall: @@ -1300,7 +1300,6 @@ ./lib/ocaml/complex.mli ./lib/ocaml/complex.p.cmt ./lib/ocaml/complex.p.cmx -./lib/ocaml/condition.mli ./lib/ocaml/digest.cmi ./lib/ocaml/digest.cmt ./lib/ocaml/digest.cmti @@ -1324,7 +1323,6 @@ ./lib/ocaml/ephemeron.mli ./lib/ocaml/ephemeron.p.cmt ./lib/ocaml/ephemeron.p.cmx -./lib/ocaml/event.mli ./lib/ocaml/expunge ./lib/ocaml/extract_crc ./lib/ocaml/filename.cmi @@ -1471,7 +1469,6 @@ ./lib/ocaml/moreLabels.mli ./lib/ocaml/moreLabels.p.cmt ./lib/ocaml/moreLabels.p.cmx -./lib/ocaml/mutex.mli ./lib/ocaml/nativeint.cmi ./lib/ocaml/nativeint.cmt ./lib/ocaml/nativeint.cmti @@ -1774,27 +1771,30 @@ ./lib/ocaml/sys.p.cmx ./lib/ocaml/target_camlheaderd ./lib/ocaml/target_camlheaderi -./lib/ocaml/thread.mli ./lib/ocaml/threads ./lib/ocaml/threads/condition.cmi ./lib/ocaml/threads/condition.cmti ./lib/ocaml/threads/condition.cmx +./lib/ocaml/threads/condition.mli ./lib/ocaml/threads/event.cmi ./lib/ocaml/threads/event.cmti ./lib/ocaml/threads/event.cmx +./lib/ocaml/threads/event.mli ./lib/ocaml/threads/mutex.cmi ./lib/ocaml/threads/mutex.cmti ./lib/ocaml/threads/mutex.cmx +./lib/ocaml/threads/mutex.mli ./lib/ocaml/threads/thread.cmi ./lib/ocaml/threads/thread.cmti ./lib/ocaml/threads/thread.cmx +./lib/ocaml/threads/thread.mli ./lib/ocaml/threads/threads.a ./lib/ocaml/threads/threads.cma ./lib/ocaml/threads/threads.cmxa ./lib/ocaml/threads/threadUnix.cmi ./lib/ocaml/threads/threadUnix.cmti ./lib/ocaml/threads/threadUnix.cmx -./lib/ocaml/threadUnix.mli +./lib/ocaml/threads/threadUnix.mli ./lib/ocaml/topdirs.cmi ./lib/ocaml/topdirs.cmt ./lib/ocaml/topdirs.cmti
2018-01-06 21:19:47 -08:00
$(INSTALL_DATA) $(MLIFILES) "$(INSTALL_THREADSLIBDIR)"
endif
$(INSTALL_DATA) threads.h "$(INSTALL_LIBDIR)/caml"
installopt:
$(INSTALL_DATA) libthreadsnat.$(A) "$(INSTALL_LIBDIR)"
cd "$(INSTALL_LIBDIR)"; $(RANLIB) libthreadsnat.$(A)
$(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) \
"$(INSTALL_THREADSLIBDIR)"
cd "$(INSTALL_THREADSLIBDIR)" && $(RANLIB) threads.$(A)
.SUFFIXES: .ml .mli .cmo .cmi .cmx
.mli.cmi:
$(CAMLC) -c $(COMPFLAGS) $<
.ml.cmo:
$(CAMLC) -c $(COMPFLAGS) $<
.ml.cmx:
$(CAMLOPT) -c $(COMPFLAGS) $(OPTCOMPFLAGS) $<
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)
%.n.$(D): OC_CPPFLAGS += $(NATIVE_CPPFLAGS)
define GEN_RULE
$(DEPDIR)/%.$(1).$(D): %.c | $(DEPDIR)
$$(DEP_CC) $$(OC_CPPFLAGS) $$< -MT '$$*.$(1).$(O)' -MF $$@
endef
$(foreach object_type, b n, $(eval $(call GEN_RULE,$(object_type))))
.PHONY: depend
depend:
$(CAMLRUN) $(ROOTDIR)/boot/ocamlc -depend -slash *.mli *.ml > .depend
include .depend