source: rtems-libbsd/freebsd-to-rtems.py @ e2d48f5

55-freebsd-126-freebsd-12
Last change on this file since e2d48f5 was 23d6e50, checked in by Sebastian Huber <sebastian.huber@…>, on 04/03/17 at 13:18:09

scripts: Support Linux import

  • Property mode set to 100755
File size: 6.5 KB
Line 
1#! /usr/bin/env python
2#
3#  Copyright (c) 2015-2016 Chris Johns <chrisj@rtems.org>. All rights reserved.
4#
5#  Copyright (c) 2009-2015 embedded brains GmbH.  All rights reserved.
6#
7#   embedded brains GmbH
8#   Dornierstr. 4
9#   82178 Puchheim
10#   Germany
11#   <info@embedded-brains.de>
12#
13#  Copyright (c) 2012 OAR Corporation. All rights reserved.
14#
15#  Redistribution and use in source and binary forms, with or without
16#  modification, are permitted provided that the following conditions
17#  are met:
18#  1. Redistributions of source code must retain the above copyright
19#     notice, this list of conditions and the following disclaimer.
20#  2. Redistributions in binary form must reproduce the above copyright
21#     notice, this list of conditions and the following disclaimer in the
22#     documentation and/or other materials provided with the distribution.
23#
24#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25#  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26#  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27#  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28#  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30#  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31#  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32#  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33#  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34#  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
36# FreeBSD: http://svn.freebsd.org/base/releng/8.2/sys (revision 222485)
37
38from __future__ import print_function
39
40import os
41import sys
42import getopt
43
44import builder
45import waf_generator
46import libbsd
47
48isForward = True
49isEarlyExit = False
50isOnlyBuildScripts = False
51statsReport = False
52
53def usage():
54    print("freebsd-to-rtems.py [args]")
55    print("  -?|-h|--help      print this and exit")
56    print("  -d|--dry-run      run program but no modifications")
57    print("  -D|--diff         provide diff of files between trees")
58    print("  -e|--early-exit   evaluate arguments, print results, and exit")
59    print("  -m|--makefile     Warning: depreciated and will be removed ")
60    print("  -b|--buildscripts just generate the build scripts")
61    print("  -S|--stats        Print a statistics report")
62    print("  -R|--reverse      default origin -> LibBSD, reverse that")
63    print("  -r|--rtems        LibBSD directory (default: '.')")
64    print("  -f|--freebsd      FreeBSD origin directory (default: 'freebsd-org')")
65    print("  -v|--verbose      enable verbose output mode")
66
67# Parse the arguments
68def parseArguments():
69    global isForward, isEarlyExit, statsReport
70    global isOnlyBuildScripts
71    try:
72        opts, args = getopt.getopt(sys.argv[1:],
73                                   "?hdDembSRr:f:v",
74                                   [ "help",
75                                     "help",
76                                     "dry-run"
77                                     "diff"
78                                     "early-exit"
79                                     "makefile"
80                                     "buildscripts"
81                                     "reverse"
82                                     "stats"
83                                     "rtems="
84                                     "freebsd="
85                                     "verbose" ])
86    except getopt.GetoptError as err:
87        # print help information and exit:
88        print(str(err)) # will print something like "option -a not recognized"
89        usage()
90        sys.exit(2)
91    for o, a in opts:
92        if o in ("-v", "--verbose"):
93            builder.verboseLevel += 1
94        elif o in ("-h", "--help", "-?"):
95            usage()
96            sys.exit()
97        elif o in ("-d", "--dry-run"):
98            builder.isDryRun = True
99        elif o in ("-D", "--diff"):
100            builder.isDiffMode = True
101        elif o in ("-e", "--early-exit"):
102            isEarlyExit = True
103        elif o in ("-b", "--buildscripts") or o in ("-m", "--makefile"):
104            isOnlyBuildScripts = True
105        elif o in ("-S", "--stats"):
106            statsReport = True
107        elif o in ("-R", "--reverse"):
108            isForward = False
109        elif o in ("-r", "--rtems"):
110            builder.LIBBSD_DIR = a
111        elif o in ("-f", "--freebsd"):
112            builder.FreeBSD_DIR = a
113        else:
114            assert False, "unhandled option"
115
116parseArguments()
117
118print("Verbose:                     %s (%d)" % (("no", "yes")[builder.verbose()],
119                                                builder.verboseLevel))
120print("Dry Run:                     %s" % (("no", "yes")[builder.isDryRun]))
121print("Diff Mode Enabled:           %s" % (("no", "yes")[builder.isDiffMode]))
122print("Only Generate Build Scripts: %s" % (("no", "yes")[isOnlyBuildScripts]))
123print("LibBSD Directory:            %s" % (builder.LIBBSD_DIR))
124print("FreeBSD Directory:           %s" % (builder.FreeBSD_DIR))
125print("Linux Directory:             %s" % (builder.Linux_DIR))
126print("Direction:                   %s" % (("reverse", "forward")[isForward]))
127
128# Check directory argument was set and exist
129def wasDirectorySet(desc, path):
130    if path == "not_set":
131        print("error:" + desc + " Directory was not specified on command line")
132        sys.exit(2)
133
134    if os.path.isdir( path ) != True:
135        print("error:" + desc + " Directory (" + path + ") does not exist")
136        sys.exit(2)
137
138# Were directories specified?
139wasDirectorySet( "LibBSD", builder.LIBBSD_DIR )
140wasDirectorySet( "FreeBSD", builder.FreeBSD_DIR )
141wasDirectorySet( "Linux", builder.Linux_DIR )
142
143# Are we generating or reverting?
144if isForward == True:
145    print("Forward from", builder.FreeBSD_DIR, "and", builder.Linux_DIR, "into", builder.LIBBSD_DIR)
146else:
147    print("Reverting from", builder.LIBBSD_DIR)
148    if isOnlyBuildScripts == True:
149        print("error: Build Script generation and Reverse are contradictory")
150        sys.exit(2)
151
152if isEarlyExit == True:
153    print("Early exit at user request")
154    sys.exit(0)
155
156try:
157    wafGen = waf_generator.ModuleManager()
158    libbsd.sources(wafGen)
159    if not isOnlyBuildScripts:
160        wafGen.processSource(isForward)
161    wafGen.generate(libbsd.rtems_version())
162    builder.changedFileSummary(statsReport)
163except IOError as ioe:
164    print('error: %s' % (str(ioe)))
165except builder.error as be:
166    print('error: %s' % (be))
167except KeyboardInterrupt:
168    print('user abort')
Note: See TracBrowser for help on using the repository browser.