summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordzwdz2022-08-26 17:11:23 +0200
committerdzwdz2022-08-26 17:11:23 +0200
commite7676411e49bfd2e0da0b785ad4ac5dc909d0a41 (patch)
tree22f4608e68684aa71d94d2f9ccfd27f7066509e5
parente6584db26da34572fb13aa236e16e19f71c8e976 (diff)
user/ports: port oed
make clean; ./port ed clean; make -j4 out/libc.a && ./port ed install && make -j4
-rw-r--r--Makefile1
-rwxr-xr-xport14
-rwxr-xr-xports/bin/camellia_path_check1
-rwxr-xr-xports/bin/cc6
-rw-r--r--ports/ed67
-rw-r--r--src/user/app/init/init.c1
6 files changed, 90 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index dd4cdbd..49a1745 100644
--- a/Makefile
+++ b/Makefile
@@ -109,6 +109,7 @@ out/initrd/font.psf: /usr/share/kbd/consolefonts/default8x16.psfu.gz
out/initrd.tar: $(patsubst %,out/%,$(shell find initrd/ -type f)) \
$(patsubst %,out/initrd/bin/amd64/%,$(USERBINS)) \
+ $(shell find out/initrd/) \
out/initrd/font.psf
@cd out/initrd; tar chf ../initrd.tar *
diff --git a/port b/port
new file mode 100755
index 0000000..78ad7b0
--- /dev/null
+++ b/port
@@ -0,0 +1,14 @@
+#!/bin/sh
+set -eu
+export REPO="$PWD"
+export PREFIX="$REPO/out/initrd/usr/"
+export PATH="$REPO/ports/bin/:$REPO/toolchain/bin/:$PATH"
+
+if [ $1 = deepclean ]; then
+ rm -rf ports/out/
+ exit
+fi
+
+mkdir -p ports/out/$1/ $PREFIX
+cd ports/out/$1/
+sh $REPO/ports/$1 $2
diff --git a/ports/bin/camellia_path_check b/ports/bin/camellia_path_check
new file mode 100755
index 0000000..96b4b06
--- /dev/null
+++ b/ports/bin/camellia_path_check
@@ -0,0 +1 @@
+#!/bin/sh \ No newline at end of file
diff --git a/ports/bin/cc b/ports/bin/cc
new file mode 100755
index 0000000..6478b6e
--- /dev/null
+++ b/ports/bin/cc
@@ -0,0 +1,6 @@
+#!/bin/sh
+exec x86_64-elf-gcc -ffreestanding -fPIE -mno-sse \
+ -nostdlib -Wl,-pie -Wl,-no-dynamic-linker -T $REPO/src/user/linker.ld \
+ -I$REPO/src/ -I$REPO/src/shared/include/ -I$REPO/src/user/lib/include/ \
+ $* \
+ -L$REPO/out/ -lc -lgcc
diff --git a/ports/ed b/ports/ed
new file mode 100644
index 0000000..87dd05c
--- /dev/null
+++ b/ports/ed
@@ -0,0 +1,67 @@
+set -eu
+camellia_path_check
+
+fetch() {
+ # TODO shallow clone, once 7.1 gets tagged
+ # better yet, use a tarball
+ git clone https://github.com/ibara/oed
+ cd oed
+ git -c advice.detachedHead=false checkout fc1497fa466ff10c7437f07a00ba888242618ce5
+}
+
+configure() {
+ cd oed
+ cat <<\EOF > Makefile
+# This Makefile automatically generated by configure.
+
+CC = cc
+CFLAGS = -g -O2 -I. -D_GNU_SOURCE
+
+PREFIX = /usr/local
+MANDIR = /usr/local/man
+
+PROG = ed
+OBJS = buf.o glbl.o io.o main.o re.o sub.o undo.o \
+ regcomp.o regerror.o regexec.o regfree.o \
+ reallocarray.o strlcat.o strlcpy.o
+
+all: ${PROG}
+
+${PROG}: ${OBJS}
+ ${CC} ${LDFLAGS} -o ${PROG} ${OBJS}
+
+install:
+ install -d ${DESTDIR}${PREFIX}/bin
+ install -d ${DESTDIR}${MANDIR}/man1
+ install -c -s -m 755 ${PROG} ${DESTDIR}${PREFIX}/bin
+ install -c -m 644 ed.1 ${DESTDIR}${MANDIR}/man1/${PROG}.1
+
+test:
+ @echo "No tests"
+
+clean:
+ rm -f ${PROG} ${OBJS}
+
+distclean: clean
+ rm -f Makefile config.h
+EOF
+ cat <<\EOF > config.h
+/* This file automatically generated by configure. */
+
+extern void *reallocarray(void *, size_t, size_t);
+extern size_t strlcat(char *, const char *, size_t);
+extern size_t strlcpy(char *, const char *, size_t);
+EOF
+}
+
+prep() {
+ [ -d oed ] || (fetch)
+ [ -e oed/Makefile ] || (configure)
+ cd oed
+}
+
+case $1 in
+ install) (prep; make; make install "PREFIX=$PREFIX" "MANDIR=$PREFIX/man/") ;;
+ clean) (prep; make clean) ;;
+ *) echo "usage: $0 install|clean"; false ;;
+esac
diff --git a/src/user/app/init/init.c b/src/user/app/init/init.c
index 9c3fa39..09ab257 100644
--- a/src/user/app/init/init.c
+++ b/src/user/app/init/init.c
@@ -44,6 +44,7 @@ int main(void) {
fs_union((const char*[]){
"/init/bin/amd64/",
"/init/bin/sh/",
+ "/init/usr/bin/",
NULL
});
}