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