Mercurial > hg > CbC > CbC_xv6
annotate src/gearsTools/pmake.pl @ 391:72c38f531ae2
macOS first try
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 29 Sep 2020 22:57:02 +0900 |
parents | 875ad11af596 |
children | b7235d42396f |
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) { |
240 | 13 if ($ARGV[0] =~ /--del/) { |
94
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/){ |
391 | 32 my $armdir = "/usr/local/Cellar/arm-none-eabi-gcc/9-2019-q4-major"; |
33 $objcopy = "$armdir/bin/arm-none-eabi-objcopy"; | |
34 my $cbcmdir = "/usr/local/Cellar/cbc/llvm10"; | |
35 $cc = "$cbcmdir/bin/clang --target=armv6-linux-gnueabihf -I$xv6_src_dir/cbclang/arm"; | |
36 $asm = $cc; | |
37 $cflags = qq|-B$armdir/bin/arm-none-eabi- | |
38 -DCBCXV6=1 -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -g -O0|; | |
39 $ld = "$armdir/bin/arm-none-eabi-ld"; | |
40 chomp($libgcc = `$cc --print-libgcc-file-name`); | |
41 # $cmake .= 3; | |
94
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
42 $ldflags = " -L. -T kernel-cmake.ld"; |
391 | 43 $kernel_cflags = '-march=armv6 -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -Werror -g -O0 -iquote ../ -c'; |
44 $kernel_ld_flags = " -L. -N -e main -Ttext 0 <OBJECTS> -o <TARGET> <LINK_LIBRARIES> -L ../ $armdir//gcc/lib/gcc/arm-none-eabi/9.2.1/libgcc.a"; | |
94
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
45 $kernel_ld_command = "$ld $kernel_ld_flags"; |
391 | 46 $initcode_cflags = '-march=armv6 -nostdinc -c'; |
94
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
47 $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
|
48 |
391 | 49 $cflags =~ s/\n//g; |
94
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
50 |
60 | 51 } else { |
107 | 52 $objcopy = "arm-none-eabi-objcopy"; |
60 | 53 $cc = '/mnt/dalmore-home/one/src/armgcc/cross/bin/arm-none-eabi-gcc'; |
54 $asm = $cc; | |
55 $cflags = qq|-B/mnt/dalmore-home/one/src/armgcc/cross/bin/arm-none-eabi- | |
86 | 56 -DCBCXV6=1 -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -g -O0|; |
60 | 57 $ld = '/mnt/dalmore-home/one/src/armgcc/cross/bin/arm-none-eabi-ld'; |
58 chomp($libgcc = `$cc --print-libgcc-file-name`); | |
59 $cmake .= 3; | |
61 | 60 $ldflags = " -L. -T kernel-cmake.ld"; |
86 | 61 $kernel_cflags = '-march=armv6 -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -Werror -g -O0 -iquote ../ -c'; |
64 | 62 # -DX_CMAKE_C_LINK_EXECUTABLE=\"$ld $ldflags -o kernel.elf <OBJECTS> $libgcc -b binary initcode usr/fs.img\" |
63 | 63 $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'; |
64 $kernel_ld_command = "$ld $kernel_ld_flags"; | |
86 | 65 $initcode_cflags = '-march=armv6 -nostdinc -c'; |
66 | 66 $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
|
67 |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
68 $cflags =~ s/\n//g; |
60 | 69 } |
70 | |
94
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
71 push(@cmake_arg, |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
72 "-DCBC_COM=$cc", |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
73 "-DPMAKE_ARGS=\"$cflags\"", |
391 | 74 # "-DCBC_ASM_COMPILER=$asm", |
94
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
75 "-DX_CMAKE_LINKER=$ld", |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
76 "-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
|
77 "-DKERNEL_LINK_EXECUTABLE=\"$kernel_ld_command\"", |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
78 "-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE", |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
79 "-DINITOCDE_CFLAGS=\"$initcode_cflags\"", |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
80 "-DINITOCDE_LINK_EXECUTABLE=\"$initcode_ld_command\"", |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
81 "-S $xv6_src_dir", |
107 | 82 "-DXV6_OBJCOPY=\"$objcopy\"", |
94
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
83 $curdir); |
63 | 84 |
94
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
85 unshift(@cmake_arg, $cmake); |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
86 |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
87 create_link_script(); |
0956648d24e5
impl cmake on macos
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
88 print_exec_system(@cmake_arg); |
63 | 89 |
60 | 90 system("make"); |
61 | 91 #system("sh","link.sh"); |
60 | 92 |
93 sub create_link_script { | |
94 my @link_script; | |
95 while (my $line = <DATA>){ | |
96 $line =~ s/LD/$ld/; | |
97 $line =~ s/LIBGCC/$libgcc/; | |
98 push @link_script,$line; | |
99 } | |
100 if ($^O =~ /darwin/){ | |
101 for (@link_script){ | |
102 s/CMakeFiles/build/; | |
103 s|kernel\.dir/||; | |
104 } | |
105 } | |
106 open my $fh, '>', 'link.sh'; | |
107 print $fh "@link_script"; | |
108 } | |
109 | |
110 sub print_exec_system { | |
111 my @query = @_; | |
112 print(join(' ',@query), "\n"); | |
90 | 113 system(join(' ',@query)); |
60 | 114 } |
115 | |
80 | 116 |
117 | |
60 | 118 __DATA__ |
119 cp initcode ./CMakeFiles/kernel.dir/initcode | |
120 cp fs.img ./CMakeFiles/kernel.dir/fs.img | |
121 | |
122 LD \ | |
123 -L. \ | |
124 -T \ | |
125 kernel-cmake.ld \ | |
126 -o \ | |
127 kernel.elf \ | |
128 \ | |
129 CMakeFiles/kernel.dir/lib/string.c.o \ | |
130 CMakeFiles/kernel.dir/arm.c.o \ | |
131 CMakeFiles/kernel.dir/asm.S.o \ | |
132 CMakeFiles/kernel.dir/bio.c.o \ | |
133 CMakeFiles/kernel.dir/buddy.c.o \ | |
134 CMakeFiles/kernel.dir/c/console.c.o \ | |
135 CMakeFiles/kernel.dir/exec.c.o \ | |
136 CMakeFiles/kernel.dir/c/file.c.o \ | |
137 CMakeFiles/kernel.dir/fs.c.o \ | |
138 CMakeFiles/kernel.dir/log.c.o \ | |
139 CMakeFiles/kernel.dir/main.c.o \ | |
140 CMakeFiles/kernel.dir/memide.c.o \ | |
141 CMakeFiles/kernel.dir/c/pipe.c.o \ | |
142 CMakeFiles/kernel.dir/c/proc.c.o \ | |
143 CMakeFiles/kernel.dir/c/spinlock.c.o \ | |
144 CMakeFiles/kernel.dir/start.c.o \ | |
145 CMakeFiles/kernel.dir/swtch.S.o \ | |
146 CMakeFiles/kernel.dir/c/syscall.c.o \ | |
147 CMakeFiles/kernel.dir/c/sysfile.c.o \ | |
148 CMakeFiles/kernel.dir/sysproc.c.o \ | |
149 CMakeFiles/kernel.dir/trap_asm.S.o \ | |
150 CMakeFiles/kernel.dir/trap.c.o \ | |
151 CMakeFiles/kernel.dir/vm.c.o \ | |
152 CMakeFiles/kernel.dir/device/picirq.c.o \ | |
153 CMakeFiles/kernel.dir/device/timer.c.o \ | |
154 CMakeFiles/kernel.dir/device/uart.c.o \ | |
155 CMakeFiles/kernel.dir/entry.S.o \ | |
156 CMakeFiles/kernel.dir/c/kernel-context.c.o \ | |
157 \ | |
158 \ | |
159 LIBGCC \ | |
160 \ | |
161 -b \ | |
162 binary \ | |
163 initcode \ | |
164 fs.img |