Makefile 5.77 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 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 svn repository: some sub-directories are not shipped;
# the documentation is pre-built.

# The hierarchy that is shipped includes:
#   demos
#   menhir.1
#   manual.pdf
#   src
#   Makefile (this one)

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

fpottier's avatar
fpottier committed
15
16
17
18
19
20
21
22
23
24
25
26
# 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
27
# By default, we attempt to use ocamlfind (if present in the PATH), but it
28
29
30
31
32
33
# is possible to prevent that externally by setting USE_OCAMLFIND to false.

ifndef USE_OCAMLFIND
  USE_OCAMLFIND = ocamlfind ocamlc -v >/dev/null 2>&1
endif

34
35
36
# ----------------------------------------------------------------------------
# Installation paths.

37
38
39
40
bindir          := $(PREFIX)/bin
docdir		:= $(PREFIX)/share/doc/menhir
libdir	        := $(PREFIX)/share/menhir
mandir          := $(PREFIX)/share/man/man1
41
42
43
44
MANS            := menhir.1
DOCS            := manual.pdf demos
MLYLIB          := src/standard.mly

45
46
47
48
# ----------------------------------------------------------------------------

# A few settings differ on Windows versus Unix.

49
50
51
# If the compiler is MSVC, then the name of the executable file ends in .exe,
# and object file names end in .obj instead of .o.

fpottier's avatar
fpottier committed
52
ifeq "$(shell ocamlc -config | grep ccomp_type)" "ccomp_type: msvc"
53
54
  MENHIREXE    := menhir.exe
  OBJ          := obj
fpottier's avatar
fpottier committed
55
56
# LIBSUFFIX    := lib
else
57
58
  MENHIREXE    := menhir
  OBJ          := o
fpottier's avatar
fpottier committed
59
60
# LIBSUFFIX    := a
endif
61

62
# The path $(libdir), which is recorded in src/installation.ml (see below),
63
64
65
66
67
68
69
70
71
72
73
# 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
POTTIER Francois's avatar
Typo.    
POTTIER Francois committed
74
# performed if "os_type" is "Win32" or "Win64", and must not be performed if
75
76
77
# "os_type" is "Cygwin" or "Unix".

ifneq (,$(findstring "os_type: Win", "$(shell ocamlc -config | grep os_type)"))
78
libdir        := $(shell cygpath -m $(libdir))
79
endif
80
81
82
83

# ----------------------------------------------------------------------------
# Compilation.

84
85
86
# The directory where things are built.
BUILDDIR := src/_stage2

87
88
89
90
91
92
# Installation time settings are recorded within src/installation.ml.
# This file is recreated every time so as to avoid becoming stale.

.PHONY: all install uninstall

all:
93
94
95
	@ rm -f src/installation.ml
	@ echo "let libdir = \"$(libdir)\"" > src/installation.ml
	@ if $(USE_OCAMLFIND) ; then \
96
97
98
99
	  echo "let ocamlfind = true" >> src/installation.ml ; \
	else \
	  echo "let ocamlfind = false" >> src/installation.ml ; \
	fi
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
	@ $(MAKE) -C src library bootstrap
	@ $(MAKE) $(BUILDDIR)/menhirLib.ml $(BUILDDIR)/menhirLib.mli

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

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

$(BUILDDIR)/menhirLib.ml:
	@ rm -f $@
	@ for m in $(MENHIRLIB_MODULES) ; do \
	  echo "module $$m = struct" >> $@ ; \
	  cat src/$$m.ml >> $@ ; \
	  echo "end" >> $@ ; \
	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.

$(BUILDDIR)/menhirLib.mli:
	@ rm -f $@
	@ for m in $(MENHIRLIB_MODULES) ; do \
	  echo "module $$m : sig" >> $@ ; \
	  if [ -f src/$$m.mli ] ; then \
	    cat src/$$m.mli >> $@ ; \
	  else \
	    cat src/$$m.ml >> $@ ; \
	  fi ; \
	  echo "end" >> $@ ; \
	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.$(OBJ)
endif
149
150
151
152

# ----------------------------------------------------------------------------
# Installation.

153
install:
154
155
156
157
	mkdir -p $(bindir)
	mkdir -p $(libdir)
	mkdir -p $(docdir)
	mkdir -p $(mandir)
158
	install $(BUILDDIR)/menhir.$(TARGET) $(bindir)/$(MENHIREXE)
159
160
161
	install -m 644 $(MLYLIB) $(libdir)
	cp -r $(DOCS) $(docdir)
	cp -r $(MANS) $(mandir)
fpottier's avatar
fpottier committed
162
	@if $(USE_OCAMLFIND) ; then \
163
	  echo Installing MenhirLib via ocamlfind. ; \
fpottier's avatar
fpottier committed
164
	  ocamlfind install menhirLib src/META $(patsubst %,$(BUILDDIR)/%,$(MENHIRLIB)) ; \
165
166
	else \
	  echo Installing MenhirLib manually. ; \
fpottier's avatar
fpottier committed
167
	  install -m 644 $(patsubst %,$(BUILDDIR)/%,$(MENHIRLIB)) $(libdir) ; \
168
169
170
171
172
173
174
175
176
177
178
	fi

uninstall:
	rm -rf $(bindir)/$(MENHIREXE)
	rm -rf $(libdir)
	rm -rf $(docdir)
	rm -rf $(mandir)/$(MANS)
	@if $(USE_OCAMLFIND) ; then \
	  echo Un-installing MenhirLib via ocamlfind. ; \
	  ocamlfind remove menhirLib ; \
	fi