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

55-freebsd-126-freebsd-12freebsd-9.3
Last change on this file since df811cf was df811cf, checked in by Sebastian Huber <sebastian.huber@…>, on 09/25/15 at 12:07:00

Makefile: Delete

Use waf instead.

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