Mercurial > hg > Members > menikon > CbC_xv6
annotate src/gearsTools/pmake.pl @ 108:8162269b5682
tweak path
author | anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 21 Nov 2019 17:25:11 +0900 |
parents | 5f01480e8f12 |
children | 875ad11af596 |
rev | line source |
---|---|
60 | 1 #!/usr/bin/env perl |
2 use strict; | |
3 use warnings; | |
89
df104b2de895
remove commnad line arguments at pmake.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
86
diff
changeset
|
4 use FindBin; |
df104b2de895
remove commnad line arguments at pmake.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
86
diff
changeset
|
5 use Cwd 'getcwd'; |
94
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
6 use File::Path 'rmtree'; |
60 | 7 |
66 | 8 my ($cc,$cflags,$asm,$ld,$ldflags,$libgcc,$cmake,$kernel_cflags,$kernel_ld_flags,$kernel_ld_command, $initcode_cflags, $initcode_ld_command); |
60 | 9 |
94
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
10 my $curdir = getcwd; |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
11 |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
12 if (@ARGV) { |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
13 if ($ARGV[0] =~ /--delete/) { |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
14 my @current_dir_file = glob "*"; |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
15 map { print "$_\n";} @current_dir_file; |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
16 print "delete all files? > [y/n]\n"; |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
17 my $ans = <STDIN>; |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
18 if ($ans =~ /y/) { |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
19 print "delete ...\n"; |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
20 map { rmtree $_ } @current_dir_file; |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
21 } |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
22 } |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
23 } |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
24 |
60 | 25 $cmake = 'cmake'; |
94
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
26 my @cmake_arg = (); |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
27 my $xv6_src_dir = $FindBin::Bin; |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
28 $xv6_src_dir =~ s|(.*)/gearsTools(.*)|$1|; |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
29 |
107 | 30 my $objcopy; |
60 | 31 if ($^O =~ /darwin/){ |
108 | 32 $objcopy = "/usr/local/opt/llvm/bin/llvm-objcopy"; |
107 | 33 my $arm_library = $ENV{ARM_LIBRARY}; |
34 $cc = $ENV{CBC_COMPILER}; | |
35 $asm = $ENV{CBC_COMPILER}; | |
94
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
36 $cflags = qq|-Wall -g --target=armv6-linux-gnueabihf -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -DCBCXV6=1 -g -O0 -nodefaultlibs |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
37 -Wno-macro-redefined -Wno-gnu-designator -Wno-sometimes-uninitialized -Wno-tautological-compare |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
38 -Wno-nullability-completeness -Wno-expansion-to-defined |; |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
39 $cflags .= ' -B' . $ENV{HOME} .'/workspace/cr/arm_library/usr/lib/gcc/arm-linux-gnueabihf/6.3.0'; |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
40 $cflags .= ' --gcc-toolchain=arm-linux-gnueabihf-raspbian'; |
107 | 41 # $ld = '/usr/local/linaro/arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-ld'; |
108 | 42 $ld = "/usr/local/opt/llvm/bin/ld.lld"; |
94
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
43 |
107 | 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"; | |
94
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
46 #chomp($libgcc = `$cc --print-libgcc-file-name`); |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
47 $ldflags = " -L. -T kernel-cmake.ld"; |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
48 $kernel_cflags = '--target=armv6-linux-gnueabihf -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -Werror -g -O0 -iquote ../ -c'; |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
49 # -DX_CMAKE_C_LINK_EXECUTABLE=\"$ld $ldflags -o kernel.elf <OBJECTS> $libgcc -b binary initcode usr/fs.img\" |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
50 $kernel_ld_flags = ' -L. -N -e main -Ttext 0 <OBJECTS> -o <TARGET> <LINK_LIBRARIES> -L ../ ' . $libgcc; |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
51 #$kernel_ld_flags = ' -L. -N -e main -Ttext 0 <OBJECTS> -o <TARGET> <LINK_LIBRARIES>' ; |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
52 $kernel_ld_command = "$ld $kernel_ld_flags"; |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
53 $initcode_cflags = '--target=armv6-linux-gnueabihf -nostdinc -c'; |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
54 $initcode_ld_command = "$ld -L. -N -e start -Ttext 0 <OBJECTS> -o <TARGET> <LINK_LIBRARIES>"; |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
55 |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
56 |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
57 push(@cmake_arg, |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
58 "-DCBC_XV6_SYSROOT=\"$arm_library\"", |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
59 # "-DCMAKE_OSX_SYSROOT=\"$arm_library\"", |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
60 #"-DCMAKE_RANLIB=\"/Users/anatofuz/workspace/compiler/llvm/llvm-project/build/bin/llvm-ar\"", |
107 | 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\"", | |
94
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
65 # "-DCMAKE_OSX_XV6_INCLUDE_DIR=\"$arm_library/usr/include\"", |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
66 ); |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
67 |
60 | 68 } else { |
107 | 69 $objcopy = "arm-none-eabi-objcopy"; |
60 | 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- | |
86 | 73 -DCBCXV6=1 -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -g -O0|; |
60 | 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; | |
61 | 77 $ldflags = " -L. -T kernel-cmake.ld"; |
86 | 78 $kernel_cflags = '-march=armv6 -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -Werror -g -O0 -iquote ../ -c'; |
64 | 79 # -DX_CMAKE_C_LINK_EXECUTABLE=\"$ld $ldflags -o kernel.elf <OBJECTS> $libgcc -b binary initcode usr/fs.img\" |
63 | 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"; | |
86 | 82 $initcode_cflags = '-march=armv6 -nostdinc -c'; |
66 | 83 $initcode_ld_command = "$ld -L. -N -e start -Ttext 0 <OBJECTS> -o <TARGET> <LINK_LIBRARIES>"; |
94
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
84 |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
85 $cflags =~ s/\n//g; |
60 | 86 } |
87 | |
94
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
88 push(@cmake_arg, |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
89 "-DCBC_COM=$cc", |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
90 "-DPMAKE_ARGS=\"$cflags\"", |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
91 "-DCBC_ASM_COMPILER=$cc", |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
92 "-DX_CMAKE_LINKER=$ld", |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
93 "-DX_CMAKE_C_LINK_EXECUTABLE=\"$ld $ldflags -o kernel.elf <OBJECTS> $libgcc -b binary initcode fs.img\"", |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
94 "-DKERNEL_LINK_EXECUTABLE=\"$kernel_ld_command\"", |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
95 "-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE", |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
96 "-DINITOCDE_CFLAGS=\"$initcode_cflags\"", |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
97 "-DINITOCDE_LINK_EXECUTABLE=\"$initcode_ld_command\"", |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
98 "-S $xv6_src_dir", |
107 | 99 "-DXV6_OBJCOPY=\"$objcopy\"", |
94
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
100 $curdir); |
63 | 101 |
94
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
102 unshift(@cmake_arg, $cmake); |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
103 |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
104 create_link_script(); |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
105 print_exec_system(@cmake_arg); |
63 | 106 |
60 | 107 system("make"); |
61 | 108 #system("sh","link.sh"); |
60 | 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"); | |
90 | 130 system(join(' ',@query)); |
60 | 131 } |
132 | |
80 | 133 |
134 | |
60 | 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 |