3 # WARNING! Do not edit! https://waf.io/book/index.html#_obtaining_the_waf_file
7 # Thomas Nagy, 2005-2015 (ita)
9 "base for all c/c++ programs and libraries"
11 from waflib import Utils, Errors
12 from waflib.Configure import conf
14 def get_extensions(lst):
16 Returns the file extensions for the list of files given as input
18 :param lst: files to process
19 :list lst: list of string or :py:class:`waflib.Node.Node`
20 :return: list of file extensions
21 :rtype: list of string
24 for x in Utils.to_list(lst):
25 if not isinstance(x, str):
27 ret.append(x[x.rfind('.') + 1:])
30 def sniff_features(**kw):
32 Computes and returns the features required for a task generator by
33 looking at the file extensions. This aimed for C/C++ mainly::
35 snif_features(source=['foo.c', 'foo.cxx'], type='shlib')
36 # returns ['cxx', 'c', 'cxxshlib', 'cshlib']
38 :param source: source files to process
39 :type source: list of string or :py:class:`waflib.Node.Node`
40 :param type: object type in *program*, *shlib* or *stlib*
42 :return: the list of features for a task generator processing the source files
43 :rtype: list of string
45 exts = get_extensions(kw['source'])
49 # watch the order, cxx will have the precedence
50 for x in 'cxx cpp c++ cc C'.split():
55 if 'c' in exts or 'vala' in exts or 'gs' in exts:
58 for x in 'f f90 F F90 for FOR'.split():
70 if typ in ('program', 'shlib', 'stlib'):
73 if x in ('cxx', 'd', 'fc', 'c'):
76 if not will_link and not kw.get('features', []):
77 raise Errors.WafError('Cannot link from %r, try passing eg: features="c cprogram"?' % kw)
80 def set_features(kw, typ):
82 Inserts data in the input dict *kw* based on existing data and on the type of target
85 :param kw: task generator parameters
87 :param typ: type of target
91 kw['features'] = Utils.to_list(kw.get('features', [])) + Utils.to_list(sniff_features(**kw))
94 def program(bld, *k, **kw):
96 Alias for creating programs by looking at the file extensions::
99 bld.program(source='foo.c', target='app')
101 # bld(features='c cprogram', source='foo.c', target='app')
104 set_features(kw, 'program')
108 def shlib(bld, *k, **kw):
110 Alias for creating shared libraries by looking at the file extensions::
113 bld.shlib(source='foo.c', target='app')
115 # bld(features='c cshlib', source='foo.c', target='app')
118 set_features(kw, 'shlib')
122 def stlib(bld, *k, **kw):
124 Alias for creating static libraries by looking at the file extensions::
127 bld.stlib(source='foo.cpp', target='app')
129 # bld(features='cxx cxxstlib', source='foo.cpp', target='app')
132 set_features(kw, 'stlib')
136 def objects(bld, *k, **kw):
138 Alias for creating object files by looking at the file extensions::
141 bld.objects(source='foo.c', target='app')
143 # bld(features='c', source='foo.c', target='app')
146 set_features(kw, 'objects')