1 #============================================================================
2 # Rules for specifying compiler and linker flags
3 #============================================================================
5 ## LinkWith target : libs [ : options ]
6 ## Link a target with libraries. The specified libraries should have
7 ## build rules in the same project. For external libraries use the
8 ## ExternalLibs rule. Specify the library names without any extensions or
12 local i libs sharedlib ;
15 if $($(i)_TYPE) = "library" {
16 if [ IsElem shared : $($(i)_OPTIONS) ] {
20 # for non shared libs add inherit the compile flags and libs
21 libs += $(i) $($(i)_LIBRARIES) ;
22 # inherit the exported flags
23 CppFlags $(<) : $($(i)_CPPFLAGS) : $(3) ;
24 CFlags $(<) : $($(i)_CFLAGS) : $(3) ;
25 C++Flags $(<) : $($(i)_C++FLAGS) : $(3) ;
26 LFlags $(<) : $($(i)_LFLAGS) : $(3) ;
29 echo "WARNING: Trying to link" $(i)
30 "with" $(<) "which is not a library." ;
33 # resolve library dependencies
34 libs = [ RemoveDups $(libs) ] ;
35 $(<)_LIBRARIES = $(libs) ;
39 libfiles += $($(i)_TARGET) ;
42 DEPENDS $($(<)_TARGET) : $(libfiles) ;
43 NEEDLIBS on $($(<)_TARGET) += $(libfiles) ;
44 # the usual libtool hack...
46 LINK on $($(<)_TARGET) = "$(LIBTOOL) $(LINK)" ;
47 INSTALL on $($(<)_INSTALLTARGET) = "$(LIBTOOL) --mode=install $(INSTALL)" ;
53 CPPFLAGS on $($(<)_OBJECTS) += $(>) ;
55 if [ IsElem export : $(3) ] {
56 $(<)_CPPFLAGS = $(>) ;
60 ## CFlags target : flags [ : options ]
61 ## Sets cflags on all sourcefiles of a target
62 ## This rule affects c++ and c compiler flags. Options:
63 ## export - export the cflags to dependent targets (for example in
64 ## a library context this will inherit the cflags to the apps using
68 CFLAGS on $($(<)_OBJECTS) += $(>) ;
70 if [ IsElem export : $(3) ] {
77 C++FLAGS on $($(<)_OBJECTS) += $(>) ;
79 if [ IsElem export : $(3) ] {
80 $(<)_C++FLAGS = $(>) ;
84 ## LFlags target : flags [ : options ]
85 ## Sets linker flags for a library, plugin or application target
88 LFLAGS on $($(<)_TARGET) += $(>) ;
90 if [ IsElem export : $(3) ] {
95 ## ExternalLibs appname : linkerflags [ : options ]
96 ## Link an application/library/plugin with external libraries. It is
97 ## possible to give a set of flags which will be passed to the linker when
98 ## building the application (typically -L and -l flags).
105 CppFlags $(<) : $($(i)_CFLAGS) : $(3) ;
106 LFlags $(<) : $($(i)_LIBS) : $(3) ;
110 ## ExtraObjects target : objectfiles
111 ## Link additional object files with a target
114 EXTRAOBJECTS on $($(<)_TARGET) += $(>) ;
115 Depends $($(<)_TARGET) : $(>) ;
116 Clean $(<)clean : $(>) ;
120 ## IncludeDir [target : ] directories
121 ## Description: Is used to specify the location of header files for a
122 ## target or the whole project if no target is given.
123 ## This rule will automatically generate the -I compiler flags and makes
124 ## sure the dependency scanner is able to locate your header files. The
125 ## directories are relative to the current subdir specified with the SubDir
127 ## Implementation: The directories are simply added to the HDRS variable
128 ## which is respected by all jam rules.
135 dir = [ ConcatDirs $(SUBDIR) $(i) ] ;
136 CppFlags $(<) : [ CreateIncludeFlags $(dir) ] ;
138 # needed for header scanning
139 HDRS on $($(<)_SOURCES) += $(dir) ;
143 dir = [ ConcatDirs $(SUBDIR) $(i) ] ;
144 CPPFLAGS += [ CreateIncludeFlags $(dir) ] ;
145 # needed for header scanning
154 CppFlags $(<) : [ CreateDefineFlags $(>) ] ;
156 CPPFLAGS += [ CreateDefineFlags $(<) ] ;