view src/gearsTools/pmake.pl @ 80:c976a8bbe8c5

add stac.h and Stac.cbc
author tobaru
date Wed, 09 Oct 2019 20:41:51 +0900
parents f236eba62a76
children 765449889623
line wrap: on
line source

#!/usr/bin/env perl
use strict;
use warnings;

my ($cc,$cflags,$asm,$ld,$ldflags,$libgcc,$cmake,$kernel_cflags,$kernel_ld_flags,$kernel_ld_command, $initcode_cflags, $initcode_ld_command);

$cmake = 'cmake';

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|;
} else {
    $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 -I. -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 -I. -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 -I. -c';
    $initcode_ld_command = "$ld -L.  -N -e start -Ttext 0 <OBJECTS> -o <TARGET> <LINK_LIBRARIES>";
}

$cflags =~ s/\n//g;
create_link_script();

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 $ARGV[1]",
$ARGV[0]);

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 

__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