4 # All of the common makefile rules.
6 # Copyright (C) 1997, 2001 Free Software Foundation, Inc.
8 # Author: Scott Christley <scottc@net-community.com>
9 # Author: Ovidiu Predescu <ovidiu@net-community.com>
10 # Author: Nicola Pero <nicola@brainstorm.co.uk>
12 # This file is part of the GNUstep Makefile Package.
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.
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 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 # prevent multiple inclusions
26 # NB: This file is internally protected against multiple inclusions.
27 # But for perfomance reasons, you might want to check the
28 # RULES_MAKE_LOADED variable yourself and include this file only if it
29 # is empty. That allows make to skip reading the file entirely when it
30 # has already been read. We use this trick for all system makefiles.
31 ifeq ($(RULES_MAKE_LOADED),)
34 # Include the Master rules at the beginning because the 'all' rule must be
35 # first on the first invocation without a specified target.
36 ifeq ($(GNUSTEP_INSTANCE),)
37 include $(GNUSTEP_MAKEFILES)/Master/rules.make
41 # If INSTALL_AS_USER and/or INSTALL_AS_GROUP are defined, pass them down
42 # to submakes. There are two reasons -
44 # 1. so that if you set them in a GNUmakefile, they get passed down
45 # to automatically generated sources/GNUmakefiles (such as Java wrappers)
46 # 2. so that if you type `make install INSTALL_AS_USER=nicola' in a directory,
47 # the INSTALL_AS_USER=nicola gets automatically used in all subdirectories.
49 # Warning - if you want to hardcode a INSTALL_AS_USER in a GNUmakefile, then
50 # you shouldn't rely on us to pass it down to subGNUmakefiles - you should
51 # rather hardcode INSTALL_AS_USER in all your GNUmakefiles (or better have
52 # a makefile fragment defining INSTALL_AS_USER in the top-level and include
53 # it in all GNUmakefiles) - otherwise what happens is that if you go in a
54 # subdirectory and type 'make install' there, it will not get the
55 # INSTALL_AS_USER from the higher level GNUmakefile, so it will install with
56 # the wrong user! For this reason, if you need to hardcode INSTALL_AS_USER
57 # in GNUmakefiles, make sure it's hardcoded *everywhere*.
59 ifneq ($(INSTALL_AS_USER),)
60 export INSTALL_AS_USER
63 ifneq ($(INSTALL_AS_GROUP),)
64 export INSTALL_AS_GROUP
68 # In subprojects, will be set by the recursive make invocation on the
69 # make command line to be [../../]../derived_src
70 DERIVED_SOURCES = derived_src
71 DERIVED_SOURCES_DIR = $(GNUSTEP_BUILD_DIR)/$(DERIVED_SOURCES)
73 # Always include all the compilation flags and generic compilation
74 # rules, because the user, in his GNUmakefile.postamble, might want to
75 # add manual commands for example to after-all, which are processed
76 # during the Master invocation, but yet can compile or install stuff
77 # and need access to all compilation/installation flags and locations
89 # Prepare the arguments to install to set user/group of installed files
93 ifneq ($(INSTALL_AS_USER),)
94 INSTALL_AS += -o $(INSTALL_AS_USER)
97 ifneq ($(INSTALL_AS_GROUP),)
98 INSTALL_AS += -g $(INSTALL_AS_GROUP)
101 # Redefine INSTALL to include these flags. This automatically
102 # redefines INSTALL_DATA and INSTALL_PROGRAM as well, because they are
103 # define in terms of INSTALL.
104 INSTALL += $(INSTALL_AS)
106 # Sometimes, we install without using INSTALL - typically using tar.
107 # In those cases, we run chown after having installed, in order to
108 # fixup the user/group.
111 # Prepare the arguments to chown to set user/group of installed files.
113 ifneq ($(INSTALL_AS_GROUP),)
114 CHOWN_TO = $(strip $(INSTALL_AS_USER)).$(strip $(INSTALL_AS_GROUP))
116 CHOWN_TO = $(strip $(INSTALL_AS_USER))
119 # You need to run CHOWN manually, but only if CHOWN_TO is non-empty.
122 # Pass the CHOWN_TO argument to MKINSTALLDIRS
123 # All installation directories should be created using MKINSTALLDIRS
124 # to make sure we set the correct user/group. Local directories should
125 # be created using MKDIRS instead because we don't want to set user/group.
128 MKINSTALLDIRS = $(MKDIRS) -c $(CHOWN_TO)
129 # Fixup the library installation commands if needed so that we change
130 # ownership of the links as well
132 AFTER_INSTALL_LIBRARY_CMD += ; $(AFTER_INSTALL_SHARED_LIB_CHOWN)
135 MKINSTALLDIRS = $(MKDIRS)
139 # If this is part of the compilation of a framework,
140 # add -I[$GNUSTEP_BUILD_DIR][../../../etc]derived_src so that the code
141 # can include framework headers simply using `#include
142 # <MyFramework/MyHeader.h>'
144 # If it's a framework makefile, FRAMEWORK_NAME will be non-empty. If
145 # it's a framework subproject, OWNING_PROJECT_HEADER_DIR_NAME will be
148 ifneq ($(FRAMEWORK_NAME)$(OWNING_PROJECT_HEADER_DIR_NAME),)
149 DERIVED_SOURCES_HEADERS_FLAG = -I$(DERIVED_SOURCES_DIR)
153 # Include rules to built the instance
155 # this fixes up ADDITIONAL_XXXFLAGS as well, which is why we include it
156 # before using ADDITIONAL_XXXFLAGS
158 ifneq ($(GNUSTEP_INSTANCE),)
159 include $(GNUSTEP_MAKEFILES)/Instance/rules.make
163 # Implement ADDITIONAL_NATIVE_LIBS
165 # A native lib is a framework on apple, and a shared library
166 # everywhere else. Here we provide the appropriate link flags
167 # to support it transparently on the two platforms.
169 ifeq ($(FOUNDATION_LIB),apple)
170 ADDITIONAL_OBJC_LIBS += $(foreach lib,$(ADDITIONAL_NATIVE_LIBS),-framework $(lib))
172 ADDITIONAL_OBJC_LIBS += $(foreach lib,$(ADDITIONAL_NATIVE_LIBS),-l$(lib))
178 # -MMD -MP tells gcc to generate a .d file for each compiled file,
179 # which includes makefile rules adding dependencies of the compiled
180 # file on all the header files the source file includes ...
182 # next time `make' is run, we include the .d files for the previous
183 # run (if we find them) ... this automatically adds dependencies on
184 # the appropriate header files
187 # Warning - the following variable name might change
188 ifeq ($(AUTO_DEPENDENCIES),yes)
189 ifeq ($(AUTO_DEPENDENCIES_FLAGS),)
190 AUTO_DEPENDENCIES_FLAGS = -MMD -MP
194 # The difference between ADDITIONAL_XXXFLAGS and AUXILIARY_XXXFLAGS is the
197 # ADDITIONAL_XXXFLAGS are set freely by the user GNUmakefile
199 # AUXILIARY_XXXFLAGS are set freely by makefile fragments installed by
200 # auxiliary packages. For example, gnustep-db installs
201 # a gdl.make file. If you want to use gnustep-db in
202 # your tool, you `include $(GNUSTEP_MAKEFILES)/gdl.make'
203 # and that will add the appropriate flags to link against
204 # gnustep-db. Those flags are added to AUXILIARY_XXXFLAGS.
206 # Why can't ADDITIONAL_XXXFLAGS and AUXILIARY_XXXFLAGS be the same variable ?
207 # Good question :-) I'm not sure but I think the original reason is that
208 # users tend to think they can do whatever they want with ADDITIONAL_XXXFLAGS,
210 # ADDITIONAL_XXXFLAGS = -Verbose
211 # (with a '=' instead of a '+=', thus discarding the previous value of
212 # ADDITIONAL_XXXFLAGS) without caring for the fact that other makefiles
213 # might need to add something to ADDITIONAL_XXXFLAGS.
215 # So the idea is that ADDITIONAL_XXXFLAGS is reserved for the users to
216 # do whatever mess they like with them, while in makefile fragments
217 # from packages we use a different variable, which is subject to a stricter
218 # control, requiring package authors to always write
220 # AUXILIARY_XXXFLAGS += -Verbose
222 # in their auxiliary makefile fragments, to make sure they don't
223 # override flags from different packages, just add to them.
225 # When building up command lines inside gnustep-make, we always need
226 # to add both AUXILIARY_XXXFLAGS and ADDITIONAL_XXXFLAGS to all
227 # compilation/linking/etc command.
230 ALL_CPPFLAGS = $(AUTO_DEPENDENCIES_FLAGS) $(CPPFLAGS) $(ADDITIONAL_CPPFLAGS) \
231 $(AUXILIARY_CPPFLAGS)
233 ALL_OBJCFLAGS = $(INTERNAL_OBJCFLAGS) $(ADDITIONAL_OBJCFLAGS) \
234 $(AUXILIARY_OBJCFLAGS) $(ADDITIONAL_INCLUDE_DIRS) \
235 $(AUXILIARY_INCLUDE_DIRS) \
236 $(DERIVED_SOURCES_HEADERS_FLAG) \
237 -I. $(SYSTEM_INCLUDES) \
238 $(GNUSTEP_HEADERS_FLAGS) \
239 $(GNUSTEP_FRAMEWORKS_FLAGS)
241 ALL_CFLAGS = $(INTERNAL_CFLAGS) $(ADDITIONAL_CFLAGS) \
242 $(AUXILIARY_CFLAGS) $(ADDITIONAL_INCLUDE_DIRS) \
243 $(AUXILIARY_INCLUDE_DIRS) \
244 $(DERIVED_SOURCES_HEADERS_FLAG) \
245 -I. $(SYSTEM_INCLUDES) \
246 $(GNUSTEP_HEADERS_FLAGS) \
247 $(GNUSTEP_FRAMEWORKS_FLAGS)
249 # if you need, you can define ADDITIONAL_CCFLAGS to add C++ specific flags
250 ALL_CCFLAGS = $(ADDITIONAL_CCFLAGS) $(AUXILIARY_CCFLAGS)
252 INTERNAL_CLASSPATHFLAGS = -classpath ./$(subst ::,:,:$(strip $(ADDITIONAL_CLASSPATH)):)$(CLASSPATH)
254 ALL_JAVACFLAGS = $(INTERNAL_CLASSPATHFLAGS) $(INTERNAL_JAVACFLAGS) \
255 $(ADDITIONAL_JAVACFLAGS) $(AUXILIARY_JAVACFLAGS)
257 ALL_JAVAHFLAGS = $(INTERNAL_CLASSPATHFLAGS) $(ADDITIONAL_JAVAHFLAGS) \
258 $(AUXILIARY_JAVAHFLAGS)
261 ALL_LDFLAGS = $(STATIC_LDFLAGS)
265 ALL_LDFLAGS += $(ADDITIONAL_LDFLAGS) $(AUXILIARY_LDFLAGS) $(GUI_LDFLAGS) \
266 $(BACKEND_LDFLAGS) $(SYSTEM_LDFLAGS) $(INTERNAL_LDFLAGS)
268 ALL_LIB_DIRS = $(ADDITIONAL_FRAMEWORK_DIRS) $(AUXILIARY_FRAMEWORK_DIRS) \
269 $(ADDITIONAL_LIB_DIRS) $(AUXILIARY_LIB_DIRS) \
270 $(GNUSTEP_LIBRARIES_FLAGS) \
271 $(GNUSTEP_FRAMEWORKS_FLAGS) \
274 # We use .plist (property-list files, see gnustep-base) in quite a few
275 # cases. Whenever a .plist file is required, you can/will be allowed
276 # to provide a .cplist file instead (at the moment, it is only
277 # implemented for applications' xxxInfo.plist). A .cplist file is a
278 # property-list file with C preprocessor conditionals. gnustep-make
279 # will automatically generate the .plist file from the .cplist file by
280 # running the C preprocessor.
282 # The CPLISTFLAGS are the flags used when running the C preprocessor
283 # to generate a .plist file from a .cplist file.
284 ALL_CPLISTFLAGS = -P -x c -traditional
286 ifeq ($(FOUNDATION_LIB), gnu)
287 ALL_CPLISTFLAGS += -DGNUSTEP
289 ifeq ($(FOUNDATION_LIB), apple)
290 ALL_CPLISTFLAGS += -DAPPLE
292 ifeq ($(FOUNDATION_LIB), nx)
293 ALL_CPLISTFLAGS += -DNEXT
295 ALL_CPLISTFLAGS += -DUNKNOWN
300 ALL_CPLISTFLAGS += $(ADDITIONAL_CPLISTFLAGS) $(AUXILIARY_CPLISTFLAGS)
303 # If we are using Windows32 DLLs, we pass -DGNUSTEP_WITH_DLL to the
304 # compiler. This preprocessor define might be used by library header
305 # files to know they are included from external code needing to use
306 # the library symbols, so that the library header files can in this
307 # case use __declspec(dllimport) to mark symbols as needing to be put
308 # into the import table for the executable/library/whatever that is
310 ifeq ($(WITH_DLL),yes)
311 ALL_CPPFLAGS += -DGNUSTEP_WITH_DLL
317 # Disable all built-in suffixes for performance.
320 # Then define our own.
321 .SUFFIXES: .m .c .psw .java .h .cpp .cxx .C .cc .cp
323 .PRECIOUS: %.c %.h $(GNUSTEP_OBJ_DIR)/%${OEXT}
325 # Disable all built-in rules with a vague % as target, for performance.
347 # In exceptional conditions, you might need to want to use different compiler
348 # flags for a file (for example, if a file doesn't compile with optimization
349 # turned on, you might want to compile that single file with optimizations
350 # turned off). gnustep-make allows you to do this - you can specify special
351 # flags to be used when compiling a *specific* file in two ways -
353 # xxx_FILE_FLAGS (where xxx is the file name, such as main.m)
354 # are special compilation flags to be used when compiling xxx
356 # xxx_FILE_FILTER_OUT_FLAGS (where xxx is the file name, such as mframe.m)
357 # is a filter-out make pattern of flags to be filtered out
358 # from the compilation flags when compiling xxx.
362 # Disable optimization flags for the file NSInvocation.m:
363 # NSInvocation.m_FILE_FILTER_OUT_FLAGS = -O%
365 # Disable optimization flags for the same file, and also remove
366 # -fomit-frame-pointer:
367 # NSInvocation.m_FILE_FILTER_OUT_FLAGS = -O% -fomit-frame-pointer
369 # Force the compiler to warn for #import if used in file file.m:
370 # file.m_FILE_FLAGS = -Wimport
371 # file.m_FILE_FILTER_OUT_FLAGS = -Wno-import
374 # Please don't be scared by the following rules ... In normal
375 # situations, $<_FILTER_OUT_FLAGS is empty, and $<_FILE_FLAGS is empty
376 # as well, so the following rule is simply equivalent to
377 # $(CC) $< -c $(ALL_CPPFLAGS) $(ALL_CFLAGS) -o $@
378 # and similarly all the rules below
379 $(GNUSTEP_OBJ_DIR)/%${OEXT} : %.c
380 $(ECHO_COMPILING)$(CC) $< -c \
381 $(filter-out $($<_FILE_FILTER_OUT_FLAGS),$(ALL_CPPFLAGS) \
383 $($<_FILE_FLAGS) -o $@$(END_ECHO)
385 $(GNUSTEP_OBJ_DIR)/%${OEXT} : %.m
386 $(ECHO_COMPILING)$(CC) $< -c \
387 $(filter-out $($<_FILE_FILTER_OUT_FLAGS),$(ALL_CPPFLAGS) \
389 $($<_FILE_FLAGS) -o $@$(END_ECHO)
391 $(GNUSTEP_OBJ_DIR)/%${OEXT} : %.C
392 $(ECHO_COMPILING)$(CC) $< -c \
393 $(filter-out $($<_FILE_FILTER_OUT_FLAGS),$(ALL_CPPFLAGS) \
396 $($<_FILE_FLAGS) -o $@$(END_ECHO)
398 $(GNUSTEP_OBJ_DIR)/%${OEXT} : %.cc
399 $(ECHO_COMPILING)$(CC) $< -c \
400 $(filter-out $($<_FILE_FILTER_OUT_FLAGS),$(ALL_CPPFLAGS) \
403 $($<_FILE_FLAGS) -o $@$(END_ECHO)
405 $(GNUSTEP_OBJ_DIR)/%${OEXT} : %.cpp
406 $(ECHO_COMPILING)$(CC) $< -c \
407 $(filter-out $($<_FILE_FILTER_OUT_FLAGS),$(ALL_CPPFLAGS) \
410 $($<_FILE_FLAGS) -o $@$(END_ECHO)
412 $(GNUSTEP_OBJ_DIR)/%${OEXT} : %.cxx
413 $(ECHO_COMPILING)$(CC) $< -c \
414 $(filter-out $($<_FILE_FILTER_OUT_FLAGS),$(ALL_CPPFLAGS) \
417 $($<_FILE_FLAGS) -o $@$(END_ECHO)
419 $(GNUSTEP_OBJ_DIR)/%${OEXT} : %.cp
420 $(ECHO_COMPILING)$(CC) $< -c \
421 $(filter-out $($<_FILE_FILTER_OUT_FLAGS),$(ALL_CPPFLAGS) \
424 $($<_FILE_FLAGS) -o $@$(END_ECHO)
427 $(ECHO_COMPILING)$(JAVAC) \
428 $(filter-out $($<_FILE_FILTER_OUT_FLAGS),$(ALL_JAVACFLAGS)) \
429 $($<_FILE_FLAGS) $<$(END_ECHO)
431 # A jni header file which is created using JAVAH
432 # Example of how this rule will be applied:
433 # gnu/gnustep/base/NSObject.h : gnu/gnustep/base/NSObject.java
434 # javah -o gnu/gnustep/base/NSObject.h gnu.gnustep.base.NSObject
436 $(ECHO_JAVAHING)$(JAVAH) \
437 $(filter-out $($<_FILE_FILTER_OUT_FLAGS),$(ALL_JAVAHFLAGS)) \
438 $($<_FILE_FLAGS) -o $@ $(subst /,.,$*)$(END_ECHO)
441 pswrap -h $*.h -o $@ $<
443 # The following rule is needed because in frameworks you might need
444 # the .h files before the .c files are compiled.
446 pswrap -h $@ -o $*.c $<
448 # Rule to generate a .plist file (a property list file) by running the
449 # preprocessor on a .cplist file (a property list file with embedded C
450 # preprocessor conditionals). Useful in order to have a single
451 # xxxInfo.plist file for multiple platforms (read GNUstep and Apple)
452 # for the same application (to make portability easier). You can have
453 # a single xxxInfo.cplist file, and xxxInfo.plist will automatically
454 # be generated by gnustep-make from xxxInfo.cplist by running the
457 # Unfortunately, on some platforms (Apple) the preprocessor emits
458 # unwanted and unrequested #pragma statements. We use sed to filter
462 $(ECHO_PREPROCESSING)$(CPP) \
463 $(filter-out $($<_FILE_FILTER_OUT_FLAGS),$(ALL_CPLISTFLAGS))\
464 $($<_FILE_FLAGS) $< | sed '/^#pragma/d' > $@$(END_ECHO)
466 # The following rule builds a .c file from a lex .l file.
467 # You can define LEX_FLAGS if you need them.
469 $(LEX) $(LEX_FLAGS) -t $< > $@
471 # The following rule builds a .c file from a yacc/bison .y file.
472 # You can define YACC_FLAGS if you need them.
474 $(YACC) $(YACC_FLAGS) $<
477 # The following dummy rules are needed for performance - we need to
478 # prevent make from spending time trying to compute how/if to rebuild
479 # the system makefiles! the following rules tell him that these files
480 # are always up-to-date
482 $(GNUSTEP_MAKEFILES)/*.make: ;
484 $(GNUSTEP_MAKEFILES)/$(GNUSTEP_TARGET_DIR)/config.make: ;
486 $(GNUSTEP_MAKEFILES)/Additional/*.make: ;
488 $(GNUSTEP_MAKEFILES)/Master/*.make: ;
490 $(GNUSTEP_MAKEFILES)/Instance/*.make: ;
492 $(GNUSTEP_MAKEFILES)/Instance/Shared/*.make: ;
494 $(GNUSTEP_MAKEFILES)/Instance/Documentation/*.make: ;
496 # The rule to create the GNUSTEP_BUILD_DIR if any.
497 ifneq ($(GNUSTEP_BUILD_DIR),.)
498 $(GNUSTEP_BUILD_DIR):
499 $(ECHO_CREATING)$(MKDIRS) $(GNUSTEP_BUILD_DIR)$(END_ECHO)
502 # The rule to create the objects file directory.
504 $(ECHO_NOTHING)cd $(GNUSTEP_BUILD_DIR); \
505 $(MKDIRS) ./$(GNUSTEP_OBJ_DIR_NAME); \
507 $(LN_S) ./$(GNUSTEP_OBJ_DIR_NAME) obj$(END_ECHO)