Skip to content

Commit

Permalink
Build system: deduplicate the rules used to generate the lexers and p…
Browse files Browse the repository at this point in the history
…arsers
  • Loading branch information
shindere committed Mar 2, 2021
1 parent 9fce0f6 commit be34be3
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 41 deletions.
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ else
OCAML_NATDYNLINKOPTS = -ccopt "$(NATDYNLINKOPTS)"
endif

BOOT_OCAMLLEX ?= $(CAMLRUN) $(ROOTDIR)/boot/ocamllex
OCAMLLEX ?= $(BOOT_OCAMLLEX)
CAMLDEP=$(CAMLRUN) boot/ocamlc -depend
DEPFLAGS=-slash
Expand Down Expand Up @@ -650,10 +649,7 @@ natruntop:
otherlibs/dynlink/dynlink.cmxa: otherlibs/dynlink/native/dynlink.ml
$(MAKE) -C otherlibs/dynlink allopt

# The lexer

%.ml: %.mll
$(OCAMLLEX) $(OCAMLLEXFLAGS) $<
# Cleanup the lexer

partialclean::
rm -f parsing/lexer.ml
Expand Down
24 changes: 22 additions & 2 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ OPTCOMPFLAGS=
ifeq "$(FUNCTION_SECTIONS)" "true"
OPTCOMPFLAGS += -function-sections
endif
# By default, request ocamllex to be quiet
OCAMLLEXFLAGS ?= -q

# Escape special characters in the argument string.
# There are four characters that need escaping:
Expand Down Expand Up @@ -120,3 +118,25 @@ ifneq ($(EXE),)
$(1): $(1)$(EXE)
endif
endef # PROGRAM_SYNONYM

# Lexer generation

BOOT_OCAMLLEX ?= $(CAMLRUN) $(ROOTDIR)/boot/ocamllex
# The OCAMLLEX command used in the recipe below is defined in the individual
# makefiles, because its default value is directory-specific.
# By default, some directories use BOOT_OCAMLLEX while others use the
# freshly compiled lexer generator.

OCAMLLEXFLAGS ?= -q

%.ml: %.mll
$(OCAMLLEX) $(OCAMLLEXFLAGS) $<

# Parser generation

OCAMLYACC ?= $(ROOTDIR)/yacc/ocamlyacc$(EXE)

OCAMLYACCFLAGS ?=

%.ml %.mli: %.mly
$(OCAMLYACC) $(OCAMLYACCFLAGS) $<
6 changes: 0 additions & 6 deletions debugger/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ include $(ROOTDIR)/Makefile.best_binaries

DYNLINKDIR=$(ROOTDIR)/otherlibs/dynlink
UNIXDIR=$(ROOTDIR)/otherlibs/$(UNIXLIB)
OCAMLYACC ?= $(ROOTDIR)/yacc/ocamlyacc$(EXE)
OCAMLYACCFLAGS =

CAMLC=$(BEST_OCAMLC) -g -nostdlib -I $(ROOTDIR)/stdlib
COMPFLAGS=$(INCLUDES) -absname -w +a-4-9-41-42-44-45-48 -warn-error A \
Expand Down Expand Up @@ -78,14 +76,10 @@ depend: beforedepend
$(CAMLDEP) $(DEPFLAGS) $(DEPINCLUDES) *.mli *.ml \
| sed -e 's,$(UNIXDIR)/,$$(UNIXDIR)/,' > .depend

%.ml: %.mll
$(OCAMLLEX) $(OCAMLLEXFLAGS) $<
clean::
rm -f debugger_lexer.ml
beforedepend:: debugger_lexer.ml

%.ml %.mli: %.mly
$(OCAMLYACC) $(OCAMLYACCFLAGS) $<
clean::
rm -f debugger_parser.ml debugger_parser.mli
beforedepend:: debugger_parser.ml debugger_parser.mli
Expand Down
8 changes: 0 additions & 8 deletions lex/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ ROOTDIR = ..

include $(ROOTDIR)/Makefile.common

OCAMLYACC ?= $(ROOTDIR)/yacc/ocamlyacc$(EXE)
OCAMLYACCFLAGS = -v

