Attention une mise à jour du service Gitlab va être effectuée le mardi 18 janvier (et non lundi 17 comme annoncé précédemment) entre 18h00 et 18h30. Cette mise à jour va générer une interruption du service dont nous ne maîtrisons pas complètement la durée mais qui ne devrait pas excéder quelques minutes.

Makefile 7.96 KB
Newer Older
1
# This is the main Makefile that is shipped as part of the source package.
2

3
# Keep in mind that the hierarchy that is shipped is not identical to the
4
5
6
7
8
# 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.
9
10
11
12
13

# The hierarchy that is shipped includes:
#   demos
#   menhir.1
#   manual.pdf
14
#   manual.html
15
16
17
18
19
#   src
#   Makefile (this one)

# ----------------------------------------------------------------------------

fpottier's avatar
fpottier committed
20
21
22
23
24
25
26
27
28
29
30
31
# The following variables must/can be configured.

ifndef PREFIX
  $(error Please define PREFIX)
endif

ifndef TARGET
  TARGET := native
endif

# ----------------------------------------------------------------------------

POTTIER Francois's avatar
Typo.    
POTTIER Francois committed
32
# By default, we attempt to use ocamlfind (if present in the PATH), but it
33
34
# is possible to prevent that externally by setting USE_OCAMLFIND to false.

35
36
37
38
39
# 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.

40
41
42
43
ifndef USE_OCAMLFIND
  USE_OCAMLFIND = ocamlfind ocamlc -v >/dev/null 2>&1
endif

44
45
# ----------------------------------------------------------------------------
# Installation paths.
46
47
# These may be overridden from outside; e.g., our opam package description
# provides its own values of docdir, libdir, and mandir.
48

49
50
51
52
bindir          := $(PREFIX)/bin
docdir		:= $(PREFIX)/share/doc/menhir
libdir	        := $(PREFIX)/share/menhir
mandir          := $(PREFIX)/share/man/man1
53
54
MANS            := doc/menhir.1
DOCS            := doc/manual.pdf doc/manual.html doc/manual*.png demos
55

56
57
# ----------------------------------------------------------------------------

58
59
# The following incantations should work on both Windows and Unix,
# and allow us to abstract away the differences.
60

61
62
63
# The extension of object files.
OBJ := $(shell ocamlc -config | sed -n '/^ext_obj:/p' | sed 's/ext_obj: //')
# The extension of executable files.
POTTIER Francois's avatar
POTTIER Francois committed
64
65
66
# 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.
67
68
69
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: //')
70

71
72
# The path $(installation_libdir), which is recorded in src/installation.ml (see
# below), must sometimes be translated using cygpath.
73
74
75
76
77
78
79
80
81
82

# 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
POTTIER Francois's avatar
Typo.    
POTTIER Francois committed
83
# performed if "os_type" is "Win32" or "Win64", and must not be performed if
84
85
# "os_type" is "Cygwin" or "Unix".

86
87
ifeq ($(OS_TYPE),$(filter $(OS_TYPE),Win32 Win64))
  installation_libdir := $(shell cygpath -m $(libdir) || echo $(libdir))
88
else
89
  installation_libdir := $(libdir)
90
endif
91

92
93
94
95
96
97
98
# -------------------------------------------------------------------------

# 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)

99
100
# ----------------------------------------------------------------------------

POTTIER Francois's avatar
POTTIER Francois committed
101
# The directories where things are built.
102

POTTIER Francois's avatar
POTTIER Francois committed
103
# For Menhir and MenhirLib.
104
BUILDDIR := src/_stage2
POTTIER Francois's avatar
POTTIER Francois committed
105
106
# For MenhirSdk.
SDKDIR   := src/_sdk
107

108
109
110
# ----------------------------------------------------------------------------

# Compilation.
111
112
113
114

.PHONY: all install uninstall

all:
115
116
# Installation time settings are recorded within src/installation.ml.
# This file is recreated every time so as to avoid becoming stale.
117
	@ rm -f src/installation.ml
118
	@ echo "let libdir = \"$(installation_libdir)\"" > src/installation.ml
119
	@ if $(USE_OCAMLFIND) ; then \
120
121
122
123
	  echo "let ocamlfind = true" >> src/installation.ml ; \
	else \
	  echo "let ocamlfind = false" >> src/installation.ml ; \
	fi
