source: rtems-libbsd/freebsd-to-rtems.py @ 70d52b8

55-freebsd-126-freebsd-12freebsd-9.3
Last change on this file since 70d52b8 was 5338089, checked in by Chris Johns <chrisj@…>, on 05/04/16 at 06:24:11

Fix coding to be CamelCase.

  • Property mode set to 100755
File size: 6.1 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
51
52def usage():
53    print("freebsd-to-rtems.py [args]")
54    print("  -?|-h|--help      print this and exit")
55    print("  -d|--dry-run      run program but no modifications")
56    print("  -D|--diff         provide diff of files between trees")
57    print("  -e|--early-exit   evaluate arguments, print results, and exit")
58    print("  -m|--makefile     Warning: depreciated and will be removed ")
59    print("  -b|--buildscripts just generate the build scripts")
60    print("  -R|--reverse      default FreeBSD -> RTEMS, reverse that")
61    print("  -r|--rtems        RTEMS Libbsd directory (default: '.')")
62    print("  -f|--freebsd      FreeBSD SVN directory (default: 'freebsd-org')")
63    print("  -v|--verbose      enable verbose output mode")
64
65# Parse the arguments
66def parseArguments():
67    global isForward, isEarlyExit
68    global isOnlyBuildScripts
69    try:
70        opts, args = getopt.getopt(sys.argv[1:],
71                                   "?hdDembRr:f:v",
72                                   [ "help",
73                                     "help",
74                                     "dry-run"
75                                     "diff"
76                                     "early-exit"
77                                     "makefile"
78                                     "buildscripts"
79                                     "reverse"
80                                     "rtems="
81                                     "freebsd="
82                                     "verbose" ])
83    except getopt.GetoptError as err:
84        # print help information and exit:
85        print(str(err)) # will print something like "option -a not recognized"
86        usage()
87        sys.exit(2)
88    for o, a in opts:
89        if o in ("-v", "--verbose"):
90            builder.verboseLevel += 1
91        elif o in ("-h", "--help", "-?"):
92            usage()
93            sys.exit()
94        elif o in ("-d", "--dry-run"):
95            builder.isDryRun = True
96        elif o in ("-D", "--diff"):
97            builder.isDiffMode = True
98        elif o in ("-e", "--early-exit"):
99            isEarlyExit = True
100        elif o in ("-b", "--buildscripts") or o in ("-m", "--makefile"):
101            isOnlyBuildScripts = True
102        elif o in ("-R", "--reverse"):
103            isForward = False
104        elif o in ("-r", "--rtems"):
105            builder.RTEMS_DIR = a
106        elif o in ("-f", "--freebsd"):
107            builder.FreeBSD_DIR = a
108        else:
109            assert False, "unhandled option"
110
111parseArguments()
112
113print("Verbose:                     %s (%d)" % (("no", "yes")[builder.verbose()],
114                                                builder.verboseLevel))
115print("Dry Run:                     %s" % (("no", "yes")[builder.isDryRun]))
116print("Diff Mode Enabled:           %s" % (("no", "yes")[builder.isDiffMode]))
117print("Only Generate Build Scripts: %s" % (("no", "yes")[isOnlyBuildScripts]))
118print("RTEMS Libbsd Directory:      %s" % (builder.RTEMS_DIR))
119print("FreeBSD SVN Directory:       %s" % (builder.FreeBSD_DIR))
120print("Direction:                   %s" % (("reverse", "forward")[isForward]))
121
122# Check directory argument was set and exist
123def wasDirectorySet(desc, path):
124    if path == "not_set":
125        print("error:" + desc + " Directory was not specified on command line")
126        sys.exit(2)
127
128    if os.path.isdir( path ) != True:
129        print("error:" + desc + " Directory (" + path + ") does not exist")
130        sys.exit(2)
131
132# Were RTEMS and FreeBSD directories specified
133wasDirectorySet( "RTEMS", builder.RTEMS_DIR )
134wasDirectorySet( "FreeBSD", builder.FreeBSD_DIR )
135
136# Are we generating or reverting?
137if isForward == True:
138    print("Forward from FreeBSD GIT into ", builder.RTEMS_DIR)
139else:
140    print("Reverting from ", builder.RTEMS_DIR)
141    if isOnlyBuildScripts == True:
142        print("error: Build Script generation and Reverse are contradictory")
143        sys.exit(2)
144
145if isEarlyExit == True:
146    print("Early exit at user request")
147    sys.exit(0)
148
149try:
150    wafGen = waf_generator.ModuleManager()
151    libbsd.sources(wafGen)
152    if not isOnlyBuildScripts:
153        wafGen.processSource(isForward)
154    wafGen.generate(libbsd.rtems_version())
155    builder.changedFileSummary()
156except IOError as ioe:
157    print('error: %s' % (str(ioe)))
158except builder.error as be:
159    print('error: %s' % (be))
160except KeyboardInterrupt:
161    print('user abort')
Note: See TracBrowser for help on using the repository browser.