applied Daniel Hedlunds patch that works around jam commandline limit
[supertux.git] / mk / jam / flags.jam
1 #============================================================================
2 # Rules for specifying compiler and linker flags
3 #============================================================================
4
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
11 {
12     local i libs sharedlib ;
13
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)_CXXFLAGS) : $(3) ;
26                 LFlags $(<) : $($(i)_LIBS) : $(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) ;
36
37     local libfiles ;
38     for i in $(libs) {
39         libfiles += $($(i)_TARGET) ;
40     }
41
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     }
49 }
50
51 rule LinkWithWholeArchive
52 {
53     local i libs sharedlib ;
54
55     for i in $(>) {
56         if $($(i)_TYPE) = "library" {
57             if [ IsElem shared : $($(i)_OPTIONS) ] {
58                 libs += $(i) ;
59                 sharedlib = true ;
60             } else {
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) ;
68             }
69         } else {
70             echo "WARNING: Trying to link" $(i)
71                 "with" $(<) "which is not a library." ;
72         }
73     }
74     # resolve library dependencies
75     libs = [ RemoveDups $(libs) ] ;    
76     $(<)_LIBRARIES = $(libs) ;
77
78     local libfiles ;
79     for i in $(libs) {
80         libfiles += $($(i)_TARGET) ;
81     }
82
83     DEPENDS $($(<)_TARGET) : $(libfiles) ;
84     NEEDLIBS_WHOLE on $($(<)_TARGET) += $(libfiles) ;
85     $(<)_WHOLE_ARCHIVE = true ;
86     # the usual libtool hack...
87     if $(sharedlib) {
88         LINK on $($(<)_TARGET) = "$(LIBTOOL) $(LINK)" ;
89         INSTALL on $($(<)_INSTALLTARGET) = "$(LIBTOOL) --mode=install $(INSTALL)" ;
90     }
91 }
92
93 rule CppFlags
94 {
95     CPPFLAGS on $($(<)_OBJECTS) += $(>) ;
96
97     if [ IsElem export : $(3) ] {
98         $(<)_CPPFLAGS = $(>) ;
99     }
100 }
101
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
107 ##              the library)
108 rule CFlags
109 {
110     CFLAGS on $($(<)_OBJECTS) += $(>) ;
111
112     if [ IsElem export : $(3) ] {
113         $(<)_CFLAGS = $(>) ;
114     }
115 }
116
117 rule C++Flags
118 {
119     CXXFLAGS on $($(<)_OBJECTS) += $(>) ;
120
121     if [ IsElem export : $(3) ] {
122         $(<)_CXXFLAGS = $(>) ;
123     }
124 }
125
126 ##  LFlags target : flags [ : options ]
127 ##    Sets linker flags for a library, plugin or application target
128 rule LFlags
129 {
130     LIBS on $($(<)_TARGET) += $(>) ;
131
132     if [ IsElem export : $(3) ] {
133         $(<)_LIBS = $(>) ;
134     }
135 }
136
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).
141 rule ExternalLibs
142 {
143     local i ;
144   
145     for i in $(>)
146     {
147         CppFlags $(<) : $($(i)_CFLAGS) : $(3) ;
148         LFlags $(<) : $($(i)_LIBS) : $(3) ;
149     }
150 }
151
152 ##  ExtraObjects target : objectfiles
153 ##    Link additional object files with a target
154 rule ExtraObjects
155 {
156     EXTRAOBJECTS on $($(<)_TARGET) += $(>) ;
157     Depends $($(<)_TARGET) : $(>) ;
158     Clean $(<)clean : $(>) ;
159     Clean clean : $(>) ;
160 }
161
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
168 ##    rule.
169 ##    Implementation: The directories are simply added to the HDRSEARCH variable
170 ##    which is respected by all jam rules.
171 rule IncludeDir
172 {
173     local dir i ;
174     
175     if $(>) {
176         for i in $(>) {
177             dir = [ ConcatDirs $(SUBDIR) $(i) ] ;
178             CppFlags $(<) : [ CreateIncludeFlags $(dir) ] ;
179
180             # needed for header scanning
181             HDRSEARCH on $($(<)_SOURCES) += $(dir) ;
182         }
183     } else {
184         for i in $(<) {
185             dir = [ ConcatDirs $(SUBDIR) $(i) ] ;
186             CPPFLAGS += [ CreateIncludeFlags $(dir) ] ;
187             # needed for header scanning
188             HDRSEARCH += $(dir) ;
189         }
190     }
191 }
192
193 rule DefineConst
194 {
195     if $(>) {
196         CppFlags $(<) : [ CreateDefineFlags $(>) ] ;
197     } else {
198         CPPFLAGS += [ CreateDefineFlags $(<) ] ;
199     }
200 }
201