summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authordzwdz2023-08-14 18:51:07 +0200
committerdzwdz2023-08-14 18:51:07 +0200
commit642b5fb0007b64c77d186fcb018d571152ee1d47 (patch)
tree1c466461f3602d306be309a053edae558ef2568e /contrib
parent8050069c57b729c18c19b1a03ab6e4bf63b4735e (diff)
reorganization: first steps
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/dep_builders/binutils27
-rwxr-xr-xcontrib/dep_builders/dl9
-rwxr-xr-xcontrib/dep_builders/gcc31
-rwxr-xr-xcontrib/sort_includes.rb42
-rw-r--r--contrib/stacktrace_resolve.awk14
5 files changed, 123 insertions, 0 deletions
diff --git a/contrib/dep_builders/binutils b/contrib/dep_builders/binutils
new file mode 100755
index 0000000..42dd04b
--- /dev/null
+++ b/contrib/dep_builders/binutils
@@ -0,0 +1,27 @@
+#!/bin/sh
+set -eu
+
+# ensure that we're in the repo root
+if [ ! -d .git ]; then
+ echo please cd to the repo\'s main directory
+ exit
+fi
+
+export PREFIX="$(pwd)/toolchain/prefix/"
+export PATH="$(pwd)/toolchain/prefix/bin/:$PATH"
+BUILDDIR="$(pwd)/toolchain/binutils-build/"
+SYSROOT="$(pwd)/sysroot/"
+mkdir -p $PREFIX
+mkdir -p $BUILDDIR
+
+cd $BUILDDIR
+
+../binutils/configure \
+ --target=x86_64-camellia \
+ --prefix="$PREFIX" \
+ --with-sysroot="$SYSROOT" \
+ --disable-nls \
+ --disable-werror
+mkdir -p gas/doc/ # stupid workaround for the broken build
+make -j4
+make install
diff --git a/contrib/dep_builders/dl b/contrib/dep_builders/dl
new file mode 100755
index 0000000..e6f279f
--- /dev/null
+++ b/contrib/dep_builders/dl
@@ -0,0 +1,9 @@
+#!/bin/sh
+# downloads a file to toolchain/cache unless it's already present there
+
+mkdir -p cache/toolchain
+OUT="cache/toolchain/$(basename $1)"
+
+[ -e "$OUT" ] && exit
+echo "downloading $1..."
+curl "$1" > $OUT
diff --git a/contrib/dep_builders/gcc b/contrib/dep_builders/gcc
new file mode 100755
index 0000000..0a37541
--- /dev/null
+++ b/contrib/dep_builders/gcc
@@ -0,0 +1,31 @@
+#!/bin/sh
+set -eu
+
+# ensure that we're in the repo root
+if [ ! -d .git ]; then
+ echo please cd to the repo\'s main directory
+ exit
+fi
+
+export PREFIX="$(pwd)/toolchain/prefix/"
+export PATH="$(pwd)/toolchain/prefix/bin/:$PATH"
+BUILDDIR="$(pwd)/toolchain/gcc-build/"
+SYSROOT="$(pwd)/sysroot/"
+mkdir -p $PREFIX
+mkdir -p $BUILDDIR
+
+cd $BUILDDIR
+
+../gcc/configure \
+ --target=x86_64-camellia \
+ --prefix="$PREFIX" \
+ --with-sysroot="$SYSROOT" \
+ --enable-languages=c,c++ \
+ --enable-default-pie \
+ --disable-nls \
+ --disable-gcov \
+ --disable-werror
+make -j4 all-gcc
+make -j4 all-target-libgcc
+make install-gcc
+make install-target-libgcc
diff --git a/contrib/sort_includes.rb b/contrib/sort_includes.rb
new file mode 100755
index 0000000..c9f7076
--- /dev/null
+++ b/contrib/sort_includes.rb
@@ -0,0 +1,42 @@
+#!/usr/bin/env ruby
+
+def is_include str
+ str.start_with? '#include'
+end
+
+files = ARGV
+if files.empty?
+ default = "src/**/*.[ch]"
+ puts "no arguments passed, defaulting to #{default}"
+ files = Dir[default]
+end
+
+files.each { |path|
+ File.open(path, "r+") do |file|
+ lines = file.readlines
+
+ last = nil
+ grouped = []
+ lines.each do |line|
+ if is_include(line) != last
+ grouped << [line]
+ last = is_include(line)
+ else
+ grouped[-1] << line
+ end
+ end
+
+ grouped.map do |group|
+ group.sort! if is_include group[0]
+ end
+ grouped = grouped.flatten
+
+ next if grouped == lines
+
+ puts path
+ file.truncate(0)
+ file.seek(0)
+ file.write grouped.join
+ end
+}
+
diff --git a/contrib/stacktrace_resolve.awk b/contrib/stacktrace_resolve.awk
new file mode 100644
index 0000000..53d6993
--- /dev/null
+++ b/contrib/stacktrace_resolve.awk
@@ -0,0 +1,14 @@
+/k\/[0-9A-Fa-f]{8}/ {
+ print;
+ while (match($0, /k\/[0-9A-Fa-f]{8}/)) {
+ addr = substr($0, RSTART + 2, RLENGTH - 2);
+ if (addr != "00000000") {
+ printf " ";
+ system("addr2line -psfe out/fs/boot/kernel 0x" addr);
+ }
+ $0 = substr($0, RSTART + RLENGTH);
+ }
+ next;
+}
+
+{ print; }