OpenCores
URL https://opencores.org/ocsvn/c0or1k/c0or1k/trunk

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [porting_tools/] [porter.py] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 9 drasko
#! /usr/bin/env python2.6
2
# -*- mode: python; coding: utf-8; -*-
3
#
4
# Top-level clean script for Codezero
5
#
6
# Cleans the Codezero environment
7
#
8
 
9
import ConfigParser
10
import string
11
import re
12
import os
13
import shutil
14
import fnmatch
15
 
16
 
17
# project root path
18
c0root = '..'
19
 
20
# read configuration file
21
conf = ConfigParser.ConfigParser()
22
conf.read("port.cfg")
23
 
24
arch = conf.get("Architecture", "ARCH")
25
prefix = conf.get("Compiler", "TOOLCHAIN_PREFIX")
26
march = conf.get("Compiler", "MARCH_FLAG")
27
 
28
 
29
########################
30
# change configure.py
31
########################
32
print "\n### Changing configure.py..."
33
 
34
confpy_in = open(c0root + "/configure.py", 'r').readlines()
35
confpy_out = open(c0root + "/configure.py", 'w')
36
 
37
for line in confpy_in:
38
    if re.match(".*options.arch = \"arm\"", line):
39
        line = line.replace("arm", arch)
40
 
41
    confpy_out.write(line)
42
 
43
confpy_out.close()
44
 
45
print "### OK"
46
 
47
 
48
########################
49
# create cml2 ruleset
50
#######################
51
print "\n### Creating " + arch + ".ruleset"
52
 
53
ruleset_path = c0root + "/config/cml/"
54
arm_ruleset = open(ruleset_path + "arm.ruleset", 'rU')
55
arch_ruleset = open(ruleset_path + arch + ".ruleset", 'w')
56
 
57
for line in arm_ruleset:
58
    line = line.replace("ARM", arch.upper())
59
    line = line.replace("arm", arch)
60
    if re.match("default TOOLCHAIN_USERSPACE from", line):
61
        line = "default TOOLCHAIN_USERSPACE from '" + prefix + "'\n"
62
    if re.match("default TOOLCHAIN_KERNEL from", line):
63
        line = "default TOOLCHAIN_KERNEL from '" + prefix + "'\n"
64
 
65
    arch_ruleset.write(line)
66
 
67
arm_ruleset.close()
68
arch_ruleset.close()
69
 
70
print "### OK"
71
 
72
 
73
########################
74
# remove march flag
75
########################
76
 
77
def remove_march(scon_file):
78
    scon_file_in = open(scon_file, 'r').readlines()
79
 
80
    scon_file_out = open(scon_file, 'w')
81
 
82
    for line in scon_file_in:
83
        if re.search(", '-march=' \+ gcc_arch_flag", line):
84
            line = line.replace(", '-march=' + gcc_arch_flag", "")
85
        elif re.search("'-march=' \+ gcc_arch_flag,", line):
86
            line = line.replace("'-march=' + gcc_arch_flag,", "")
87
 
88
        scon_file_out.write(line)
89
 
90
    scon_file_out.close()
91
 
92
# ENDF remove_march()
93
 
94
if (march == 'N'):
95
    print "\n### Removing -march flag from SConscript files..."
96
 
97
    for top, dirs, filenames in os.walk(c0root):
98
        for filename in filenames:
99
            if re.match("SConstruct[.*]?", filename):
100
                scon_file = os.path.join(top, filename)
101
                print "Processing", scon_file
102
                remove_march(scon_file)
103
 
104
print "### OK"
105
 
106
 
107
###########################
108
# Hide all assebly files
109
###########################
110
print "\n### Renaming <name>.S files to <name>.S.ARM (to remove them from the compilation)..."
111
 
112
for top, dirs, filenames in os.walk(c0root):
113
    for file in filenames:
114
        if fnmatch.fnmatch(file, '*.S'):
115
            S_path = os.path.join(top, file)
116
            print "Renaming file", S_path
117
            os.rename(S_path, S_path + ".ARM")
118
 
119
print "### OK"
120
 
121
 
122
########################
123
# Create <arch> dirs
124
########################
125
print "\n### Adding missing <arch> directories (by copying existing arm and arch-arm dirs)..."
126
 
127
for top, dirs, filenames in os.walk(c0root):
128
    for dir in dirs:
129
        if re.match("(arch-)?arm", dir):
130
            arm_dir = os.path.join(top, dir)
131
            arch_dir = arm_dir.replace("arm", arch)
132
            #print "Copying", arm_dir,"to", arch_dir, "..."
133
            #shutil.copytree(arm_dir, arch_dir)
134
            print arch_dir
135
 
136
print "### OK"
137
 
138
 
139
########################
140
# Fix broken symlinks
141
########################
142
print "\n### Fixing broken symlinks (possibly produced by moving arm dirs to <arch> dirs)..."
143
 
144
for top, dirs, filenames in os.walk(c0root):
145
    for file in filenames:
146
        symlink_path = os.path.join(top, file)
147
        if os.path.islink(symlink_path) and not os.path.exists(symlink_path):
148
            symlink_source = os.readlink(symlink_path)
149
            if re.search("arm", symlink_source):
150
                fixed_symlink_source = symlink_source.replace("arm", arch)
151
                print "Fixing", symlink_path, "to point to", fixed_symlink_source
152
                os.unlink(symlink_path)
153
                os.symlink(fixed_symlink_source, symlink_path)
154
 
155
print "### OK"
156
 
157
"""
158
#######################################
159
# Hard coded stuff in main SConstruct
160
######################################
161
 
162
 
163
#create_kernel_linker = Command(join(builddir, 'include/l4/arch/arm/linker.lds'), \
164
#                               join(PROJROOT, 'include/l4/arch/arm/linker.lds.in'), \
165
#                               generate_kernel_linker_script)
166
 
167
"""
168
 
169
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.