GNUmakefile 10.3 KB
Newer Older
1
2
3
4
5
6
7
8
# -------------------------------------------------------------------------

# This is the development Makefile. It is used for compiling
# development versions and for creating the distributed package.
# This Makefile is not distributed.

SHELL := bash

9
.PHONY: all test clean headache package check export tag opam local unlocal pin unpin mdl
10
11
12

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

fpottier's avatar
fpottier committed
13
# A dummy entry.
14
15

all:
fpottier's avatar
fpottier committed
16
	@echo Please go down into src/ if you wish to compile Menhir.
17
18
19

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

POTTIER Francois's avatar
POTTIER Francois committed
20
21
22
23
24
25
26
27
# Utilities.

SED     := $(shell if hash gsed 2>/dev/null ; then echo gsed ; else echo sed ; fi)
CUT     := $(shell if hash gcut 2>/dev/null ; then echo gcut ; else echo cut ; fi)
MD5SUM  := $(shell if hash md5  2>/dev/null ; then echo "md5 -r" ; else echo md5sum ; fi)

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

28
# Testing.
29
30
# Assumes that "make bootstrap" has been run in src/
# or that MENHIR is properly set.
31
32

test:
POTTIER Francois's avatar
POTTIER Francois committed
33
	$(MAKE) -C test
34
35
36
37
38
39

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

# Cleaning up.

clean:
POTTIER Francois's avatar
POTTIER Francois committed
40
	@ for i in test demos src ; do \
fpottier's avatar
fpottier committed
41
	  $(MAKE) -C $$i $@ ; \
42
	done
POTTIER Francois's avatar
POTTIER Francois committed
43
	@ $(MAKE) -rs -C doc $@
44
45
46
47
48
49
50

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

# Prevent the built-in bash cd from displaying information.

export CDPATH=

51
52
# -------------------------------------------------------------------------

53
# Distribution.
POTTIER Francois's avatar
POTTIER Francois committed
54

fpottier's avatar
fpottier committed
55
# The version number is automatically set to the current date,
POTTIER Francois's avatar
Typo.    
POTTIER Francois committed
56
# unless DATE is defined on the command line.
57
DATE     := $(shell /bin/date +%Y%m%d)
fpottier's avatar
fpottier committed
58

59
60
61
62
PACKAGE  := menhir-$(DATE)
CURRENT  := $(shell pwd)
TARBALL  := $(CURRENT)/$(PACKAGE).tar.gz

63
# -------------------------------------------------------------------------
64
65
66
67
68
69

# A list of files to copy without changes to the package.
#
# This does not include the src/ and doc/ directories, which require
# special treatment.

POTTIER Francois's avatar
POTTIER Francois committed
70
DISTRIBUTED_FILES := CHANGES.md INSTALLATION.md LICENSE Makefile README.md demos
71

72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# -------------------------------------------------------------------------

# 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 names of the source files in MenhirLib are obtained by adding
# an .ml or .mli extension to the module name. (We assume that the
# first letter of the file name is a capital letter.)

MENHIRLIB_FILES   := $(shell for m in $(MENHIRLIB_MODULES) ; do \
	                       ls src/$$m.{ml,mli} 2>/dev/null ; \
	                     done)

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

89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Propagating an appropriate header into every file.

# This requires a version of headache that supports UTF-8; please use
# https://github.com/fpottier/headache

# This used to be done at release time and not in the repository, but
# it is preferable to do in it the repository too, for two reasons: 1-
# the repository is (or will be) publicly accessible; and 2- this makes
# it easier to understand the line numbers that we sometimes receive as
# part of bug reports.

# Menhir's standard library (standard.mly) as well as the source files
# in MenhirLib carry the "library" license, while every other file
# carries the "regular" license.

HEADACHE := headache
SRCHEAD  := $(CURRENT)/headers/regular-header
LIBHEAD  := $(CURRENT)/headers/library-header
107
FIND     := $(shell if command -v gfind >/dev/null ; then echo gfind ; else echo find ; fi)
108
109

headache:
110
	@ cd src && $(FIND) . -regex ".*\.ml\(i\|y\|l\)?" \
111
112
113
114
115
116
117
	    -exec $(HEADACHE) -h $(SRCHEAD) "{}" ";"
	@ for file in src/standard.mly $(MENHIRLIB_FILES) ; do \
	    $(HEADACHE) -h $(LIBHEAD) $$file ; \
	  done

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

118
# Creating a tarball for distribution.
119
120
121

