1 | # |
---|
2 | # RTEMS Tools Project (http://www.rtems.org/) |
---|
3 | # Copyright 2010-2012 Chris Johns (chrisj@rtems.org) |
---|
4 | # All rights reserved. |
---|
5 | # |
---|
6 | # This file is part of the RTEMS Tools package in 'rtems-tools'. |
---|
7 | # |
---|
8 | # Permission to use, copy, modify, and/or distribute this software for any |
---|
9 | # purpose with or without fee is hereby granted, provided that the above |
---|
10 | # copyright notice and this permission notice appear in all copies. |
---|
11 | # |
---|
12 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
---|
13 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
---|
14 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
---|
15 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
---|
16 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
---|
17 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
---|
18 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
---|
19 | |
---|
20 | # |
---|
21 | # This code is based on what ever doco about spec files I could find and |
---|
22 | # RTEMS project's spec files. |
---|
23 | # |
---|
24 | |
---|
25 | import pprint |
---|
26 | import os |
---|
27 | |
---|
28 | import execute |
---|
29 | import path |
---|
30 | |
---|
31 | def load(): |
---|
32 | uname = os.uname() |
---|
33 | smp_mflags = '' |
---|
34 | processors = '/bin/grep processor /proc/cpuinfo' |
---|
35 | e = execute.capture_execution() |
---|
36 | exit_code, proc, output = e.shell(processors) |
---|
37 | if exit_code == 0: |
---|
38 | cpus = 0 |
---|
39 | for l in output.split('\n'): |
---|
40 | count = l.split(':')[1].strip() |
---|
41 | if count > cpus: |
---|
42 | cpus = int(count) |
---|
43 | if cpus > 0: |
---|
44 | smp_mflags = '-j%d' % (cpus) |
---|
45 | defines = { |
---|
46 | '_os': ('none', 'none', 'linux'), |
---|
47 | '_host': ('triplet', 'required', uname[4] + '-linux-gnu'), |
---|
48 | '_host_vendor': ('none', 'none', 'gnu'), |
---|
49 | '_host_os': ('none', 'none', 'linux'), |
---|
50 | '_host_cpu': ('none', 'none', uname[4]), |
---|
51 | '_host_alias': ('none', 'none', '%{nil}'), |
---|
52 | '_host_arch': ('none', 'none', uname[4]), |
---|
53 | '_usr': ('dir', 'required', '/usr'), |
---|
54 | '_var': ('dir', 'required', '/var'), |
---|
55 | 'optflags': ('none', 'none', '-O2 -pipe'), |
---|
56 | '_smp_mflags': ('none', 'none', smp_mflags), |
---|
57 | '__bzip2': ('exe', 'required', '/usr/bin/bzip2'), |
---|
58 | '__gzip': ('exe', 'required', '/bin/gzip'), |
---|
59 | '__tar': ('exe', 'required', '/bin/tar') |
---|
60 | } |
---|
61 | variations = { |
---|
62 | '__bzip2': ('exe', 'required', '/bin/bzip2'), # Ubuntu |
---|
63 | '__chgrp': ('exe', 'required', '/bin/chgrp'), # Ubuntu |
---|
64 | '__chown': ('exe', 'required', '/bin/chown'), # Ubuntu |
---|
65 | '__grep': ('exe', 'required', '/bin/grep'), # Ubuntu |
---|
66 | '__sed': ('exe', 'required', '/bin/sed'), # Ubuntu |
---|
67 | '__install_info': ('exe', 'required', '/sbin/install-info') # Fedora |
---|
68 | } |
---|
69 | for v in variations: |
---|
70 | if path.exists(variations[v][2]): |
---|
71 | defines[v] = variations[v] |
---|
72 | return defines |
---|
73 | |
---|
74 | if __name__ == '__main__': |
---|
75 | pprint.pprint(load()) |
---|