Skip to content

Commit

Permalink
Merge makefiles in otherlibs/systhreads (ocaml#785)
Browse files Browse the repository at this point in the history
* Make sure the PTHREAD_CAML_LINK variable is defined everywhere.

* Merge makefiles in otherlibs/systhreads

Before this commit, the .cma and .cmxa libraries were linked using -linkall
under Windows but not under Unix.

It was not possible to clarify why -linkall was useful, but given the small
size of the involved modules and the fact that, for most modules, it
does not seem to make much sense to use one without the others, it has been
decided to use -linkall everywhere.

This commit also stops building the .cmxs shared library under Windows, for
consistency reasons (it was built only under Windows before).
  • Loading branch information
shindere authored and alainfrisch committed Sep 13, 2016
1 parent b28148d commit 5c4c41b
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 156 deletions.
1 change: 1 addition & 0 deletions config/Makefile.mingw
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ EXT_ASM=.$(S)
MANEXT=1
HASHBANGSCRIPTS=false
PTHREAD_LINK=
PTHREAD_CAML_LINK=
X11_INCLUDES=
X11_LINK=
BYTECCRPATH=
Expand Down
1 change: 1 addition & 0 deletions config/Makefile.mingw64
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ EXT_ASM=.$(S)
MANEXT=1
HASHBANGSCRIPTS=false
PTHREAD_LINK=
PTHREAD_CAML_LINK=
X11_INCLUDES=
X11_LINK=
BYTECCRPATH=
Expand Down
1 change: 1 addition & 0 deletions config/Makefile.msvc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ EXT_ASM=.$(S)
MANEXT=1
HASHBANGSCRIPTS=false
PTHREAD_LINK=
PTHREAD_CAML_LINK=
X11_INCLUDES=
X11_LINK=
BYTECCRPATH=
Expand Down
1 change: 1 addition & 0 deletions config/Makefile.msvc64
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ EXT_ASM=.$(S)
MANEXT=1
HASHBANGSCRIPTS=false
PTHREAD_LINK=
PTHREAD_CAML_LINK=
X11_INCLUDES=
X11_LINK=
BYTECCRPATH=
Expand Down
121 changes: 68 additions & 53 deletions otherlibs/systhreads/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,96 +13,107 @@
#* *
#**************************************************************************

include ../../config/Makefile
CAMLRUN ?= ../../boot/ocamlrun
CAMLYACC ?= ../../boot/ocamlyacc

ROOTDIR=../..
CAMLC=$(CAMLRUN) $(ROOTDIR)/ocamlc -nostdlib \
-I $(ROOTDIR)/stdlib -I $(ROOTDIR)/otherlibs/unix
CAMLOPT=$(CAMLRUN) $(ROOTDIR)/ocamlopt -nostdlib \
-I $(ROOTDIR)/stdlib -I $(ROOTDIR)/otherlibs/unix
MKLIB=$(CAMLRUN) ../../tools/ocamlmklib

include $(ROOTDIR)/config/Makefile

CAMLRUN ?= $(ROOTDIR)/boot/ocamlrun
CAMLYACC ?= $(ROOTDIR)/boot/ocamlyacc

LIBS = -nostdlib -I $(ROOTDIR)/stdlib -I $(ROOTDIR)/otherlibs/$(UNIXLIB)

CAMLC=$(CAMLRUN) $(ROOTDIR)/ocamlc $(LIBS)
CAMLOPT=$(CAMLRUN) $(ROOTDIR)/ocamlopt $(LIBS)
MKLIB=$(CAMLRUN) $(ROOTDIR)/tools/ocamlmklib
COMPFLAGS=-w +33..39 -warn-error A -g -bin-annot -safe-string
ifeq "$(FLAMBDA)" "true"
OPTCOMPFLAGS=-O3
else
OPTCOMPFLAGS=
endif

BYTECODE_C_OBJS=st_stubs_b.o
NATIVECODE_C_OBJS=st_stubs_n.o
LIBNAME=threads

THREAD_OBJS= thread.cmo mutex.cmo condition.cmo event.cmo threadUnix.cmo
ifeq "$(UNIX_OR_WIN32)" "unix"
HEADER = st_posix.h
else # Windows
HEADER = st_win32.h
endif

BYTECODE_C_OBJS=st_stubs_b.$(O)
NATIVECODE_C_OBJS=st_stubs_n.$(O)

all: libthreads.a threads.cma
THREADS_SOURCES = thread.ml mutex.ml condition.ml event.ml threadUnix.ml

allopt: libthreadsnat.a threads.cmxa
THREADS_BCOBJS = $(THREADS_SOURCES:.ml=.cmo)
THREADS_NCOBJS = $(THREADS_SOURCES:.ml=.cmx)

libthreads.a: $(BYTECODE_C_OBJS)
$(MKLIB) -o threads $(BYTECODE_C_OBJS) $(PTHREAD_LINK)
MLIFILES=thread.mli mutex.mli condition.mli event.mli threadUnix.mli
CMIFILES=$(MLIFILES:.mli=.cmi)

st_stubs_b.o: st_stubs.c st_posix.h
$(BYTECC) -I../../byterun $(BYTECCCOMPOPTS) $(SHAREDCCCOMPOPTS) \
-c st_stubs.c
mv st_stubs.o st_stubs_b.o
all: lib$(LIBNAME).$(A) $(LIBNAME).cma $(CMIFILES)

# Dynamic linking with -lpthread is risky on many platforms, so
# do not create a shared object for libthreadsnat.
libthreadsnat.a: $(NATIVECODE_C_OBJS)
$(AR) rc libthreadsnat.a $(NATIVECODE_C_OBJS)
allopt: lib$(LIBNAME)nat.$(A) $(LIBNAME).cmxa $(CMIFILES)

st_stubs_n.o: st_stubs.c st_posix.h
$(NATIVECC) -I../../asmrun -I../../byterun $(NATIVECCCOMPOPTS) \
$(SHAREDCCCOMPOPTS) -DNATIVE_CODE -DTARGET_$(ARCH) \
-DMODEL_$(MODEL) -DSYS_$(SYSTEM) -c st_stubs.c
mv st_stubs.o st_stubs_n.o
lib$(LIBNAME).$(A): $(BYTECODE_C_OBJS)
$(MKLIB) -o $(LIBNAME) $(BYTECODE_C_OBJS) $(PTHREAD_LINK)

threads.cma: $(THREAD_OBJS)
$(MKLIB) -ocamlc '$(CAMLC)' -o threads $(THREAD_OBJS) \
-cclib -lunix $(PTHREAD_CAML_LINK)
lib$(LIBNAME)nat.$(A): $(NATIVECODE_C_OBJS)
$(MKLIB) -o $(LIBNAME)nat $^

$(LIBNAME).cma: $(THREADS_BCOBJS)
ifeq "$(UNIX_OR_WIN32)" "unix"
$(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
$(MKLIB) -o $(LIBNAME) -ocamlc "$(CAMLC)" -linkall $(PTHREAD_CAML_LINK) $^
endif

# See remark above: force static linking of libthreadsnat.a
threads.cmxa: $(THREAD_OBJS:.cmo=.cmx)
$(CAMLOPT) -a -o threads.cmxa $(THREAD_OBJS:.cmo=.cmx) \
-cclib -lthreadsnat $(PTHREAD_CAML_LINK)
$(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

st_stubs_b.$(O): st_stubs.c $(HEADER)
$(BYTECC) -I$(ROOTDIR)/byterun $(BYTECCCOMPOPTS) $(SHAREDCCCOMPOPTS) -c $<
mv st_stubs.$(O) $@

$(THREAD_OBJS:.cmo=.cmx): ../../ocamlopt
st_stubs_n.$(O): st_stubs.c $(HEADER)
$(NATIVECC) -I$(ROOTDIR)/asmrun -I$(ROOTDIR)/byterun $(NATIVECCCOMPOPTS) \
$(SHAREDCCCOMPOPTS) -DNATIVE_CODE -DTARGET_$(ARCH) \
-DMODEL_$(MODEL) -DSYS_$(SYSTEM) -c $<
mv st_stubs.$(O) $@

partialclean:
rm -f *.cm*

clean: partialclean
rm -f *.o *.a *.so
rm -f *.$(A) *.$(O)

INSTALL_LIBDIR=$(DESTDIR)$(LIBDIR)
THREADS_LIBDIR=$(INSTALL_LIBDIR)/$(LIBNAME)
INSTALL_STUBLIBDIR=$(DESTDIR)$(STUBLIBDIR)

install:
if test -f dllthreads.so; then \
cp dllthreads.so $(INSTALL_STUBLIBDIR)/dllthreads.so; fi
cp libthreads.a $(INSTALL_LIBDIR)/libthreads.a
cd $(INSTALL_LIBDIR); $(RANLIB) libthreads.a
if test -d $(INSTALL_LIBDIR)/threads; then :; \
else mkdir $(INSTALL_LIBDIR)/threads; fi
cp $(THREAD_OBJS:.cmo=.cmi) threads.cma $(INSTALL_LIBDIR)/threads
rm -f $(INSTALL_LIBDIR)/threads/stdlib.cma
cp thread.mli mutex.mli condition.mli event.mli threadUnix.mli \
$(INSTALL_LIBDIR)
cp threads.h $(INSTALL_LIBDIR)/caml/threads.h
cp libthreads.$(A) "$(INSTALL_LIBDIR)"
cd "$(INSTALL_LIBDIR)"; $(RANLIB) libthreads.$(A)
mkdir -p "$(THREADS_LIBDIR)"
cp $(CMIFILES) threads.cma "$(THREADS_LIBDIR)"
cp $(MLIFILES) "$(INSTALL_LIBDIR)"
cp threads.h "$(INSTALL_LIBDIR)/caml"

installopt:
cp libthreadsnat.a $(INSTALL_LIBDIR)/libthreadsnat.a
cd $(INSTALL_LIBDIR); $(RANLIB) libthreadsnat.a
cp $(THREAD_OBJS:.cmo=.cmx) threads.cmxa threads.a \
$(INSTALL_LIBDIR)/threads
cd $(INSTALL_LIBDIR)/threads && $(RANLIB) threads.a
cp libthreadsnat.$(A) "$(INSTALL_LIBDIR)"
cd "$(INSTALL_LIBDIR)"; $(RANLIB) libthreadsnat.$(A)
cp $(THREADS_NCOBJS) threads.cmxa threads.$(A) "$(THREADS_LIBDIR)"
cd "$(THREADS_LIBDIR)" && $(RANLIB) threads.$(A)

.SUFFIXES: .ml .mli .cmo .cmi .cmx

Expand All @@ -115,8 +126,12 @@ installopt:
.ml.cmx:
$(CAMLOPT) -c $(COMPFLAGS) $(OPTCOMPFLAGS) $<

ifeq "$(UNIX_OR_WIN32)" "unix"
depend: $(GENFILES)
-$(CC) -MM -I../../byterun *.c > .depend
$(CAMLRUN) ../../tools/ocamldep -slash *.mli *.ml >> .depend
else # Windows
depend:
endif

include .depend
104 changes: 1 addition & 103 deletions otherlibs/systhreads/Makefile.nt
Original file line number Diff line number Diff line change
Expand Up @@ -13,106 +13,4 @@
#* *
#**************************************************************************

include ../../config/Makefile
CAMLRUN ?= ../../boot/ocamlrun
CAMLYACC ?= ../../boot/ocamlyacc

# Compilation options
CAMLC=$(CAMLRUN) ../../ocamlc -I ../../stdlib -I ../win32unix
CAMLOPT=$(CAMLRUN) ../../ocamlopt -I ../../stdlib -I ../win32unix
COMPFLAGS=-w +33 -warn-error A -g
ifeq "$(FLAMBDA)" "true"
OPTCOMPFLAGS=-O3
else
OPTCOMPFLAGS=
endif
MKLIB=$(CAMLRUN) ../../tools/ocamlmklib
CFLAGS=-I../../byterun $(EXTRACFLAGS)

ifeq "$(wildcard ../../flexdll/Makefile)" ""
export OCAML_FLEXLINK:=
else
export OCAML_FLEXLINK:=../../boot/ocamlrun ../../flexdll/flexlink.exe
endif

THREAD_OBJS=thread.cmo mutex.cmo condition.cmo event.cmo threadUnix.cmo
CMIFILES=$(THREAD_OBJS:.cmo=.cmi)
COBJS=st_stubs_b.$(O)
COBJS_NAT=st_stubs_n.$(O)

LIBNAME=threads

all: lib$(LIBNAME).$(A) $(LIBNAME).cma $(CMIFILES)

allopt: lib$(LIBNAME).$(A) $(LIBNAME).cmxa $(LIBNAME).cmxs $(CMIFILES)

$(LIBNAME).cma: $(THREAD_OBJS)
$(MKLIB) -o $(LIBNAME) -ocamlc "$(CAMLRUN) ../../ocamlc" \
-linkall $(THREAD_OBJS) $(LINKOPTS)

lib$(LIBNAME).$(A): $(COBJS)
$(MKLIB) -o $(LIBNAME) $(COBJS) $(LDOPTS)

st_stubs_b.$(O): st_stubs.c st_win32.h
$(BYTECC) $(BYTECCCOMPOPTS) $(CFLAGS) -c st_stubs.c
mv st_stubs.$(O) st_stubs_b.$(O)



$(LIBNAME).cmxa: $(THREAD_OBJS:.cmo=.cmx)
$(MKLIB) -o $(LIBNAME)nat \
-ocamlopt "$(CAMLRUN) ../../ocamlopt" -linkall \
$(THREAD_OBJS:.cmo=.cmx) $(LINKOPTS)
mv $(LIBNAME)nat.cmxa $(LIBNAME).cmxa
mv $(LIBNAME)nat.$(A) $(LIBNAME).$(A)

$(LIBNAME).cmxs: $(LIBNAME).cmxa lib$(LIBNAME)nat.$(A)
$(CAMLOPT) -shared -o $(LIBNAME).cmxs -I . $(LIBNAME).cmxa -linkall

lib$(LIBNAME)nat.$(A): $(COBJS_NAT)
$(MKLIB) -o $(LIBNAME)nat $(COBJS_NAT) $(LDOPTS)

st_stubs_n.$(O): st_stubs.c st_win32.h
$(NATIVECC) -DNATIVE_CODE -I../../asmrun -I../../byterun \
$(NATIVECCCOMPOPTS) -c st_stubs.c
mv st_stubs.$(O) st_stubs_n.$(O)

$(THREAD_OBJS:.cmo=.cmx): ../../ocamlopt

partialclean:
rm -f *.cm*

clean: partialclean
rm -f *.dll *.$(A) *.$(O)

INSTALL_LIBDIR=$(DESTDIR)$(LIBDIR)
INSTALL_STUBLIBDIR=$(DESTDIR)$(STUBLIBDIR)

install:
cp dllthreads.dll "$(INSTALL_STUBLIBDIR)/dllthreads.dll"
cp libthreads.$(A) "$(INSTALL_LIBDIR)/libthreads.$(A)"
mkdir -p "$(INSTALL_LIBDIR)/threads"
cp $(CMIFILES) threads.cma "$(INSTALL_LIBDIR)/threads"
rm -f "$(INSTALL_LIBDIR)/threads/stdlib.cma"
cp threads.h "$(INSTALL_LIBDIR)/caml/threads.h"

installopt:
cp libthreadsnat.$(A) "$(INSTALL_LIBDIR)/libthreadsnat.$(A)"
cp $(THREAD_OBJS:.cmo=.cmx) threads.cmxa threads.$(A) \
"$(INSTALL_LIBDIR)/threads"
cp threads.cmxs "$(INSTALL_LIBDIR)/threads"

.SUFFIXES: .ml .mli .cmo .cmi .cmx

.mli.cmi:
$(CAMLC) -c $(COMPFLAGS) $<

.ml.cmo:
$(CAMLC) -c -g $(COMPFLAGS) $<

.ml.cmx:
$(CAMLOPT) -c $(COMPFLAGS) $(OPTCOMPFLAGS) $<

depend:

include .depend
include Makefile

0 comments on commit 5c4c41b

Please sign in to comment.