summaryrefslogtreecommitdiffstats
path: root/scripts/lib
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lib')
-rw-r--r--scripts/lib/recipetool/__init__.py0
-rw-r--r--scripts/lib/recipetool/create.py413
-rw-r--r--scripts/lib/recipetool/create_buildsys.py319
3 files changed, 732 insertions, 0 deletions
diff --git a/scripts/lib/recipetool/__init__.py b/scripts/lib/recipetool/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/scripts/lib/recipetool/__init__.py
diff --git a/scripts/lib/recipetool/create.py b/scripts/lib/recipetool/create.py
new file mode 100644
index 0000000000..6dba07819b
--- /dev/null
+++ b/scripts/lib/recipetool/create.py
@@ -0,0 +1,413 @@
1# Recipe creation tool - create command plugin
2#
3# Copyright (C) 2014 Intel Corporation
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License version 2 as
7# published by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License along
15# with this program; if not, write to the Free Software Foundation, Inc.,
16# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18import sys
19import os
20import argparse
21import glob
22import fnmatch
23import re
24import logging
25
26logger = logging.getLogger('recipetool')
27
28tinfoil = None
29plugins = None
30
31def plugin_init(pluginlist):
32 # Take a reference to the list so we can use it later
33 global plugins
34 plugins = pluginlist
35
36def tinfoil_init(instance):
37 global tinfoil
38 tinfoil = instance
39
40class RecipeHandler():
41 @staticmethod
42 def checkfiles(path, speclist):
43 results = []
44 for spec in speclist:
45 results.extend(glob.glob(os.path.join(path, spec)))
46 return results
47
48 def genfunction(self, outlines, funcname, content):
49 outlines.append('%s () {' % funcname)
50 for line in content:
51 outlines.append('\t%s' % line)
52 outlines.append('}')
53 outlines.append('')
54
55 def process(self, srctree, classes, lines_before, lines_after, handled):
56 return False
57
58
59
60def fetch_source(uri, destdir):
61 import bb.data
62 bb.utils.mkdirhier(destdir)
63 localdata = bb.data.createCopy(tinfoil.config_data)
64 bb.data.update_data(localdata)
65 localdata.setVar('BB_STRICT_CHECKSUM', '')
66 localdata.setVar('SRCREV', '${AUTOREV}')
67 ret = (None, None)
68 olddir = os.getcwd()
69 try:
70 fetcher = bb.fetch2.Fetch([uri], localdata)
71 for u in fetcher.ud:
72 ud = fetcher.ud[u]
73 ud.ignore_checksums = True
74 fetcher.download()
75 fetcher.unpack(destdir)
76 for u in fetcher.ud:
77 ud = fetcher.ud[u]
78 if ud.method.recommends_checksum(ud):
79 md5value = bb.utils.md5_file(ud.localpath)
80 sha256value = bb.utils.sha256_file(ud.localpath)
81 ret = (md5value, sha256value)
82 except bb.fetch2.BBFetchException, e:
83 raise bb.build.FuncFailed(e)
84 finally:
85 os.chdir(olddir)
86 return ret
87
88def supports_srcrev(uri):
89 localdata = bb.data.createCopy(tinfoil.config_data)
90 bb.data.update_data(localdata)
91 fetcher = bb.fetch2.Fetch([uri], localdata)
92 urldata = fetcher.ud
93 for u in urldata:
94 if urldata[u].method.supports_srcrev():
95 return True
96 return False
97
98def create_recipe(args):
99 import bb.process
100 import tempfile
101 import shutil
102
103 pkgarch = ""
104 if args.machine:
105 pkgarch = "${MACHINE_ARCH}"
106
107 checksums = (None, None)
108 tempsrc = ''
109 srcsubdir = ''
110 if '://' in args.source:
111 # Fetch a URL
112 srcuri = args.source
113 if args.externalsrc:
114 srctree = args.externalsrc
115 else:
116 tempsrc = tempfile.mkdtemp(prefix='recipetool-')
117 srctree = tempsrc
118 logger.info('Fetching %s...' % srcuri)
119 checksums = fetch_source(args.source, srctree)
120 dirlist = os.listdir(srctree)
121 if 'git.indirectionsymlink' in dirlist:
122 dirlist.remove('git.indirectionsymlink')
123 if len(dirlist) == 1 and os.path.isdir(os.path.join(srctree, dirlist[0])):
124 # We unpacked a single directory, so we should use that
125 srcsubdir = dirlist[0]
126 srctree = os.path.join(srctree, srcsubdir)
127 else:
128 # Assume we're pointing to an existing source tree
129 if args.externalsrc:
130 logger.error('externalsrc cannot be specified if source is a directory')
131 sys.exit(1)
132 if not os.path.isdir(args.source):
133 logger.error('Invalid source directory %s' % args.source)
134 sys.exit(1)
135 srcuri = ''
136 srctree = args.source
137
138 outfile = args.outfile
139 if outfile and outfile != '-':
140 if os.path.exists(outfile):
141 logger.error('Output file %s already exists' % outfile)
142 sys.exit(1)
143
144 lines_before = []
145 lines_after = []
146
147 lines_before.append('# Recipe created by %s' % os.path.basename(sys.argv[0]))
148 lines_before.append('# This is the basis of a recipe and may need further editing in order to be fully functional.')
149 lines_before.append('# (Feel free to remove these comments when editing.)')
150 lines_before.append('#')
151
152 licvalues = guess_license(srctree)
153 lic_files_chksum = []
154 if licvalues:
155 licenses = []
156 for licvalue in licvalues:
157 if not licvalue[0] in licenses:
158 licenses.append(licvalue[0])
159 lic_files_chksum.append('file://%s;md5=%s' % (licvalue[1], licvalue[2]))
160 lines_before.append('# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is')
161 lines_before.append('# your responsibility to verify that the values are complete and correct.')
162 if len(licvalues) > 1:
163 lines_before.append('#')
164 lines_before.append('# NOTE: multiple licenses have been detected; if that is correct you should separate')
165 lines_before.append('# these in the LICENSE value using & if the multiple licenses all apply, or | if there')
166 lines_before.append('# is a choice between the multiple licenses. If in doubt, check the accompanying')
167 lines_before.append('# documentation to determine which situation is applicable.')
168 else:
169 lines_before.append('# Unable to find any files that looked like license statements. Check the accompanying')
170 lines_before.append('# documentation and source headers and set LICENSE and LIC_FILES_CHKSUM accordingly.')
171 lines_before.append('#')
172 lines_before.append('# NOTE: LICENSE is being set to "CLOSED" to allow you to at least start building - if')
173 lines_before.append('# this is not accurate with respect to the licensing of the software being built (it')
174 lines_before.append('# will not be in most cases) you must specify the correct value before using this')
175 lines_before.append('# recipe for anything other than initial testing/development!')
176 licenses = ['CLOSED']
177 lines_before.append('LICENSE = "%s"' % ' '.join(licenses))
178 lines_before.append('LIC_FILES_CHKSUM = "%s"' % ' \\\n '.join(lic_files_chksum))
179 lines_before.append('')
180
181 # FIXME This is kind of a hack, we probably ought to be using bitbake to do this
182 # we'd also want a way to automatically set outfile based upon auto-detecting these values from the source if possible
183 recipefn = os.path.splitext(os.path.basename(outfile))[0]
184 fnsplit = recipefn.split('_')
185 if len(fnsplit) > 1:
186 pn = fnsplit[0]
187 pv = fnsplit[1]
188 else:
189 pn = recipefn
190 pv = None
191
192 if srcuri:
193 if pv and pv not in 'git svn hg'.split():
194 srcuri = srcuri.replace(pv, '${PV}')
195 else:
196 lines_before.append('# No information for SRC_URI yet (only an external source tree was specified)')
197 lines_before.append('SRC_URI = "%s"' % srcuri)
198 (md5value, sha256value) = checksums
199 if md5value:
200 lines_before.append('SRC_URI[md5sum] = "%s"' % md5value)
201 if sha256value:
202 lines_before.append('SRC_URI[sha256sum] = "%s"' % sha256value)
203 if srcuri and supports_srcrev(srcuri):
204 lines_before.append('')
205 lines_before.append('# Modify these as desired')
206 lines_before.append('PV = "1.0+git${SRCPV}"')
207 lines_before.append('SRCREV = "${AUTOREV}"')
208 lines_before.append('')
209
210 if srcsubdir and pv:
211 if srcsubdir == "%s-%s" % (pn, pv):
212 # This would be the default, so we don't need to set S in the recipe
213 srcsubdir = ''
214 if srcsubdir:
215 lines_before.append('S = "${WORKDIR}/%s"' % srcsubdir)
216 lines_before.append('')
217
218 if pkgarch:
219 lines_after.append('PACKAGE_ARCH = "%s"' % pkgarch)
220 lines_after.append('')
221
222 # Find all plugins that want to register handlers
223 handlers = []
224 for plugin in plugins:
225 if hasattr(plugin, 'register_recipe_handlers'):
226 plugin.register_recipe_handlers(handlers)
227
228 # Apply the handlers
229 classes = []
230 handled = []
231 for handler in handlers:
232 handler.process(srctree, classes, lines_before, lines_after, handled)
233
234 outlines = []
235 outlines.extend(lines_before)
236 if classes:
237 outlines.append('inherit %s' % ' '.join(classes))
238 outlines.append('')
239 outlines.extend(lines_after)
240
241 if outfile == '-':
242 sys.stdout.write('\n'.join(outlines) + '\n')
243 else:
244 with open(outfile, 'w') as f:
245 f.write('\n'.join(outlines) + '\n')
246 logger.info('Recipe %s has been created; further editing may be required to make it fully functional' % outfile)
247
248 if tempsrc:
249 shutil.rmtree(tempsrc)
250
251 return 0
252
253def get_license_md5sums(d, static_only=False):
254 import bb.utils
255 md5sums = {}
256 if not static_only:
257 # Gather md5sums of license files in common license dir
258 commonlicdir = d.getVar('COMMON_LICENSE_DIR', True)
259 for fn in os.listdir(commonlicdir):
260 md5value = bb.utils.md5_file(os.path.join(commonlicdir, fn))
261 md5sums[md5value] = fn
262 # The following were extracted from common values in various recipes
263 # (double checking the license against the license file itself, not just
264 # the LICENSE value in the recipe)
265 md5sums['94d55d512a9ba36caa9b7df079bae19f'] = 'GPLv2'
266 md5sums['b234ee4d69f5fce4486a80fdaf4a4263'] = 'GPLv2'
267 md5sums['59530bdf33659b29e73d4adb9f9f6552'] = 'GPLv2'
268 md5sums['0636e73ff0215e8d672dc4c32c317bb3'] = 'GPLv2'
269 md5sums['eb723b61539feef013de476e68b5c50a'] = 'GPLv2'
270 md5sums['751419260aa954499f7abaabaa882bbe'] = 'GPLv2'
271 md5sums['393a5ca445f6965873eca0259a17f833'] = 'GPLv2'
272 md5sums['12f884d2ae1ff87c09e5b7ccc2c4ca7e'] = 'GPLv2'
273 md5sums['8ca43cbc842c2336e835926c2166c28b'] = 'GPLv2'
274 md5sums['ebb5c50ab7cab4baeffba14977030c07'] = 'GPLv2'
275 md5sums['c93c0550bd3173f4504b2cbd8991e50b'] = 'GPLv2'
276 md5sums['9ac2e7cff1ddaf48b6eab6028f23ef88'] = 'GPLv2'
277 md5sums['4325afd396febcb659c36b49533135d4'] = 'GPLv2'
278 md5sums['18810669f13b87348459e611d31ab760'] = 'GPLv2'
279 md5sums['d7810fab7487fb0aad327b76f1be7cd7'] = 'GPLv2' # the Linux kernel's COPYING file
280 md5sums['bbb461211a33b134d42ed5ee802b37ff'] = 'LGPLv2.1'
281 md5sums['7fbc338309ac38fefcd64b04bb903e34'] = 'LGPLv2.1'
282 md5sums['4fbd65380cdd255951079008b364516c'] = 'LGPLv2.1'
283 md5sums['2d5025d4aa3495befef8f17206a5b0a1'] = 'LGPLv2.1'
284 md5sums['fbc093901857fcd118f065f900982c24'] = 'LGPLv2.1'
285 md5sums['a6f89e2100d9b6cdffcea4f398e37343'] = 'LGPLv2.1'
286 md5sums['d8045f3b8f929c1cb29a1e3fd737b499'] = 'LGPLv2.1'
287 md5sums['fad9b3332be894bab9bc501572864b29'] = 'LGPLv2.1'
288 md5sums['3bf50002aefd002f49e7bb854063f7e7'] = 'LGPLv2'
289 md5sums['9f604d8a4f8e74f4f5140845a21b6674'] = 'LGPLv2'
290 md5sums['5f30f0716dfdd0d91eb439ebec522ec2'] = 'LGPLv2'
291 md5sums['55ca817ccb7d5b5b66355690e9abc605'] = 'LGPLv2'
292 md5sums['252890d9eee26aab7b432e8b8a616475'] = 'LGPLv2'
293 md5sums['d32239bcb673463ab874e80d47fae504'] = 'GPLv3'
294 md5sums['f27defe1e96c2e1ecd4e0c9be8967949'] = 'GPLv3'
295 md5sums['6a6a8e020838b23406c81b19c1d46df6'] = 'LGPLv3'
296 md5sums['3b83ef96387f14655fc854ddc3c6bd57'] = 'Apache-2.0'
297 md5sums['385c55653886acac3821999a3ccd17b3'] = 'Artistic-1.0 | GPL-2.0' # some perl modules
298 return md5sums
299
300def guess_license(srctree):
301 import bb
302 md5sums = get_license_md5sums(tinfoil.config_data)
303
304 licenses = []
305 licspecs = ['LICENSE*', 'COPYING*', '*[Ll]icense*', 'LICENCE*', 'LEGAL*', '[Ll]egal*', '*GPL*', 'README.lic*', 'COPYRIGHT*', '[Cc]opyright*']
306 licfiles = []
307 for root, dirs, files in os.walk(srctree):
308 for fn in files:
309 for spec in licspecs:
310 if fnmatch.fnmatch(fn, spec):
311 licfiles.append(os.path.join(root, fn))
312 for licfile in licfiles:
313 md5value = bb.utils.md5_file(licfile)
314 license = md5sums.get(md5value, 'Unknown')
315 licenses.append((license, os.path.relpath(licfile, srctree), md5value))
316
317 # FIXME should we grab at least one source file with a license header and add that too?
318
319 return licenses
320
321def read_pkgconfig_provides(d):
322 pkgdatadir = d.getVar('PKGDATA_DIR', True)
323 pkgmap = {}
324 for fn in glob.glob(os.path.join(pkgdatadir, 'shlibs2', '*.pclist')):
325 with open(fn, 'r') as f:
326 for line in f:
327 pkgmap[os.path.basename(line.rstrip())] = os.path.splitext(os.path.basename(fn))[0]
328 recipemap = {}
329 for pc, pkg in pkgmap.iteritems():
330 pkgdatafile = os.path.join(pkgdatadir, 'runtime', pkg)
331 if os.path.exists(pkgdatafile):
332 with open(pkgdatafile, 'r') as f:
333 for line in f:
334 if line.startswith('PN: '):
335 recipemap[pc] = line.split(':', 1)[1].strip()
336 return recipemap
337
338def convert_pkginfo(pkginfofile):
339 values = {}
340 with open(pkginfofile, 'r') as f:
341 indesc = False
342 for line in f:
343 if indesc:
344 if line.strip():
345 values['DESCRIPTION'] += ' ' + line.strip()
346 else:
347 indesc = False
348 else:
349 splitline = line.split(': ', 1)
350 key = line[0]
351 value = line[1]
352 if key == 'LICENSE':
353 for dep in value.split(','):
354 dep = dep.split()[0]
355 mapped = depmap.get(dep, '')
356 if mapped:
357 depends.append(mapped)
358 elif key == 'License':
359 values['LICENSE'] = value
360 elif key == 'Summary':
361 values['SUMMARY'] = value
362 elif key == 'Description':
363 values['DESCRIPTION'] = value
364 indesc = True
365 return values
366
367def convert_debian(debpath):
368 # FIXME extend this mapping - perhaps use distro_alias.inc?
369 depmap = {'libz-dev': 'zlib'}
370
371 values = {}
372 depends = []
373 with open(os.path.join(debpath, 'control')) as f:
374 indesc = False
375 for line in f:
376 if indesc:
377 if line.strip():
378 if line.startswith(' This package contains'):
379 indesc = False
380 else:
381 values['DESCRIPTION'] += ' ' + line.strip()
382 else:
383 indesc = False
384 else:
385 splitline = line.split(':', 1)
386 key = line[0]
387 value = line[1]
388 if key == 'Build-Depends':
389 for dep in value.split(','):
390 dep = dep.split()[0]
391 mapped = depmap.get(dep, '')
392 if mapped:
393 depends.append(mapped)
394 elif key == 'Section':
395 values['SECTION'] = value
396 elif key == 'Description':
397 values['SUMMARY'] = value
398 indesc = True
399
400 if depends:
401 values['DEPENDS'] = ' '.join(depends)
402
403 return values
404
405
406def register_command(subparsers):
407 parser_create = subparsers.add_parser('create', help='Create a new recipe')
408 parser_create.add_argument('source', help='Path or URL to source')
409 parser_create.add_argument('-o', '--outfile', help='Full path and filename to recipe to add', required=True)
410 parser_create.add_argument('-m', '--machine', help='Make recipe machine-specific as opposed to architecture-specific', action='store_true')
411 parser_create.add_argument('-x', '--externalsrc', help='Assuming source is a URL, fetch it and extract it to the specified directory')
412 parser_create.set_defaults(func=create_recipe)
413
diff --git a/scripts/lib/recipetool/create_buildsys.py b/scripts/lib/recipetool/create_buildsys.py
new file mode 100644
index 0000000000..6c9e0efa2a
--- /dev/null
+++ b/scripts/lib/recipetool/create_buildsys.py
@@ -0,0 +1,319 @@
1# Recipe creation tool - create command build system handlers
2#
3# Copyright (C) 2014 Intel Corporation
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License version 2 as
7# published by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License along
15# with this program; if not, write to the Free Software Foundation, Inc.,
16# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18import re
19import logging
20from recipetool.create import RecipeHandler, read_pkgconfig_provides
21
22logger = logging.getLogger('recipetool')
23
24tinfoil = None
25
26def tinfoil_init(instance):
27 global tinfoil
28 tinfoil = instance
29
30class CmakeRecipeHandler(RecipeHandler):
31 def process(self, srctree, classes, lines_before, lines_after, handled):
32 if 'buildsystem' in handled:
33 return False
34
35 if RecipeHandler.checkfiles(srctree, ['CMakeLists.txt']):
36 classes.append('cmake')
37 lines_after.append('# Specify any options you want to pass to cmake using EXTRA_OECMAKE:')
38 lines_after.append('EXTRA_OECMAKE = ""')
39 lines_after.append('')
40 handled.append('buildsystem')
41 return True
42 return False
43
44class SconsRecipeHandler(RecipeHandler):
45 def process(self, srctree, classes, lines_before, lines_after, handled):
46 if 'buildsystem' in handled:
47 return False
48
49 if RecipeHandler.checkfiles(srctree, ['SConstruct', 'Sconstruct', 'sconstruct']):
50 classes.append('scons')
51 lines_after.append('# Specify any options you want to pass to scons using EXTRA_OESCONS:')
52 lines_after.append('EXTRA_OESCONS = ""')
53 lines_after.append('')
54 handled.append('buildsystem')
55 return True
56 return False
57
58class QmakeRecipeHandler(RecipeHandler):
59 def process(self, srctree, classes, lines_before, lines_after, handled):
60 if 'buildsystem' in handled:
61 return False
62
63 if RecipeHandler.checkfiles(srctree, ['*.pro']):
64 classes.append('qmake2')
65 handled.append('buildsystem')
66 return True
67 return False
68
69class AutotoolsRecipeHandler(RecipeHandler):
70 def process(self, srctree, classes, lines_before, lines_after, handled):
71 if 'buildsystem' in handled:
72 return False
73
74 autoconf = False
75 if RecipeHandler.checkfiles(srctree, ['configure.ac', 'configure.in']):
76 autoconf = True
77 values = AutotoolsRecipeHandler.extract_autotools_deps(lines_before, srctree)
78 classes.extend(values.pop('inherit', '').split())
79 for var, value in values.iteritems():
80 lines_before.append('%s = "%s"' % (var, value))
81 else:
82 conffile = RecipeHandler.checkfiles(srctree, ['configure'])
83 if conffile:
84 # Check if this is just a pre-generated autoconf configure script
85 with open(conffile[0], 'r') as f:
86 for i in range(1, 10):
87 if 'Generated by GNU Autoconf' in f.readline():
88 autoconf = True
89 break
90
91 if autoconf:
92 lines_before.append('# NOTE: if this software is not capable of being built in a separate build directory')
93 lines_before.append('# from the source, you should replace autotools with autotools-brokensep in the')
94 lines_before.append('# inherit line')
95 classes.append('autotools')
96 lines_after.append('# Specify any options you want to pass to the configure script using EXTRA_OECONF:')
97 lines_after.append('EXTRA_OECONF = ""')
98 lines_after.append('')
99 handled.append('buildsystem')
100 return True
101
102 return False
103
104 @staticmethod
105 def extract_autotools_deps(outlines, srctree, acfile=None):
106 import shlex
107 import oe.package
108
109 values = {}
110 inherits = []
111
112 # FIXME this mapping is very thin
113 progmap = {'flex': 'flex-native',
114 'bison': 'bison-native',
115 'm4': 'm4-native'}
116 progclassmap = {'gconftool-2': 'gconf',
117 'pkg-config': 'pkgconfig'}
118
119 ignoredeps = ['gcc-runtime', 'glibc', 'uclibc']
120
121 pkg_re = re.compile('PKG_CHECK_MODULES\(\[?[a-zA-Z0-9]*\]?, \[?([^,\]]*)[),].*')
122 lib_re = re.compile('AC_CHECK_LIB\(\[?([a-zA-Z0-9]*)\]?, .*')
123 progs_re = re.compile('_PROGS?\(\[?[a-zA-Z0-9]*\]?, \[?([^,\]]*)\]?[),].*')
124 dep_re = re.compile('([^ ><=]+)( [<>=]+ [^ ><=]+)?')
125
126 # Build up lib library->package mapping
127 shlib_providers = oe.package.read_shlib_providers(tinfoil.config_data)
128 libdir = tinfoil.config_data.getVar('libdir', True)
129 base_libdir = tinfoil.config_data.getVar('base_libdir', True)
130 libpaths = list(set([base_libdir, libdir]))
131 libname_re = re.compile('^lib(.+)\.so.*$')
132 pkglibmap = {}
133 for lib, item in shlib_providers.iteritems():
134 for path, pkg in item.iteritems():
135 if path in libpaths:
136 res = libname_re.match(lib)
137 if res:
138 libname = res.group(1)
139 if not libname in pkglibmap:
140 pkglibmap[libname] = pkg[0]
141 else:
142 logger.debug('unable to extract library name from %s' % lib)
143
144 # Now turn it into a library->recipe mapping
145 recipelibmap = {}
146 pkgdata_dir = tinfoil.config_data.getVar('PKGDATA_DIR', True)
147 for libname, pkg in pkglibmap.iteritems():
148 try:
149 with open(os.path.join(pkgdata_dir, 'runtime', pkg)) as f:
150 for line in f:
151 if line.startswith('PN:'):
152 recipelibmap[libname] = line.split(':', 1)[-1].strip()
153 break
154 except IOError as ioe:
155 if ioe.errno == 2:
156 logger.warn('unable to find a pkgdata file for package %s' % pkg)
157 else:
158 raise
159
160 # Since a configure.ac file is essentially a program, this is only ever going to be
161 # a hack unfortunately; but it ought to be enough of an approximation
162 if acfile:
163 srcfiles = [acfile]
164 else:
165 srcfiles = RecipeHandler.checkfiles(srctree, ['configure.ac', 'configure.in'])
166 pcdeps = []
167 deps = []
168 unmapped = []
169 unmappedlibs = []
170 with open(srcfiles[0], 'r') as f:
171 for line in f:
172 if 'PKG_CHECK_MODULES' in line:
173 res = pkg_re.search(line)
174 if res:
175 res = dep_re.findall(res.group(1))
176 if res:
177 pcdeps.extend([x[0] for x in res])
178 inherits.append('pkgconfig')
179 if line.lstrip().startswith('AM_GNU_GETTEXT'):
180 inherits.append('gettext')
181 elif 'AC_CHECK_PROG' in line or 'AC_PATH_PROG' in line:
182 res = progs_re.search(line)
183 if res:
184 for prog in shlex.split(res.group(1)):
185 prog = prog.split()[0]
186 progclass = progclassmap.get(prog, None)
187 if progclass:
188 inherits.append(progclass)
189 else:
190 progdep = progmap.get(prog, None)
191 if progdep:
192 deps.append(progdep)
193 else:
194 if not prog.startswith('$'):
195 unmapped.append(prog)
196 elif 'AC_CHECK_LIB' in line:
197 res = lib_re.search(line)
198 if res:
199 lib = res.group(1)
200 libdep = recipelibmap.get(lib, None)
201 if libdep:
202 deps.append(libdep)
203 else:
204 if libdep is None:
205 if not lib.startswith('$'):
206 unmappedlibs.append(lib)
207 elif 'AC_PATH_X' in line:
208 deps.append('libx11')
209
210 if unmapped:
211 outlines.append('# NOTE: the following prog dependencies are unknown, ignoring: %s' % ' '.join(unmapped))
212
213 if unmappedlibs:
214 outlines.append('# NOTE: the following library dependencies are unknown, ignoring: %s' % ' '.join(unmappedlibs))
215 outlines.append('# (this is based on recipes that have previously been built and packaged)')
216
217 recipemap = read_pkgconfig_provides(tinfoil.config_data)
218 unmapped = []
219 for pcdep in pcdeps:
220 recipe = recipemap.get(pcdep, None)
221 if recipe:
222 deps.append(recipe)
223 else:
224 if not pcdep.startswith('$'):
225 unmapped.append(pcdep)
226
227 deps = set(deps).difference(set(ignoredeps))
228
229 if unmapped:
230 outlines.append('# NOTE: unable to map the following pkg-config dependencies: %s' % ' '.join(unmapped))
231 outlines.append('# (this is based on recipes that have previously been built and packaged)')
232
233 if deps:
234 values['DEPENDS'] = ' '.join(deps)
235
236 if inherits:
237 values['inherit'] = ' '.join(list(set(inherits)))
238
239 return values
240
241
242class MakefileRecipeHandler(RecipeHandler):
243 def process(self, srctree, classes, lines_before, lines_after, handled):
244 if 'buildsystem' in handled:
245 return False
246
247 makefile = RecipeHandler.checkfiles(srctree, ['Makefile'])
248 if makefile:
249 lines_after.append('# NOTE: this is a Makefile-only piece of software, so we cannot generate much of the')
250 lines_after.append('# recipe automatically - you will need to examine the Makefile yourself and ensure')
251 lines_after.append('# that the appropriate arguments are passed in.')
252 lines_after.append('')
253
254 scanfile = os.path.join(srctree, 'configure.scan')
255 skipscan = False
256 try:
257 stdout, stderr = bb.process.run('autoscan', cwd=srctree, shell=True)
258 except bb.process.ExecutionError as e:
259 skipscan = True
260 if scanfile and os.path.exists(scanfile):
261 values = AutotoolsRecipeHandler.extract_autotools_deps(lines_before, srctree, acfile=scanfile)
262 classes.extend(values.pop('inherit', '').split())
263 for var, value in values.iteritems():
264 if var == 'DEPENDS':
265 lines_before.append('# NOTE: some of these dependencies may be optional, check the Makefile and/or upstream documentation')
266 lines_before.append('%s = "%s"' % (var, value))
267 lines_before.append('')
268 for f in ['configure.scan', 'autoscan.log']:
269 fp = os.path.join(srctree, f)
270 if os.path.exists(fp):
271 os.remove(fp)
272
273 self.genfunction(lines_after, 'do_configure', ['# Specify any needed configure commands here'])
274
275 func = []
276 func.append('# You will almost certainly need to add additional arguments here')
277 func.append('oe_runmake')
278 self.genfunction(lines_after, 'do_compile', func)
279
280 installtarget = True
281 try:
282 stdout, stderr = bb.process.run('make -qn install', cwd=srctree, shell=True)
283 except bb.process.ExecutionError as e:
284 if e.exitcode != 1:
285 installtarget = False
286 func = []
287 if installtarget:
288 func.append('# This is a guess; additional arguments may be required')
289 makeargs = ''
290 with open(makefile[0], 'r') as f:
291 for i in range(1, 100):
292 if 'DESTDIR' in f.readline():
293 makeargs += " 'DESTDIR=${D}'"
294 break
295 func.append('oe_runmake install%s' % makeargs)
296 else:
297 func.append('# NOTE: unable to determine what to put here - there is a Makefile but no')
298 func.append('# target named "install", so you will need to define this yourself')
299 self.genfunction(lines_after, 'do_install', func)
300
301 handled.append('buildsystem')
302 else:
303 lines_after.append('# NOTE: no Makefile found, unable to determine what needs to be done')
304 lines_after.append('')
305 self.genfunction(lines_after, 'do_configure', ['# Specify any needed configure commands here'])
306 self.genfunction(lines_after, 'do_compile', ['# Specify compilation commands here'])
307 self.genfunction(lines_after, 'do_install', ['# Specify install commands here'])
308
309
310def plugin_init(pluginlist):
311 pass
312
313def register_recipe_handlers(handlers):
314 # These are in a specific order so that the right one is detected first
315 handlers.append(CmakeRecipeHandler())
316 handlers.append(AutotoolsRecipeHandler())
317 handlers.append(SconsRecipeHandler())
318 handlers.append(QmakeRecipeHandler())
319 handlers.append(MakefileRecipeHandler())