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)_CXXFLAGS) : $(3) ;
26 LFlags $(<) : $($(i)_LIBS) : $(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)" ;
51 rule LinkWithWholeArchive
53 local i libs sharedlib ;
56 if $($(i)_TYPE) = "library" {
57 if [ IsElem shared : $($(i)_OPTIONS) ] {
61 # for non shared libs add inherit the compile flags and libs
62 libs += $(i) $($(i)_LIBRARIES) ;
63 # inherit the exported flags
64 CppFlags $(<) : $($(i)_CPPFLAGS) : $(3) ;
65 CFlags $(<) : $($(i)_CFLAGS) : $(3) ;
66 C++Flags $(<) : $($(i)_CXXFLAGS) : $(3) ;
67 LFlags $(<) : $($(i)_LIBS) : $(3) ;
70 echo "WARNING: Trying to link" $(i)
71 "with" $(<) "which is not a library." ;
74 # resolve library dependencies
75 libs = [ RemoveDups $(libs) ] ;
76 $(<)_LIBRARIES = $(libs) ;
80 libfiles += $($(i)_TARGET) ;
83 DEPENDS $($(<)_TARGET) : $(libfiles) ;
84 NEEDLIBS_WHOLE on $($(<)_TARGET) += $(libfiles) ;
85 $(<)_WHOLE_ARCHIVE = true ;
86 # the usual libtool hack...
88 LINK on $($(<)_TARGET) = "$(LIBTOOL) $(LINK)" ;
89 INSTALL on $($(<)_INSTALLTARGET) = "$(LIBTOOL) --mode=install $(INSTALL)" ;
95 CPPFLAGS on $($(<)_OBJECTS) += $(>) ;
97 if [ IsElem export : $(3) ] {
98 $(<)_CPPFLAGS = $(>) ;
102 ## CFlags target : flags [ : options ]
103 ## Sets cflags on all sourcefiles of a target
104 ## This rule affects c++ and c compiler flags. Options:
105 ## export - export the cflags to dependent targets (for example in
106 ## a library context this will inherit the cflags to the apps using
110 CFLAGS on $($(<)_OBJECTS) += $(>) ;
112 if [ IsElem export : $(3) ] {
119 CXXFLAGS on $($(<)_OBJECTS) += $(>) ;
121 if [ IsElem export : $(3) ] {
122 $(<)_CXXFLAGS = $(>) ;
126 ## LFlags target : flags [ : options ]
127 ## Sets linker flags for a library, plugin or application target
130 LIBS on $($(<)_TARGET) += $(>) ;
132 if [ IsElem export : $(3) ] {
137 ## ExternalLibs appname : linkerflags [ : options ]
138 ## Link an application/library/plugin with external libraries. It is
139 ## possible to give a set of flags which will be passed to the linker when
140 ## building the application (typically -L and -l flags).
147 CppFlags $(<) : $($(i)_CFLAGS) : $(3) ;
148 LFlags $(<) : $($(i)_LIBS) : $(3) ;
152 ## ExtraObjects target : objectfiles
153 ## Link additional object files with a target
156 EXTRAOBJECTS on $($(<)_TARGET) += $(>) ;
157 Depends $($(<)_TARGET) : $(>) ;
158 Clean $(<)clean : $(>) ;
162 ## IncludeDir [target : ] directories
163 ## Description: Is used to specify the location of header files for a
164 ## target or the whole project if no target is given.
165 ## This rule will automatically generate the -I compiler flags and makes
166 ## sure the dependency scanner is able to locate your header files. The
167 ## directories are relative to the current subdir specified with the SubDir
169 ## Implementation: The directories are simply added to the HDRSEARCH variable
170 ## which is respected by all jam rules.
177 dir = [ ConcatDirs $(SUBDIR) $(i) ] ;
178 CppFlags $(<) : [ CreateIncludeFlags $(dir) ] ;
180 # needed for header scanning
181 HDRSEARCH on $($(<)_SOURCES) += $(dir) ;
185 dir = [ ConcatDirs $(SUBDIR) $(i) ] ;
186 CPPFLAGS += [ CreateIncludeFlags $(dir) ] ;
187 # needed for header scanning
188 HDRSEARCH += $(dir) ;
196 CppFlags $(<) : [ CreateDefineFlags $(>) ] ;
198 CPPFLAGS += [ CreateDefineFlags $(<) ] ;