]> err.no Git - sope/blob - gnustep-make/Master/rules.make
merging gnustep-make 1.11.0 into trunk
[sope] / gnustep-make / Master / rules.make
1 #   -*-makefile-*-
2 #   rules.make
3 #
4 #   Makefile rules for the Master invocation.
5 #
6 #   Copyright (C) 1997, 2001, 2002 Free Software Foundation, Inc.
7 #
8 #   Author:  Scott Christley <scottc@net-community.com>
9 #   Author:  Ovidiu Predescu <ovidiu@net-community.com>
10 #   Author:  Nicola Pero <nicola@brainstorm.co.uk>
11 #
12 #   This file is part of the GNUstep Makefile Package.
13 #
14 #   This library is free software; you can redistribute it and/or
15 #   modify it under the terms of the GNU General Public License
16 #   as published by the Free Software Foundation; either version 2
17 #   of the License, or (at your option) any later version.
18 #   
19 #   You should have received a copy of the GNU General Public
20 #   License along with this library; see the file COPYING.LIB.
21 #   If not, write to the Free Software Foundation,
22 #   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23
24 #
25 # Quick explanation - 
26 #
27 # Say that you run `make all'.  The rule for `all' is below here, and
28 # depends on internal-all.  Rules for internal-all are found in
29 # tool.make, library.make etc; there, internal-all will depend on a
30 # list of appropriate %.variables targets, such as
31 # gsdoc.tool.all.variables <which means we need to make `all' for the
32 # `tool' called `gsdoc'> - to process these prerequisites, the
33 # %.variables rule below is used.  this rule gets an appropriate make
34 # subprocess going, with the task of building that specific
35 # instance-type-operation prerequisite.  The make subprocess will be run
36 # as in `make internal-tool-all INTERNAL_tool_NAME=gsdoc ...<and other
37 # variables>' and this make subprocess wil find the internal-tool-all
38 # rule in tool.make, and execute that, building the tool.
39 #
40 # Hint: run make with `make -n' to see the recursive method invocations 
41 #       with the parameters used
42 #
43
44 #
45 # Global targets
46 #
47
48 # The first time you invoke `make', if you have not given a target,
49 # `all' is executed as it is the first one.  If a GNUSTEP_BUILD_DIR is
50 # specifed, make sure to create it before anything else is done.
51 ifeq ($(GNUSTEP_BUILD_DIR),.)
52 all:: before-all internal-all after-all
53 else
54 all:: $(GNUSTEP_BUILD_DIR) before-all internal-all after-all
55 endif
56
57 # internal-after-install is used by packaging to get the list of files 
58 # installed (see rpm.make); it must come after *all* the installation 
59 # rules have been executed.
60 # internal-check-installation-permissions comes before everything so
61 # that we run any command if we aren't allowed to install
62 # install depends on all as per GNU/Unix habits, conventions and standards.
63 ifeq ($(MAKELEVEL),0)
64 install:: internal-check-install-permissions all \
65           before-install internal-install after-install internal-after-install
66 else
67 install:: before-install internal-install after-install internal-after-install
68 endif
69
70 uninstall:: before-uninstall internal-uninstall after-uninstall
71
72 clean:: before-clean internal-clean after-clean
73
74 ifeq ($(MAKELEVEL),0)
75 distclean:: clean before-distclean internal-distclean after-distclean
76 else 
77 distclean:: before-distclean internal-distclean after-distclean
78 endif
79
80 check:: before-check internal-check after-check
81
82 strings:: before-strings internal-strings after-strings
83
84 #
85 # Placeholders for internal targets
86 #
87
88 before-all::
89
90 internal-all::
91
92 after-all::
93
94 # In case of problems, we print a message trying to educate the user
95 # about how to install elsewhere, except if the installation dir is
96 # GNUSTEP_SYSTEM_ROOT, in that case we don't want to suggest to
97 # install the software elsewhere, because it is likely to be system
98 # software like the gnustep-base library.  NB: the check of
99 # GNUSTEP_INSTALLATION_DIR against GNUSTEP_SYSTEM_ROOT is not perfect
100 # as /usr/GNUstep/System/ might not match /usr/GNUstep/System (note
101 # the missing '/' at the end) but what we really want to catch is the
102 # GNUSTEP_INSTALLATION_DIR = $(GNUSTEP_SYSTEM_ROOT) command in the
103 # makefiles, and the check of course works with it.
104 internal-check-install-permissions:
105         @if [ -d "$(GNUSTEP_INSTALLATION_DIR)" \
106               -a ! -w "$(GNUSTEP_INSTALLATION_DIR)" ]; then \
107           echo "*ERROR*: the software is configured to install itself into $(GNUSTEP_INSTALLATION_DIR)"; \
108           echo "but you do not have permissions to write in that directory:";\
109           echo "Aborting installation."; \
110           echo ""; \
111           if [ "$(GNUSTEP_INSTALLATION_DIR)" != "$(GNUSTEP_SYSTEM_ROOT)" ]; then \
112             echo "Suggestion: if you can't get permissions to install there, you can try";\
113             echo "to install the software in a different directory by setting";\
114             echo "GNUSTEP_INSTALLATION_DIR.  For example, to install into";\
115             echo "$(GNUSTEP_USER_ROOT), which is your own GNUstep directory, just type"; \
116             echo ""; \
117             echo "make install GNUSTEP_INSTALLATION_DIR=\"$(GNUSTEP_USER_ROOT)\""; \
118             echo ""; \
119             echo "You should always be able to install into $(GNUSTEP_USER_ROOT),";\
120             echo "so this might be a good option.  The other meaningful values for";\
121             echo "GNUSTEP_INSTALLATION_DIR on your system are:";\
122             echo "$(GNUSTEP_SYSTEM_ROOT) (the System directory)";\
123             echo "$(GNUSTEP_LOCAL_ROOT) (the Local directory)";\
124             echo "$(GNUSTEP_NETWORK_ROOT) (the Network directory)";\
125             echo "but you might need special permissions to install in those directories.";\
126           fi; \
127           exit 1; \
128         fi
129
130 before-install::
131
132 internal-install::
133
134 after-install::
135
136 # The following for exclusive use of packaging code
137 internal-after-install::
138
139 before-uninstall::
140
141 internal-uninstall::
142
143 after-uninstall::
144
145 before-clean::
146
147 internal-clean::
148         rm -rf $(GNUSTEP_BUILD_DIR)/*~ $(GNUSTEP_BUILD_DIR)/obj
149
150 after-clean::
151
152 before-distclean::
153
154 internal-distclean::
155         rm -f $(GNUSTEP_BUILD_DIR)/core
156
157 after-distclean::
158
159 before-check::
160
161 internal-check::
162
163 after-check::
164
165 before-strings::
166
167 internal-strings::
168
169 after-strings::
170
171 # declare targets as PHONY
172
173 .PHONY: all before-all internal-all after-all \
174          install before-install internal-install after-install \
175                  internal-after-install \
176          uninstall before-uninstall internal-uninstall after-uninstall \
177          clean before-clean internal-clean after-clean \
178          distclean before-distclean internal-distclean after-distclean \
179          check before-check internal-check after-check \
180          strings before-strings internal-strings after-strings
181
182 # Prevent make from trying to remove stuff like
183 # libcool.library.all.subprojects thinking that it is a temporary file
184 .PRECIOUS: %.variables %.subprojects
185
186 #
187 ## The magical %.variables rules, thank you GNU make!
188 #
189
190 # The %.variables target has to be called with the name of the actual
191 # instance, followed by the operation, then the makefile fragment to be
192 # called and then the variables word. Suppose for example we build the
193 # library libgmodel, the target should look like:
194 #
195 #       libgmodel.all.library.variables
196 #
197 # when the rule is executed, $* is libgmodel.all.libray;
198 #  instance will be libgmodel
199 #  operation will be all
200 #  type will be library 
201 #
202 # this rule might be executed many times, for different targets to build.
203
204 # the rule then calls a submake, which runs the real code
205
206 # the following is the code used in %.variables and %.subprojects
207 # to extract the instance, operation and type from the $* (the stem) of the 
208 # rule.  with GNU make => 3.78, we could define the following as macros 
209 # and use $(call ...) to call them; but because we have users who are using 
210 # GNU make older than that, we have to manually `paste' this code 
211 # wherever we need to access instance or type or operation.
212 #
213 # Anyway, the following table tells you what these commands do - 
214 #
215 # instance=$(basename $(basename $(1)))
216 # operation=$(subst .,,$(suffix $(basename $(1))))
217 # type=$(subst -,_,$(subst .,,$(suffix $(1))))
218 #
219 # It's very important to notice that $(basename $(basename $*)) in
220 # these rules is simply the instance (such as libgmodel).
221
222 # NB: INTERNAL_$${type}_NAME and TARGET are deprecated - use
223 # GNUSTEP_INSTANCE instead.
224
225 # Before building the real thing, we must build the subprojects
226
227 # If we are at the very first make invocation, convert
228 # GNUSTEP_BUILD_DIR into an absolute path.  All other make invocations
229 # can then assume it is already an absolute path form, and avoid the
230 # shell invocation to convert into absolute path.  Let's avoid the
231 # shell invocation unless strictly necessary - it's slow.
232 ifeq ($(MAKELEVEL),0)
233   ifneq ($(GNUSTEP_BUILD_DIR),.)
234
235     # We can't use ':=' here (which we'd like, since it would guarantee
236     # that the shell command is executed only once) because ':=' would
237     # cause the shell command to be executed immediately, which is *now*
238     # during parsing, before any rule has been executed; in particular,
239     # before the rule which creates GNUSTEP_BUILD_DIR has been executed
240     # (if it had to be executed), and that might cause the 'cd' in the
241     # following shell command to fail.  So what we do, is we define this
242     # as a simple variable with '=', which means it will be evaluated
243     # every time it is used, but not before, and then we make sure to
244     # use it as little as possible and only in rules which are executed
245     # after the rule to build GNUSTEP_BUILD_DIR.  Please note that in
246     # this setup, *any* reference to this variable causes a slow
247     # subshell invocation.  At the moment, it's used when running
248     # the subprojects/variables and when running the aggregate
249     # projects.
250
251     # That makes 1 invocation per type of project per type of target
252     # used in the top-level makefile.  For example, if the top-level
253     # makefile includes aggregate.make and documentation.make and does
254     # a make all, we evaluate this variable twice.  If it does a make
255     # distclean (which automatically invokes make clean as well) we
256     # evaluate this variable 4 times.  All non-top-level make code 
257     # is free from overhead.
258     # In the rules which need the ABS_GNUSTEP_BUILD_DIR variable more
259     # than once we copy it into a shell variable and reuse the shell
260     # variable to avoid evaluating ABS_GNUSTEP_BUILD_DIR multiple
261     # times in the same rule.
262     # DO NOT EVER USE THIS VARIABLE UNLESS YOU FULLY UNDERSTAND THE
263     # PERFORMANCE IMPLICATIONS JUST DESCRIBED.
264     ABS_GNUSTEP_BUILD_DIR = $(shell (cd "$(GNUSTEP_BUILD_DIR)"; pwd))
265   else
266     ABS_GNUSTEP_BUILD_DIR = .
267   endif
268 else
269   ABS_GNUSTEP_BUILD_DIR = $(strip $(GNUSTEP_BUILD_DIR))
270 endif
271
272 # If you change the subprojects code here, make sure to update the
273 # %.subprojects rule below too!  The code from the %.subprojects rule
274 # below is 'inlined' here for speed (so that we don't run a separate
275 # shell just to execute that code).
276 %.variables:
277         @ \
278 instance=$(basename $(basename $*)); \
279 operation=$(subst .,,$(suffix $(basename $*))); \
280 type=$(subst -,_,$(subst .,,$(suffix $*))); \
281 abs_build_dir="$(ABS_GNUSTEP_BUILD_DIR)"; \
282 if [ "$($(basename $(basename $*))_SUBPROJECTS)" != "" ]; then \
283   echo Making $$operation in subprojects of $$type $$instance...; \
284   for f in $($(basename $(basename $*))_SUBPROJECTS) __done; do \
285     if [ $$f != __done ]; then       \
286       mf=$(MAKEFILE_NAME); \
287       if [ ! -f $$f/$$mf -a -f $$f/Makefile ]; then \
288         mf=Makefile; \
289         echo "WARNING: No $(MAKEFILE_NAME) found for subproject $$f; using 'Makefile'"; \
290       fi; \
291       if [ "$${abs_build_dir}" = "." ]; then \
292         gsbuild="."; \
293       else \
294         gsbuild="$${abs_build_dir}/$$f"; \
295       fi; \
296       if [ "$(OWNING_PROJECT_HEADER_DIR_NAME)" = "" ]; then \
297         if [ "$$type" = "framework" ]; then \
298           if [ "$(FRAMEWORK_VERSION_SUPPORT)" = "yes" ]; then \
299             framework_version="$($(basename $(basename $*))_CURRENT_VERSION_NAME)"; \
300             if [ "$$framework_version" = "" ]; then framework_version="A"; fi; \
301             owning_project_header_dir="../$${instance}.framework/Versions/$${framework_version}/Headers"; \
302           else \
303             owning_project_header_dir="../$${instance}.framework/Headers"; \
304           fi; \
305        else owning_project_header_dir=""; \
306        fi; \
307       else \
308         owning_project_header_dir="../$(OWNING_PROJECT_HEADER_DIR_NAME)"; \
309       fi; \
310       if $(MAKE) -C $$f -f $$mf --no-keep-going $$operation \
311           OWNING_PROJECT_HEADER_DIR_NAME="$${owning_project_header_dir}" \
312           DERIVED_SOURCES="../$(DERIVED_SOURCES)" \
313           GNUSTEP_BUILD_DIR="$$gsbuild" \
314         ; then \
315         :; \
316       else exit $$?; \
317       fi; \
318     fi; \
319   done; \
320 fi; \
321 echo Making $$operation for $$type $$instance...; \
322 $(MAKE) -f $(MAKEFILE_NAME) --no-print-directory --no-keep-going \
323     internal-$${type}-$$operation \
324     GNUSTEP_TYPE=$$type \
325     GNUSTEP_INSTANCE=$$instance \
326     GNUSTEP_OPERATION=$$operation \
327     INTERNAL_$${type}_NAME=$$instance \
328     TARGET=$$instance \
329     GNUSTEP_BUILD_DIR="$${abs_build_dir}"
330
331 #
332 # This rule provides exactly the same code as the %.variables one with
333 # respect to subprojects; it is available for clean targets when they
334 # want to run make clean in subprojects but do not need a full Instance
335 # invocation.  In that case, they can depend on %.subprojects only.
336 #
337 # NB: The OWNING_PROJECT_HEADER_DIR_NAME hack in this rule is sort of
338 # horrible, because it pollutes this general rule with code specific
339 # to the framework implementation (eg, where the framework headers are
340 # located).  Still, it's the least evil we could think of at the
341 # moment :-) The framework code is now completely confined into
342 # framework.make makefiles, except for this little hack in here.  It
343 # would be nice to remove this hack without loosing functionality (or
344 # polluting other general-purpose makefiles).
345 %.subprojects:
346         @ \
347 instance=$(basename $(basename $*)); \
348 operation=$(subst .,,$(suffix $(basename $*))); \
349 type=$(subst -,_,$(subst .,,$(suffix $*))); \
350 abs_build_dir="$(ABS_GNUSTEP_BUILD_DIR)"; \
351 if [ "$($(basename $(basename $*))_SUBPROJECTS)" != "" ]; then \
352   echo Making $$operation in subprojects of $$type $$instance...; \
353   for f in $($(basename $(basename $*))_SUBPROJECTS) __done; do \
354     if [ $$f != __done ]; then       \
355       mf=$(MAKEFILE_NAME); \
356       if [ ! -f $$f/$$mf -a -f $$f/Makefile ]; then \
357         mf=Makefile; \
358         echo "WARNING: No $(MAKEFILE_NAME) found for subproject $$f; using 'Makefile'"; \
359       fi; \
360       if [ "$${abs_build_dir}" = "." ]; then \
361         gsbuild="."; \
362       else \
363         gsbuild="$${abs_build_dir}/$$f"; \
364       fi; \
365       if [ "$(OWNING_PROJECT_HEADER_DIR_NAME)" = "" ]; then \
366         if [ "$$type" = "framework" ]; then \
367           if [ "$(FRAMEWORK_VERSION_SUPPORT)" = "yes" ]; then \
368             framework_version="$($(basename $(basename $*))_CURRENT_VERSION_NAME)"; \
369             if [ "$$framework_version" = "" ]; then framework_version="A"; fi; \
370             owning_project_header_dir="../$${instance}.framework/Versions/$${framework_version}/Headers"; \
371           else \
372             owning_project_header_dir="../$${instance}.framework/Headers"; \
373           fi; \
374        else owning_project_header_dir=""; \
375        fi; \
376       else \
377         owning_project_header_dir="../$(OWNING_PROJECT_HEADER_DIR_NAME)"; \
378       fi; \
379       if $(MAKE) -C $$f -f $$mf --no-keep-going $$operation \
380           OWNING_PROJECT_HEADER_DIR_NAME="$${owning_project_header_dir}" \
381           DERIVED_SOURCES="../$(DERIVED_SOURCES)" \
382           GNUSTEP_BUILD_DIR="$$gsbuild" \
383         ; then \
384         :; \
385       else exit $$?; \
386       fi; \
387     fi; \
388   done; \
389 fi
390
391 #
392 # Now rules for packaging - all automatically included
393
394
395 PACKAGE_NAME := $(strip $(PACKAGE_NAME))
396
397 ifeq ($(PACKAGE_NAME),)
398   # Use a default of unnamed-package if nothing better is provided.
399   PACKAGE_NAME := unnamed-package
400 endif
401
402 # For backwards compatibility, take value of PACKAGE_VERSION from
403 # VERSION.  New GNUmakefiles should all use the PACKAGE_VERSION
404 # variable rather than the VERSION variable.
405 ifeq ($(PACKAGE_VERSION),)
406
407   PACKAGE_VERSION = $(VERSION)
408
409   # Use a default of 0.0.1 if nothing better is provided.
410   ifeq ($(PACKAGE_VERSION),)
411     PACKAGE_VERSION = 0.0.1
412   endif
413
414 endif
415
416 #
417 # Rules for building source distributions
418 #
419 include $(GNUSTEP_MAKEFILES)/Master/source-distribution.make
420
421 #
422 # Rules for building spec files/file lists for RPMs, and RPMs
423 #
424 include $(GNUSTEP_MAKEFILES)/Master/rpm.make
425
426 #
427 # Rules for building debian/* scripts for DEBs, and DEBs
428
429 #include $(GNUSTEP_MAKEFILES)/Master/deb.make <TODO>