Skip to content

Commit

Permalink
Add the $(EXE) suffix to all programs at build rather than install time
Browse files Browse the repository at this point in the history
This commit touches neither boot/ocamlc nor boot/ocamllex

It has the side-effect of fixing the cleanup rules which did not use the
$(EXE) extension when removing a file although it was produced with the
$(EXE) extension.
  • Loading branch information
shindere committed Jun 17, 2020
1 parent 5a6f27e commit d4987b6
Show file tree
Hide file tree
Showing 16 changed files with 243 additions and 179 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ _build
/tools/ocamlmklib.opt
/tools/ocamlmklibconfig.ml
/tools/objinfo_helper
/tools/read_cmt
/tools/read_cmt.opt
/tools/ocamlcmt
/tools/ocamlcmt.opt
/tools/cmpbyt
/tools/cmpbyt.opt
/tools/stripdebug
Expand Down
122 changes: 66 additions & 56 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ endif
include stdlib/StdlibModules

CAMLC=$(BOOT_OCAMLC) -g -nostdlib -I boot -use-prims runtime/primitives
CAMLOPT=$(CAMLRUN) ./ocamlopt -g -nostdlib -I stdlib -I otherlibs/dynlink
CAMLOPT=$(CAMLRUN) ./ocamlopt$(EXE) -g -nostdlib -I stdlib -I otherlibs/dynlink
ARCHES=amd64 i386 arm arm64 power s390x riscv
INCLUDES=-I utils -I parsing -I typing -I bytecomp -I file_formats \
-I lambda -I middle_end -I middle_end/closure \
Expand Down Expand Up @@ -77,7 +77,7 @@ LIBFILES=stdlib.cma std_exit.cmo *.cmi camlheader
COMPLIBDIR=$(LIBDIR)/compiler-libs

TOPINCLUDES=$(addprefix -I otherlibs/,$(filter-out %threads,$(OTHERLIBRARIES)))
RUNTOP=./runtime/ocamlrun ./ocaml \
RUNTOP=./runtime/ocamlrun$(EXE) ./ocaml$(EXE) \
-nostdlib -I stdlib \
-noinit $(TOPFLAGS) $(TOPINCLUDES)
NATRUNTOP=./ocamlnat$(EXE) \
Expand All @@ -96,11 +96,14 @@ FLEXDLL_SUBMODULE_PRESENT := $(wildcard flexdll/Makefile)
ifeq "$(FLEXDLL_SUBMODULE_PRESENT)" ""
BOOT_FLEXLINK_CMD =
else
BOOT_FLEXLINK_CMD = FLEXLINK_CMD="../boot/ocamlrun ../flexdll/flexlink.exe"
BOOT_FLEXLINK_CMD = \
FLEXLINK_CMD="../boot/ocamlrun$(EXE) ../flexdll/flexlink.exe"
endif
else
endif

expunge := expunge$(EXE)

# targets for the compilerlibs/*.{cma,cmxa} archives
include compilerlibs/Makefile.compilerlibs

Expand Down Expand Up @@ -129,6 +132,10 @@ partialclean::
.PHONY: beforedepend
beforedepend:: utils/config.ml utils/domainstate.ml utils/domainstate.mli

programs := expunge ocaml ocamlc ocamlc.opt ocamlnat ocamlopt ocamlopt.opt

$(foreach program, $(programs), $(eval $(call PROGRAM_SYNONYM,$(program))))

# Start up the system from the distribution compiler
.PHONY: coldstart
coldstart:
Expand All @@ -152,12 +159,12 @@ core: coldstart

# Check if fixpoint reached

CMPBYT := $(CAMLRUN) tools/cmpbyt
CMPBYT := $(CAMLRUN) tools/cmpbyt$(EXE)

.PHONY: compare
compare:
@if $(CMPBYT) boot/ocamlc ocamlc \
&& $(CMPBYT) boot/ocamllex lex/ocamllex; \
@if $(CMPBYT) boot/ocamlc ocamlc$(EXE) \
&& $(CMPBYT) boot/ocamllex lex/ocamllex$(EXE); \
then echo "Fixpoint reached, bootstrap succeeded."; \
else \
echo "Fixpoint not reached, try one more bootstrapping cycle."; \
Expand All @@ -170,8 +177,8 @@ PROMOTE ?= cp

