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 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ALL_AOT_JAVAFLAGS = $(INTERNAL_AOT_JAVAFLAGS) $(ADDITIONAL_AOT_JAVAFLAGS) \
250 $(AUXILIARY_AOT_JAVAFLAGS) $(ADDITIONAL_INCLUDE_DIRS) \
251 $(AUXILIARY_INCLUDE_DIRS) \
252 $(DERIVED_SOURCES_HEADERS_FLAG) \
253 -I. $(SYSTEM_INCLUDES) \
254 $(GNUSTEP_HEADERS_FLAGS) \
255 $(GNUSTEP_FRAMEWORKS_FLAGS)
257 # if you need, you can define ADDITIONAL_CCFLAGS to add C++ specific flags
258 ALL_CCFLAGS = $(ADDITIONAL_CCFLAGS) $(AUXILIARY_CCFLAGS)
260 INTERNAL_CLASSPATHFLAGS = -classpath ./$(subst ::,:,:$(strip $(ADDITIONAL_CLASSPATH)):)$(CLASSPATH)
262 ALL_JAVACFLAGS = $(INTERNAL_CLASSPATHFLAGS) $(INTERNAL_JAVACFLAGS) \
263 $(ADDITIONAL_JAVACFLAGS) $(AUXILIARY_JAVACFLAGS)
265 ALL_JAVAHFLAGS = $(INTERNAL_CLASSPATHFLAGS) $(ADDITIONAL_JAVAHFLAGS) \
266 $(AUXILIARY_JAVAHFLAGS)
269 ALL_LDFLAGS = $(STATIC_LDFLAGS)
273 ALL_LDFLAGS += $(ADDITIONAL_LDFLAGS) $(AUXILIARY_LDFLAGS) $(GUI_LDFLAGS) \
274 $(BACKEND_LDFLAGS) $(SYSTEM_LDFLAGS) $(INTERNAL_LDFLAGS)
276 ALL_LIB_DIRS = $(ADDITIONAL_FRAMEWORK_DIRS) $(AUXILIARY_FRAMEWORK_DIRS) \
277 $(ADDITIONAL_LIB_DIRS) $(AUXILIARY_LIB_DIRS) \
278 $(GNUSTEP_LIBRARIES_FLAGS) \
279 $(GNUSTEP_FRAMEWORKS_FLAGS) \
282 # We use .plist (property-list files, see gnustep-base) in quite a few
283 # cases. Whenever a .plist file is required, you can/will be allowed
284 # to provide a .cplist file instead (at the moment, it is only
285 # implemented for applications' xxxInfo.plist). A .cplist file is a
286 # property-list file with C preprocessor conditionals. gnustep-make
287 # will automatically generate the .plist file from the .cplist file by
288 # running the C preprocessor.
290 # The CPLISTFLAGS are the flags used when running the C preprocessor
291 # to generate a .plist file from a .cplist file.
292 ALL_CPLISTFLAGS = -P -x c -traditional
294 ifeq ($(FOUNDATION_LIB), gnu)
295 ALL_CPLISTFLAGS += -DGNUSTEP
297 ifeq ($(FOUNDATION_LIB), apple)
298 ALL_CPLISTFLAGS += -DAPPLE
300 ifeq ($(FOUNDATION_LIB), nx)
301 ALL_CPLISTFLAGS += -DNEXT
303 ALL_CPLISTFLAGS += -DUNKNOWN
308 ALL_CPLISTFLAGS += $(ADDITIONAL_CPLISTFLAGS) $(AUXILIARY_CPLISTFLAGS)
311 # If we are using Windows32 DLLs, we pass -DGNUSTEP_WITH_DLL to the
312 # compiler. This preprocessor define might be used by library header
313 # files to know they are included from external code needing to use
314 # the library symbols, so that the library header files can in this
315 # case use __declspec(dllimport) to mark symbols as needing to be put
316 # into the import table for the executable/library/whatever that is
319 # In the new DLL support, this is usually no longer needed. The
320 # compiler does it all automatically. But in some cases, some symbols
321 # can not be automatically imported and you might want to declare them
322 # specially. For those symbols, this define is handy.
324 ifeq ($(BUILD_DLL),yes)
325 ALL_CPPFLAGS += -DGNUSTEP_WITH_DLL
331 # Disable all built-in suffixes for performance.
334 # Then define our own.
335 .SUFFIXES: .m .c .psw .java .h .cpp .cxx .C .cc .cp
337 .PRECIOUS: %.c %.h $(GNUSTEP_OBJ_DIR)/%${OEXT}
339 # Disable all built-in rules with a vague % as target, for performance.
361 # In exceptional conditions, you might need to want to use different compiler
362 # flags for a file (for example, if a file doesn't compile with optimization
363 # turned on, you might want to compile that single file with optimizations
364 # turned off). gnustep-make allows you to do this - you can specify special
365 # flags to be used when compiling a *specific* file in two ways -
367 # xxx_FILE_FLAGS (where xxx is the file name, such as main.m)
368 # are special compilation flags to be used when compiling xxx
370 # xxx_FILE_FILTER_OUT_FLAGS (where xxx is the file name, such as mframe.m)
371 # is a filter-out make pattern of flags to be filtered out
372 # from the compilation flags when compiling xxx.
376 # Disable optimization flags for the file NSInvocation.m:
377 # NSInvocation.m_FILE_FILTER_OUT_FLAGS = -O%
379 # Disable optimization flags for the same file, and also remove
380 # -fomit-frame-pointer:
381 # NSInvocation.m_FILE_FILTER_OUT_FLAGS = -O% -fomit-frame-pointer
383 # Force the compiler to warn for #import if used in file file.m:
384 # file.m_FILE_FLAGS = -Wimport
385 # file.m_FILE_FILTER_OUT_FLAGS = -Wno-import
388 # Please don't be scared by the following rules ... In normal
389 # situations, $<_FILTER_OUT_FLAGS is empty, and $<_FILE_FLAGS is empty
390 # as well, so the following rule is simply equivalent to
391 # $(CC) $< -c $(ALL_CPPFLAGS) $(ALL_CFLAGS) -o $@
392 # and similarly all the rules below
393 $(GNUSTEP_OBJ_DIR)/%${OEXT} : %.c
394 $(ECHO_COMPILING)$(CC) $< -c \
395 $(filter-out $($<_FILE_FILTER_OUT_FLAGS),$(ALL_CPPFLAGS) \
397 $($<_FILE_FLAGS) -o $@$(END_ECHO)
399 $(GNUSTEP_OBJ_DIR)/%${OEXT} : %.m
400 $(ECHO_COMPILING)$(CC) $< -c \
401 $(filter-out $($<_FILE_FILTER_OUT_FLAGS),$(ALL_CPPFLAGS) \
403 $(PCH_INCLUDE_FLAG) \
404 $($<_FILE_FLAGS) -o $@$(END_ECHO)
406 $(GNUSTEP_OBJ_DIR)/%${OEXT} : %.java
407 $(ECHO_COMPILING)$(CC) $< -c \
408 $(filter-out -D%,$(ALL_CPPFLAGS) $(ALL_AOT_JAVAFLAGS)) \
409 $(PCH_INCLUDE_FLAG) \
410 $($<_FILE_FLAGS) -o $@$(END_ECHO)
412 $(GNUSTEP_OBJ_DIR)/%${OEXT} : %.C
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} : %.cc
420 $(ECHO_COMPILING)$(CC) $< -c \
421 $(filter-out $($<_FILE_FILTER_OUT_FLAGS),$(ALL_CPPFLAGS) \
424 $($<_FILE_FLAGS) -o $@$(END_ECHO)
426 $(GNUSTEP_OBJ_DIR)/%${OEXT} : %.cpp
427 $(ECHO_COMPILING)$(CC) $< -c \
428 $(filter-out $($<_FILE_FILTER_OUT_FLAGS),$(ALL_CPPFLAGS) \
431 $($<_FILE_FLAGS) -o $@$(END_ECHO)
433 $(GNUSTEP_OBJ_DIR)/%${OEXT} : %.cxx
434 $(ECHO_COMPILING)$(CC) $< -c \
435 $(filter-out $($<_FILE_FILTER_OUT_FLAGS),$(ALL_CPPFLAGS) \
438 $($<_FILE_FLAGS) -o $@$(END_ECHO)
440 $(GNUSTEP_OBJ_DIR)/%${OEXT} : %.cp
441 $(ECHO_COMPILING)$(CC) $< -c \
442 $(filter-out $($<_FILE_FILTER_OUT_FLAGS),$(ALL_CPPFLAGS) \
445 $($<_FILE_FLAGS) -o $@$(END_ECHO)
447 # precompiled header files
448 # TODO: should go into GNUSTEP_OBJ_DIR?
449 # TODO: we need to create the derived_src here because there is no rule yet
450 # in the include path?
452 $(DERIVED_SOURCES_DIR)/%$(GCH_SUFFIX): %.h
453 $(ECHO_NOTHING)if ! test -d $(DERIVED_SOURCES_DIR); then \
454 $(MKDIRS) $(DERIVED_SOURCES_DIR); \
456 $(ECHO_COMPILING)$(CC) -x objective-c-header $< -c \
457 $(filter-out $($<_FILE_FILTER_OUT_FLAGS),$(ALL_CPPFLAGS) \
459 $($<_FILE_FLAGS) -o $@$(END_ECHO)
462 $(ECHO_COMPILING)$(JAVAC) \
463 $(filter-out $($<_FILE_FILTER_OUT_FLAGS),$(ALL_JAVACFLAGS)) \
464 $($<_FILE_FLAGS) $<$(END_ECHO)
466 # A jni header file which is created using JAVAH
467 # Example of how this rule will be applied:
468 # gnu/gnustep/base/NSObject.h : gnu/gnustep/base/NSObject.java
469 # javah -o gnu/gnustep/base/NSObject.h gnu.gnustep.base.NSObject
471 $(ECHO_JAVAHING)$(JAVAH) \
472 $(filter-out $($<_FILE_FILTER_OUT_FLAGS),$(ALL_JAVAHFLAGS)) \
473 $($<_FILE_FLAGS) -o $@ $(subst /,.,$*)$(END_ECHO)
476 pswrap -h $*.h -o $@ $<
478 # The following rule is needed because in frameworks you might need
479 # the .h files before the .c files are compiled.
481 pswrap -h $@ -o $*.c $<
483 # Rule to generate a .plist file (a property list file) by running the
484 # preprocessor on a .cplist file (a property list file with embedded C
485 # preprocessor conditionals). Useful in order to have a single
486 # xxxInfo.plist file for multiple platforms (read GNUstep and Apple)
487 # for the same application (to make portability easier). You can have
488 # a single xxxInfo.cplist file, and xxxInfo.plist will automatically
489 # be generated by gnustep-make from xxxInfo.cplist by running the
492 # Unfortunately, on some platforms (Apple) the preprocessor emits
493 # unwanted and unrequested #pragma statements. We use sed to filter
497 $(ECHO_PREPROCESSING)$(CPP) \
498 $(filter-out $($<_FILE_FILTER_OUT_FLAGS),$(ALL_CPLISTFLAGS))\
499 $($<_FILE_FLAGS) $< | sed '/^#pragma/d' > $@$(END_ECHO)
501 # The following rule builds a .c file from a lex .l file.
502 # You can define LEX_FLAGS if you need them.
504 $(LEX) $(LEX_FLAGS) -t $< > $@
506 # The following rule builds a .c file from a yacc/bison .y file.
507 # You can define YACC_FLAGS if you need them.
509 $(YACC) $(YACC_FLAGS) $<
513 # Special mingw32 specific rules to compile Windows resource files (.rc files)
516 ifeq ($(findstring mingw32, $(GNUSTEP_TARGET_OS)), mingw32)
517 # Add the .rc suffix on Windows.
520 # A rule to generate a .o file from the .rc file.
521 $(GNUSTEP_OBJ_DIR)/%${OEXT}: %.rc
522 $(ECHO_COMPILING)windres $< $@$(END_ECHO)
526 # The following dummy rules are needed for performance - we need to
527 # prevent make from spending time trying to compute how/if to rebuild
528 # the system makefiles! the following rules tell him that these files
529 # are always up-to-date
531 $(GNUSTEP_MAKEFILES)/*.make: ;
533 $(GNUSTEP_MAKEFILES)/$(GNUSTEP_TARGET_DIR)/config.make: ;
535 $(GNUSTEP_MAKEFILES)/Additional/*.make: ;
537 $(GNUSTEP_MAKEFILES)/Master/*.make: ;
539 $(GNUSTEP_MAKEFILES)/Instance/*.make: ;
541 $(GNUSTEP_MAKEFILES)/Instance/Shared/*.make: ;
543 $(GNUSTEP_MAKEFILES)/Instance/Documentation/*.make: ;
545 # The rule to create the GNUSTEP_BUILD_DIR if any.
546 ifneq ($(GNUSTEP_BUILD_DIR),.)
547 $(GNUSTEP_BUILD_DIR):
548 $(ECHO_CREATING)$(MKDIRS) $(GNUSTEP_BUILD_DIR)$(END_ECHO)
551 # The rule to create the objects file directory.
553 $(ECHO_NOTHING)cd $(GNUSTEP_BUILD_DIR); \
554 $(MKDIRS) ./$(GNUSTEP_OBJ_DIR_NAME); \
556 $(LN_S) ./$(GNUSTEP_OBJ_DIR_NAME) obj$(END_ECHO)