]> err.no Git - sope/blob - rules.make
332e369c276bf2fca5eff2ece8fcf1433d165b48
[sope] / rules.make
1 #   -*-makefile-*-
2 #   rules.make
3 #
4 #   All of the common makefile rules.
5 #
6 #   Copyright (C) 1997, 2001 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 #   59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24 # prevent multiple inclusions
25
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),)
32 RULES_MAKE_LOADED=yes
33
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
38 endif
39
40 #
41 # If INSTALL_AS_USER and/or INSTALL_AS_GROUP are defined, pass them down
42 # to submakes.  There are two reasons - 
43 #
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.
48 #
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*.
58 #
59 ifneq ($(INSTALL_AS_USER),)
60   export INSTALL_AS_USER
61 endif
62
63 ifneq ($(INSTALL_AS_GROUP),)
64   export INSTALL_AS_GROUP
65 endif
66
67
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)
72
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
78 # and basic rules.
79
80 #
81 # Manage stripping
82 #
83 ifeq ($(strip),yes)
84 INSTALL_PROGRAM += -s
85 export strip
86 endif
87
88 #
89 # Prepare the arguments to install to set user/group of installed files
90 #
91 INSTALL_AS = 
92
93 ifneq ($(INSTALL_AS_USER),)
94 INSTALL_AS += -o $(INSTALL_AS_USER)
95 endif
96
97 ifneq ($(INSTALL_AS_GROUP),)
98 INSTALL_AS += -g $(INSTALL_AS_GROUP)
99 endif
100
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)
105
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.
109
110 #
111 # Prepare the arguments to chown to set user/group of installed files.
112 #
113 ifneq ($(INSTALL_AS_GROUP),)
114 CHOWN_TO = $(strip $(INSTALL_AS_USER)).$(strip $(INSTALL_AS_GROUP))
115 else 
116 CHOWN_TO = $(strip $(INSTALL_AS_USER))
117 endif
118
119 # You need to run CHOWN manually, but only if CHOWN_TO is non-empty.
120
121 #
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.
126 #
127 ifneq ($(CHOWN_TO),)
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
131  ifeq ($(shared),yes)
132   AFTER_INSTALL_LIBRARY_CMD += ; $(AFTER_INSTALL_SHARED_LIB_CHOWN)
133  endif
134 else
135  MKINSTALLDIRS = $(MKDIRS)
136 endif
137
138 #
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>'
143 #
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
146 # non-empty.
147 #
148 ifneq ($(FRAMEWORK_NAME)$(OWNING_PROJECT_HEADER_DIR_NAME),)
149   DERIVED_SOURCES_HEADERS_FLAG = -I$(DERIVED_SOURCES_DIR)
150 endif
151
152 #
153 # Include rules to built the instance
154 #
155 # this fixes up ADDITIONAL_XXXFLAGS as well, which is why we include it
156 # before using ADDITIONAL_XXXFLAGS
157 #
158 ifneq ($(GNUSTEP_INSTANCE),)
159 include $(GNUSTEP_MAKEFILES)/Instance/rules.make
160 endif
161
162 #
163 # Implement ADDITIONAL_NATIVE_LIBS
164 #
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.
168 #
169 ifeq ($(FOUNDATION_LIB),apple)
170   ADDITIONAL_OBJC_LIBS += $(foreach lib,$(ADDITIONAL_NATIVE_LIBS),-framework $(lib))
171 else
172   ADDITIONAL_OBJC_LIBS += $(foreach lib,$(ADDITIONAL_NATIVE_LIBS),-l$(lib))
173 endif
174
175 #
176 # Auto dependencies
177 #
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 ...
181 #
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 
185 #
186
187 # Warning - the following variable name might change
188 ifeq ($(AUTO_DEPENDENCIES),yes)
189 ifeq ($(AUTO_DEPENDENCIES_FLAGS),)
190   AUTO_DEPENDENCIES_FLAGS = -MMD -MP
191 endif
192 endif
193
194 # The difference between ADDITIONAL_XXXFLAGS and AUXILIARY_XXXFLAGS is the
195 # following:
196 #
197 #  ADDITIONAL_XXXFLAGS are set freely by the user GNUmakefile
198 #
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.
205 #
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,
209 # like writing 
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.
214 #
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
219 #
220 #  AUXILIARY_XXXFLAGS += -Verbose
221 #
222 # in their auxiliary makefile fragments, to make sure they don't
223 # override flags from different packages, just add to them.
224 #
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.
228 #
229
230 ALL_CPPFLAGS = $(AUTO_DEPENDENCIES_FLAGS) $(CPPFLAGS) $(ADDITIONAL_CPPFLAGS) \
231                $(AUXILIARY_CPPFLAGS)
232
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)
240
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)
248
249 # if you need, you can define ADDITIONAL_CCFLAGS to add C++ specific flags
250 ALL_CCFLAGS = $(ADDITIONAL_CCFLAGS) $(AUXILIARY_CCFLAGS)
251
252 INTERNAL_CLASSPATHFLAGS = -classpath ./$(subst ::,:,:$(strip $(ADDITIONAL_CLASSPATH)):)$(CLASSPATH)
253
254 ALL_JAVACFLAGS = $(INTERNAL_CLASSPATHFLAGS) $(INTERNAL_JAVACFLAGS) \
255 $(ADDITIONAL_JAVACFLAGS) $(AUXILIARY_JAVACFLAGS)
256
257 ALL_JAVAHFLAGS = $(INTERNAL_CLASSPATHFLAGS) $(ADDITIONAL_JAVAHFLAGS) \
258 $(AUXILIARY_JAVAHFLAGS)
259
260 ifeq ($(shared),no)
261   ALL_LDFLAGS = $(STATIC_LDFLAGS)
262 else
263   ALL_LDFLAGS =
264 endif
265 ALL_LDFLAGS += $(ADDITIONAL_LDFLAGS) $(AUXILIARY_LDFLAGS) $(GUI_LDFLAGS) \
266                $(BACKEND_LDFLAGS) $(SYSTEM_LDFLAGS) $(INTERNAL_LDFLAGS)
267
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) \
272    $(SYSTEM_LIB_DIR)
273
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.
281
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
285
286 ifeq ($(FOUNDATION_LIB), gnu)
287   ALL_CPLISTFLAGS += -DGNUSTEP
288 else
289   ifeq ($(FOUNDATION_LIB), apple)
290     ALL_CPLISTFLAGS += -DAPPLE
291   else
292       ifeq ($(FOUNDATION_LIB), nx)
293         ALL_CPLISTFLAGS += -DNEXT
294       else
295         ALL_CPLISTFLAGS += -DUNKNOWN
296       endif
297   endif
298 endif
299
300 ALL_CPLISTFLAGS += $(ADDITIONAL_CPLISTFLAGS) $(AUXILIARY_CPLISTFLAGS)
301
302
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
309 # being compiled.
310 ifeq ($(WITH_DLL),yes)
311 ALL_CPPFLAGS += -DGNUSTEP_WITH_DLL
312 endif
313
314 # General rules
315 VPATH = .
316
317 # Disable all built-in suffixes for performance.
318 .SUFFIXES:
319
320 # Then define our own.
321 .SUFFIXES: .m .c .psw .java .h .cpp .cxx .C .cc .cp
322
323 .PRECIOUS: %.c %.h $(GNUSTEP_OBJ_DIR)/%${OEXT}
324
325 # Disable all built-in rules with a vague % as target, for performance.
326 %: %.c
327
328 %: %.cpp
329
330 %: %.cc
331
332 %: %.C
333
334 (%): %
335
336 %:: %,v
337
338 %:: RCS/%,v
339
340 %:: RCS/%
341
342 %:: s.%
343
344 %:: SCCS/s.%
345
346 #
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 - 
352 #
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
355 #
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.
359 #
360 # Typical examples:
361 #
362 # Disable optimization flags for the file NSInvocation.m:
363 # NSInvocation.m_FILE_FILTER_OUT_FLAGS = -O%
364 #
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
368 #
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
372 #
373
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) \
382                                                         $(ALL_CFLAGS)) \
383               $($<_FILE_FLAGS) -o $@$(END_ECHO)
384
385 $(GNUSTEP_OBJ_DIR)/%${OEXT} : %.m
386         $(ECHO_COMPILING)$(CC) $< -c \
387               $(filter-out $($<_FILE_FILTER_OUT_FLAGS),$(ALL_CPPFLAGS) \
388                                                         $(ALL_OBJCFLAGS)) \
389               $($<_FILE_FLAGS) -o $@$(END_ECHO)
390
391 $(GNUSTEP_OBJ_DIR)/%${OEXT} : %.C
392         $(ECHO_COMPILING)$(CC) $< -c \
393               $(filter-out $($<_FILE_FILTER_OUT_FLAGS),$(ALL_CPPFLAGS) \
394                                                         $(ALL_CFLAGS)   \
395                                                         $(ALL_CCFLAGS)) \
396               $($<_FILE_FLAGS) -o $@$(END_ECHO)
397
398 $(GNUSTEP_OBJ_DIR)/%${OEXT} : %.cc
399         $(ECHO_COMPILING)$(CC) $< -c \
400               $(filter-out $($<_FILE_FILTER_OUT_FLAGS),$(ALL_CPPFLAGS) \
401                                                         $(ALL_CFLAGS)   \
402                                                         $(ALL_CCFLAGS)) \
403               $($<_FILE_FLAGS) -o $@$(END_ECHO)
404
405 $(GNUSTEP_OBJ_DIR)/%${OEXT} : %.cpp
406         $(ECHO_COMPILING)$(CC) $< -c \
407               $(filter-out $($<_FILE_FILTER_OUT_FLAGS),$(ALL_CPPFLAGS) \
408                                                         $(ALL_CFLAGS)   \
409                                                         $(ALL_CCFLAGS)) \
410               $($<_FILE_FLAGS) -o $@$(END_ECHO)
411
412 $(GNUSTEP_OBJ_DIR)/%${OEXT} : %.cxx
413         $(ECHO_COMPILING)$(CC) $< -c \
414               $(filter-out $($<_FILE_FILTER_OUT_FLAGS),$(ALL_CPPFLAGS) \
415                                                         $(ALL_CFLAGS)   \
416                                                         $(ALL_CCFLAGS)) \
417               $($<_FILE_FLAGS) -o $@$(END_ECHO)
418
419 $(GNUSTEP_OBJ_DIR)/%${OEXT} : %.cp
420         $(ECHO_COMPILING)$(CC) $< -c \
421               $(filter-out $($<_FILE_FILTER_OUT_FLAGS),$(ALL_CPPFLAGS) \
422                                                         $(ALL_CFLAGS)   \
423                                                         $(ALL_CCFLAGS)) \
424               $($<_FILE_FLAGS) -o $@$(END_ECHO)
425
426 %.class : %.java
427         $(ECHO_COMPILING)$(JAVAC) \
428                  $(filter-out $($<_FILE_FILTER_OUT_FLAGS),$(ALL_JAVACFLAGS)) \
429                  $($<_FILE_FLAGS) $<$(END_ECHO)
430
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
435 %.h : %.java
436         $(ECHO_JAVAHING)$(JAVAH) \
437                  $(filter-out $($<_FILE_FILTER_OUT_FLAGS),$(ALL_JAVAHFLAGS)) \
438                  $($<_FILE_FLAGS) -o $@ $(subst /,.,$*)$(END_ECHO)
439
440 %.c : %.psw
441         pswrap -h $*.h -o $@ $<
442
443 # The following rule is needed because in frameworks you might need
444 # the .h files before the .c files are compiled.
445 %.h : %.psw
446         pswrap -h $@ -o $*.c $<
447
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
455 # preprocessor.
456 #
457 # Unfortunately, on some platforms (Apple) the preprocessor emits
458 # unwanted and unrequested #pragma statements.  We use sed to filter
459 # them out.
460 #
461 %.plist : %.cplist
462         $(ECHO_PREPROCESSING)$(CPP) \
463                   $(filter-out $($<_FILE_FILTER_OUT_FLAGS),$(ALL_CPLISTFLAGS))\
464                   $($<_FILE_FLAGS) $< | sed '/^#pragma/d' > $@$(END_ECHO)
465
466 # The following rule builds a .c file from a lex .l file.
467 # You can define LEX_FLAGS if you need them.
468 %.c: %.l
469         $(LEX) $(LEX_FLAGS) -t $< > $@
470
471 # The following rule builds a .c file from a yacc/bison .y file.
472 # You can define YACC_FLAGS if you need them.
473 %.c: %.y
474         $(YACC) $(YACC_FLAGS) $<
475         mv -f y.tab.c $@
476
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
481
482 $(GNUSTEP_MAKEFILES)/*.make: ;
483
484 $(GNUSTEP_MAKEFILES)/$(GNUSTEP_TARGET_DIR)/config.make: ;
485
486 $(GNUSTEP_MAKEFILES)/Additional/*.make: ;
487
488 $(GNUSTEP_MAKEFILES)/Master/*.make: ;
489
490 $(GNUSTEP_MAKEFILES)/Instance/*.make: ;
491
492 $(GNUSTEP_MAKEFILES)/Instance/Shared/*.make: ;
493
494 $(GNUSTEP_MAKEFILES)/Instance/Documentation/*.make: ;
495
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)
500 endif
501
502 # The rule to create the objects file directory.
503 $(GNUSTEP_OBJ_DIR):
504         $(ECHO_NOTHING)cd $(GNUSTEP_BUILD_DIR); \
505         $(MKDIRS) ./$(GNUSTEP_OBJ_DIR_NAME); \
506         rm -f obj; \
507         $(LN_S) ./$(GNUSTEP_OBJ_DIR_NAME) obj$(END_ECHO)
508
509 endif
510 # rules.make loaded