GNUmakefile 10.4 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

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

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:
33
	$(MAKE) -C test
34 35 36 37 38 39

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

# Cleaning up.

clean:
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
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
# Clean up the demos, including those that are not built by default
# because they require dune.
131
	@ $(MAKE) -C $(PACKAGE)/demos clean
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 145 146
	@ mv $(PACKAGE)/doc/manual.pdf $(PACKAGE)/manual.pdf
	@ mv $(PACKAGE)/doc/manual.html $(PACKAGE)/manual.html
	@ mv $(PACKAGE)/doc/manual*.png $(PACKAGE)/
147
	@ mv $(PACKAGE)/doc/menhir.1 $(PACKAGE)/
148 149 150 151
# 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
152 153
# Create the tarball.
	@ echo "-> Tarball creation."
154
	tar --exclude=.gitignore -cvz -f $(TARBALL) $(PACKAGE)
155 156
	@ echo "-> Package $(PACKAGE).tar.gz is ready."

157 158 159 160
# -------------------------------------------------------------------------

# Checking the tarball that was created above.

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

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

208
# Copying the tarball to my Web site.
209

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

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

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

230 231 232 233 234 235 236
# Creating a git tag.

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

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

237 238 239 240 241 242
# 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
243
CSUM  = $(shell $(MD5SUM) menhir-$(DATE).tar.gz | cut -d ' ' -f 1)
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259

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
260 261
# Copy the file "opam" from Menhir's repository to opam's.
	@ cp -f opam $(OPAM)/packages/menhir/menhir.$(DATE)
262 263 264 265 266 267 268
# 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:"
269
	@ echo "  cd $(OPAM)/packages/menhir && git commit -a && git push && firefox https://github.com/fpottier/opam-repository.git"
270
	@ echo "and issue a pull request."
271 272 273 274 275 276 277

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

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

local:
	$(MAKE) package
278 279 280 281
	$(MAKE) -C $(PACKAGE) PREFIX=/usr/local USE_OCAMLFIND=true all
	sudo PATH="$(PATH)" $(MAKE) -C $(PACKAGE) PREFIX=/usr/local USE_OCAMLFIND=true install

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

284 285 286 287 288
pin:
	opam pin add menhir `pwd` -k git

unpin:
	opam pin remove menhir
289 290 291 292 293 294 295 296 297

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

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