60
|
1 #!/usr/bin/env perl
|
|
2 use strict;
|
|
3 use warnings;
|
|
4
|
63
|
5 my ($cc,$cflags,$asm,$ld,$ldflags,$libgcc,$cmake,$kernel_cflags,$kernel_ld_flags,$kernel_ld_command);
|
60
|
6
|
|
7 $cmake = 'cmake';
|
|
8
|
|
9 if ($^O =~ /darwin/){
|
|
10 $cc = $ENV{CBC_LANG_COMPILER};
|
|
11 $cflags = qq|-Wall -g -arch arm -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -Werror -I. -g -O0
|
|
12 -Wno-macro-redefined -Wno-gnu-designator -Wno-sometimes-uninitialized -Wno-tautological-compare
|
|
13 -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include
|
|
14 -Wno-nullability-completeness -Wno-expansion-to-defined"|;
|
|
15 $ldflags = qq|-B/mnt/dalmore-home/one/src/armgcc/cross/bin/arm-none-eabi-
|
|
16 -DCBCXV6=1 -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -I. -g -O0|;
|
|
17 } else {
|
|
18 $cc = '/mnt/dalmore-home/one/src/armgcc/cross/bin/arm-none-eabi-gcc';
|
|
19 $asm = $cc;
|
|
20 $cflags = qq|-B/mnt/dalmore-home/one/src/armgcc/cross/bin/arm-none-eabi-
|
|
21 -DCBCXV6=1 -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -I. -g -O0|;
|
|
22 $ld = '/mnt/dalmore-home/one/src/armgcc/cross/bin/arm-none-eabi-ld';
|
|
23 chomp($libgcc = `$cc --print-libgcc-file-name`);
|
|
24 $cflags .= " $libgcc";
|
|
25 $cmake .= 3;
|
61
|
26 $ldflags = " -L. -T kernel-cmake.ld";
|
63
|
27 $kernel_cflags = '-march=armv6 -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -Werror -I. -g -O0 -iquote ../ -c';
|
64
|
28 # -DX_CMAKE_C_LINK_EXECUTABLE=\"$ld $ldflags -o kernel.elf <OBJECTS> $libgcc -b binary initcode usr/fs.img\"
|
63
|
29 $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';
|
|
30 $kernel_ld_command = "$ld $kernel_ld_flags";
|
60
|
31 }
|
|
32
|
|
33 $cflags =~ s/\n//g;
|
|
34 create_link_script();
|
63
|
35
|
65
|
36 print_exec_system($cmake, "-DGCC_LIB=$libgcc", "-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",@ARGV);
|
63
|
37
|
60
|
38 system("make");
|
61
|
39 #system("sh","link.sh");
|
60
|
40
|
|
41 sub create_link_script {
|
|
42 my @link_script;
|
|
43 while (my $line = <DATA>){
|
|
44 $line =~ s/LD/$ld/;
|
|
45 $line =~ s/LIBGCC/$libgcc/;
|
|
46 push @link_script,$line;
|
|
47 }
|
|
48 if ($^O =~ /darwin/){
|
|
49 for (@link_script){
|
|
50 s/CMakeFiles/build/;
|
|
51 s|kernel\.dir/||;
|
|
52 }
|
|
53 }
|
|
54 open my $fh, '>', 'link.sh';
|
|
55 print $fh "@link_script";
|
|
56 }
|
|
57
|
|
58 sub print_exec_system {
|
|
59 my @query = @_;
|
|
60 print(join(' ',@query), "\n");
|
|
61 system(join(' ',@query));
|
|
62 }
|
|
63
|
|
64 __DATA__
|
|
65 cp initcode ./CMakeFiles/kernel.dir/initcode
|
|
66 cp fs.img ./CMakeFiles/kernel.dir/fs.img
|
|
67
|
|
68 LD \
|
|
69 -L. \
|
|
70 -T \
|
|
71 kernel-cmake.ld \
|
|
72 -o \
|
|
73 kernel.elf \
|
|
74 \
|
|
75 CMakeFiles/kernel.dir/lib/string.c.o \
|
|
76 CMakeFiles/kernel.dir/arm.c.o \
|
|
77 CMakeFiles/kernel.dir/asm.S.o \
|
|
78 CMakeFiles/kernel.dir/bio.c.o \
|
|
79 CMakeFiles/kernel.dir/buddy.c.o \
|
|
80 CMakeFiles/kernel.dir/c/console.c.o \
|
|
81 CMakeFiles/kernel.dir/exec.c.o \
|
|
82 CMakeFiles/kernel.dir/c/file.c.o \
|
|
83 CMakeFiles/kernel.dir/fs.c.o \
|
|
84 CMakeFiles/kernel.dir/log.c.o \
|
|
85 CMakeFiles/kernel.dir/main.c.o \
|
|
86 CMakeFiles/kernel.dir/memide.c.o \
|
|
87 CMakeFiles/kernel.dir/c/pipe.c.o \
|
|
88 CMakeFiles/kernel.dir/c/proc.c.o \
|
|
89 CMakeFiles/kernel.dir/c/spinlock.c.o \
|
|
90 CMakeFiles/kernel.dir/start.c.o \
|
|
91 CMakeFiles/kernel.dir/swtch.S.o \
|
|
92 CMakeFiles/kernel.dir/c/syscall.c.o \
|
|
93 CMakeFiles/kernel.dir/c/sysfile.c.o \
|
|
94 CMakeFiles/kernel.dir/sysproc.c.o \
|
|
95 CMakeFiles/kernel.dir/trap_asm.S.o \
|
|
96 CMakeFiles/kernel.dir/trap.c.o \
|
|
97 CMakeFiles/kernel.dir/vm.c.o \
|
|
98 CMakeFiles/kernel.dir/device/picirq.c.o \
|
|
99 CMakeFiles/kernel.dir/device/timer.c.o \
|
|
100 CMakeFiles/kernel.dir/device/uart.c.o \
|
|
101 CMakeFiles/kernel.dir/entry.S.o \
|
|
102 CMakeFiles/kernel.dir/c/kernel-context.c.o \
|
|
103 \
|
|
104 \
|
|
105 LIBGCC \
|
|
106 \
|
|
107 -b \
|
|
108 binary \
|
|
109 initcode \
|
|
110 fs.img
|