hehe %-)
[syren.git] / mk / jam / flags.jam
blob4fd4bb4086cd197bb4932d0577409421a3546180
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
9 ##    the leading "lib".
10 rule LinkWith
12         local i libs sharedlib ;
14         for i in $(>) {
15                 if $($(i)_TYPE) = "library" {
16                         if [ IsElem shared : $($(i)_OPTIONS) ] {
17                                 libs += $(i) ;
18                                 sharedlib = true ;
19                         } else {
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) ;
27                         }
28                 } else {
29                         echo "WARNING: Trying to link" $(i)
30                                 "with" $(<) "which is not a library." ;
31                 }
32         }
33         # resolve library dependencies
34         libs = [ RemoveDups $(libs) ] ;    
35         $(<)_LIBRARIES = $(libs) ;
37         local libfiles ;
38         for i in $(libs) {
39                 libfiles += $($(i)_TARGET) ;
40         }
42         DEPENDS $($(<)_TARGET) : $(libfiles) ;
43         NEEDLIBS on $($(<)_TARGET) += $(libfiles) ;
44         # the usual libtool hack...
45         if $(sharedlib) {
46                 LINK on $($(<)_TARGET) = "$(LIBTOOL) $(LINK)" ;
47                 INSTALL on $($(<)_INSTALLTARGET) = "$(LIBTOOL) --mode=install $(INSTALL)" ;
48         }
51 rule CppFlags
53         CPPFLAGS on $($(<)_OBJECTS) += $(>) ;
55         if [ IsElem export : $(3) ] {
56                 $(<)_CPPFLAGS = $(>) ;
57         }
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
65 ##              the library)
66 rule CFlags
68         CFLAGS on $($(<)_OBJECTS) += $(>) ;
70         if [ IsElem export : $(3) ] {
71                 $(<)_CFLAGS = $(>) ;
72         }
75 rule C++Flags
77         C++FLAGS on $($(<)_OBJECTS) += $(>) ;
79         if [ IsElem export : $(3) ] {
80                 $(<)_C++FLAGS = $(>) ;
81         }
84 ##  LFlags target : flags [ : options ]
85 ##    Sets linker flags for a library, plugin or application target
86 rule LFlags
88         LFLAGS on $($(<)_TARGET) += $(>) ;
90         if [ IsElem export : $(3) ] {
91                 $(<)_LFLAGS = $(>) ;
92         }
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).
99 rule ExternalLibs
101         local i ;
103         for i in $(>)
104         {
105                 CppFlags $(<) : $($(i)_CFLAGS) : $(3) ;
106                 LFlags $(<) : $($(i)_LIBS) : $(3) ;
107         }
110 ##  ExtraObjects target : objectfiles
111 ##    Link additional object files with a target
112 rule ExtraObjects
114         EXTRAOBJECTS on $($(<)_TARGET) += $(>) ;
115         Depends $($(<)_TARGET) : $(>) ;
116         Clean $(<)clean : $(>) ;
117         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
126 ##    rule.
127 ##    Implementation: The directories are simply added to the HDRS variable
128 ##    which is respected by all jam rules.
129 rule IncludeDir
131         local dir i ;
132         
133         if $(>) {
134                 for i in $(>) {
135                         dir = [ ConcatDirs $(SUBDIR) $(i) ] ;
136                         CppFlags $(<) : [ CreateIncludeFlags $(dir) ] ;
138                         # needed for header scanning
139                         HDRS on $($(<)_SOURCES) += $(dir) ;
140                 }
141         } else {
142                 for i in $(<) {
143                         dir = [ ConcatDirs $(SUBDIR) $(i) ] ;
144                         CPPFLAGS += [ CreateIncludeFlags $(dir) ] ;
145                         # needed for header scanning
146                         HDRS += $(dir) ;
147                 }
148         }
151 rule DefineConst
153         if $(>) {
154                 CppFlags $(<) : [ CreateDefineFlags $(>) ] ;
155         } else {
156                 CPPFLAGS += [ CreateDefineFlags $(<) ] ;
157         }