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 3
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.
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 GNUSTEP_INSTANCE=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.
51ifeq ($(GNUSTEP_BUILD_DIR),.)
52all:: before-all internal-all after-all
53else
54all:: $(GNUSTEP_BUILD_DIR) before-all internal-all after-all
55
56
57
58$(GNUSTEP_BUILD_DIR):
59	$(ECHO_CREATING)$(MKDIRS) $(GNUSTEP_BUILD_DIR)$(END_ECHO)
60endif
61
62
63jar:: all before-jar internal-jar after-jar
64
65# The rule to create the objects file directory.  This should be done
66# in the Master invocation before any parallel stuff is started (to
67# avoid race conditions in trying to create it).
68$(GNUSTEP_OBJ_DIR):
69	$(ECHO_NOTHING)cd $(GNUSTEP_BUILD_DIR); \
70	$(MKDIRS) ./$(GNUSTEP_OBJ_DIR_NAME)$(END_ECHO)
71
72# internal-after-install is used by packaging to get the list of files
73# installed (see rpm.make); it must come after *all* the installation
74# rules have been executed.
75# internal-check-installation-permissions comes before everything so
76# that we run any command if we aren't allowed to install
77# install depends on all as per GNU/Unix habits, conventions and standards.
78
79# The very first top-most make invocation we want to have install
80# depend on all, and distclean depend on clean.
81# We used to check MAKELEVEL=0 here to
82# determine if this is the top-most invocation of make, but that does
83# not work if the top-most invocation of make is done from within a
84# (non-gnustep-make) makefile itself!  So we use a marker variable.
85# _GNUSTEP_TOP_INVOCATION_DONE is not set the very first / top-most
86# make invocation , but we set it for all sub-invocations, so all
87# subinvocations will have it set and we can distinguish them.
88ifeq ($(_GNUSTEP_TOP_INVOCATION_DONE),)
89# Top-most invocation of make
90install:: all \
91          before-install internal-install after-install internal-after-install
92
93distclean:: clean before-distclean internal-distclean after-distclean
94
95# Further make invocations will have this variable set
96export _GNUSTEP_TOP_INVOCATION_DONE = 1
97else
98#  Sub-invocation of make
99install:: internal-before-install before-install internal-install after-install internal-after-install
100
101distclean:: before-distclean internal-distclean after-distclean
102endif
103
104
105uninstall:: before-uninstall internal-uninstall after-uninstall internal-after-uninstall
106
107clean:: before-clean internal-clean after-clean
108
109check:: before-check internal-check after-check
110
111strings:: before-strings internal-strings after-strings
112
113#
114# Placeholders for internal targets
115#
116
117before-all::
118
119internal-all::
120
121after-all::
122
123before-jar::
124
125internal-jar::
126
127after-jar::
128
129
130# By adding an ADDITIONAL_INSTALL_DIRS variable you can request
131# additional installation directories to be created before the first
132# installation target is executed.  You can also have xxx_INSTALL_DIRS
133# for specific instances, which are processed in the Instance
134# invocation.
135$(ADDITIONAL_INSTALL_DIRS):
136	$(ECHO_CREATING)$(MKINSTALLDIRS) $@$(END_ECHO)
137
138internal-before-install:: $(ADDITIONAL_INSTALL_DIRS)
139
140before-install::
141
142internal-install::
143
144after-install::
145
146# The following for exclusive use of packaging code
147internal-after-install::
148
149before-uninstall::
150
151internal-uninstall::
152
153after-uninstall::
154
155internal-after-uninstall::
156ifneq ($(ADDITIONAL_INSTALL_DIRS),)
157	-$(ECHO_NOTHING)for dir in $(ADDITIONAL_INSTALL_DIRS); do \
158	  rmdir $$dir ; \
159	done$(END_ECHO)
160endif
161
162before-clean::
163
164internal-clean::
165	rm -rf $(GNUSTEP_BUILD_DIR)/*~ $(GNUSTEP_BUILD_DIR)/obj
166
167after-clean::
168
169before-distclean::
170
171internal-distclean::
172
173after-distclean::
174
175before-check::
176
177internal-check::
178
179after-check::
180
181before-strings::
182
183internal-strings::
184
185after-strings::
186
187# declare targets as PHONY
188
189.PHONY: \
190 all before-all internal-all after-all \
191 jar before-jar internal-jar after-jar \
192 install before-install internal-install after-install \
193 internal-after-install \
194 uninstall before-uninstall internal-uninstall after-uninstall \
195 clean before-clean internal-clean after-clean \
196 distclean before-distclean internal-distclean after-distclean \
197 check before-check internal-check after-check \
198 strings before-strings internal-strings after-strings \
199 build-headers before-build-headers after-build-headers
200
201# Prevent make from trying to remove stuff like
202# libcool.library.all.subprojects thinking that it is a temporary file
203# FIXME - we really want to declare these as .PHONY, not .PRECIOUS,
204# we only declare them .PRECIOUS because .PHONY doesn't seem to support
205# wildcards (FIXME)!
206.PRECIOUS: %.variables %.subprojects
207
208#
209## The magical %.variables rules, thank you GNU make!
210#
211
212# The %.variables target has to be called with the name of the actual
213# instance, followed by the operation, then the makefile fragment to be
214# called and then the variables word. Suppose for example we build the
215# library libgmodel, the target should look like:
216#
217#	libgmodel.all.library.variables
218#
219# when the rule is executed, $* is libgmodel.all.libray;
220#  instance will be libgmodel
221#  operation will be all
222#  type will be library
223#
224# this rule might be executed many times, for different targets to build.
225
226# the rule then calls a submake, which runs the real code
227
228# the following is the code used in %.variables and %.subprojects
229# to extract the instance, operation and type from the $* (the stem) of the
230# rule.  with GNU make => 3.78, we could define the following as macros
231# and use $(call ...) to call them; but because we have users who are using
232# GNU make older than that, we have to manually `paste' this code
233# wherever we need to access instance or type or operation.
234# (FIXME: Requiring GNU make >= 3.78 should be OK nowadays)
235#
236# Anyway, the following table tells you what these commands do -
237#
238# instance=$(basename $(basename $(1)))
239# operation=$(subst .,,$(suffix $(basename $(1))))
240# type=$(subst -,_,$(subst .,,$(suffix $(1))))
241#
242# It's very important to notice that $(basename $(basename $*)) in
243# these rules is simply the instance (such as libgmodel).
244
245# Before building the real thing, we must build the subprojects
246
247# If we are at the very first make invocation, convert
248# GNUSTEP_BUILD_DIR into an absolute path.  All other make invocations
249# can then assume it is already an absolute path form, and avoid the
250# shell invocation to convert into absolute path.  Let's avoid the
251# shell invocation unless strictly necessary - it's slow.
252ifeq ($(MAKELEVEL),0)
253  ifneq ($(GNUSTEP_BUILD_DIR),.)
254
255    # We can't use ':=' here (which we'd like, since it would guarantee
256    # that the shell command is executed only once) because ':=' would
257    # cause the shell command to be executed immediately, which is *now*
258    # during parsing, before any rule has been executed; in particular,
259    # before the rule which creates GNUSTEP_BUILD_DIR has been executed
260    # (if it had to be executed), and that might cause the 'cd' in the
261    # following shell command to fail.  So what we do, is we define this
262    # as a simple variable with '=', which means it will be evaluated
263    # every time it is used, but not before, and then we make sure to
264    # use it as little as possible and only in rules which are executed
265    # after the rule to build GNUSTEP_BUILD_DIR.  Please note that in
266    # this setup, *any* reference to this variable causes a slow
267    # subshell invocation.  At the moment, it's used when running
268    # the subprojects/variables and when running the aggregate
269    # projects.
270
271    # That makes 1 invocation per type of project per type of target
272    # used in the top-level makefile.  For example, if the top-level
273    # makefile includes aggregate.make and documentation.make and does
274    # a make all, we evaluate this variable twice.  If it does a make
275    # distclean (which automatically invokes make clean as well) we
276    # evaluate this variable 4 times.  All non-top-level make code
277    # is free from overhead.
278    # In the rules which need the ABS_GNUSTEP_BUILD_DIR variable more
279    # than once we copy it into a shell variable and reuse the shell
280    # variable to avoid evaluating ABS_GNUSTEP_BUILD_DIR multiple
281    # times in the same rule.
282    # DO NOT EVER USE THIS VARIABLE UNLESS YOU FULLY UNDERSTAND THE
283    # PERFORMANCE IMPLICATIONS JUST DESCRIBED.
284    ABS_GNUSTEP_BUILD_DIR = $(shell (cd "$(GNUSTEP_BUILD_DIR)"; pwd))
285  else
286    ABS_GNUSTEP_BUILD_DIR = .
287  endif
288else
289  ABS_GNUSTEP_BUILD_DIR = $(strip $(GNUSTEP_BUILD_DIR))
290endif
291
292# If you change the subprojects code here, make sure to update the
293# %.subprojects rule below too!  The code from the %.subprojects rule
294# below is 'inlined' here for speed (so that we don't run a separate
295# shell just to execute that code).
296%.variables:
297	$(ECHO_NOTHING_RECURSIVE_MAKE) \
298instance=$(basename $(basename $*)); \
299operation=$(subst .,,$(suffix $(basename $*))); \
300type=$(subst -,_,$(subst .,,$(suffix $*))); \
301abs_build_dir="$(ABS_GNUSTEP_BUILD_DIR)"; \
302if [ "$($(basename $(basename $*))_SUBPROJECTS)" != "" ]; then \
303  $(INSIDE_ECHO_MAKING_OPERATION_IN_SUBPROJECTS) \
304  for f in $($(basename $(basename $*))_SUBPROJECTS) __done; do \
305    if [ $$f != __done ]; then       \
306      if [ "$${abs_build_dir}" = "." ]; then \
307        gsbuild="."; \
308      else \
309        gsbuild="$${abs_build_dir}/$$f"; \
310      fi; \
311      if [ "$(OWNING_PROJECT_HEADER_DIR_NAME)" = "" ]; then \
312        if [ "$$type" = "framework" ]; then \
313          if [ "$(FRAMEWORK_VERSION_SUPPORT)" = "yes" ]; then \
314            framework_version="$($(basename $(basename $*))_CURRENT_VERSION_NAME)"; \
315            if [ "$$framework_version" = "" ]; then \
316              framework_version="$($(basename $(basename $*))_INTERFACE_VERSION)"; \
317              if [ "$$framework_version" = "" ]; then \
318                framework_version="$(word 1,$(subst ., ,$($(basename $(basename $*))_VERSION)))"; \
319                if [ "$$framework_version" = "" ]; then \
320                  framework_version="0"; \
321                fi; \
322              fi; \
323            fi; \
324            owning_project_header_dir="../$${instance}.framework/Versions/$${framework_version}/Headers"; \
325          else \
326            owning_project_header_dir="../$${instance}.framework/Headers"; \
327          fi; \
328       else owning_project_header_dir=""; \
329       fi; \
330      else \
331        owning_project_header_dir="../$(OWNING_PROJECT_HEADER_DIR_NAME)"; \
332      fi; \
333      if $(MAKE) -C $$f -f $(MAKEFILE_NAME) $(GNUSTEP_MAKE_NO_PRINT_DIRECTORY_FLAG) --no-keep-going $$operation \
334          OWNING_PROJECT_HEADER_DIR_NAME="$${owning_project_header_dir}" \
335          DERIVED_SOURCES="../$(DERIVED_SOURCES)" \
336          GNUSTEP_BUILD_DIR="$$gsbuild" \
337	  _GNUSTEP_MAKE_PARALLEL=no \
338        ; then \
339        :; \
340      else exit $$?; \
341      fi; \
342    fi; \
343  done; \
344fi; \
345$(INSIDE_ECHO_MAKING_OPERATION) \
346$(MAKE) -f $(MAKEFILE_NAME) --no-print-directory --no-keep-going \
347    internal-$${type}-$$operation \
348    GNUSTEP_TYPE=$$type \
349    GNUSTEP_INSTANCE=$$instance \
350    GNUSTEP_OPERATION=$$operation \
351    GNUSTEP_BUILD_DIR="$${abs_build_dir}" \
352    _GNUSTEP_MAKE_PARALLEL=no$(END_ECHO_RECURSIVE_MAKE)
353
354#
355# This rule provides exactly the same code as the %.variables one with
356# respect to subprojects; it is available for clean targets when they
357# want to run make clean in subprojects but do not need a full Instance
358# invocation.  In that case, they can depend on %.subprojects only.
359#
360# NB: The OWNING_PROJECT_HEADER_DIR_NAME hack in this rule is sort of
361# horrible, because it pollutes this general rule with code specific
362# to the framework implementation (eg, where the framework headers are
363# located).  Still, it's the least evil we could think of at the
364# moment :-) The framework code is now completely confined into
365# framework.make makefiles, except for this little hack in here.  It
366# would be nice to remove this hack without loosing functionality (or
367# polluting other general-purpose makefiles).
368%.subprojects:
369	$(ECHO_NOTHING_RECURSIVE_MAKE) \
370instance=$(basename $(basename $*)); \
371operation=$(subst .,,$(suffix $(basename $*))); \
372type=$(subst -,_,$(subst .,,$(suffix $*))); \
373abs_build_dir="$(ABS_GNUSTEP_BUILD_DIR)"; \
374if [ "$($(basename $(basename $*))_SUBPROJECTS)" != "" ]; then \
375  $(INSIDE_ECHO_MAKING_OPERATION_IN_SUBPROJECTS) \
376  for f in $($(basename $(basename $*))_SUBPROJECTS) __done; do \
377    if [ $$f != __done ]; then       \
378      if [ "$${abs_build_dir}" = "." ]; then \
379        gsbuild="."; \
380      else \
381        gsbuild="$${abs_build_dir}/$$f"; \
382      fi; \
383      if [ "$(OWNING_PROJECT_HEADER_DIR_NAME)" = "" ]; then \
384        if [ "$$type" = "framework" ]; then \
385          if [ "$(FRAMEWORK_VERSION_SUPPORT)" = "yes" ]; then \
386            framework_version="$($(basename $(basename $*))_CURRENT_VERSION_NAME)"; \
387            if [ "$$framework_version" = "" ]; then \
388              framework_version="$($(basename $(basename $*))_INTERFACE_VERSION)"; \
389              if [ "$$framework_version" = "" ]; then \
390                framework_version="$(word 1,$(subst ., ,$($(basename $(basename $*))_VERSION)))"; \
391                if [ "$$framework_version" = "" ]; then \
392                  framework_version="0"; \
393                fi; \
394              fi; \
395            fi; \
396            owning_project_header_dir="../$${instance}.framework/Versions/$${framework_version}/Headers"; \
397          else \
398            owning_project_header_dir="../$${instance}.framework/Headers"; \
399          fi; \
400       else owning_project_header_dir=""; \
401       fi; \
402      else \
403        owning_project_header_dir="../$(OWNING_PROJECT_HEADER_DIR_NAME)"; \
404      fi; \
405      if $(MAKE) -C $$f -f $(MAKEFILE_NAME) $(GNUSTEP_MAKE_NO_PRINT_DIRECTORY_FLAG) --no-keep-going $$operation \
406          OWNING_PROJECT_HEADER_DIR_NAME="$${owning_project_header_dir}" \
407          DERIVED_SOURCES="../$(DERIVED_SOURCES)" \
408          GNUSTEP_BUILD_DIR="$$gsbuild" \
409	  _GNUSTEP_MAKE_PARALLEL=no \
410        ; then \
411        :; \
412      else exit $$?; \
413      fi; \
414    fi; \
415  done; \
416fi$(END_ECHO_RECURSIVE_MAKE)
417
418#
419# Now rules for packaging - all automatically included
420#
421
422PACKAGE_NAME := $(strip $(PACKAGE_NAME))
423
424ifeq ($(PACKAGE_NAME),)
425  # Use a default of unnamed-package if nothing better is provided.
426  PACKAGE_NAME = unnamed-package
427endif
428
429# For backwards compatibility, take value of PACKAGE_VERSION from
430# VERSION.  New GNUmakefiles should all use the PACKAGE_VERSION
431# variable rather than the VERSION variable.
432ifeq ($(PACKAGE_VERSION),)
433
434  PACKAGE_VERSION = $(VERSION)
435
436  # Use a default of 0.0.1 if nothing better is provided.
437  ifeq ($(PACKAGE_VERSION),)
438    PACKAGE_VERSION = 0.0.1
439  endif
440
441endif
442
443#
444# Rules for building source distributions
445#
446include $(GNUSTEP_MAKEFILES)/Master/source-distribution.make
447
448#
449# Rules for building spec files/file lists for RPMs, and RPMs
450#
451include $(GNUSTEP_MAKEFILES)/Master/rpm.make
452
453#
454# Rules for building debian/* scripts for DEBs, and DEBs
455#
456#include $(GNUSTEP_MAKEFILES)/Master/deb.make <TODO>
457
458