fix install-docs for non-html docs
[ghc-hetmet.git] / mk / install.mk
1 #
2 #       install* installcheck installdirs
3 #       install-docs*
4 #
5 #    Some of the above targets have a version that
6 #    recursively invokes that target in sub-directories.
7 #    This relies on the importing Makefile setting SUBDIRS
8 #
9 #    The recursive targets are marked with a * above
10 #
11
12 ##################################################################
13 #               GNU Standard targets
14 #
15 #       Every Makefile should define the following targets
16
17 # `install'
18 #      Compile the program and copy the executables, libraries, and so on
19 #      to the file names where they should reside for actual use. If
20 #      there is a simple test to verify that a program is properly
21 #      installed, this target should run that test.
22
23 #      The commands should create all the directories in which files are
24 #      to be installed, if they don't already exist. This includes the
25 #      directories specified as the values of the variables prefix and
26 #      exec_prefix , as well as all subdirectories that are needed. One
27 #      way to do this is by means of an installdirs target as described
28 #      below.
29
30 #      Use `-' before any command for installing a man page, so that make
31 #      will ignore any errors.  This is in case there are systems that
32 #      don't have the Unix man page documentation system installed.
33
34 # The following targets are suggested as conventional names, for programs
35 # in which they are useful.
36
37 # installcheck
38 #      Perform installation tests (if any). The user must build and
39 #      install the program before running the tests. You should not
40 #      assume that `$(bindir)' is in the search path.
41
42 # installdirs
43 #      It's useful to add a target named `installdirs' to create the
44 #      directories where files are installed, and their parent
45 #      directories. There is a script called `mkinstalldirs' which is
46 #      convenient for this; find it in the Texinfo package.
47 #      (GHC: we use a close relative of the suggested script, situated
48 #       in glafp-utils/mkdirhier -- SOF)
49
50
51
52 # ---------------------------------------------------------------------------
53 # Symbolic links
54
55 # links to programs: we sometimes install a program as
56 # <name>-<version> with a link from <name> to the real program.
57
58 ifneq "$(LINK)" ""
59
60 ifeq "$(LINK_TARGET)" ""
61 ifneq "$(HS_PROG)" ""
62 LINK_TARGET = $(HS_PROG)
63 else
64 ifneq "$(C_PROG)" ""
65 LINK_TARGET = $(C_PROG)
66 else
67 $(error Cannot deduce LINK_TARGET)
68 endif
69 endif
70 endif
71
72 #
73 # install links to script drivers.
74 #
75 install ::
76         $(INSTALL_DIR) $(DESTDIR)$(bindir)
77         if ( $(PERL) -e '$$fn="$(DESTDIR)$(bindir)/$(LINK)"; exit ((! -f $$fn || -l $$fn) ? 0 : 1);' ); then \
78            echo "Creating a symbolic link from $(LINK_TARGET) to $(LINK) in $(DESTDIR)$(bindir)"; \
79            $(RM) $(DESTDIR)$(bindir)/$(LINK); \
80            $(LN_S) $(LINK_TARGET) $(DESTDIR)$(bindir)/$(LINK); \
81          else \
82            echo "Creating a symbolic link from $(LINK_TARGET) to $(LINK) in $(DESTDIR)$(bindir) failed: \`$(DESTDIR)$(bindir)/$(LINK)' already exists"; \
83            echo "Perhaps remove \`$(DESTDIR)$(bindir)/$(LINK)' manually?"; \
84            exit 1; \
85          fi;
86
87 endif # LINK 
88
89
90 ###########################################
91 #
92 #       Targets: install install-strip
93 #
94 ###########################################
95
96 # For each of these variables that is defined, you
97 # get one install rule
98 #
99 #       INSTALL_PROGS        executable programs in $(bindir)
100 #       INSTALL_SCRIPTS      executable scripts in $(bindir)
101 #       INSTALL_LIBS         platform-dependent libraries in $(libdir) (ranlib'ed)
102 #       INSTALL_LIB_SCRIPTS  platform-dependent scripts   in $(libdir)
103 #       INSTALL_LIBEXECS     platform-dependent execs in $(libdir)
104 #       INSTALL_DATAS        platform-independent files in $(datadir)
105 #       INSTALL_IFACES       platform-dependent interface files in $(ifacedir)
106 #
107 # If the installation directory variable is undefined, the install rule simply
108 # emits a suitable error message.
109 #
110 # Remember, too, that the installation directory variables ($(bindir) and
111 # friends can be overridden from their original settings in mk/config.mk.in
112 # || mk/build.mk
113 #
114 .PHONY: install install-docs installdirs install-strip install-docs show-install
115
116 show-install :
117         @echo "DESTDIR = $(DESTDIR)"
118         @echo "bindir = $(bindir)"
119         @echo "libdir = $(libdir)"
120         @echo "libexecdir = $(libexecdir)  # by default, same as libdir"
121         @echo "datadir = $(datadir)  # unused for ghc project"
122         @echo "ifacedir = $(ifacedir)"
123         @echo "headerdir = $(headerdir)"
124         @echo "includedir = $(includedir)"
125
126 #
127 # Setting user/group ownership for the installed entities
128 #
129 ifneq "$(INSTALL_OWNER)" ""
130 SRC_INSTALL_OPTS += -o $(INSTALL_OWNER)
131 endif
132 ifneq "$(INSTALL_GROUP)" ""
133 SRC_INSTALL_OPTS += -g $(INSTALL_GROUP)
134 endif
135
136
137 ifneq "$(strip $(INSTALL_PROGS))" ""
138
139 #
140 # Here's an interesting one - when using the win32 version
141 # of install (provided via the cygwin toolkit), we have to
142 # supply the .exe suffix, *if* there's no other suffix.
143 #
144 # The rule below does this by ferreting out the suffix of each
145 # entry in the INSTALL_PROGS list. If there's no suffix, use
146 # $(exeext).
147
148 INSTALL_PROGS := $(foreach p, $(INSTALL_PROGS), $(addsuffix $(if $(suffix $(p)),,$(exeext)), $(basename $(p))))
149
150 install:: $(INSTALL_PROGS)
151         $(INSTALL_DIR) $(DESTDIR)$(bindir)
152         for i in $(INSTALL_PROGS); do \
153                     $(INSTALL_PROGRAM) $(INSTALL_BIN_OPTS) $$i $(DESTDIR)$(bindir) ;  \
154                     if test "$(darwin_TARGET_OS)" = "1"; then \
155                       sh $(FPTOOLS_TOP)/mk/fix_install_names.sh $(libdir) $(DESTDIR)$(bindir)/$$i ; \
156                     fi ; \
157         done
158 endif
159
160 #
161 # Just like INSTALL_PROGS, but prefix with install sites bin/lib/data and
162 # install without stripping.
163 #
164 ifneq "$(strip $(INSTALL_SCRIPTS))" ""
165 install:: $(INSTALL_SCRIPTS)
166         $(INSTALL_DIR) $(DESTDIR)$(bindir)
167         for i in $(INSTALL_SCRIPTS); do \
168                 $(INSTALL_SCRIPT) $(INSTALL_OPTS) $$i $(DESTDIR)$(bindir); \
169         done
170 endif
171
172 ifneq "$(strip $(INSTALL_LIB_SCRIPTS))" ""
173 install:: $(INSTALL_LIB_SCRIPTS)
174         $(INSTALL_DIR) $(DESTDIR)$(libdir)
175         for i in $(INSTALL_LIB_SCRIPTS); do \
176                 $(INSTALL_SCRIPT) $(INSTALL_OPTS) $$i $(DESTDIR)$(libdir); \
177         done
178 endif
179
180 ifneq "$(strip $(INSTALL_LIBEXEC_SCRIPTS))" ""
181 install:: $(INSTALL_LIBEXEC_SCRIPTS)
182         $(INSTALL_DIR) $(DESTDIR)$(libexecdir)
183         for i in $(INSTALL_LIBEXEC_SCRIPTS); do \
184                 $(INSTALL_SCRIPT) $(INSTALL_OPTS) $$i $(DESTDIR)$(libexecdir); \
185         done
186 endif
187
188 ifneq "$(strip $(INSTALL_LIBS))" ""
189 install:: $(INSTALL_LIBS)
190         $(INSTALL_DIR) $(DESTDIR)$(libdir)
191         for i in $(INSTALL_LIBS); do \
192                 case $$i in \
193                   *.a) \
194                     $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(DESTDIR)$(libdir); \
195                     $(RANLIB) $(DESTDIR)$(libdir)/`basename $$i` ;; \
196                   *.dll) \
197                     $(INSTALL_DATA) -s $(INSTALL_OPTS) $$i $(DESTDIR)$(libdir) ;; \
198                   *.so) \
199                     $(INSTALL_SHLIB) $(INSTALL_OPTS) $$i $(DESTDIR)$(libdir) ;; \
200                   *.dylib) \
201                     $(INSTALL_SHLIB) $(INSTALL_OPTS) $$i $(DESTDIR)$(libdir); \
202                     install_name_tool -id $(DESTDIR)$(libdir)/`basename $$i` $(DESTDIR)$(libdir)/`basename $$i` ;; \
203                   *) \
204                     $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(DESTDIR)$(libdir); \
205                 esac; \
206         done
207 endif
208
209 ifneq "$(strip $(INSTALL_LIBEXECS))" ""
210 #
211 # See above comment next to defn of INSTALL_PROGS for what
212 # the purpose of this one-liner is.
213
214 INSTALL_LIBEXECS := $(foreach p, $(INSTALL_LIBEXECS), $(addsuffix $(subst _,,$(subst __,$(exeext),_$(suffix $(p))_)), $(basename $(p))))
215
216 install:: $(INSTALL_LIBEXECS)
217         $(INSTALL_DIR) $(DESTDIR)$(libexecdir)
218         -for i in $(INSTALL_LIBEXECS); do \
219                 $(INSTALL_PROGRAM) $(INSTALL_BIN_OPTS) $$i $(DESTDIR)$(libexecdir); \
220                 if test "$(darwin_TARGET_OS)" = "1"; then \
221                         sh $(FPTOOLS_TOP)/mk/fix_install_names.sh $(libdir) $(DESTDIR)$(libexecdir)/`basename $$i` ; \
222                 fi ; \
223         done
224 endif
225
226 ifneq "$(strip $(INSTALL_DATAS))" ""
227 install:: $(INSTALL_DATAS)
228         $(INSTALL_DIR) $(DESTDIR)$(datadir)
229         for i in $(INSTALL_DATAS); do \
230                 $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(DESTDIR)$(datadir); \
231         done
232 endif
233
234 ifneq "$(strip $(INSTALL_HEADERS))" ""
235 install:: $(INSTALL_HEADERS)
236         $(INSTALL_DIR) $(DESTDIR)$(headerdir)
237         for i in $(INSTALL_HEADERS); do \
238                 $(INSTALL_HEADER) $(INSTALL_OPTS) $$i $(DESTDIR)$(headerdir); \
239         done
240 endif
241
242 ifneq "$(strip $(INSTALL_IFACES))" ""
243 install:: $(INSTALL_IFACES)
244         $(INSTALL_DIR) $(DESTDIR)$(ifacedir)
245         for i in $(INSTALL_IFACES); do \
246                 $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(DESTDIR)$(ifacedir); \
247         done
248 endif
249
250 ifneq "$(strip $(INSTALL_IFACES_WITH_DIRS))" ""
251 install:: $(INSTALL_IFACES_WITH_DIRS)
252         $(INSTALL_DIR) $(DESTDIR)$(ifacedir)
253         for i in $(INSTALL_IFACES_WITH_DIRS); do \
254                 $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(DESTDIR)$(ifacedir)/`dirname $$i`; \
255         done
256 endif
257
258 ifneq "$(strip $(INSTALL_DOCS))" ""
259 ifneq "$(XMLDocWays)" ""
260 install-docs:: $(INSTALL_DOCS)
261         $(INSTALL_DIR) $(DESTDIR)$(datadir)
262         for i in $(INSTALL_DOCS); do \
263                 $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(DESTDIR)$(datadir); \
264         done
265 endif
266 endif
267
268 ifneq "$(strip $(INSTALL_XML_DOC))" ""
269 ifneq "$(XMLDocWays)" ""
270 # TODO: The following could be an entry for an Obfuscated Makefile Contest...
271 install-docs:: $(foreach i,$(XMLDocWays),$(INSTALL_XML_DOC)$(patsubst %.html-no-chunks,%.html,$(patsubst %.html,%/index.html,.$(i))))
272
273 install-docs:: $(foreach i,$(XMLDocWays),install-docs-$i)
274
275 install-docs-html:
276         $(INSTALL_DIR) $(DESTDIR)$(htmldir)
277         $(INSTALL_DIR) $(DESTDIR)$(htmldir)/$(INSTALL_XML_DOC)
278         $(INSTALL_DIR) $(DESTDIR)$(htmldir)/$(INSTALL_XML_DOC)/html
279         $(CP) $(INSTALL_XML_DOC)/* $(DESTDIR)$(htmldir)/$(INSTALL_XML_DOC)/html
280
281 install-docs-html-no-chunks:
282         $(INSTALL_DIR) $(DESTDIR)$(htmldir)
283         $(INSTALL_DATA) $(INSTALL_OPTS) $(INSTALL_XML_DOC).html $(DESTDIR)$(htmldir)
284         $(CP) $(FPTOOLS_CSS_ABS) $(DESTDIR)$(htmldir)
285
286 install-docs-%:
287         $(INSTALL_DIR) $(DESTDIR)$($*dir)
288         $(INSTALL_DATA) $(INSTALL_OPTS) $(INSTALL_XML_DOC).$* $(DESTDIR)$($*dir)
289 endif
290 endif
291
292 #
293 # install-strip is from the GNU Makefile standard.
294 #
295 ifneq "$(way)" ""
296 install-strip::
297         $(MAKE) EXTRA_INSTALL_OPTS='-s' install
298 endif
299