124
125
# Compile the Menhir executable.
# This causes MenhirLib to be compiled, too, as it is used inside Menhir.
POTTIER Francois's avatar
POTTIER Francois committed
126
127
# Compile MenhirSdk.
	@ $(MAKE) -C src bootstrap sdk
128
129
130
131
132
# 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).
133
134
	@ echo "Creating menhirLib.ml"
	@ rm -f $(BUILDDIR)/menhirLib.ml
135
	@ for m in $(MENHIRLIB_MODULES) ; do \
136
137
138
	  echo "module $$m = struct" >> $(BUILDDIR)/menhirLib.ml ; \
	  cat src/$$m.ml >> $(BUILDDIR)/menhirLib.ml ; \
	  echo "end" >> $(BUILDDIR)/menhirLib.ml ; \
139
140
141
142
143
	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.
144
145
	@ echo "Creating menhirLib.mli"
	@ rm -f $(BUILDDIR)/menhirLib.mli
146
	@ for m in $(MENHIRLIB_MODULES) ; do \
147
	  echo "module $$m : sig" >> $(BUILDDIR)/menhirLib.mli ; \
148
	  if [ -f src/$$m.mli ] ; then \
149
	    cat src/$$m.mli >> $(BUILDDIR)/menhirLib.mli ; \
150
	  else \
151
	    cat src/$$m.ml >> $(BUILDDIR)/menhirLib.mli ; \
152
	  fi ; \
153
	  echo "end" >> $(BUILDDIR)/menhirLib.mli ; \
154
155
156
157
158
159
160
161
	done

# -------------------------------------------------------------------------

# The files that should be installed as part of menhirLib.

MENHIRLIB       := menhirLib.mli menhirLib.ml menhirLib.cmi menhirLib.cmo
ifneq ($(TARGET),byte)
162
MENHIRLIB       := $(MENHIRLIB) menhirLib.cmx menhirLib.cmxs menhirLib$(OBJ)
163
endif
164

POTTIER Francois's avatar
POTTIER Francois committed
165
166
167
168
169
170
# -------------------------------------------------------------------------

# The files that should be installed as part of menhirSdk.

MENHIRSDK       := menhirSdk.cmi menhirSdk.cmo
ifneq ($(TARGET),byte)
171
MENHIRSDK       := $(MENHIRSDK) menhirSdk.cmx menhirSdk.cmxs menhirSdk$(OBJ)
POTTIER Francois's avatar
POTTIER Francois committed
172
173
endif

174
175
176
# ----------------------------------------------------------------------------
# Installation.

177
install:
178
# Install the executable.
179
	mkdir -p $(bindir)
180
	install $(BUILDDIR)/menhir.$(TARGET) $(bindir)/menhir$(EXE)
POTTIER Francois's avatar
POTTIER Francois committed
181
# Install Menhir's standard library.
182
	mkdir -p $(libdir)
POTTIER Francois's avatar
POTTIER Francois committed
183
# Install MenhirLib and MenhirSdk.
184
	@if `$(BUILDDIR)/menhir.$(TARGET) --suggest-ocamlfind | tr -d '\r'` ; then \
POTTIER Francois's avatar
POTTIER Francois committed
185
186
187
188
189
190
	  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 ; \
191
	else \
POTTIER Francois's avatar
POTTIER Francois committed
192
	  echo 'Installing MenhirLib and MenhirSdk manually.' ; \
fpottier's avatar
fpottier committed
193
	  install -m 644 $(patsubst %,$(BUILDDIR)/%,$(MENHIRLIB)) $(libdir) ; \
POTTIER Francois's avatar
POTTIER Francois committed
194
	  install -m 644 $(patsubst %,$(SDKDIR)/%,$(MENHIRSDK)) $(libdir) ; \
195
	fi
196
197
198
199
200
201
202
# 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
203
204

uninstall:
Nicolás Ojeda Bär's avatar
Nicolás Ojeda Bär committed
205
	@if `$(bindir)/menhir$(EXE) --suggest-ocamlfind | tr -d '\r'` ; then \
POTTIER Francois's avatar
POTTIER Francois committed
206
	  echo 'Un-installing MenhirLib and MenhirSdk via ocamlfind.' ; \
207
	  ocamlfind remove menhirLib ; \
POTTIER Francois's avatar
POTTIER Francois committed
208
	  ocamlfind remove menhirSdk ; \
209
	fi
210
	rm -rf $(bindir)/menhir$(EXE)
211
	rm -rf $(libdir)
212
213
	rm -rf $(docdir)
	rm -rf $(mandir)/$(MANS)