60
|
1 #!/usr/bin/env perl
|
|
2 use strict;
|
|
3 use warnings;
|
|
4
|
66
|
5 my ($cc,$cflags,$asm,$ld,$ldflags,$libgcc,$cmake,$kernel_cflags,$kernel_ld_flags,$kernel_ld_command, $initcode_cflags, $initcode_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 $cmake .= 3;
|
61
|
25 $ldflags = " -L. -T kernel-cmake.ld";
|
63
|
26 $kernel_cflags = '-march=armv6 -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -Werror -I. -g -O0 -iquote ../ -c';
|
64
|
27 # -DX_CMAKE_C_LINK_EXECUTABLE=\"$ld $ldflags -o kernel.elf <OBJECTS> $libgcc -b binary initcode usr/fs.img\"
|
63
|
28 $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';
|
|
29 $kernel_ld_command = "$ld $kernel_ld_flags";
|
66
|
30 $initcode_cflags = '-march=armv6 -nostdinc -I. -c';
|
|
31 $initcode_ld_command = "$ld -L. -N -e start -Ttext 0 <OBJECTS> -o <TARGET> <LINK_LIBRARIES>";
|
60
|
32 }
|
|
33
|
|
34 $cflags =~ s/\n//g;
|
|
35 create_link_script();
|
63
|
36
|
66
|
37 print_exec_system($cmake,
|
|
38 "-DCBC_COM=$cc",
|
|
39 "-DPMAKE_ARGS=\"$cflags\"",
|
|
40 "-DCMAKE_ASM_COMPILER=$cc",
|
|
41 "-DX_CMAKE_LINKER=$ld",
|
|
42 "-DX_CMAKE_C_LINK_EXECUTABLE=\"$ld $ldflags -o kernel.elf <OBJECTS> $libgcc -b binary initcode fs.img\"",
|
|
43 "-DKERNEL_LINK_EXECUTABLE=\"$kernel_ld_command\"",
|
|
44 "-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE",
|
|
45 "-DINITOCDE_CFLAGS=\"$initcode_cflags\"",
|
|
46 "-DINITOCDE_LINK_EXECUTABLE=\"$initcode_ld_command\"",
|
69
|
47 "-S $ARGV[1]",
|
|
48 $ARGV[0]);
|
63
|
49
|
60
|
50 system("make");
|
61
|
51 #system("sh","link.sh");
|
60
|
52
|
|
53 sub create_link_script {
|
|
54 my @link_script;
|
|
55 while (my $line = <DATA>){
|
|
56 $line =~ s/LD/$ld/;
|
|
57 $line =~ s/LIBGCC/$libgcc/;
|
|
58 push @link_script,$line;
|
|
59 }
|
|
60 if ($^O =~ /darwin/){
|
|
61 for (@link_script){
|
|
62 s/CMakeFiles/build/;
|
|
63 s|kernel\.dir/||;
|
|
64 }
|
|
65 }
|
|
66 open my $fh, '>', 'link.sh';
|
|
67 print $fh "@link_script";
|
|
68 }
|
|
69
|
|
70 sub print_exec_system {
|
|
71 my @query = @_;
|
|
72 print(join(' ',@query), "\n");
|
|
73 system(join(' ',@query));
|
|
74 }
|
|
75
|
|
76 __DATA__
|
|
77 cp initcode ./CMakeFiles/kernel.dir/initcode
|
|
78 cp fs.img ./CMakeFiles/kernel.dir/fs.img
|
|
79
|
|
80 LD \
|
|
81 -L. \
|
|
82 -T \
|
|
83 kernel-cmake.ld \
|
|
84 -o \
|
|
85 kernel.elf \
|
|
86 \
|
|
87 CMakeFiles/kernel.dir/lib/string.c.o \
|
|
88 CMakeFiles/kernel.dir/arm.c.o \
|
|
89 CMakeFiles/kernel.dir/asm.S.o \
|
|
90 CMakeFiles/kernel.dir/bio.c.o \
|
|
91 CMakeFiles/kernel.dir/buddy.c.o \
|
|
92 CMakeFiles/kernel.dir/c/console.c.o \
|
|
93 CMakeFiles/kernel.dir/exec.c.o \
|
|
94 CMakeFiles/kernel.dir/c/file.c.o \
|
|
95 CMakeFiles/kernel.dir/fs.c.o \
|
|
96 CMakeFiles/kernel.dir/log.c.o \
|
|
97 CMakeFiles/kernel.dir/main.c.o \
|
|
98 CMakeFiles/kernel.dir/memide.c.o \
|
|
99 CMakeFiles/kernel.dir/c/pipe.c.o \
|
|
100 CMakeFiles/kernel.dir/c/proc.c.o \
|
|
101 CMakeFiles/kernel.dir/c/spinlock.c.o \
|
|
102 CMakeFiles/kernel.dir/start.c.o \
|
|
103 CMakeFiles/kernel.dir/swtch.S.o \
|
|
104 CMakeFiles/kernel.dir/c/syscall.c.o \
|
|
105 CMakeFiles/kernel.dir/c/sysfile.c.o \
|
|
106 CMakeFiles/kernel.dir/sysproc.c.o \
|
|
107 CMakeFiles/kernel.dir/trap_asm.S.o \
|
|
108 CMakeFiles/kernel.dir/trap.c.o \
|
|
109 CMakeFiles/kernel.dir/vm.c.o \
|
|
110 CMakeFiles/kernel.dir/device/picirq.c.o \
|
|
111 CMakeFiles/kernel.dir/device/timer.c.o \
|
|
112 CMakeFiles/kernel.dir/device/uart.c.o \
|
|
113 CMakeFiles/kernel.dir/entry.S.o \
|
|
114 CMakeFiles/kernel.dir/c/kernel-context.c.o \
|
|
115 \
|
|
116 \
|
|
117 LIBGCC \
|
|
118 \
|
|
119 -b \
|
|
120 binary \
|
|
121 initcode \
|
|
122 fs.img
|