Mercurial > hg > Gears > GearsTools
comparison pmake.pl @ 1:9a4279c88aa7 default tip
copy from xv6 repository
author | anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 06 Mar 2020 14:59:59 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:720e9c0936e0 | 1:9a4279c88aa7 |
---|---|
1 #!/usr/bin/env perl | |
2 use strict; | |
3 use warnings; | |
4 use FindBin; | |
5 use Cwd 'getcwd'; | |
6 use File::Path 'rmtree'; | |
7 | |
8 my ($cc,$cflags,$asm,$ld,$ldflags,$libgcc,$cmake,$kernel_cflags,$kernel_ld_flags,$kernel_ld_command, $initcode_cflags, $initcode_ld_command); | |
9 | |
10 my $curdir = getcwd; | |
11 | |
12 if (@ARGV) { | |
13 if ($ARGV[0] =~ /--del/) { | |
14 my @current_dir_file = glob "*"; | |
15 map { print "$_\n";} @current_dir_file; | |
16 print "delete all files? > [y/n]\n"; | |
17 my $ans = <STDIN>; | |
18 if ($ans =~ /y/) { | |
19 print "delete ...\n"; | |
20 map { rmtree $_ } @current_dir_file; | |
21 } | |
22 } | |
23 } | |
24 | |
25 $cmake = 'cmake'; | |
26 my @cmake_arg = (); | |
27 my $xv6_src_dir = $FindBin::Bin; | |
28 $xv6_src_dir =~ s|(.*)/gearsTools(.*)|$1|; | |
29 | |
30 my $objcopy; | |
31 if ($^O =~ /darwin/){ | |
32 $objcopy = "/usr/local/opt/llvm/bin/llvm-objcopy"; | |
33 my $arm_library = $ENV{ARM_LIBRARY}; | |
34 $cc = $ENV{CBC_COMPILER}; | |
35 $asm = $ENV{CBC_COMPILER}; | |
36 $cflags = qq|-Wall -g --target=armv6-linux-gnueabihf -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -DCBCXV6=1 -g -O0 -nodefaultlibs | |
37 -Wno-macro-redefined -Wno-gnu-designator -Wno-sometimes-uninitialized -Wno-tautological-compare | |
38 -Wno-nullability-completeness -Wno-expansion-to-defined |; | |
39 $cflags .= ' -B' . $ENV{HOME} .'/workspace/cr/arm_library/usr/lib/gcc/arm-linux-gnueabihf/6.3.0'; | |
40 $cflags .= ' --gcc-toolchain=arm-linux-gnueabihf-raspbian'; | |
41 # $ld = '/usr/local/linaro/arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-ld'; | |
42 $ld = "/usr/local/opt/llvm/bin/ld.lld"; | |
43 | |
44 # $libgcc = '/usr/local/lib/gcc/arm-none-eabi/7.3.1/libgcc.a'; | |
45 $libgcc = "$arm_library/usr/lib/gcc/arm-linux-gnueabihf/6.3.0/libgcc.a"; | |
46 #chomp($libgcc = `$cc --print-libgcc-file-name`); | |
47 $ldflags = " -L. -T kernel-cmake.ld"; | |
48 $kernel_cflags = '--target=armv6-linux-gnueabihf -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -Werror -g -O0 -iquote ../ -c'; | |
49 # -DX_CMAKE_C_LINK_EXECUTABLE=\"$ld $ldflags -o kernel.elf <OBJECTS> $libgcc -b binary initcode usr/fs.img\" | |
50 $kernel_ld_flags = ' -L. -N -e main -Ttext 0 <OBJECTS> -o <TARGET> <LINK_LIBRARIES> -L ../ ' . $libgcc; | |
51 #$kernel_ld_flags = ' -L. -N -e main -Ttext 0 <OBJECTS> -o <TARGET> <LINK_LIBRARIES>' ; | |
52 $kernel_ld_command = "$ld $kernel_ld_flags"; | |
53 $initcode_cflags = '--target=armv6-linux-gnueabihf -nostdinc -c'; | |
54 $initcode_ld_command = "$ld -L. -N -e start -Ttext 0 <OBJECTS> -o <TARGET> <LINK_LIBRARIES>"; | |
55 | |
56 | |
57 push(@cmake_arg, | |
58 "-DCBC_XV6_SYSROOT=\"$arm_library\"", | |
59 # "-DCMAKE_OSX_SYSROOT=\"$arm_library\"", | |
60 #"-DCMAKE_RANLIB=\"/Users/anatofuz/workspace/compiler/llvm/llvm-project/build/bin/llvm-ar\"", | |
61 "-DCMAKE_AR=\"/usr/local/opt/llvm/bin/llvm-ar\"", | |
62 "-DCMAKE_RANLIB=\"/usr/local/opt/llvm/bin/llvm-ranlib\"", | |
63 # "-DCMAKE_AR=\"/usr/local/linaro/arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-ar\"", | |
64 # "-DCMAKE_RANLIB=\"/usr/local/linaro/arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-ranlib\"", | |
65 # "-DCMAKE_OSX_XV6_INCLUDE_DIR=\"$arm_library/usr/include\"", | |
66 ); | |
67 | |
68 } else { | |
69 $objcopy = "arm-none-eabi-objcopy"; | |
70 $cc = '/mnt/dalmore-home/one/src/armgcc/cross/bin/arm-none-eabi-gcc'; | |
71 $asm = $cc; | |
72 $cflags = qq|-B/mnt/dalmore-home/one/src/armgcc/cross/bin/arm-none-eabi- | |
73 -DCBCXV6=1 -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -g -O0|; | |
74 $ld = '/mnt/dalmore-home/one/src/armgcc/cross/bin/arm-none-eabi-ld'; | |
75 chomp($libgcc = `$cc --print-libgcc-file-name`); | |
76 $cmake .= 3; | |
77 $ldflags = " -L. -T kernel-cmake.ld"; | |
78 $kernel_cflags = '-march=armv6 -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -Werror -g -O0 -iquote ../ -c'; | |
79 # -DX_CMAKE_C_LINK_EXECUTABLE=\"$ld $ldflags -o kernel.elf <OBJECTS> $libgcc -b binary initcode usr/fs.img\" | |
80 $kernel_ld_flags = ' -L. -N -e main -Ttext 0 <OBJECTS> -o <TARGET> <LINK_LIBRARIES> -L ../ /mnt/dalmore-home/one/src/gcc-arm-none-eabi-6-2017-q2-update/bin/../lib/gcc/arm-none-eabi/6.3.1/libgcc.a'; | |
81 $kernel_ld_command = "$ld $kernel_ld_flags"; | |
82 $initcode_cflags = '-march=armv6 -nostdinc -c'; | |
83 $initcode_ld_command = "$ld -L. -N -e start -Ttext 0 <OBJECTS> -o <TARGET> <LINK_LIBRARIES>"; | |
84 | |
85 $cflags =~ s/\n//g; | |
86 } | |
87 | |
88 push(@cmake_arg, | |
89 "-DCBC_COM=$cc", | |
90 "-DPMAKE_ARGS=\"$cflags\"", | |
91 "-DCBC_ASM_COMPILER=$cc", | |
92 "-DX_CMAKE_LINKER=$ld", | |
93 "-DX_CMAKE_C_LINK_EXECUTABLE=\"$ld $ldflags -o kernel.elf <OBJECTS> $libgcc -b binary initcode fs.img\"", | |
94 "-DKERNEL_LINK_EXECUTABLE=\"$kernel_ld_command\"", | |
95 "-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE", | |
96 "-DINITOCDE_CFLAGS=\"$initcode_cflags\"", | |
97 "-DINITOCDE_LINK_EXECUTABLE=\"$initcode_ld_command\"", | |
98 "-S $xv6_src_dir", | |
99 "-DXV6_OBJCOPY=\"$objcopy\"", | |
100 $curdir); | |
101 | |
102 unshift(@cmake_arg, $cmake); | |
103 | |
104 create_link_script(); | |
105 print_exec_system(@cmake_arg); | |
106 | |
107 system("make"); | |
108 #system("sh","link.sh"); | |
109 | |
110 sub create_link_script { | |
111 my @link_script; | |
112 while (my $line = <DATA>){ | |
113 $line =~ s/LD/$ld/; | |
114 $line =~ s/LIBGCC/$libgcc/; | |
115 push @link_script,$line; | |
116 } | |
117 if ($^O =~ /darwin/){ | |
118 for (@link_script){ | |
119 s/CMakeFiles/build/; | |
120 s|kernel\.dir/||; | |
121 } | |
122 } | |
123 open my $fh, '>', 'link.sh'; | |
124 print $fh "@link_script"; | |
125 } | |
126 | |
127 sub print_exec_system { | |
128 my @query = @_; | |
129 print(join(' ',@query), "\n"); | |
130 system(join(' ',@query)); | |
131 } | |
132 | |
133 | |
134 | |
135 __DATA__ | |
136 cp initcode ./CMakeFiles/kernel.dir/initcode | |
137 cp fs.img ./CMakeFiles/kernel.dir/fs.img | |
138 | |
139 LD \ | |
140 -L. \ | |
141 -T \ | |
142 kernel-cmake.ld \ | |
143 -o \ | |
144 kernel.elf \ | |
145 \ | |
146 CMakeFiles/kernel.dir/lib/string.c.o \ | |
147 CMakeFiles/kernel.dir/arm.c.o \ | |
148 CMakeFiles/kernel.dir/asm.S.o \ | |
149 CMakeFiles/kernel.dir/bio.c.o \ | |
150 CMakeFiles/kernel.dir/buddy.c.o \ | |
151 CMakeFiles/kernel.dir/c/console.c.o \ | |
152 CMakeFiles/kernel.dir/exec.c.o \ | |
153 CMakeFiles/kernel.dir/c/file.c.o \ | |
154 CMakeFiles/kernel.dir/fs.c.o \ | |
155 CMakeFiles/kernel.dir/log.c.o \ | |
156 CMakeFiles/kernel.dir/main.c.o \ | |
157 CMakeFiles/kernel.dir/memide.c.o \ | |
158 CMakeFiles/kernel.dir/c/pipe.c.o \ | |
159 CMakeFiles/kernel.dir/c/proc.c.o \ | |
160 CMakeFiles/kernel.dir/c/spinlock.c.o \ | |
161 CMakeFiles/kernel.dir/start.c.o \ | |
162 CMakeFiles/kernel.dir/swtch.S.o \ | |
163 CMakeFiles/kernel.dir/c/syscall.c.o \ | |
164 CMakeFiles/kernel.dir/c/sysfile.c.o \ | |
165 CMakeFiles/kernel.dir/sysproc.c.o \ | |
166 CMakeFiles/kernel.dir/trap_asm.S.o \ | |
167 CMakeFiles/kernel.dir/trap.c.o \ | |
168 CMakeFiles/kernel.dir/vm.c.o \ | |
169 CMakeFiles/kernel.dir/device/picirq.c.o \ | |
170 CMakeFiles/kernel.dir/device/timer.c.o \ | |
171 CMakeFiles/kernel.dir/device/uart.c.o \ | |
172 CMakeFiles/kernel.dir/entry.S.o \ | |
173 CMakeFiles/kernel.dir/c/kernel-context.c.o \ | |
174 \ | |
175 \ | |
176 LIBGCC \ | |
177 \ | |
178 -b \ | |
179 binary \ | |
180 initcode \ | |
181 fs.img |