Mercurial > hg > Gears > GearsTools
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pmake.pl Fri Mar 06 14:59:59 2020 +0900 @@ -0,0 +1,181 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use FindBin; +use Cwd 'getcwd'; +use File::Path 'rmtree'; + +my ($cc,$cflags,$asm,$ld,$ldflags,$libgcc,$cmake,$kernel_cflags,$kernel_ld_flags,$kernel_ld_command, $initcode_cflags, $initcode_ld_command); + +my $curdir = getcwd; + +if (@ARGV) { + if ($ARGV[0] =~ /--del/) { + my @current_dir_file = glob "*"; + map { print "$_\n";} @current_dir_file; + print "delete all files? > [y/n]\n"; + my $ans = <STDIN>; + if ($ans =~ /y/) { + print "delete ...\n"; + map { rmtree $_ } @current_dir_file; + } + } +} + +$cmake = 'cmake'; +my @cmake_arg = (); +my $xv6_src_dir = $FindBin::Bin; +$xv6_src_dir =~ s|(.*)/gearsTools(.*)|$1|; + +my $objcopy; +if ($^O =~ /darwin/){ + $objcopy = "/usr/local/opt/llvm/bin/llvm-objcopy"; + my $arm_library = $ENV{ARM_LIBRARY}; + $cc = $ENV{CBC_COMPILER}; + $asm = $ENV{CBC_COMPILER}; + $cflags = qq|-Wall -g --target=armv6-linux-gnueabihf -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -DCBCXV6=1 -g -O0 -nodefaultlibs + -Wno-macro-redefined -Wno-gnu-designator -Wno-sometimes-uninitialized -Wno-tautological-compare + -Wno-nullability-completeness -Wno-expansion-to-defined |; + $cflags .= ' -B' . $ENV{HOME} .'/workspace/cr/arm_library/usr/lib/gcc/arm-linux-gnueabihf/6.3.0'; + $cflags .= ' --gcc-toolchain=arm-linux-gnueabihf-raspbian'; + # $ld = '/usr/local/linaro/arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-ld'; + $ld = "/usr/local/opt/llvm/bin/ld.lld"; + + # $libgcc = '/usr/local/lib/gcc/arm-none-eabi/7.3.1/libgcc.a'; + $libgcc = "$arm_library/usr/lib/gcc/arm-linux-gnueabihf/6.3.0/libgcc.a"; + #chomp($libgcc = `$cc --print-libgcc-file-name`); + $ldflags = " -L. -T kernel-cmake.ld"; + $kernel_cflags = '--target=armv6-linux-gnueabihf -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -Werror -g -O0 -iquote ../ -c'; + # -DX_CMAKE_C_LINK_EXECUTABLE=\"$ld $ldflags -o kernel.elf <OBJECTS> $libgcc -b binary initcode usr/fs.img\" + $kernel_ld_flags = ' -L. -N -e main -Ttext 0 <OBJECTS> -o <TARGET> <LINK_LIBRARIES> -L ../ ' . $libgcc; + #$kernel_ld_flags = ' -L. -N -e main -Ttext 0 <OBJECTS> -o <TARGET> <LINK_LIBRARIES>' ; + $kernel_ld_command = "$ld $kernel_ld_flags"; + $initcode_cflags = '--target=armv6-linux-gnueabihf -nostdinc -c'; + $initcode_ld_command = "$ld -L. -N -e start -Ttext 0 <OBJECTS> -o <TARGET> <LINK_LIBRARIES>"; + + + push(@cmake_arg, + "-DCBC_XV6_SYSROOT=\"$arm_library\"", + # "-DCMAKE_OSX_SYSROOT=\"$arm_library\"", + #"-DCMAKE_RANLIB=\"/Users/anatofuz/workspace/compiler/llvm/llvm-project/build/bin/llvm-ar\"", + "-DCMAKE_AR=\"/usr/local/opt/llvm/bin/llvm-ar\"", + "-DCMAKE_RANLIB=\"/usr/local/opt/llvm/bin/llvm-ranlib\"", + # "-DCMAKE_AR=\"/usr/local/linaro/arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-ar\"", + # "-DCMAKE_RANLIB=\"/usr/local/linaro/arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-ranlib\"", + # "-DCMAKE_OSX_XV6_INCLUDE_DIR=\"$arm_library/usr/include\"", + ); + +} else { + $objcopy = "arm-none-eabi-objcopy"; + $cc = '/mnt/dalmore-home/one/src/armgcc/cross/bin/arm-none-eabi-gcc'; + $asm = $cc; + $cflags = qq|-B/mnt/dalmore-home/one/src/armgcc/cross/bin/arm-none-eabi- + -DCBCXV6=1 -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -g -O0|; + $ld = '/mnt/dalmore-home/one/src/armgcc/cross/bin/arm-none-eabi-ld'; + chomp($libgcc = `$cc --print-libgcc-file-name`); + $cmake .= 3; + $ldflags = " -L. -T kernel-cmake.ld"; + $kernel_cflags = '-march=armv6 -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -Werror -g -O0 -iquote ../ -c'; + # -DX_CMAKE_C_LINK_EXECUTABLE=\"$ld $ldflags -o kernel.elf <OBJECTS> $libgcc -b binary initcode usr/fs.img\" + $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'; + $kernel_ld_command = "$ld $kernel_ld_flags"; + $initcode_cflags = '-march=armv6 -nostdinc -c'; + $initcode_ld_command = "$ld -L. -N -e start -Ttext 0 <OBJECTS> -o <TARGET> <LINK_LIBRARIES>"; + + $cflags =~ s/\n//g; +} + +push(@cmake_arg, + "-DCBC_COM=$cc", + "-DPMAKE_ARGS=\"$cflags\"", + "-DCBC_ASM_COMPILER=$cc", + "-DX_CMAKE_LINKER=$ld", + "-DX_CMAKE_C_LINK_EXECUTABLE=\"$ld $ldflags -o kernel.elf <OBJECTS> $libgcc -b binary initcode fs.img\"", + "-DKERNEL_LINK_EXECUTABLE=\"$kernel_ld_command\"", + "-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE", + "-DINITOCDE_CFLAGS=\"$initcode_cflags\"", + "-DINITOCDE_LINK_EXECUTABLE=\"$initcode_ld_command\"", + "-S $xv6_src_dir", + "-DXV6_OBJCOPY=\"$objcopy\"", + $curdir); + +unshift(@cmake_arg, $cmake); + +create_link_script(); +print_exec_system(@cmake_arg); + +system("make"); +#system("sh","link.sh"); + +sub create_link_script { + my @link_script; + while (my $line = <DATA>){ + $line =~ s/LD/$ld/; + $line =~ s/LIBGCC/$libgcc/; + push @link_script,$line; + } + if ($^O =~ /darwin/){ + for (@link_script){ + s/CMakeFiles/build/; + s|kernel\.dir/||; + } + } + open my $fh, '>', 'link.sh'; + print $fh "@link_script"; +} + +sub print_exec_system { + my @query = @_; + print(join(' ',@query), "\n"); + system(join(' ',@query)); +} + + + +__DATA__ +cp initcode ./CMakeFiles/kernel.dir/initcode +cp fs.img ./CMakeFiles/kernel.dir/fs.img + +LD \ +-L. \ +-T \ +kernel-cmake.ld \ +-o \ +kernel.elf \ + \ +CMakeFiles/kernel.dir/lib/string.c.o \ +CMakeFiles/kernel.dir/arm.c.o \ +CMakeFiles/kernel.dir/asm.S.o \ +CMakeFiles/kernel.dir/bio.c.o \ +CMakeFiles/kernel.dir/buddy.c.o \ +CMakeFiles/kernel.dir/c/console.c.o \ +CMakeFiles/kernel.dir/exec.c.o \ +CMakeFiles/kernel.dir/c/file.c.o \ +CMakeFiles/kernel.dir/fs.c.o \ +CMakeFiles/kernel.dir/log.c.o \ +CMakeFiles/kernel.dir/main.c.o \ +CMakeFiles/kernel.dir/memide.c.o \ +CMakeFiles/kernel.dir/c/pipe.c.o \ +CMakeFiles/kernel.dir/c/proc.c.o \ +CMakeFiles/kernel.dir/c/spinlock.c.o \ +CMakeFiles/kernel.dir/start.c.o \ +CMakeFiles/kernel.dir/swtch.S.o \ +CMakeFiles/kernel.dir/c/syscall.c.o \ +CMakeFiles/kernel.dir/c/sysfile.c.o \ +CMakeFiles/kernel.dir/sysproc.c.o \ +CMakeFiles/kernel.dir/trap_asm.S.o \ +CMakeFiles/kernel.dir/trap.c.o \ +CMakeFiles/kernel.dir/vm.c.o \ +CMakeFiles/kernel.dir/device/picirq.c.o \ +CMakeFiles/kernel.dir/device/timer.c.o \ +CMakeFiles/kernel.dir/device/uart.c.o \ +CMakeFiles/kernel.dir/entry.S.o \ +CMakeFiles/kernel.dir/c/kernel-context.c.o \ + \ + \ +LIBGCC \ + \ +-b \ +binary \ +initcode \ +fs.img