Skip to content
Commits on Source (3)
FROM ocaml/opam2:4.07
LABEL maintainer="Thierry.Martinez@inria.fr"
WORKDIR /home/opam
COPY . /coccinelle/
RUN opam pin add -n file:///coccinelle
RUN opam depext -i coccinelle
\ No newline at end of file
......@@ -98,12 +98,10 @@ PREFIX_spatch :=
PREFIX_spgen := tools/spgen/source/
STDCOMPATDIR := bundles/stdcompat
CORE_LIBS := unix bigarray str \
$(STDCOMPATDIR)/stdcompat \
$(patsubst %,bytes,$(BYTESDIR)) \
$(patsubst %,pcre,$(filter %/pcre.cma,$(LNKLIBS))) \
$(STDCOMPATDIR)/stdcompat
$(patsubst %,pcre,$(filter %/pcre.cma,$(LNKLIBS)))
ifeq ($(FEATURE_OCAML),1)
CORE_LIBS += dynlink
......@@ -119,7 +117,7 @@ LIBRARIES_spatch := $(LIBRARIES)
LIBRARIES_spgen := $(CORE_LIBRARIES)
CORE_BUNDLES=menhirLib pcre stdcompat
CORE_BUNDLES=stdcompat menhirLib pcre
ALL_BUNDLES=$(CORE_BUNDLES) parmap pyml
......@@ -381,7 +379,7 @@ endef
%.ml : %.mll
$(RUN_OCAMLLEX) $<
ml_files := $(ml_files_but_parsers) parsing_c/parser_c.ml
ml_files := $(ml_files_but_parsers) parsing_c/parser_c.ml parsing_cocci/parser_cocci_menhir.ml
ml_and_mli_files := $(ml_files) $(ml_files:.ml=.mli)
ifneq ($(MAKECMDGOALS),clean)
......@@ -404,25 +402,29 @@ endif
endif
endif
define foreach_ml_files
ifeq ($(DEPEND_METHOD),onefile)
%.cmi : %.mli .depend
$(RUN_OCAMLC) -c $<
$(sourcefile:.ml=.cmi) : $(sourcefile:.ml=.mli) .depend
$$(RUN_OCAMLC) -c $$<
%.cmo : %.ml .depend
$(RUN_OCAMLC) -for-pack Coccinelle_modules -c $<
$(sourcefile:.ml=.cmo) : $(sourcefile) .depend
$$(RUN_OCAMLC) -for-pack Coccinelle_modules -c $$<
%.cmx : %.ml .depend
$(RUN_OCAMLOPT) -for-pack Coccinelle_modules -c $<
$(sourcefile:.ml=.cmx) : $(sourcefile) .depend
$$(RUN_OCAMLOPT) -for-pack Coccinelle_modules -c $$<
else
%.cmi : %.mli %.mli.d
$(RUN_OCAMLC) -c $<
$(sourcefile:.ml=.cmi) : $(sourcefile:.ml=.mli) $(sourcefile:.ml=.mli.d)
$$(RUN_OCAMLC) -c $$<
%.cmo : %.ml %.ml.d
$(RUN_OCAMLC) -for-pack Coccinelle_modules -c $<
$(sourcefile:.ml=.cmo) : $(sourcefile) $(sourcefile:.ml=.ml.d)
$$(RUN_OCAMLC) -for-pack Coccinelle_modules -c $$<
%.cmx : %.ml %.ml.d
$(RUN_OCAMLOPT) -for-pack Coccinelle_modules -c $<
$(sourcefile:.ml=.cmx) : $(sourcefile) $(sourcefile:.ml=.ml.d)
$$(RUN_OCAMLOPT) -for-pack Coccinelle_modules -c $$<
endif
endef
$(foreach sourcefile,$(ml_files),\
$(eval $(foreach_ml_files)))
## Parser_c
......@@ -489,11 +491,11 @@ endif
ifneq ($(PCRE_LIB),)
ifeq ($(NATIVE),yes)
$(PCRE_LIB):
$(PCRE_LIB): $(STDCOMPAT_LIB)
$(MAKE) -C bundles/pcre all
$(MAKE) -C bundles/pcre all.opt
else
$(PCRE_LIB):
$(PCRE_LIB): $(STDCOMPAT_LIB)
$(MAKE) -C bundles/pcre all
endif
endif
......
......@@ -62,7 +62,7 @@ export CPPFLAGS=@CPPFLAGS@
MKDIR_P=@MKDIR_P@
# the default Make target
# Can be overriden e.g. in Makefile.local
# Can be overridden e.g. in Makefile.local
TARGET_ALL=all-release
EXTRA_OCAML_FLAGS=-unsafe
TARGET_SPATCH=@MAKETARGET_SPATCH@
......@@ -119,6 +119,7 @@ PYMLDIR=@PATH_pyml@
MENHIRDIR=@PATH_menhirLib@
DYNLINKDIR=@PATH_dynlink@
BYTESDIR=@PATH_bytes@
STDCOMPATDIR=@PATH_stdcompat@
# selected ocaml modules
PYCOCCI_FILE=@PYCOCCI_FILE@
......
......@@ -8,7 +8,7 @@
#
# Template:
# LOCAL_$lib = modules to include when compiling $lib locally with bytecode ocaml
# LOCALOPT_$lib = moduels to include when compiling $lib locally with optimizing ocaml
# LOCALOPT_$lib = modules to include when compiling $lib locally with optimizing ocaml
# GLOBAL_$lib = modules to include when using $lib globally with bytecode ocaml
# GLOBALOPT_$lib = modules to include when using $lib globally with optimizing ocaml
# FLAGS_$lib = extra flags to pass to optimizing ocaml when using $lib at link time
......
......@@ -40,7 +40,7 @@ ifndef OCAMLVERSION
OCAMLVERSION=$(shell ocaml -version |perl -p -e 's/.*version (.*)/$$1/;')
endif
# can be overriden in the environment
# can be overridden in the environment
ifndef GIT
GIT=git
endif
......
......@@ -6,3 +6,4 @@ else
fi
aclocal -I setup
autoconf -Wall
cd bundles/stdcompat/stdcompat-current && aclocal && autoconf -Wall && automake
OCAML_INCLUDE_FLAGS := -I $(SRC_DIR)
OCAMLFLAGS += $(OCAML_INCLUDE_FLAGS)
OCAMLC_CMD= \
$(OCAMLC) $(OCAMLCFLAGS) $(OCAMLFLAGS) \
$(EXTRACFLAGS)
OCAMLOPT_CMD= \
$(OCAMLOPT) $(OCAMLOPTFLAGS) $(OCAMLFLAGS) \
$(EXTRACFLAGS)
OCAMLMKLIB_CMD=$(OCAMLMKLIB) -linkall $(EXTRALNKFLAGS)
OCAMLDEP_CMD=$(OCAMLDEP) $(OCAMLDEPFLAGS) $(OCAML_INCLUDE_FLAGS)
OCAMLC_LDFLAGS = $(patsubst %,-custom -cclib -l%_stubs,$(LIBRARY)) \
$(addprefix -cclib -l,$(C_LIBS))
OCAMLOPT_LDFLAGS = $(patsubst %,-cclib -l%_stubs,$(LIBRARY)) \
$(addprefix -cclib -l,$(C_LIBS))
OCAMLCCFLAGS+=-ccopt -fPIC
SIDEPRODUCTS+= \
$(INTERFACES:=.cmi) \
$(patsubst %,lib%_stubs.a,$(LIBRARY))
all: depend
@$(MAKE) all-build
all-build: all-build-targets $(OTHERS)
all-build-targets: \
$(addsuffix .cma,$(ARCHIVE)) \
$(SIDEPRODUCTS) \
$(SIDEPRODUCTS_BYTECODE) \
$(patsubst %,dll%_stubs.so,$(LIBRARY))
define foreach_file_to_copy_from_src
$(file) : $(SRC_DIR)/$(file)
cp $$< $$@
endef
$(foreach file, \
$(addsuffix .cma, $(ARCHIVE)) \
$(addsuffix .cmxa, $(ARCHIVE)) \
$(addsuffix .cmx, $(INTERFACES)) \
$(addsuffix .a, $(LIBRARY)) \
$(SIDEPRODUCTS) \
$(SIDEPRODUCTS_NATIVE) \
$(SIDEPRODUCTS_BYTECODE) \
$(patsubst %,dll%_stubs.so,$(LIBRARY)), \
$(eval $(foreach_file_to_copy_from_src)))
all.opt: depend
@$(MAKE) all-opt-build
all-opt-build: all-opt-build-targets $(OTHERS)
all-opt-build-targets: \
$(addsuffix .cmxa,$(ARCHIVE)) \
$(addsuffix .cmx,$(INTERFACES)) \
$(addsuffix .a,$(LIBRARY)) \
$(SIDEPRODUCTS) \
$(SIDEPRODUCTS_NATIVE) \
$(patsubst %,dll%_stubs.so,$(LIBRARY))
clean:
rm -f .depend $(ARCHIVE:=.cma) $(ARCHIVE:=.cmxa) \
$(SIDEPRODUCTS) $(SIDEPRODUCTS_NATIVE) \
$(SIDEPRODUCTS_BYTECODE) \
$(INTERFACES:=.cmx) $(LIBRARY:=.a) $(CLEANOTHERS) \
$(patsubst %,$(SRC_DIR)/%.mli,$(PRODUCTS)) \
$(patsubst %,$(SRC_DIR)/%.ml,$(PRODUCTS)) $(OTHERS) \
$(patsubst %,dll%_stubs.so,$(LIBRARY)) \
$(patsubst %,$(SRC_DIR)/dll%_stubs.so,$(LIBRARY)) \
$(patsubst %,$(SRC_DIR)/%.a,$(LIBRARY)) \
$(patsubst %,$(SRC_DIR)/lib%_stubs.a,$(LIBRARY)) \
$(patsubst %,$(SRC_DIR)/%.o,$(MODULES)) \
$(patsubst %,$(SRC_DIR)/%.cmi,$(MODULES)) \
$(patsubst %,$(SRC_DIR)/%.cmx,$(MODULES)) \
$(patsubst %,$(SRC_DIR)/%.cmo,$(MODULES)) \
$(patsubst %,$(SRC_DIR)/%.cmt,$(MODULES)) \
$(patsubst %,$(SRC_DIR)/%.cmti,$(MODULES)) \
$(patsubst %,$(SRC_DIR)/%.cma,$(ARCHIVE)) \
$(patsubst %,$(SRC_DIR)/%.cmxa,$(ARCHIVE)) \
$(patsubst %,$(SRC_DIR)/%.cmi,$(MERE_INTERFACES)) \
$(patsubst %,$(SRC_DIR)/%.cmti,$(MERE_INTERFACES))
depend: .depend
yacc_files := $(wildcard $(patsubst %,$(SRC_DIR)/%.mly,$(MODULES)))
lex_files := $(wildcard $(patsubst %,$(SRC_DIR)/%.mll,$(MODULES)))
source_files := \
$(wildcard $(patsubst %,$(SRC_DIR)/%.mli,$(MODULES))) \
$(patsubst %,$(SRC_DIR)/%.mli,$(MERE_INTERFACES)) \
$(wildcard $(patsubst %,$(SRC_DIR)/%.ml,$(MODULES))) \
$(patsubst %.mly,%.ml,$(yacc_files)) \
$(patsubst %.mly,%.mli,$(yacc_files)) \
$(patsubst %.mll,%.ml,$(lex_files)) \
$(GENERATED_SOURCE_FILES)
.PHONY: depend-rec
depend-rec: $(source_files)
$(OCAMLDEP_CMD) $(source_files) >.depend
.depend:
$(MAKE) depend-rec
.PHONY: \
all all-build all-build-targets all.opt all-opt-build \
all-opt-build-targets clean distclean depend
$(SRC_DIR)/$(ARCHIVE).cma: \
$(add_suffix ($add_prefix $(LIBRARY),$(SRC_DIR)/dll),_stubs.so)\
$(patsubst %,$(SRC_DIR)/%.cmo,$(OBJS))
$(OCAMLC_CMD) $(OCAMLC_LDFLAGS) -a $^ -o $@
$(SRC_DIR)/$(ARCHIVE).cmxa: \
$(add_suffix ($add_prefix $(LIBRARY),$(SRC_DIR)/dll),_stubs.so)\
$(patsubst %,$(SRC_DIR)/%.cmx,$(OBJS))
$(OCAMLOPT_CMD) $(OCAMLOPT_LDFLAGS) -a $^ -o $@
$(SRC_DIR)/$(ARCHIVE).a : $(SRC_DIR)/$(ARCHIVE).cmxa
$(SRC_DIR)/lib$(LIBRARY)_stubs.a : \
$(patsubst %,$(SRC_DIR)/%_stubs.o,$(C_OBJS))
$(OCAMLMKLIB_CMD) -o $(SRC_DIR)/$(LIBRARY)_stubs $^
$(SRC_DIR)/dll$(LIBRARY)_stubs.so: $(SRC_DIR)/lib$(LIBRARY)_stubs.a
%.ml: %.mll
$(OCAMLLEX) $< -o $@
%.ml %.mli: %.mly
$(OCAMLYACC) $<
%.cmi: %.mli
$(OCAMLC_CMD) -c $< -o $@
%.cmo: %.ml
$(OCAMLC_CMD) $(OCAML_BUNDLES_FLAGS) -c $< -o $@
%.cmx: %.ml
$(OCAMLOPT_CMD) $(OCAML_BUNDLES_FLAGS) -c $< -o $@
define bundle_without_mli
ifeq ($(wildcard $(SRC_DIR)/$(SOURCE).mli),)
ifeq ($(OCAMLOPT),)
$(SRC_DIR)/$(SOURCE).cmi: $(SRC_DIR)/$(SOURCE).cmo
else
$(SRC_DIR)/$(SOURCE).cmo: $(SRC_DIR)/$(SOURCE).cmx
$(SRC_DIR)/$(SOURCE).cmi: $(SRC_DIR)/$(SOURCE).cmx
endif
endif
endef
$(foreach SOURCE,$(MODULES),$(eval $(bundle_without_mli)))
%.o: %.c
$(OCAMLC_CMD) $(OCAMLCCFLAGS) $< -o $@
# Workaround for what looks like a bug with object compilation...
- mv $(notdir $@) $@
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(MAKECMDGOALS),distclean)
include ../../Makefile.config
-include ../../Makefile.local
endif
endif
ifeq ($(MAKECMDGOALS),all-build)
include .depend
endif
ifeq ($(MAKECMDGOALS),all-opt-build)
include .depend
endif
META
menhir-20140422
.prepare
standard.mly
menhir
# Bundles the original menhirLib package without modifications.
# This Makefile integrates its build process with coccinelle.
MENHIR_VERSION=20181113
PACKAGE_DIR=menhir-$(MENHIR_VERSION)
MENHIR_MODULES= \
Fix IO installation keyword lineCount positions stringSet version \
settings printer codeBits action mark stringMap menhirLib error misc codeBits gSet \
compressedBitSet option dot InputFile parameters InputFile lexpointfree parserAux \
parser lexer \
tarjan unionFind expandTokenAliases partialGrammar time \
unparameterizedSyntax tokenType nonterminalType interface lexdep \
lexmli infer listMonad chopInlined sequence CompletedNatWitness \
Unifier Memoize SortUnification SortInference GroundSort SelectiveExpansion syntax Drop CheckSafeParameterizedGrammar \
nonTerminalDefinitionInlining reachability unparameterizedPrinter \
FixSolver Boolean Maps patricia grammarFunctor keywordExpansion \
anonymous Driver front gMap grammar codePieces item derivation \
lr0 slr lr1 DependencyGraph lr1partial conflict invariant default Trie MySet resizableArray LowIntegerPriorityQueue LRijkstraCore \
codeBackend coqBackend \
pprint cst traverse inliner referenceInterpreter sentenceParser \
sentenceLexer segment sentenceParserAux interpret tableBackend \
astar LRijkstra cmly_api \
cmly_format cmly_read cmly_write back menhir
MERE_INTERFACES=stretch IL lookahead
PRODUCTS=chopInlined lexer lexdep lexmli parser sentenceLexer sentenceParser lexpointfree lineCount segment
SIDEPRODUCTS=menhir menhirLib.cmi
SIDEPRODUCTS_BYTECODE=menhirLib.cmo
SIDEPRODUCTS_NATIVE=menhirLib.cmx menhirLib.o
OTHERS=standard.mly
SRC_DIR := $(PACKAGE_DIR)/src
GENERATED_SOURCE_FILES := $(SRC_DIR)/installation.ml
CLEANOTHERS := menhirLib.ml menhirLib.mli syntax.cmi $(SRC_DIR)/parser.mly $(SRC_DIR)/menhir $(SRC_DIR)/installation.ml
OCAMLLDFLAGS=unix.cmxa
OCAMLFLAGS+=-I $(STDCOMPATDIR)
MENHIRLIB_MODULES= \
General IncrementalEngine InfiniteArray PackedIntArray LinearizedArray RowDisplacement \
EngineTypes Engine TableFormat TableInterpreter Convert
MODULES=$(MENHIR_MODULES) $(MENHIRLIB_MODULES)
OCAML_BUNDLES_FLAGS=$(shell \
if echo $(MENHIRLIB_MODULES) \
| grep -w $(notdir $(basename $<)) >/dev/null; then \
echo -for-pack MenhirLib; \
fi)
include ../Makefile.bundles
include ../../Makefile.package
depend: .depend
.PHONY: distclean
distclean: clean
$(SRC_DIR)/installation.ml:
echo "let libdir = \"$(shell pwd\)\"" > $(SRC_DIR)/installation.ml
echo "let ocamlfind = false" >> $(SRC_DIR)/installation.ml
.depend: $(SRC_DIR)/parser.mly
$(SRC_DIR)/Driver.ml: $(SRC_DIR)/yaccDriver.ml
cp $< $@
ifeq ($(OCAMLOPT_CMD),)
$(SRC_DIR)/menhir: $(patsubst %,$(SRC_DIR)/%.cmo,$(MENHIR_MODULES))
$(OCAMLC_CMD) $(OCAMLLDFLAGS) $(LINK_BYTECODE) stdcompat.cma $^ -o $@
else
$(SRC_DIR)/menhir: $(patsubst %,$(SRC_DIR)/%.cmx,$(MENHIR_MODULES))
$(OCAMLOPT_CMD) $(OCAMLLDFLAGS) $(LINK_NATIVE) stdcompat.cmxa $^ -o $@
endif
standard.mly: $(SRC_DIR)/standard.mly
cp $< $@
$(SRC_DIR)/misc.cmo: $(SRC_DIR)/menhirLib.cmi
$(SRC_DIR)/misc.cmx: $(SRC_DIR)/menhirLib.cmx
$(SRC_DIR)/menhirLib.cmo: \
$(patsubst %,$(SRC_DIR)/%.cmo,$(MENHIRLIB_MODULES))
$(OCAMLC_CMD) -pack \
$(patsubst %,$(SRC_DIR)/%.cmo,$(MENHIRLIB_MODULES)) \
-o $(SRC_DIR)/menhirLib.cmo
$(SRC_DIR)/menhirLib.cmi: $(SRC_DIR)/menhirLib.cmo
$(SRC_DIR)/menhirLib.cmx: \
$(patsubst %,$(SRC_DIR)/%.cmx,$(MENHIRLIB_MODULES))
$(OCAMLOPT_CMD) -pack \
$(patsubst %,$(SRC_DIR)/%.cmx,$(MENHIRLIB_MODULES)) \
-o $(SRC_DIR)/menhirLib.cmx
$(SRC_DIR)/menhirLib.o: $(SRC_DIR)/menhirLib.cmx
$(SRC_DIR)/parser.mly: $(SRC_DIR)/yacc-parser.mly
cp $< $@
$(SRC_DIR)/Driver.cmo $(SRC_DIR)/Driver.cmx: $(SRC_DIR)/Driver.cmi
$(SRC_DIR)/astar.cmo $(SRC_DIR)/astar.cmx: $(SRC_DIR)/menhirLib.cmi
# Includes the sources of the
# bundles' source directory if
# this directory is included.
<menhir-20120123/src>: include
image: alpine
pages:
stage: deploy
script:
- echo 'Nothing to do...'
artifacts:
paths:
- public
only:
- master
This diff is collapsed.
# Installation
## Requirements
You need OCaml 4.02 or later, ocamlbuild, and GNU make.
## Configuration Choices
### `PREFIX`
The value of the `PREFIX` variable can be changed to control where the software,
the standard library, and the documentation are stored. These files are copied
to the following places:
```
$PREFIX/bin/
$PREFIX/share/menhir/
$PREFIX/share/doc/menhir/
$PREFIX/share/man/man1/
```
`PREFIX` must be set when invoking `make all` and `make install` (see below).
### `USE_OCAMLFIND`
The support libraries, `MenhirLib` and `MenhirSdk`, are installed either via
ocamlfind or directly in the directory `$PREFIX/share/menhir`. Installing via
ocamlfind is recommended (and is the default). It requires the `ocamlfind`
executable to be found in the `PATH`. An explicit choice can be made by setting
`USE_OCAMLFIND` to `true` or `false` when running `make all` (see below).
### `TARGET`
If your machine does not have the native code OCaml compiler (`ocamlopt`), but
does have the bytecode compiler (`ocamlc`), then you should define `TARGET=byte`
when running `make all` and `make install`.
## Compilation and Installation
Compile and install as follows:
```
make -f Makefile PREFIX=/usr/local USE_OCAMLFIND=true all
sudo make -f Makefile PREFIX=/usr/local install
```
If necessary, adjust `PREFIX`, `USE_OCAMLFIND` and `TARGET` as described above.
This diff is collapsed.
# This is the main Makefile that is shipped as part of the source package.
# Keep in mind that the hierarchy that is shipped is not identical to the
# hierarchy within the git repository. Some sub-directories are not shipped.
# The documentation (manual.pdf, menhir.1) is pre-built and stored at the root.
# This Makefile can also be used directly in the repository. In that case,
# the documentation and demos are not installed.
# The hierarchy that is shipped includes:
# demos
# menhir.1
# manual.pdf
# manual.html
# src
# Makefile (this one)
# ----------------------------------------------------------------------------
# The following variables must/can be configured.
ifndef PREFIX
$(error Please define PREFIX)
endif
ifndef TARGET
TARGET := native
endif
# ----------------------------------------------------------------------------
# By default, we attempt to use ocamlfind (if present in the PATH), but it
# is possible to prevent that externally by setting USE_OCAMLFIND to false.
# USE_OCAMLFIND is used only at build time (i.e., by "make all"). At
# (un)installation time, instead, we query menhir using --suggest-ocamlfind.
# This should protect us against people who pass USE_OCAMLFIND at build time
# and forget to pass it at (un)installation time.
ifndef USE_OCAMLFIND
USE_OCAMLFIND = ocamlfind ocamlc -v >/dev/null 2>&1
endif
# ----------------------------------------------------------------------------
# Installation paths.
# These may be overridden from outside; e.g., our opam package description
# provides its own values of docdir, libdir, and mandir.
bindir := $(PREFIX)/bin
docdir := $(PREFIX)/share/doc/menhir
libdir := $(PREFIX)/share/menhir
mandir := $(PREFIX)/share/man/man1
MANS := doc/menhir.1
DOCS := doc/manual.pdf doc/manual.html doc/manual*.png demos
MLYLIB := src/standard.mly
# ----------------------------------------------------------------------------
# The following incantations should work on both Windows and Unix,
# and allow us to abstract away the differences.
# The extension of object files.
OBJ := $(shell ocamlc -config | sed -n '/^ext_obj:/p' | sed 's/ext_obj: //')
# The extension of executable files.
# Note: the field "ext_exe" seems to have appeared in OCaml 4.05.
# With earlier versions of OCaml, this incantation defines $(EXE)
# as the empty string, which could be a problem under Windows.
EXE := $(shell ocamlc -config | sed -n '/^ext_exe:/p' | sed 's/ext_exe: //')
# The OS type.
OS_TYPE := $(shell ocamlc -config | sed -n '/^os_type:/p' | sed 's/os_type: //')
# The path $(installation_libdir), which is recorded in src/installation.ml (see
# below), must sometimes be translated using cygpath.
# This one is tricky. To summarize, if I understood correctly, we can assume
# that Cygwin always exists when Menhir is compiled and installed (because
# executing a Makefile, like this one, requires Cygwin), but we cannot assume
# that Menhir will be executed under Cygwin. If the OCaml compiler is
# configured to produce a Cygwin executable, then, yes, Cygwin is there at
# execution time, so path translation is not necessary (and should not be
# performed). On the other hand, if the OCaml compiler is configured to
# produce a native Windows executable, then Cygwin is not there at execution
# time and path translation is required. In summary, path translation must be
# performed if "os_type" is "Win32" or "Win64", and must not be performed if
# "os_type" is "Cygwin" or "Unix".
ifeq ($(OS_TYPE),$(filter $(OS_TYPE),Win32 Win64))
installation_libdir := $(shell cygpath -m $(libdir) || echo $(libdir))
else
installation_libdir := $(libdir)
endif
# -------------------------------------------------------------------------
# The names of the modules in MenhirLib are obtained by reading the
# non-comment lines in menhirLib.mlpack.
MENHIRLIB_MODULES := $(shell grep -ve "^[ \t\n\r]*\#" src/menhirLib.mlpack)
# ----------------------------------------------------------------------------
# The directories where things are built.
# For Menhir and MenhirLib.
BUILDDIR := src/_stage2
# For MenhirSdk.
SDKDIR := src/_sdk
# ----------------------------------------------------------------------------
# Compilation.
.PHONY: all install uninstall
all:
# Installation time settings are recorded within src/installation.ml.
# This file is recreated every time so as to avoid becoming stale.
@ rm -f src/installation.ml
@ echo "let libdir = \"$(installation_libdir)\"" > src/installation.ml
@ if $(USE_OCAMLFIND) ; then \
echo "let ocamlfind = true" >> src/installation.ml ; \
else \
echo "let ocamlfind = false" >> src/installation.ml ; \
fi
# Compile the Menhir executable.
# This causes MenhirLib to be compiled, too, as it is used inside Menhir.
# Compile MenhirSdk.
@ $(MAKE) -C src bootstrap sdk
# The source file menhirLib.ml is created by concatenating all of the source
# files that make up MenhirLib. This file is not needed to compile Menhir or
# MenhirLib. It is installed at the same time as MenhirLib and is copied by
# Menhir when the user requests a self-contained parser (one that is not
# dependent on MenhirLib).
@ echo "Creating menhirLib.ml"
@ rm -f $(BUILDDIR)/menhirLib.ml
@ for m in $(MENHIRLIB_MODULES) ; do \
echo "module $$m = struct" >> $(BUILDDIR)/menhirLib.ml ; \
cat src/$$m.ml >> $(BUILDDIR)/menhirLib.ml ; \
echo "end" >> $(BUILDDIR)/menhirLib.ml ; \
done
# The source file menhirLib.mli is created in the same way. If a module
# does not have an .mli file, then we assume that its .ml file contains
# type (and module type) definitions only, so we copy it instead of the
# (non-existent) .mli file.
@ echo "Creating menhirLib.mli"
@ rm -f $(BUILDDIR)/menhirLib.mli
@ for m in $(MENHIRLIB_MODULES) ; do \
echo "module $$m : sig" >> $(BUILDDIR)/menhirLib.mli ; \
if [ -f src/$$m.mli ] ; then \
cat src/$$m.mli >> $(BUILDDIR)/menhirLib.mli ; \
else \
cat src/$$m.ml >> $(BUILDDIR)/menhirLib.mli ; \
fi ; \
echo "end" >> $(BUILDDIR)/menhirLib.mli ; \
done
# -------------------------------------------------------------------------
# The files that should be installed as part of menhirLib.
MENHIRLIB := menhirLib.mli menhirLib.ml menhirLib.cmi menhirLib.cmo
ifneq ($(TARGET),byte)
MENHIRLIB := $(MENHIRLIB) menhirLib.cmx menhirLib.cmxs menhirLib$(OBJ)
endif
# -------------------------------------------------------------------------
# The files that should be installed as part of menhirSdk.
MENHIRSDK := menhirSdk.cmi menhirSdk.cmo
ifneq ($(TARGET),byte)
MENHIRSDK := $(MENHIRSDK) menhirSdk.cmx menhirSdk.cmxs menhirSdk$(OBJ)
endif
# ----------------------------------------------------------------------------
# Installation.
install:
# Install the executable.
mkdir -p $(bindir)
install $(BUILDDIR)/menhir.$(TARGET) $(bindir)/menhir$(EXE)
# Install Menhir's standard library.
mkdir -p $(libdir)
install -m 644 $(MLYLIB) $(libdir)
# Install MenhirLib and MenhirSdk.
@if `$(BUILDDIR)/menhir.$(TARGET) --suggest-ocamlfind | tr -d '\r'` ; then \
echo 'Installing MenhirLib and MenhirSdk via ocamlfind.' ; \
cp -f src/menhirLib.META META ; \
ocamlfind install menhirLib META $(patsubst %,$(BUILDDIR)/%,$(MENHIRLIB)) ; \
cp -f src/menhirSdk.META META ; \
ocamlfind install menhirSdk META $(patsubst %,$(SDKDIR)/%,$(MENHIRSDK)) ; \
rm -f META ; \
else \
echo 'Installing MenhirLib and MenhirSdk manually.' ; \
install -m 644 $(patsubst %,$(BUILDDIR)/%,$(MENHIRLIB)) $(libdir) ; \
install -m 644 $(patsubst %,$(SDKDIR)/%,$(MENHIRSDK)) $(libdir) ; \
fi
# Install the documentation. (If building from the repository, the documentation
# may be absent.)
if [ -f doc/manual.pdf ] ; then \
mkdir -p $(docdir) $(mandir) ; \
cp -r $(DOCS) $(docdir) ; \
cp -r $(MANS) $(mandir) ; \
fi
uninstall:
@if `$(bindir)/menhir$(EXE) --suggest-ocamlfind` ; then \
echo 'Un-installing MenhirLib and MenhirSdk via ocamlfind.' ; \
ocamlfind remove menhirLib ; \
ocamlfind remove menhirSdk ; \
fi
rm -rf $(bindir)/menhir$(EXE)
rm -rf $(libdir)
rm -rf $(docdir)
rm -rf $(mandir)/$(MANS)
# Menhir
Menhir is an LR(1) parser generator for OCaml.
Menhir has a [home page](http://gallium.inria.fr/~fpottier/menhir/).
## Installation
OCaml (4.02 or later), ocamlbuild, and GNU make are needed.
The latest released version of Menhir can be easily installed via
`opam`, OCaml's package manager. Just type `opam install menhir`.
For manual installation, see [INSTALLATION.md](INSTALLATION.md).
Some instructions for developers can be found in [HOWTO.md](HOWTO.md).
## Authors
* [François Pottier](Francois.Pottier@inria.fr)
* [Yann Régis-Gianas](Yann.Regis-Gianas@pps.jussieu.fr)
## Contributors
* Frédéric Bour (incremental engine, inspection API, attributes, SDK)
* Jacques-Henri Jourdan (Coq back-end)
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
# This script checks that a Menhir tarball can be compiled and installed.
# The command line argument should be the tarball's name without .tar.gz.
PACKAGE="$1"
TARBALL=$PACKAGE.tar.gz
# Some of the demos assume Menhir has been installed using ocamlfind, so that
# is what we do. For this reason, we must first check that ocamlfind does not
# already have some version of menhirLib and menhirSdk.
# We could also create a fresh opam switch, but that would be time-consuming.
if ocamlfind query menhirLib >/dev/null 2>/dev/null ; then
if opam list -i menhir 2>/dev/null | grep -v -e "^#" | grep menhir ; then
echo "Warning: menhir is already installed." ;
read -p "Can I remove it [Enter/^C]?" -n 1 -r ;
opam remove menhir ;
else
echo "Warning: menhirLib is already installed." ;
read -p "Can I remove it [Enter/^C]?" -n 1 -r ;
ocamlfind remove menhirLib ;
ocamlfind remove menhirSdk || true ;
fi ;
fi
# Create a temporary directory; extract, build, and install the package into
# it; build the demos using the installed binary.
TEMPDIR=`mktemp -d /tmp/menhir-test.XXXXXX`
INSTALL=$TEMPDIR/install
cp $TARBALL $TEMPDIR
echo " * Extracting. "
(cd $TEMPDIR && tar xfz $TARBALL)
echo " * Compiling and installing."
mkdir $INSTALL
(cd $TEMPDIR/$PACKAGE &&
make PREFIX=$INSTALL USE_OCAMLFIND=true &&
make PREFIX=$INSTALL USE_OCAMLFIND=true install
) > $TEMPDIR/install.log 2>&1 || (cat $TEMPDIR/install.log; exit 1)
echo " * Building the demos."
(cd $TEMPDIR/$PACKAGE &&
make MENHIR=$INSTALL/bin/menhir -C demos
) > $TEMPDIR/demos.log 2>&1 || (cat $TEMPDIR/demos.log; exit 1)
echo " * Uninstalling."
(cd $TEMPDIR/$PACKAGE &&
make PREFIX=$INSTALL USE_OCAMLFIND=true uninstall
) > $TEMPDIR/uninstall.log 2>&1 || (cat $TEMPDIR/uninstall.log; exit 1)
rm -rf $TEMPDIR
# These demos assume that Menhir has been installed and is available
# under the name "menhir". This can be overridden by setting MENHIR.
# The following demos require menhirLib:
# calc-incremental
# calc-inspection
# The following demos require menhirSdk and OCaml >= 4.03:
# generate-printers
# The demos whose name ends in -dune require dune 1.4.
# If dune is absent, attempting to build these demos
# succeeds without actually doing anything.
DEMOS := \
calc \
calc-alias \
calc-two \
calc-param \
calc-incremental \
calc-inspection \
generate-printers \
calc-dune \
calc-new-syntax-dune \
calc-ast-dune \
calc-param-dune \
calc-two-dune \
calc-incremental-dune \
calc-inspection-dune \
generate-printers-dune \
.PHONY: all clean test
all clean test::
@ for i in $(DEMOS) ; do \
$(MAKE) --no-print-directory -C $$i $@ ; \
done
clean::
/bin/rm -f *~ .*~