Mercurial > hg > CbC > CbC_xv6
annotate src/gearsTools/pmake.pl @ 94:0956648d24e5
impl cmake on macos
author | anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 23 Oct 2019 17:33:25 +0900 |
parents | dd1d9ea1b7b5 |
children | 5f01480e8f12 |
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 |
60 | 30 |
31 if ($^O =~ /darwin/){ | |
94
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
32 $cc = "$ENV{CBC_LANG_COMPILER}-7.0"; |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
33 $asm = "$ENV{CBC_LANG_COMPILER}-7.0"; |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
34 $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
|
35 -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
|
36 -Wno-nullability-completeness -Wno-expansion-to-defined |; |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
37 $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
|
38 $cflags .= ' --gcc-toolchain=arm-linux-gnueabihf-raspbian'; |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
39 #$ld = '/Users/anatofuz/workspace/compiler/llvm/llvm-project/build/bin/lld'; |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
40 #$ld = '/Users/anatofuz/workspace/compiler/llvm/llvm-project/build/bin/ld.lld'; |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
41 $ld = '/usr/local/linaro/arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-ld'; |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
42 |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
43 #$libgcc = '/Users/anatofuz/workspace/cr/arm_library/usr/lib/gcc/arm-linux-gnueabihf/6.3.0/libgcc.a'; |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
44 $libgcc = '/usr/local/lib/gcc/arm-none-eabi/7.3.1/libgcc.a'; |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
45 #chomp($libgcc = `$cc --print-libgcc-file-name`); |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
46 $ldflags = " -L. -T kernel-cmake.ld"; |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
47 $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
|
48 # -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
|
49 $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
|
50 #$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
|
51 $kernel_ld_command = "$ld $kernel_ld_flags"; |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
52 $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
|
53 $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
|
54 |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
55 my $arm_library = '/Users/anatofuz/workspace/cr/arm_library'; |
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_AR=\"/Users/anatofuz/workspace/compiler/llvm/llvm-project/build/bin/llvm-ar\"", |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
61 #"-DCMAKE_RANLIB=\"/Users/anatofuz/workspace/compiler/llvm/llvm-project/build/bin/llvm-ar\"", |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
62 "-DCMAKE_AR=\"/usr/local/linaro/arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-ar\"", |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
63 "-DCMAKE_RANLIB=\"/usr/local/linaro/arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-ranlib\"", |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
64 # "-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
|
65 ); |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
66 |
60 | 67 } else { |
68 $cc = '/mnt/dalmore-home/one/src/armgcc/cross/bin/arm-none-eabi-gcc'; | |
69 $asm = $cc; | |
70 $cflags = qq|-B/mnt/dalmore-home/one/src/armgcc/cross/bin/arm-none-eabi- | |
86 | 71 -DCBCXV6=1 -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -g -O0|; |
60 | 72 $ld = '/mnt/dalmore-home/one/src/armgcc/cross/bin/arm-none-eabi-ld'; |
73 chomp($libgcc = `$cc --print-libgcc-file-name`); | |
74 $cmake .= 3; | |
61 | 75 $ldflags = " -L. -T kernel-cmake.ld"; |
86 | 76 $kernel_cflags = '-march=armv6 -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -Werror -g -O0 -iquote ../ -c'; |
64 | 77 # -DX_CMAKE_C_LINK_EXECUTABLE=\"$ld $ldflags -o kernel.elf <OBJECTS> $libgcc -b binary initcode usr/fs.img\" |
63 | 78 $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'; |
79 $kernel_ld_command = "$ld $kernel_ld_flags"; | |
86 | 80 $initcode_cflags = '-march=armv6 -nostdinc -c'; |
66 | 81 $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
|
82 |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
83 $cflags =~ s/\n//g; |
60 | 84 } |
85 | |
94
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
86 push(@cmake_arg, |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
87 "-DCBC_COM=$cc", |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
88 "-DPMAKE_ARGS=\"$cflags\"", |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
89 "-DCBC_ASM_COMPILER=$cc", |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
90 "-DX_CMAKE_LINKER=$ld", |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
91 "-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
|
92 "-DKERNEL_LINK_EXECUTABLE=\"$kernel_ld_command\"", |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
93 "-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE", |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
94 "-DINITOCDE_CFLAGS=\"$initcode_cflags\"", |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
95 "-DINITOCDE_LINK_EXECUTABLE=\"$initcode_ld_command\"", |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
96 "-S $xv6_src_dir", |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
97 $curdir); |
63 | 98 |
94
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
99 unshift(@cmake_arg, $cmake); |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
100 |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
101 create_link_script(); |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
102 print_exec_system(@cmake_arg); |
63 | 103 |
60 | 104 system("make"); |
61 | 105 #system("sh","link.sh"); |
60 | 106 |
107 sub create_link_script { | |
108 my @link_script; | |
109 while (my $line = <DATA>){ | |
110 $line =~ s/LD/$ld/; | |
111 $line =~ s/LIBGCC/$libgcc/; | |
112 push @link_script,$line; | |
113 } | |
114 if ($^O =~ /darwin/){ | |
115 for (@link_script){ | |
116 s/CMakeFiles/build/; | |
117 s|kernel\.dir/||; | |
118 } | |
119 } | |
120 open my $fh, '>', 'link.sh'; | |
121 print $fh "@link_script"; | |
122 } | |
123 | |
124 sub print_exec_system { | |
125 my @query = @_; | |
126 print(join(' ',@query), "\n"); | |
90 | 127 system(join(' ',@query)); |
60 | 128 } |
129 | |
80 | 130 |
131 | |
60 | 132 __DATA__ |
133 cp initcode ./CMakeFiles/kernel.dir/initcode | |
134 cp fs.img ./CMakeFiles/kernel.dir/fs.img | |
135 | |
136 LD \ | |
137 -L. \ | |
138 -T \ | |
139 kernel-cmake.ld \ | |
140 -o \ | |
141 kernel.elf \ | |
142 \ | |
143 CMakeFiles/kernel.dir/lib/string.c.o \ | |
144 CMakeFiles/kernel.dir/arm.c.o \ | |
145 CMakeFiles/kernel.dir/asm.S.o \ | |
146 CMakeFiles/kernel.dir/bio.c.o \ | |
147 CMakeFiles/kernel.dir/buddy.c.o \ | |
148 CMakeFiles/kernel.dir/c/console.c.o \ | |
149 CMakeFiles/kernel.dir/exec.c.o \ | |
150 CMakeFiles/kernel.dir/c/file.c.o \ | |
151 CMakeFiles/kernel.dir/fs.c.o \ | |
152 CMakeFiles/kernel.dir/log.c.o \ | |
153 CMakeFiles/kernel.dir/main.c.o \ | |
154 CMakeFiles/kernel.dir/memide.c.o \ | |
155 CMakeFiles/kernel.dir/c/pipe.c.o \ | |
156 CMakeFiles/kernel.dir/c/proc.c.o \ | |
157 CMakeFiles/kernel.dir/c/spinlock.c.o \ | |
158 CMakeFiles/kernel.dir/start.c.o \ | |
159 CMakeFiles/kernel.dir/swtch.S.o \ | |
160 CMakeFiles/kernel.dir/c/syscall.c.o \ | |
161 CMakeFiles/kernel.dir/c/sysfile.c.o \ | |
162 CMakeFiles/kernel.dir/sysproc.c.o \ | |
163 CMakeFiles/kernel.dir/trap_asm.S.o \ | |
164 CMakeFiles/kernel.dir/trap.c.o \ | |
165 CMakeFiles/kernel.dir/vm.c.o \ | |
166 CMakeFiles/kernel.dir/device/picirq.c.o \ | |
167 CMakeFiles/kernel.dir/device/timer.c.o \ | |
168 CMakeFiles/kernel.dir/device/uart.c.o \ | |
169 CMakeFiles/kernel.dir/entry.S.o \ | |
170 CMakeFiles/kernel.dir/c/kernel-context.c.o \ | |
171 \ | |
172 \ | |
173 LIBGCC \ | |
174 \ | |
175 -b \ | |
176 binary \ | |
177 initcode \ | |
178 fs.img |