3 # Thomas Nagy, 2006 (ita)
5 "Base for c programs/libraries"
8 import TaskGen
, Build
, Utils
, Task
11 from TaskGen
import feature
, before
, extension
, after
14 'CCDEPS', 'FRAMEWORK', 'FRAMEWORKPATH',
15 'STATICLIB', 'LIB', 'LIBPATH', 'LINKFLAGS', 'RPATH',
16 'CCFLAGS', 'CPPPATH', 'CPPFLAGS', 'CCDEFINES']
20 g_cc_type_vars
= ['CCFLAGS', 'LINKFLAGS']
22 # TODO remove in waf 1.6
23 class cc_taskgen(ccroot
.ccroot_abstract
):
27 @before('apply_type_vars')
30 self
.p_flag_vars
= set(self
.p_flag_vars
).union(g_cc_flag_vars
)
31 self
.p_type_vars
= set(self
.p_type_vars
).union(g_cc_type_vars
)
33 if not self
.env
['CC_NAME']:
34 raise Utils
.WafError("At least one compiler (gcc, ..) must be selected")
37 @after('apply_incpaths')
38 def apply_obj_vars_cc(self
):
39 """after apply_incpaths for INC_PATHS"""
41 app
= env
.append_unique
42 cpppath_st
= env
['CPPPATH_ST']
44 # local flags come first
45 # set the user-defined includes paths
46 for i
in env
['INC_PATHS']:
47 app('_CCINCFLAGS', cpppath_st
% i
.bldpath(env
))
48 app('_CCINCFLAGS', cpppath_st
% i
.srcpath(env
))
50 # set the library include paths
51 for i
in env
['CPPPATH']:
52 app('_CCINCFLAGS', cpppath_st
% i
)
55 @after('apply_lib_vars')
56 def apply_defines_cc(self
):
57 """after uselib is set for CCDEFINES"""
58 self
.defines
= getattr(self
, 'defines', [])
59 lst
= self
.to_list(self
.defines
) + self
.to_list(self
.env
['CCDEFINES'])
62 # now process the local defines
68 libs
= self
.to_list(self
.uselib
)
70 val
= self
.env
['CCDEFINES_'+l
]
72 self
.env
['DEFLINES'] = ["%s %s" % (x
[0], Utils
.trimquotes('='.join(x
[1:]))) for x
in [y
.split('=') for y
in milst
]]
73 y
= self
.env
['CCDEFINES_ST']
74 self
.env
.append_unique('_CCDEFFLAGS', [y
%x for x
in milst
])
77 def c_hook(self
, node
):
78 # create the compilation task: cpp or cc
79 if getattr(self
, 'obj_ext', None):
80 obj_ext
= self
.obj_ext
82 obj_ext
= '_%d.o' % self
.idx
84 task
= self
.create_task('cc', node
, node
.change_ext(obj_ext
))
86 self
.compiled_tasks
.append(task
)
87 except AttributeError:
88 raise Utils
.WafError('Have you forgotten to set the feature "cc" on %s?' % str(self
))
91 cc_str
= '${CC} ${CCFLAGS} ${CPPFLAGS} ${_CCINCFLAGS} ${_CCDEFFLAGS} ${CC_SRC_F}${SRC} ${CC_TGT_F}${TGT}'
92 cls
= Task
.simple_task_type('cc', cc_str
, 'GREEN', ext_out
='.o', ext_in
='.c', shell
=False)
93 cls
.scan
= ccroot
.scan
94 cls
.vars.append('CCDEPS')
96 link_str
= '${LINK_CC} ${CCLNK_SRC_F}${SRC} ${CCLNK_TGT_F}${TGT[0].abspath(env)} ${LINKFLAGS}'
97 cls
= Task
.simple_task_type('cc_link', link_str
, color
='YELLOW', ext_in
='.o', ext_out
='.bin', shell
=False)
99 cls
.install
= Utils
.nada