diff src/gearsTools/pmake.pl @ 94:d876c9a65239 default tip

impl mac os target
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Wed, 23 Oct 2019 14:31:38 +0900
parents dd1d9ea1b7b5
children
line wrap: on
line diff
--- a/src/gearsTools/pmake.pl	Sat Oct 19 18:44:57 2019 +0900
+++ b/src/gearsTools/pmake.pl	Wed Oct 23 14:31:38 2019 +0900
@@ -3,19 +3,67 @@
 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] =~ /--delete/) {
+    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|;
+
 
 if ($^O =~ /darwin/){
-    $cc      = $ENV{CBC_LANG_COMPILER};
-    $cflags  = qq|-Wall -g -arch arm -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -Werror -I. -g -O0 
-             -Wno-macro-redefined -Wno-gnu-designator -Wno-sometimes-uninitialized -Wno-tautological-compare 
-             -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include
-             -Wno-nullability-completeness -Wno-expansion-to-defined"|;
-    $ldflags = qq|-B/mnt/dalmore-home/one/src/armgcc/cross/bin/arm-none-eabi-  
-             -DCBCXV6=1 -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -I. -g -O0|;
+    $cc      = "$ENV{CBC_LANG_COMPILER}-7.0";
+    $asm     = "$ENV{CBC_LANG_COMPILER}-7.0";
+    $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 = '/Users/anatofuz/workspace/compiler/llvm/llvm-project/build/bin/lld';
+             #$ld = '/Users/anatofuz/workspace/compiler/llvm/llvm-project/build/bin/ld.lld';
+    $ld = '/usr/local/linaro/arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-ld';
+
+    #$libgcc = '/Users/anatofuz/workspace/cr/arm_library/usr/lib/gcc/arm-linux-gnueabihf/6.3.0/libgcc.a';
+    $libgcc = '/usr/local/lib/gcc/arm-none-eabi/7.3.1/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>";
+
+    my $arm_library = '/Users/anatofuz/workspace/cr/arm_library';
+
+    push(@cmake_arg,
+      "-DCBC_XV6_SYSROOT=\"$arm_library\"",
+      # "-DCMAKE_OSX_SYSROOT=\"$arm_library\"",
+      #"-DCMAKE_AR=\"/Users/anatofuz/workspace/compiler/llvm/llvm-project/build/bin/llvm-ar\"",
+      #"-DCMAKE_RANLIB=\"/Users/anatofuz/workspace/compiler/llvm/llvm-project/build/bin/llvm-ar\"",
+      "-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 {
     $cc     = '/mnt/dalmore-home/one/src/armgcc/cross/bin/arm-none-eabi-gcc';
     $asm    = $cc;
@@ -31,26 +79,27 @@
     $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;
 }
 
-$cflags =~ s/\n//g;
-create_link_script();
-my $curdir = getcwd;
-my $xv6_src_dir = $FindBin::Bin;
-$xv6_src_dir =~  s|(.*)/gearsTools(.*)|$1|;
+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",
+  $curdir);
 
-print_exec_system($cmake,
-     "-DCBC_COM=$cc",
-     "-DPMAKE_ARGS=\"$cflags\"",
-    "-DCMAKE_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",
-$curdir);
+unshift(@cmake_arg, $cmake);
+
+create_link_script();
+print_exec_system(@cmake_arg);
 
 system("make");
 #system("sh","link.sh");
@@ -127,17 +176,3 @@
 binary \
 initcode \
 fs.img 
-
-__END__
-
-=encoding utf-8
-
-=head1 NAME
-
-pmake.pl - pmake is a wrapper at cmake in xv6.
-
-=head1 SYNOPSIS
-
-     pmake.pl <build directory> <cbcxv6 src direcory>
-
-=cut