package: clean
# Create a directory to store the distributed files temporarily.
122
# In src/_tags, every line tagged "my_warnings" is removed.
123
124
125
	@ rm -fr $(PACKAGE)
	@ mkdir -p $(PACKAGE)/src
	@ cp -fr $(DISTRIBUTED_FILES) $(PACKAGE)
POTTIER Francois's avatar
POTTIER Francois committed
126
	@ cp -fr src/*.ml{,i,y,l,pack} src/*.messages src/Makefile src/*.META $(PACKAGE)/src
127
	@ rm -f $(PACKAGE)/src/installation.ml
128
	@ grep -v my_warnings src/_tags > $(PACKAGE)/src/_tags
129
130
131
# Clean up the demos, including those that are not built by default
# because they require dune.
	@ $(MAKE) -C $(PACKAGE)/demos realclean
132
# Set the version number into the files that mention it. These
133
# include version.ml, StaticVersion.{ml,mli}, version.tex, META.
134
135
136
	@ echo "-> Setting version to $(DATE)."
	@ echo let version = \"$(DATE)\" > $(PACKAGE)/src/version.ml
	@ echo version = \"$(DATE)\" >> $(PACKAGE)/src/META
137
138
	@ echo "let require_$(DATE) = ()" > $(PACKAGE)/src/StaticVersion.ml
	@ echo "val require_$(DATE) : unit" > $(PACKAGE)/src/StaticVersion.mli
139
140
141
142
# Copy and compile the documentation.
	@ echo "-> Generating the documentation."
	@ cp -r doc $(PACKAGE)
	@ echo '\gdef\menhirversion{$(DATE)}' > $(PACKAGE)/doc/version.tex
fpottier's avatar
fpottier committed
143
	@ make -C $(PACKAGE)/doc clean all
144
	@ mv $(PACKAGE)/doc/main.pdf $(PACKAGE)/manual.pdf
145
	@ mv $(PACKAGE)/doc/main.html $(PACKAGE)/manual.html
146
	@ mv $(PACKAGE)/doc/menhir.1 $(PACKAGE)/
147
148
149
150
# Include a copy of the sources of the documentation,
# as Debian requires this for the PDF to be included
# in their package.
	@ make -C $(PACKAGE)/doc clean
151
152
# Create the tarball.
	@ echo "-> Tarball creation."
153
	tar --exclude=.gitignore -cvz -f $(TARBALL) $(PACKAGE)
154
155
	@ echo "-> Package $(PACKAGE).tar.gz is ready."

156
157
158
159
# -------------------------------------------------------------------------

# Checking the tarball that was created above.

160
161
162
check:
	@ echo "-> Checking the package ..."
# Create a temporary directory; extract, build, and install the
163
164
# package into it; build the demos and run the test suite using
# the installed binary.
165
166
167
168
169
# Some of the demos assume Menhir has been installed using ocamlfind,
# so that is what we do. For this reason, we must check first that
# ocamlfind does not already have some version of menhirLib.
	@ if ocamlfind query menhirLib >/dev/null 2>/dev/null ; then \
	  if opam list -i menhir >/dev/null ; then \
170
171
172
	    echo "Warning: menhir is already installed." ; \
	    read -p "Can I remove it [Enter/^C]?" -n 1 -r ; \
	    opam remove menhir ; \
173
	  else \
174
175
176
177
	    echo "Warning: menhirLib is already installed." ; \
	    read -p "Can I remove it [Enter/^C]?" -n 1 -r ; \
	    ocamlfind remove menhirLib ; \
	    ocamlfind remove menhirSdk || true ; \
178
179
	  fi ; \
	fi
180
181
182
183
184
	@ TEMPDIR=`mktemp -d /tmp/menhir-test.XXXXXX` && { \
	echo "   * Extracting. " && \
	(cd $$TEMPDIR && tar xfz $(TARBALL)) && \
	echo "   * Compiling and installing." && \
	mkdir $$TEMPDIR/install && \
185
	(cd $$TEMPDIR/$(PACKAGE) \
186
		&& make PREFIX=$$TEMPDIR/install USE_OCAMLFIND=true all install \
187
188
	) > $$TEMPDIR/install.log 2>&1 \
		|| (cat $$TEMPDIR/install.log; exit 1) && \
189
190
191
192
193
	echo "   * Building the demos." && \
	(cd $$TEMPDIR/$(PACKAGE) \
		&& $(MAKE) MENHIR=$$TEMPDIR/install/bin/menhir -C demos \
	) > $$TEMPDIR/demos.log 2>&1 \
		|| (cat $$TEMPDIR/demos.log; exit 1) && \
194
195
196
	echo "   * Running the test suite." && \
	$(MAKE) MENHIR=$$TEMPDIR/install/bin/menhir test > $$TEMPDIR/test.log 2>&1 \
		|| (cat $$TEMPDIR/test.log; exit 1) && \
197
198
199
200
201
	echo "   * Uninstalling." && \
	(cd $$TEMPDIR/$(PACKAGE) \
		&& make PREFIX=$$TEMPDIR/install USE_OCAMLFIND=true uninstall \
	) > $$TEMPDIR/uninstall.log 2>&1 \
		|| (cat $$TEMPDIR/uninstall.log; exit 1) && \
202
203
204
205
206
	rm -fr $$TEMPDIR ; }
	@ echo "-> Package $(PACKAGE) seems ready for distribution!"

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

207
# Copying the tarball to my Web site.
208

fpottier's avatar
fpottier committed
209
RSYNC   := scp -p -C
210
211
212
TARGET  := yquem.inria.fr:public_html/menhir/
PAGE    := /home/fpottier/dev/page

213
export:
214
# Copier l'archive et la doc vers yquem.
215
	$(RSYNC) $(TARBALL) $(PACKAGE)/manual.pdf $(PACKAGE)/manual.html $(TARGET)
216
217
# Mettre  jour la page Web de Menhir avec le nouveau numro de version.
	cd $(PAGE) && \
POTTIER Francois's avatar
POTTIER Francois committed
218
	  cvs up && \
219
	  $(SED) --in-place=.bak "s/menhir-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]/$(PACKAGE)/" menhir.xml && \
POTTIER Francois's avatar
POTTIER Francois committed
220
	  cvs commit -m "Updated Menhir's version number." && \
221
	  if command -v cduce >/dev/null ; then $(MAKE) export ; fi
222
223
224

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

225
226
227
228
229
230
231
# Creating a git tag.

tag:
	git tag -a $(DATE) -m "Release $(DATE)."

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

232
233
234
235
236
237
# Updating the opam package.

# This entry assumes that "make package" and "make export" have been
# run on the same day.

OPAM := $(HOME)/dev/opam-repository
POTTIER Francois's avatar
POTTIER Francois committed
238
CSUM  = $(shell $(MD5SUM) menhir-$(DATE).tar.gz | cut -d ' ' -f 1)
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254

opam:
# Update my local copy of the opam repository.
	@ echo "Updating local opam repository..."
	@ cd $(OPAM) && \
	  git fetch upstream && \
	  git merge upstream/master
# Create a new Menhir package, based on the last one.
	@ echo "Creating a new package description menhir-$(DATE)..."
	@ cd $(OPAM)/packages/menhir && \
	  cp -r `ls | grep menhir | tail -1` menhir.$(DATE)
# Update the file "url".
	@ cd $(OPAM)/packages/menhir/menhir.$(DATE) && \
	  rm url && \
	  echo 'archive: "http://gallium.inria.fr/~fpottier/menhir/menhir-$(DATE).tar.gz"' >> url && \
	  echo 'checksum: "$(CSUM)"' >> url
255
256
# Copy the file "opam" from Menhir's repository to opam's.
	@ cp -f opam $(OPAM)/packages/menhir/menhir.$(DATE)
257
258
259
260
261
262
263
# Prepare a commit.
	@ echo "Preparing a new commit..."
	@ cd $(OPAM)/packages/menhir && \
	  git add menhir.$(DATE) && \
	  git status
# Ask for review.
	@ echo "If happy, please run:"
264
	@ echo "  cd $(OPAM)/packages/menhir && git commit -a && git push && firefox https://github.com/fpottier/opam-repository.git"
265
	@ echo "and issue a pull request."
266
267
268
269
270
271
272

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

# Re-installing locally. This can overwrite an existing local installation.

local:
	$(MAKE) package
273
274
275
276
	$(MAKE) -C $(PACKAGE) PREFIX=/usr/local USE_OCAMLFIND=true all
	sudo PATH="$(PATH)" $(MAKE) -C $(PACKAGE) PREFIX=/usr/local USE_OCAMLFIND=true install

unlocal:
277
	sudo PATH="$(PATH)" $(MAKE) -f Makefile PREFIX=/usr/local USE_OCAMLFIND=true uninstall
278

279
280
281
282
283
pin:
	opam pin add menhir `pwd` -k git

unpin:
	opam pin remove menhir
284
285
286
287
288
289
290
291
292

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

# Running the Markdown linter on our Markdown files.

# For an explanation of mdl's error messages, see:
# https://github.com/mivok/markdownlint/blob/master/docs/RULES.md

mdl:
293
	@ mdl *.md */*.md