.PHONY: promote-common
promote-common:
$(PROMOTE) ocamlc boot/ocamlc
$(PROMOTE) lex/ocamllex boot/ocamllex
$(PROMOTE) ocamlc$(EXE) boot/ocamlc
$(PROMOTE) lex/ocamllex$(EXE) boot/ocamllex
cd stdlib; cp $(LIBFILES) ../boot

# Promote the newly compiled system to the rank of cross compiler
Expand Down Expand Up @@ -231,7 +238,7 @@ coreboot:
# Rebuild the library (using runtime/ocamlrun ./ocamlc)
$(MAKE) library-cross
# Promote the new compiler and the new runtime
$(MAKE) CAMLRUN=runtime/ocamlrun promote
$(MAKE) CAMLRUN=runtime/ocamlrun$(EXE) promote
# Rebuild the core system
$(MAKE) partialclean
$(MAKE) core
Expand Down Expand Up @@ -293,6 +300,7 @@ flexdll: flexdll/Makefile flexlink
MSVC_DETECT=0 CHAINS=$(FLEXDLL_CHAIN) NATDYNLINK=false support

# Bootstrapping flexlink - leaves a bytecode image of flexlink.exe in flexdll/
FLEXLINK_OCAMLOPT = ../boot/ocamlrun$(EXE) ../boot/ocamlc -nostdlib -I ../boot
.PHONY: flexlink
flexlink: flexdll/Makefile
$(MAKE) -C runtime BOOTSTRAPPING_FLEXLINK=yes ocamlrun$(EXE)
Expand All @@ -302,7 +310,7 @@ flexlink: flexdll/Makefile
cd stdlib && cp $(LIBFILES) ../boot/
$(MAKE) -C flexdll MSVC_DETECT=0 OCAML_CONFIG_FILE=../Makefile.config \
CHAINS=$(FLEXDLL_CHAIN) NATDYNLINK=false \
OCAMLOPT="../boot/ocamlrun ../boot/ocamlc -nostdlib -I ../boot" \
OCAMLOPT="$(FLEXLINK_OCAMLOPT)" \
flexlink.exe
$(MAKE) -C runtime clean
$(MAKE) partialclean
Expand All @@ -311,9 +319,9 @@ flexlink: flexdll/Makefile
flexlink.opt:
cd flexdll && \
mv flexlink.exe flexlink && \
($(MAKE) OCAML_FLEXLINK="../boot/ocamlrun ./flexlink" MSVC_DETECT=0 \
OCAML_CONFIG_FILE=../Makefile.config \
OCAMLOPT="../ocamlopt.opt -nostdlib -I ../stdlib" \
($(MAKE) OCAML_FLEXLINK="../boot/ocamlrun$(EXE) ./flexlink" \
MSVC_DETECT=0 OCAML_CONFIG_FILE=../Makefile.config \
OCAMLOPT="../ocamlopt.opt$(EXE) -nostdlib -I ../stdlib" \
flexlink.exe || \
(mv flexlink flexlink.exe && false)) && \
mv flexlink.exe flexlink.opt && \
Expand Down Expand Up @@ -345,13 +353,14 @@ install:
VERSION \
"$(INSTALL_LIBDIR)"
$(MAKE) -C runtime install
$(INSTALL_PROG) ocaml "$(INSTALL_BINDIR)/ocaml$(EXE)"
$(INSTALL_PROG) ocaml$(EXE) "$(INSTALL_BINDIR)/ocaml$(EXE)"
ifeq "$(INSTALL_BYTECODE_PROGRAMS)" "true"
$(INSTALL_PROG) ocamlc "$(INSTALL_BINDIR)/ocamlc.byte$(EXE)"
$(INSTALL_PROG) ocamlc$(EXE) "$(INSTALL_BINDIR)/ocamlc.byte$(EXE)"
endif
$(MAKE) -C stdlib install
ifeq "$(INSTALL_BYTECODE_PROGRAMS)" "true"
$(INSTALL_PROG) lex/ocamllex "$(INSTALL_BINDIR)/ocamllex.byte$(EXE)"
$(INSTALL_PROG) lex/ocamllex$(EXE) \
"$(INSTALL_BINDIR)/ocamllex.byte$(EXE)"
endif
$(INSTALL_PROG) yacc/ocamlyacc$(EXE) "$(INSTALL_BINDIR)/ocamlyacc$(EXE)"
$(INSTALL_DATA) \
Expand Down Expand Up @@ -382,7 +391,7 @@ endif
$(INSTALL_DATA) \
$(BYTESTART) $(TOPLEVELSTART) \
"$(INSTALL_COMPLIBDIR)"
$(INSTALL_PROG) expunge "$(INSTALL_LIBDIR)/expunge$(EXE)"
$(INSTALL_PROG) $(expunge) "$(INSTALL_LIBDIR)/$(expunge)"
$(INSTALL_DATA) \
toplevel/topdirs.cmi \
"$(INSTALL_LIBDIR)"
Expand Down Expand Up @@ -413,21 +422,21 @@ ifeq "$(UNIX_OR_WIN32)" "win32"
endif
$(INSTALL_DATA) Makefile.config "$(INSTALL_LIBDIR)/Makefile.config"
ifeq "$(INSTALL_BYTECODE_PROGRAMS)" "true"
if test -f ocamlopt; then $(MAKE) installopt; else \
if test -f ocamlopt$(EXE); then $(MAKE) installopt; else \
cd "$(INSTALL_BINDIR)"; \
$(LN) ocamlc.byte$(EXE) ocamlc$(EXE); \
$(LN) ocamllex.byte$(EXE) ocamllex$(EXE); \
fi
else
if test -f ocamlopt; then $(MAKE) installopt; fi
if test -f ocamlopt$(EXE); then $(MAKE) installopt; fi
endif

# Installation of the native-code compiler
.PHONY: installopt
installopt:
$(MAKE) -C runtime installopt
ifeq "$(INSTALL_BYTECODE_PROGRAMS)" "true"
$(INSTALL_PROG) ocamlopt "$(INSTALL_BINDIR)/ocamlopt.byte$(EXE)"
$(INSTALL_PROG) ocamlopt$(EXE) "$(INSTALL_BINDIR)/ocamlopt.byte$(EXE)"
endif
$(MAKE) -C stdlib installopt
$(INSTALL_DATA) \
Expand Down Expand Up @@ -485,27 +494,28 @@ endif
$(MAKE) -C otherlibs/$$i installopt || exit $$?; \
done
ifeq "$(INSTALL_BYTECODE_PROGRAMS)" "true"
if test -f ocamlopt.opt ; then $(MAKE) installoptopt; else \
if test -f ocamlopt.opt$(EXE); then $(MAKE) installoptopt; else \
cd "$(INSTALL_BINDIR)"; \
$(LN) ocamlc.byte$(EXE) ocamlc$(EXE); \
$(LN) ocamlopt.byte$(EXE) ocamlopt$(EXE); \
$(LN) ocamllex.byte$(EXE) ocamllex$(EXE); \
fi
else
if test -f ocamlopt.opt ; then $(MAKE) installoptopt; fi
if test -f ocamlopt.opt$(EXE); then $(MAKE) installoptopt; fi
endif
$(MAKE) -C tools installopt
if test -f ocamlopt.opt -a -f flexdll/flexlink.opt ; then \
if test -f ocamlopt.opt$(EXE) -a -f flexdll/flexlink.opt ; then \
$(INSTALL_PROG) \
flexdll/flexlink.opt "$(INSTALL_BINDIR)/flexlink$(EXE)" ; \
fi

.PHONY: installoptopt
installoptopt:
$(INSTALL_PROG) ocamlc.opt "$(INSTALL_BINDIR)/ocamlc.opt$(EXE)"
$(INSTALL_PROG) ocamlopt.opt "$(INSTALL_BINDIR)/ocamlopt.opt$(EXE)"
$(INSTALL_PROG) ocamlc.opt$(EXE) "$(INSTALL_BINDIR)/ocamlc.opt$(EXE)"
$(INSTALL_PROG) ocamlopt.opt$(EXE) \
"$(INSTALL_BINDIR)/ocamlopt.opt$(EXE)"
$(INSTALL_PROG) \
lex/ocamllex.opt "$(INSTALL_BINDIR)/ocamllex.opt$(EXE)"
lex/ocamllex.opt$(EXE) "$(INSTALL_BINDIR)/ocamllex.opt$(EXE)"
cd "$(INSTALL_BINDIR)"; \
$(LN) ocamlc.opt$(EXE) ocamlc$(EXE); \
$(LN) ocamlopt.opt$(EXE) ocamlopt$(EXE); \
Expand Down Expand Up @@ -575,23 +585,25 @@ manual-pregen: opt.opt

# The clean target
clean:: partialclean
rm -f $(programs) $(programs:=.exe)

# The bytecode compiler

ocamlc: compilerlibs/ocamlcommon.cma compilerlibs/ocamlbytecomp.cma $(BYTESTART)
ocamlc$(EXE): compilerlibs/ocamlcommon.cma \
compilerlibs/ocamlbytecomp.cma $(BYTESTART)
$(CAMLC) $(LINKFLAGS) -compat-32 -o $@ $^

partialclean::
rm -rf ocamlc
rm -rf ocamlc$(EXE)

# The native-code compiler

ocamlopt: compilerlibs/ocamlcommon.cma compilerlibs/ocamloptcomp.cma \
ocamlopt$(EXE): compilerlibs/ocamlcommon.cma compilerlibs/ocamloptcomp.cma \
$(OPTSTART)
$(CAMLC) $(LINKFLAGS) -o $@ $^

partialclean::
rm -f ocamlopt
rm -f ocamlopt$(EXE)

# The toplevel

Expand All @@ -604,11 +616,11 @@ ocaml_dependencies := \
ocaml.tmp: $(ocaml_dependencies)
$(CAMLC) $(LINKFLAGS) -linkall -o $@ $^

ocaml: expunge ocaml.tmp
ocaml$(EXE): $(expunge) ocaml.tmp
- $(CAMLRUN) $^ $@ $(PERVASIVES)

partialclean::
rm -f ocaml
rm -f ocaml$(EXE)

.PHONY: runtop
runtop:
Expand Down Expand Up @@ -644,21 +656,23 @@ beforedepend:: parsing/lexer.ml

# The bytecode compiler compiled with the native-code compiler

ocamlc.opt: compilerlibs/ocamlcommon.cmxa compilerlibs/ocamlbytecomp.cmxa \
$(BYTESTART:.cmo=.cmx)
ocamlc.opt$(EXE): compilerlibs/ocamlcommon.cmxa \
compilerlibs/ocamlbytecomp.cmxa $(BYTESTART:.cmo=.cmx)
$(CAMLOPT_CMD) $(LINKFLAGS) -o $@ $^ -cclib "$(BYTECCLIBS)"

partialclean::
rm -f ocamlc.opt
rm -f ocamlc.opt$(EXE)

# The native-code compiler compiled with itself

ocamlopt.opt: compilerlibs/ocamlcommon.cmxa compilerlibs/ocamloptcomp.cmxa \
$(OPTSTART:.cmo=.cmx)
ocamlopt.opt$(EXE): \
compilerlibs/ocamlcommon.cmxa \
compilerlibs/ocamloptcomp.cmxa \
$(OPTSTART:.cmo=.cmx)
$(CAMLOPT_CMD) $(LINKFLAGS) -o $@ $^

partialclean::
rm -f ocamlopt.opt
rm -f ocamlopt.opt$(EXE)

# The predefined exceptions and primitives

Expand Down Expand Up @@ -696,27 +710,29 @@ asmcomp/scheduling.ml: asmcomp/$(ARCH)/scheduling.ml

# Preprocess the code emitters

asmcomp/emit.ml: asmcomp/$(ARCH)/emit.mlp tools/cvt_emit
cvt_emit := tools/cvt_emit$(EXE)

asmcomp/emit.ml: asmcomp/$(ARCH)/emit.mlp $(cvt_emit)
echo \# 1 \"$(ARCH)/emit.mlp\" > $@
$(CAMLRUN) tools/cvt_emit < $< >> $@ \
$(CAMLRUN) $(cvt_emit) < $< >> $@ \
|| { rm -f $@; exit 2; }

partialclean::
rm -f asmcomp/emit.ml

beforedepend:: asmcomp/emit.ml

tools/cvt_emit: tools/cvt_emit.mll
$(cvt_emit): tools/cvt_emit.mll
$(MAKE) -C tools cvt_emit

# The "expunge" utility

expunge: compilerlibs/ocamlcommon.cma compilerlibs/ocamlbytecomp.cma \
$(expunge): compilerlibs/ocamlcommon.cma compilerlibs/ocamlbytecomp.cma \
toplevel/expunge.cmo
$(CAMLC) $(LINKFLAGS) -o $@ $^

partialclean::
rm -f expunge
rm -f $(expunge)

# The runtime system for the bytecode compiler

Expand Down Expand Up @@ -766,7 +782,8 @@ library: ocamlc

.PHONY: library-cross
library-cross:
$(MAKE) -C stdlib $(BOOT_FLEXLINK_CMD) CAMLRUN=../runtime/ocamlrun all
$(MAKE) -C stdlib \
$(BOOT_FLEXLINK_CMD) CAMLRUN=../runtime/ocamlrun$(EXE) all

.PHONY: libraryopt
libraryopt:
Expand Down Expand Up @@ -983,14 +1000,6 @@ endif

# The native toplevel

# When the native toplevel executable has an extension (e.g. ".exe"),
# provide a phony 'ocamlnat' synonym

ifneq ($(EXE),)
.PHONY: ocamlnat
ocamlnat: ocamlnat$(EXE)
endif

ocamlnat$(EXE): compilerlibs/ocamlcommon.cmxa compilerlibs/ocamloptcomp.cmxa \
compilerlibs/ocamlbytecomp.cmxa \
otherlibs/dynlink/dynlink.cmxa \
Expand All @@ -1005,13 +1014,15 @@ toplevel/opttoploop.cmx: otherlibs/dynlink/dynlink.cmxa

# The numeric opcodes

bytecomp/opcodes.ml: runtime/caml/instruct.h tools/make_opcodes
runtime/ocamlrun tools/make_opcodes -opcodes < $< > $@
make_opcodes := tools/make_opcodes$(EXE)

bytecomp/opcodes.ml: runtime/caml/instruct.h $(make_opcodes)
runtime/ocamlrun$(EXE) $(make_opcodes) -opcodes < $< > $@

bytecomp/opcodes.mli: bytecomp/opcodes.ml
$(CAMLC) -i $< > $@

tools/make_opcodes: tools/make_opcodes.mll
$(make_opcodes): tools/make_opcodes.mll
$(MAKE) -C tools make_opcodes

partialclean::
Expand Down Expand Up @@ -1065,7 +1076,6 @@ distclean: clean
rm -f config.log config.status libtool
rm -f tools/eventlog_metadata
rm -f tools/*.bak
rm -f ocaml ocamlc
rm -f testsuite/_log*

include .depend
Expand Down
14 changes: 7 additions & 7 deletions Makefile.best_binaries
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ or rebuilding it (or `touch`-ing it) if you want it used.), \
ok)

choose_best = $(strip $(if \
$(and $(wildcard $(ROOTDIR)/$1.opt),$(strip \
$(call check_not_stale,$1,$1.opt))), \
$(ROOTDIR)/$1.opt, \
$(CAMLRUN) $(ROOTDIR)/$1))
$(and $(wildcard $(ROOTDIR)/$1.opt$(EXE)),$(strip \
$(call check_not_stale,$1$(EXE),$1.opt$(EXE)))), \
$(ROOTDIR)/$1.opt$(EXE), \
$(CAMLRUN) $(ROOTDIR)/$1$(EXE)))

BEST_OCAMLC := $(call choose_best,ocamlc)
BEST_OCAMLOPT := $(call choose_best,ocamlopt)
Expand All @@ -50,7 +50,7 @@ BEST_OCAMLLEX := $(call choose_best,lex/ocamllex)
# bootrap-compiler and host-compiler object files, as ocamldep only
# produces text output.
BEST_OCAMLDEP := $(strip $(if \
$(and $(wildcard $(ROOTDIR)/ocamlc.opt),$(strip \
$(call check_not_stale,boot/ocamlc,ocamlc.opt))), \
$(ROOTDIR)/ocamlc.opt -depend, \
$(and $(wildcard $(ROOTDIR)/ocamlc.opt$(EXE)),$(strip \
$(call check_not_stale,boot/ocamlc,ocamlc.opt$(EXE)))), \
$(ROOTDIR)/ocamlc.opt$(EXE) -depend, \
$(BOOT_OCAMLC) -depend))

0 comments on commit d4987b6

Please sign in to comment.