CAMLC = $(BOOT_OCAMLC) -strict-sequence -nostdlib \
Expand All @@ -28,7 +27,6 @@ CAMLOPT = $(CAMLRUN) $(ROOTDIR)/ocamlopt$(EXE) -nostdlib -I $(ROOTDIR)/stdlib
COMPFLAGS = -absname -w +a-4-9-41-42-44-45-48 -warn-error A \
-safe-string -strict-sequence -strict-formats -bin-annot
LINKFLAGS =
BOOT_OCAMLLEX ?= $(CAMLRUN) $(ROOTDIR)/boot/ocamllex
OCAMLLEX ?= $(BOOT_OCAMLLEX)
CAMLDEP = $(BOOT_OCAMLC) -depend
DEPFLAGS = -slash
Expand Down Expand Up @@ -56,17 +54,11 @@ clean::
rm -f $(programs) $(programs:=.exe)
rm -f *.cmo *.cmi *.cmx *.cmt *.cmti *.o *.obj

%.ml %.mli: %.mly
$(OCAMLYACC) $(OCAMLYACCFLAGS) $<

clean::
rm -f parser.ml parser.mli parser.output

beforedepend:: parser.ml parser.mli

%.ml: %.mll
$(OCAMLLEX) $(OCAMLLEXFLAGS) $<

clean::
rm -f lexer.ml

Expand Down
7 changes: 0 additions & 7 deletions ocamldoc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ ROOTDIR = ..
include $(ROOTDIR)/Makefile.common
include $(ROOTDIR)/Makefile.best_binaries

OCAMLYACC ?= $(ROOTDIR)/yacc/ocamlyacc$(EXE)
OCAMLYACCFLAGS = --strict -v

STDLIBFLAGS = -nostdlib -I $(ROOTDIR)/stdlib
Expand Down Expand Up @@ -222,12 +221,6 @@ DEPEND_PREREQS = $(LEXERS:.mll=.ml) \
.ml.cmxs:
$(OCAMLOPT_CMD) -shared -o $@ $(COMPFLAGS) $<

%.ml: %.mll
$(OCAMLLEX) $(OCAMLLEXFLAGS) $<

%.ml %.mli: %.mly
$(OCAMLYACC) $(OCAMLYACCFLAGS) $<

# Installation targets
######################

Expand Down
9 changes: 0 additions & 9 deletions ocamltest/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,6 @@ depincludes :=

OCAMLLEX ?= $(BEST_OCAMLLEX)

OCAMLYACC ?= $(ROOTDIR)/yacc/ocamlyacc$(EXE)
OCAMLYACCFLAGS =

.SECONDARY: $(lexers:.mll=.ml) $(parsers:.mly=.mli) $(parsers:.mly=.ml)

.PHONY: all allopt opt.opt # allopt and opt.opt are synonyms
Expand Down Expand Up @@ -239,12 +236,6 @@ ocamltest.opt$(EXE): $(deps_opt) $(native_modules)
%.cmi: %.mli $(deps_byte)
$(ocamlc) -c $<

%.ml %.mli: %.mly
$(OCAMLYACC) $(OCAMLYACCFLAGS) $<

%.ml: %.mll
$(OCAMLLEX) $(OCAMLLEXFLAGS) $<

ocamltest_unix.ml: ocamltest_unix_$(ocamltest_unix).ml
echo '# 1 "$^"' > $@
cat $^ >> $@
Expand Down
4 changes: 0 additions & 4 deletions tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ endef
CAMLC = $(BOOT_OCAMLC) -g -nostdlib -I $(ROOTDIR)/boot \
-use-prims $(ROOTDIR)/runtime/primitives -I $(ROOTDIR)
CAMLOPT = $(CAMLRUN) $(ROOTDIR)/ocamlopt$(EXE) -g -nostdlib -I $(ROOTDIR)/stdlib
BOOT_OCAMLLEX ?= $(CAMLRUN) $(ROOTDIR)/boot/ocamllex
OCAMLLEX ?= $(BOOT_OCAMLLEX)
INCLUDES = $(addprefix -I $(ROOTDIR)/,utils parsing typing bytecomp \
middle_end middle_end/closure middle_end/flambda \
Expand Down Expand Up @@ -332,9 +331,6 @@ clean::

# Common stuff

%.ml: %.mll
$(OCAMLLEX) $(OCAMLLEXFLAGS) $<

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

Expand Down

0 comments on commit be34be3

Please sign in to comment.