Skip to content

Commit

Permalink
Merge build systems in the stdlib directory (#866)
Browse files Browse the repository at this point in the history
Changes specific to the Unix build system:

  - allopt target: replace invocations to $(MAKE) by prerequisites.

  - installopt-noprof tartget: call ln with the -f option rather than
    removing the destination file before creating the symlink

Changes specific to the Windows build system:

  - allopt target: add the allopt-$(PROFILING) target as a prereq
    Currently, $(PROFILING) is set to noprof in the default Windows
    configuration files (see config/Makefile.*) so this will not change
    anything in practice, except when PROFILING is set to "prof"
    under Windows. From now on this will be honored, whereas it was not,
    before this commit.

  - installopt now also supports installing the library with
    profiling support

Changes affecting both build systems:

  - Declare rules that do not build a file as PHONY.
    This was mostly done in the Unix build system but not in the Windows one.
    However, this commit adds one .PHONY declaration for each
    concerned rule, just above the rule itself, rather than declaring
    several rules PHONY simultaneously. Although this is longer, it
    feels better because that way the information specific to each
    rule is more local.
  • Loading branch information
shindere authored and dra27 committed Nov 9, 2016
1 parent 52587b2 commit db12391
Show file tree
Hide file tree
Showing 3 changed files with 217 additions and 215 deletions.
262 changes: 216 additions & 46 deletions stdlib/Makefile
Expand Up @@ -13,66 +13,236 @@
#* *
#**************************************************************************

include Makefile.shared
include ../config/Makefile
CAMLRUN ?= ../boot/ocamlrun
CAMLYACC ?= ../boot/ocamlyacc
TARGET_BINDIR ?= $(BINDIR)

allopt:
$(MAKE) stdlib.cmxa std_exit.cmx
$(MAKE) allopt-$(PROFILING)
COMPILER=../ocamlc
CAMLC=$(CAMLRUN) $(COMPILER)
COMPFLAGS=-strict-sequence -absname -w +a-4-9-41-42-44-45-48 \
-g -warn-error A -bin-annot -nostdlib \
-safe-string -strict-formats
ifeq "$(FLAMBDA)" "true"
OPTCOMPFLAGS=-O3
else
OPTCOMPFLAGS=
endif
OPTCOMPILER=../ocamlopt
CAMLOPT=$(CAMLRUN) $(OPTCOMPILER)
CAMLDEP=$(CAMLRUN) ../tools/ocamldep

OBJS=camlinternalFormatBasics.cmo pervasives.cmo $(OTHERS)
OTHERS=list.cmo char.cmo bytes.cmo string.cmo sys.cmo \
sort.cmo marshal.cmo obj.cmo array.cmo \
int32.cmo int64.cmo nativeint.cmo \
lexing.cmo parsing.cmo \
set.cmo map.cmo stack.cmo queue.cmo \
camlinternalLazy.cmo lazy.cmo stream.cmo \
buffer.cmo camlinternalFormat.cmo printf.cmo \
arg.cmo printexc.cmo gc.cmo \
digest.cmo random.cmo hashtbl.cmo weak.cmo \
format.cmo uchar.cmo scanf.cmo callback.cmo \
camlinternalOO.cmo oo.cmo camlinternalMod.cmo \
genlex.cmo ephemeron.cmo \
filename.cmo complex.cmo \
arrayLabels.cmo listLabels.cmo bytesLabels.cmo \
stringLabels.cmo moreLabels.cmo stdLabels.cmo \
spacetime.cmo

.PHONY: all
all: stdlib.cma std_exit.cmo camlheader target_camlheader camlheader_ur

ifeq "$(RUNTIMED)" "runtimed"
all: camlheaderd
endif

ifeq "$(RUNTIMEI)" "true"
all: camlheaderi
endif

.PHONY: allopt
allopt: stdlib.cmxa std_exit.cmx allopt-$(PROFILING)

.PHONY: allopt-noprof
allopt-noprof:

.PHONY: allopt-prof
allopt-prof: stdlib.p.cmxa std_exit.p.cmx
rm -f std_exit.p.cmi

INSTALL_LIBDIR=$(DESTDIR)$(LIBDIR)

.PHONY: install
install::
cp stdlib.cma std_exit.cmo *.cmi *.cmt *.cmti *.mli *.ml \
camlheader_ur \
"$(INSTALL_LIBDIR)"
cp target_camlheader "$(INSTALL_LIBDIR)/camlheader"

ifeq "$(RUNTIMED)" "runtimed"
install::
cp target_camlheaderd $(INSTALL_LIBDIR)
endif

ifeq "$(RUNTIMEI)" "true"
install::
cp target_camlheaderi $(INSTALL_LIBDIR)
endif

.PHONY: installopt
installopt: installopt-default installopt-$(PROFILING)

.PHONY: installopt-default
installopt-default:
cp stdlib.cmxa stdlib.a std_exit.o *.cmx "$(INSTALL_LIBDIR)"
cd "$(INSTALL_LIBDIR)"; $(RANLIB) stdlib.a
cp stdlib.cmxa stdlib.$(A) std_exit.$(O) *.cmx "$(INSTALL_LIBDIR)"
cd "$(INSTALL_LIBDIR)"; $(RANLIB) stdlib.$(A)

.PHONY: installopt-noprof
installopt-noprof:
rm -f "$(INSTALL_LIBDIR)/stdlib.p.cmxa"; \
ln -s stdlib.cmxa "$(INSTALL_LIBDIR)/stdlib.p.cmxa"
rm -f "$(INSTALL_LIBDIR)/stdlib.p.a"; \
ln -s stdlib.a "$(INSTALL_LIBDIR)/stdlib.p.a"
rm -f "$(INSTALL_LIBDIR)/std_exit.p.cmx"; \
ln -s std_exit.cmx "$(INSTALL_LIBDIR)/std_exit.p.cmx"
rm -f "$(INSTALL_LIBDIR)/std_exit.p.o"; \
ln -s std_exit.o "$(INSTALL_LIBDIR)/std_exit.p.o"
ln -sf stdlib.cmxa "$(INSTALL_LIBDIR)/stdlib.p.cmxa"
ln -sf stdlib.$(A) "$(INSTALL_LIBDIR)/stdlib.p.$(A)"
ln -sf std_exit.cmx "$(INSTALL_LIBDIR)/std_exit.p.cmx"
ln -sf std_exit.$(O) "$(INSTALL_LIBDIR)/std_exit.p.$(O)"

.PHONY: installopt-prof
installopt-prof:
cp stdlib.p.cmxa stdlib.p.a std_exit.p.cmx std_exit.p.o \
cp stdlib.p.cmxa stdlib.p.$(A) std_exit.p.cmx std_exit.p.$(O) \
"$(INSTALL_LIBDIR)"
cd "$(INSTALL_LIBDIR)"; $(RANLIB) stdlib.p.a
cd "$(INSTALL_LIBDIR)"; $(RANLIB) stdlib.p.$(A)

ifeq "$(UNIX_OR_WIN32)" "unix"
HEADERPROGRAM = header.c
else # Windows
HEADERPROGRAM = headernt.c
endif

CAMLHEADERS =\
camlheader target_camlheader camlheader_ur \
camlheaderd target_camlheaderd \
camlheaderi target_camlheaderi

ifeq "$(HASHBANGSCRIPTS)" "true"
$(CAMLHEADERS): ../config/Makefile
for suff in '' d i; do \
echo '#!$(BINDIR)/ocamlrun'$$suff > camlheader$$suff && \
echo '#!$(TARGET_BINDIR)/ocamlrun'$$suff >target_camlheader$$suff; \
done && \
echo '#!' | tr -d '\012' > camlheader_ur;
else # Hashbang scripts not supported

$(CAMLHEADERS): $(HEADERPROGRAM) ../config/Makefile

ifeq "$(UNIX_OR_WIN32)" "unix"
$(CAMLHEADERS):
for suff in '' d i; do \
$(BYTECC) $(BYTECCCOMPOPTS) $(BYTECCLINKOPTS) \
-DRUNTIME_NAME='"$(BINDIR)/ocamlrun'$$suff'"' \
header.c -o tmpheader$(EXE) && \
strip tmpheader$(EXE) && \
mv tmpheader$(EXE) camlheader$$suff && \
$(BYTECC) $(BYTECCCOMPOPTS) $(BYTECCLINKOPTS) \
-DRUNTIME_NAME='"$(TARGET_BINDIR)/ocamlrun'$$suff'"' \
header.c -o tmpheader$(EXE) && \
strip tmpheader$(EXE) && \
mv tmpheader$(EXE) target_camlheader$$suff; \
done && \
cp camlheader camlheader_ur

else # Windows

# TODO: see whether there is a way to further merge the rules below
# with those above

camlheader target_camlheader camlheader_ur:
$(BYTECC) $(BYTECCCOMPOPTS) -c -I../byterun \
-DRUNTIME_NAME='"ocamlrun"' headernt.c
$(MKEXE) -o tmpheader.exe headernt.$(O) $(EXTRALIBS)
rm -f camlheader.exe
mv tmpheader.exe camlheader
cp camlheader target_camlheader
cp camlheader camlheader_ur

camlheaderd target_camlheaderd:
$(BYTECC) $(BYTECCCOMPOPTS) -c -I../byterun \
-DRUNTIME_NAME='"ocamlrund"' headernt.c
$(MKEXE) -o tmpheader.exe headernt.$(O) $(EXTRALIBS)
mv tmpheader.exe camlheaderd
cp camlheaderd target_camlheaderd

camlheaderi:
$(BYTECC) $(BYTECCCOMPOPTS) -c -I../byterun \
-DRUNTIME_NAME='"ocamlruni"' headernt.c
$(MKEXE) -o tmpheader.exe headernt.$(O) $(EXTRALIBS)
mv tmpheader.exe camlheaderi

# TODO: do not call flexlink to build tmpheader.exe (we don't need
# the export table)

endif # ifeq "$(UNIX_OR_WIN32)" "unix"

endif # ifeq "$(HASHBANGSCRIPTS)" "true"

stdlib.cma: $(OBJS)
$(CAMLC) -a -o $@ $^

stdlib.cmxa: $(OBJS:.cmo=.cmx)
$(CAMLOPT) -a -o $@ $^

stdlib.p.cmxa: $(OBJS:.cmo=.p.cmx)
$(CAMLOPT) -a -o stdlib.p.cmxa $(OBJS:.cmo=.p.cmx)

camlheader target_camlheader camlheader_ur \
camlheaderd target_camlheaderd \
camlheaderi target_camlheaderi: \
header.c ../config/Makefile
if $(HASHBANGSCRIPTS); then \
for suff in '' d i; do \
echo '#!$(BINDIR)/ocamlrun'$$suff > camlheader$$suff && \
echo '#!$(TARGET_BINDIR)/ocamlrun'$$suff >target_camlheader$$suff; \
done && \
echo '#!' | tr -d '\012' > camlheader_ur; \
else \
for suff in '' d i; do \
$(BYTECC) $(BYTECCCOMPOPTS) $(BYTECCLINKOPTS) \
-DRUNTIME_NAME='"$(BINDIR)/ocamlrun'$$suff'"' \
header.c -o tmpheader$(EXE) && \
strip tmpheader$(EXE) && \
mv tmpheader$(EXE) camlheader$$suff && \
$(BYTECC) $(BYTECCCOMPOPTS) $(BYTECCLINKOPTS) \
-DRUNTIME_NAME='"$(TARGET_BINDIR)/ocamlrun'$$suff'"' \
header.c -o tmpheader$(EXE) && \
strip tmpheader$(EXE) && \
mv tmpheader$(EXE) target_camlheader$$suff; \
done && \
cp camlheader camlheader_ur; \
fi

.PHONY: all allopt allopt-noprof allopt-prof install installopt
.PHONY: installopt-default installopt-noprof installopt-prof clean depend
$(CAMLOPT) -a -o $@ $^

sys.ml: sys.mlp ../VERSION
sed -e "s|%%VERSION%%|`sed -e 1q ../VERSION`|" sys.mlp >sys.ml

.PHONY: clean
clean::
rm -f sys.ml

clean::
rm -f $(CAMLHEADERS)

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

.mli.cmi:
$(CAMLC) $(COMPFLAGS) `./Compflags $@` -c $<

.ml.cmo:
$(CAMLC) $(COMPFLAGS) `./Compflags $@` -c $<

.ml.cmx:
$(CAMLOPT) $(COMPFLAGS) $(OPTCOMPFLAGS) `./Compflags $@` -c $<

.ml.p.cmx:
$(CAMLOPT) $(COMPFLAGS) $(OPTCOMPFLAGS) `./Compflags $@` \
-p -c -o $*.p.cmx $<

# Dependencies on the compiler
COMPILER_DEPS=$(filter-out -use-prims, $(COMPILER))
$(OBJS) std_exit.cmo: $(COMPILER_DEPS)
$(OBJS:.cmo=.cmi) std_exit.cmi: $(COMPILER_DEPS)
$(OBJS:.cmo=.cmx) std_exit.cmx: $(OPTCOMPILER)
$(OBJS:.cmo=.p.cmx) std_exit.p.cmx: $(OPTCOMPILER)

# Dependencies on Pervasives (not tracked by ocamldep)
$(OTHERS) std_exit.cmo: pervasives.cmi
$(OTHERS:.cmo=.cmi) std_exit.cmi: pervasives.cmi
$(OBJS:.cmo=.cmx) std_exit.cmx: pervasives.cmi
$(OBJS:.cmo=.p.cmx) std_exit.p.cmx: pervasives.cmi
$(OTHERS:.cmo=.cmx) std_exit.cmx: pervasives.cmx
$(OTHERS:.cmo=.p.cmx) std_exit.p.cmx: pervasives.cmx

clean::
rm -f *.cm* *.$(O) *.$(A)
rm -f *~
rm -f camlheader*

include .depend

# Note that .p.cmx targets do not depend (for compilation) upon other
# .p.cmx files. When the compiler imports another compilation unit,
# it looks for the .cmx file (not .p.cmx).
.PHONY: depend
depend:
$(CAMLDEP) -slash *.mli *.ml > .depend
$(CAMLDEP) -slash *.ml | sed -e 's/\.cmx : /.p.cmx : /g' >>.depend
32 changes: 1 addition & 31 deletions stdlib/Makefile.nt
Expand Up @@ -13,34 +13,4 @@
#* *
#**************************************************************************

include Makefile.shared

allopt: stdlib.cmxa std_exit.cmx

installopt:
cp stdlib.cmxa stdlib.$(A) std_exit.$(O) *.cmx "$(INSTALL_LIBDIR)"

camlheader target_camlheader camlheader_ur: headernt.c ../config/Makefile
$(BYTECC) $(BYTECCCOMPOPTS) -c -I../byterun \
-DRUNTIME_NAME='"ocamlrun"' headernt.c
$(MKEXE) -o tmpheader.exe headernt.$(O) $(EXTRALIBS)
rm -f camlheader.exe
mv tmpheader.exe camlheader
cp camlheader target_camlheader
cp camlheader camlheader_ur

camlheaderd target_camlheaderd: headernt.c ../config/Makefile
$(BYTECC) $(BYTECCCOMPOPTS) -c -I../byterun \
-DRUNTIME_NAME='"ocamlrund"' headernt.c
$(MKEXE) -o tmpheader.exe headernt.$(O) $(EXTRALIBS)
mv tmpheader.exe camlheaderd
cp camlheaderd target_camlheaderd

camlheaderi: headernt.c ../config/Makefile
$(BYTECC) $(BYTECCCOMPOPTS) -c -I../byterun \
-DRUNTIME_NAME='"ocamlruni"' headernt.c
$(MKEXE) -o tmpheader.exe headernt.$(O) $(EXTRALIBS)
mv tmpheader.exe camlheaderi

# TODO: do not call flexlink to build tmpheader.exe (we don't need
# the export table)
include Makefile

0 comments on commit db12391

Please sign in to comment.