GNUmakefile 10.1 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
107
108
# 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

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

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

117
# Creating a tarball for distribution.
118
119
120

package: clean
# Create a directory to store the distributed files temporarily.
121
# In src/_tags, every line tagged "my_warnings" is removed.
122
123
124
	@ rm -fr $(PACKAGE)
	@ mkdir -p $(PACKAGE)/src
	@ cp -fr $(DISTRIBUTED_FILES) $(PACKAGE)
POTTIER Francois's avatar
POTTIER Francois committed
125
	@ cp -fr src/*.ml{,i,y,l,pack} src/*.messages src/Makefile src/*.META $(PACKAGE)/src
126
	@ rm -f $(PACKAGE)/src/installation.ml
127
	@ grep -v my_warnings src/_tags > $(PACKAGE)/src/_tags
128
129
	@ $(MAKE) -C $(PACKAGE)/demos clean
# Set the version number into the files that mention it. These
130
# include version.ml, StaticVersion.{ml,mli}, version.tex, META.
131
132
133
	@ echo "-> Setting version to $(DATE)."
	@ echo let version = \"$(DATE)\" > $(PACKAGE)/src/version.ml
	@ echo version = \"$(DATE)\" >> $(PACKAGE)/src/META
134
135
	@ echo "let require_$(DATE) = ()" > $(PACKAGE)/src/StaticVersion.ml
	@ echo "val require_$(DATE) : unit" > $(PACKAGE)/src/StaticVersion.mli
136
137
138
139
# 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
140
	@ make -C $(PACKAGE)/doc clean all
141
142
	@ mv $(PACKAGE)/doc/main.pdf $(PACKAGE)/manual.pdf
	@ mv $(PACKAGE)/doc/menhir.1 $(PACKAGE)/
143
144
145
146
# 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
147
148
# Create the tarball.
	@ echo "-> Tarball creation."
149
	tar --exclude=.gitignore -cvz -f $(TARBALL) $(PACKAGE)
150
151
	@ echo "-> Package $(PACKAGE).tar.gz is ready."

152
153
154
155
# -------------------------------------------------------------------------

# Checking the tarball that was created above.

156
157
158
check:
	@ echo "-> Checking the package ..."
# Create a temporary directory; extract, build, and install the
159
160
# package into it; build the demos and run the test suite using
# the installed binary.
161
162
163
164
165
# 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 \
166
167
168
	    echo "Warning: menhir is already installed." ; \
	    read -p "Can I remove it [Enter/^C]?" -n 1 -r ; \
	    opam remove menhir ; \
169
	  else \
170
171
172
173
	    echo "Warning: menhirLib is already installed." ; \
	    read -p "Can I remove it [Enter/^C]?" -n 1 -r ; \
	    ocamlfind remove menhirLib ; \
	    ocamlfind remove menhirSdk || true ; \
174
175
	  fi ; \
	fi
176
177
178
179
180
	@ TEMPDIR=`mktemp -d /tmp/menhir-test.XXXXXX` && { \
	echo "   * Extracting. " && \
	(cd $$TEMPDIR && tar xfz $(TARBALL)) && \
	echo "   * Compiling and installing." && \
	mkdir $$TEMPDIR/install && \
181
	(cd $$TEMPDIR/$(PACKAGE) \
182
		&& make PREFIX=$$TEMPDIR/install USE_OCAMLFIND=true all install \
183
184
	) > $$TEMPDIR/install.log 2>&1 \
		|| (cat $$TEMPDIR/install.log; exit 1) && \
185
186
187
188
189
	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) && \
190
191
192
	echo "   * Running the test suite." && \
	$(MAKE) MENHIR=$$TEMPDIR/install/bin/menhir test > $$TEMPDIR/test.log 2>&1 \
		|| (cat $$TEMPDIR/test.log; exit 1) && \
193
194
195
196
197
	echo "   * Uninstalling." && \
	(cd $$TEMPDIR/$(PACKAGE) \
		&& make PREFIX=$$TEMPDIR/install USE_OCAMLFIND=true uninstall \
	) > $$TEMPDIR/uninstall.log 2>&1 \
		|| (cat $$TEMPDIR/uninstall.log; exit 1) && \
198
199
200
201
202
	rm -fr $$TEMPDIR ; }
	@ echo "-> Package $(PACKAGE) seems ready for distribution!"

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

203
# Copying the tarball to my Web site.
204

fpottier's avatar
fpottier committed
205
RSYNC   := scp -p -C
206
207
208
TARGET  := yquem.inria.fr:public_html/menhir/
PAGE    := /home/fpottier/dev/page

209
export:
210
211
212
213
214
# Copier l'archive et la doc vers yquem.
	$(RSYNC) $(TARBALL) $(TARGET)
	$(RSYNC) $(PACKAGE)/manual.pdf $(TARGET)
# Mettre  jour la page Web de Menhir avec le nouveau numro de version.
	cd $(PAGE) && \
POTTIER Francois's avatar
POTTIER Francois committed
215
	  cvs up && \
216
	  $(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
217
	  cvs commit -m "Updated Menhir's version number." && \
218
	  if command -v cduce >/dev/null ; then $(MAKE) export ; fi
219
220
221

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

222
223
224
225
226
227
228
# Creating a git tag.

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

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

229
230
231
232
233
234
# 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
235
CSUM  = $(shell $(MD5SUM) menhir-$(DATE).tar.gz | cut -d ' ' -f 1)
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251

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
252
253
# Copy the file "opam" from Menhir's repository to opam's.
	@ cp -f opam $(OPAM)/packages/menhir/menhir.$(DATE)
254
255
256
257
258
259
260
# 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:"
261
	@ echo "  cd $(OPAM)/packages/menhir && git commit -a && git push && firefox https://github.com/fpottier/opam-repository.git"
262
	@ echo "and issue a pull request."
263
264
265
266
267
268
269

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

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

local:
	$(MAKE) package
270
271
272
273
	$(MAKE) -C $(PACKAGE) PREFIX=/usr/local USE_OCAMLFIND=true all
	sudo PATH="$(PATH)" $(MAKE) -C $(PACKAGE) PREFIX=/usr/local USE_OCAMLFIND=true install

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

276
277
278
279
280
pin:
	opam pin add menhir `pwd` -k git

unpin:
	opam pin remove menhir
281
282
283
284
285
286
287
288
289

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

# 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:
290
	@ mdl *.md */*.md