source: rtems-libbsd/freebsd-to-rtems.py @ 314be23

4.1155-freebsd-126-freebsd-12freebsd-9.3
Last change on this file since 314be23 was 314be23, checked in by Chris Johns <chrisj@…>, on 05/01/15 at 06:02:22

freebsd-to-rtems: Refactor the conversion support to allow multiples build systems.

Split the freebsd-to-rtems.py into separate parts to allow more than
a single build system generator.

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