Skip to content

Commit

Permalink
Ports/alpine: Add patches to build Alpine on Serenity
Browse files Browse the repository at this point in the history
  • Loading branch information
tajmorton authored and linusg committed Dec 3, 2022
1 parent 69f41eb commit 14baf35
Show file tree
Hide file tree
Showing 6 changed files with 357 additions and 0 deletions.
1 change: 1 addition & 0 deletions Ports/AvailablePorts.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This list is also available at [ports.serenityos.net](https://ports.serenityos.n
|-----------------------------------------------------|-----------------------------------------------------------------|--------------------------|--------------------------------------------------------------------------------|
| [`aclock`](aclock/) | aclock | 2.3 | https://github.com/tenox7/aclock |
| [`acpica-tools`](acpica-tools/) | ACPI Component Architecture Project Userspace Utilities | 20220331 | https://acpica.org/downloads |
| [`alpine`](alpine/) | Alpine Email Client | 2.26 | https://alpineapp.email |
| [`angband`](angband/) | Angband | 4.2.4 | https://rephial.org |
| [`Another-World`](Another-World/) | Another World Bytecode Interpreter | | https://github.com/fabiensanglard/Another-World-Bytecode-Interpreter |
| [`aria2`](aria2/) | aria2 | 1.36.0 | https://aria2.github.io |
Expand Down
64 changes: 64 additions & 0 deletions Ports/alpine/package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env -S bash ../.port_include.sh
port='alpine'
version='2.26'
useconfigure='true'
configopts=(
'--disable-static'
'--enable-shared'
)
use_fresh_config_sub='true'
use_fresh_config_guess='true'
files="https://alpineapp.email/alpine/release/src/alpine-2.26.tar.xz alpine-${version}.tar.xz c0779c2be6c47d30554854a3e14ef5e36539502b331068851329275898a9baba"
auth_type='sha256'
depends=(
'openssl'
'ncurses'
'ca-certificates'
)
launcher_name='Alpine'
launcher_category='Internet'
launcher_command='/usr/local/bin/alpine'
launcher_run_in_terminal='true'
icon_file='web/cgi/favicon.ico'

pre_configure() {
# Rebuild after patching configure.ac to support serenity host.

# `automake` may exit with a warning about how there is a mismatch
# between the versions of autoconf and automake that were previously
# used to generate aclocal and specifed in configure.ac.
# We just need `automake` to generate `./compile` (so that we can run
# autoreconf to regenerate everything).
run automake --add-missing || true
run autoreconf
}

configure() {
run ./"$configscript" \
"${configopts[@]}" \
--host="${SERENITY_ARCH}-pc-serenity" \
--build="$($workdir/config.guess)" \
--with-ssl-lib-dir="${SERENITY_INSTALL_ROOT}/usr/local/lib" \
--with-include-path="${SERENITY_INSTALL_ROOT}/usr/local/include:${SERENITY_INSTALL_ROOT}/usr/local/include/openssl" \
--with-system-pinerc='/etc/pine.conf' \
--with-system-fixed-pinerc='/etc/pine.conf.fixed'
}

install() {
run make DESTDIR="$DESTDIR" "${installopts[@]}" install
# Install system configuration file that tells Alpine where to find CA certificates
# installed from the `ca-certificates` package.
# (The full `/usr/bin/install` path is used because `install()` is a function within this script.)
run /usr/bin/install \
--mode=644 \
--no-target-directory \
-D \
pine-system.serenity.conf "${SERENITY_INSTALL_ROOT}/etc/pine.conf"
}

post_install() {
echo "==== Post Installation Instructions ===="
echo "To save account passwords, create an empty file named .alpine.pwd"
echo "in your home diretory:"
echo " touch ~/.alpine.pwd"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taj Morton <[email protected]>
Date: Sun, 27 Nov 2022 16:27:48 -0800
Subject: [PATCH] Compiler helpers for build system, not host.

---
pith/Makefile.am | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/pith/Makefile.am b/pith/Makefile.am
index 748b9ececd2b7e120a0bc25b1e949788bf55fc06..bfee7cce61e1a5b589aa153038064563d8f94220 100644
--- a/pith/Makefile.am
+++ b/pith/Makefile.am
@@ -30,12 +30,12 @@ libpith_a_SOURCES = ablookup.c abdlc.c addrbook.c addrstring.c adrbklib.c bldadd
state.c status.c store.c stream.c string.c strlst.c takeaddr.c tempfile.c text.c \
thread.c adjtime.c url.c util.c helptext.c smkeys.c smime.c

-help_c_gen$(EXEEXT): $(help_c_gen_OBJECTS) $(help_c_gen_DEPENDENCIES)
- @rm -f help_c_gen$(EXEEXT)
- $(LINK) $(help_c_gen_OBJECTS) $(help_c_gen_LDADD)
-help_h_gen$(EXEEXT): $(help_h_gen_OBJECTS) $(help_h_gen_DEPENDENCIES)
- @rm -f help_h_gen$(EXEEXT)
- $(LINK) $(help_h_gen_OBJECTS) $(help_h_gen_LDADD)
+help_c_gen$(BUILD_EXEEXT): help_c_gen.c
+ @rm -f help_c_gen$(BUILD_EXEEXT)
+ $(CC_FOR_BUILD) help_c_gen.c -o help_c_gen$(BUILD_EXEEXT)
+help_h_gen$(BUILD_EXEEXT):
+ @rm -f help_h_gen$(BUILD_EXEEXT)
+ $(CC_FOR_BUILD) help_h_gen.c -o help_h_gen$(BUILD_EXEEXT)

helptext.c: help_c_gen pine.hlp
./help_c_gen < pine.hlp > $@
198 changes: 198 additions & 0 deletions Ports/alpine/patches/0002-Add-serenity-as-OS-type-in-Alpine.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taj Morton <[email protected]>
Date: Mon, 28 Nov 2022 19:55:04 -0800
Subject: [PATCH] Add serenity as OS type in Alpine.

---
configure.ac | 6 +++
imap/Makefile | 2 +-
imap/src/osdep/unix/Makefile | 9 +++++
imap/src/osdep/unix/os_serenity.c | 59 +++++++++++++++++++++++++++++
imap/src/osdep/unix/os_serenity.h | 62 +++++++++++++++++++++++++++++++
5 files changed, 137 insertions(+), 1 deletion(-)
create mode 100644 imap/src/osdep/unix/os_serenity.c
create mode 100644 imap/src/osdep/unix/os_serenity.h

diff --git a/configure.ac b/configure.ac
index 4fa94f16078daf6187131177b4153845fc0f2bce..1d899fa29ffb698a396a5756e707a51f20367679 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1289,6 +1289,12 @@ case "$host" in
alpine_mode_readonly="(0600)"
alpine_c_client_target="neb"
;;
+ *-*-serenity*)
+ systype="SERENITY"
+ alpine_path_delim="/"
+ alpine_mode_readonly="(0600)"
+ alpine_c_client_target="serenity"
+ ;;
*-*-bsdi*)
systype="BSI"
alpine_path_delim="/"
diff --git a/imap/Makefile b/imap/Makefile
index d459ef3f1cd3fe0e8bb50f4e57c65aa05f312a50..213a58f908d70fdf74caed712a90926be4a739a5 100644
--- a/imap/Makefile
+++ b/imap/Makefile
@@ -310,7 +310,7 @@ SPECIALS:

# Note on SCO you may have to set LN to "ln".

-a32 a41 a52 aix bs3 bsi d-g d54 do4 drs epx ga4 gas gh9 ghp ghs go5 gsc gsg gso gul h11 hpp hpx lnp lyn mct mnt nec nto nxt nx3 osf os4 ptx qnx qn6 sc5 sco sgi sg6 shp sl4 sl5 slx snx soc sol sos uw2: an
+a32 a41 a52 aix bs3 bsi d-g d54 do4 drs epx ga4 gas gh9 ghp ghs go5 gsc gsg gso gul h11 hpp hpx lnp lyn mct mnt nec nto nxt nx3 osf os4 ptx qnx qn6 sc5 sco serenity sgi sg6 shp sl4 sl5 slx snx soc sol sos uw2: an
$(BUILD) BUILDTYPE=$@

# If you use sv4, you may find that it works to move it to use the an process.
diff --git a/imap/src/osdep/unix/Makefile b/imap/src/osdep/unix/Makefile
index 249d324c9da6b4af0a4a4e33cdbe5c10c46e91ac..c10c4965ca210e97ddfdb7bc324138427e205706 100644
--- a/imap/src/osdep/unix/Makefile
+++ b/imap/src/osdep/unix/Makefile
@@ -659,6 +659,15 @@ sco: # Santa Cruz Operation
BASELDFLAGS="-lsocket -lprot -lcrypt_i -lx -los" \
RANLIB=true LN=ln

+serenity:
+ $(BUILD) `$(CAT) SPECIALS` OS=$@ \
+ SIGTYPE=psx CHECKPW=psx CRXTYPE=nfs \
+ SPOOLDIR=/var/spool \
+ ACTIVEFILE=/var/lib/news/active \
+ RSHPATH=/usr/bin/rsh \
+ BASECFLAGS="$(GCCCFLAGS)" \
+ BASELDFLAGS="-lcrypt"
+
# Note: setting _POSIX_SOURCE doesn't seem to build it as of SGI IRIX 5.3

sgi: # Silicon Graphics
diff --git a/imap/src/osdep/unix/os_serenity.c b/imap/src/osdep/unix/os_serenity.c
new file mode 100644
index 0000000000000000000000000000000000000000..807cdcbc51b97706c352f01159ef3255eb38e0f9
--- /dev/null
+++ b/imap/src/osdep/unix/os_serenity.c
@@ -0,0 +1,59 @@
+/* ========================================================================
+ * Copyright 2022 Taj Morton
+ * ========================================================================
+ */
+
+/*
+ * Program: Operating-system dependent routines -- SerenityOS version
+ *
+ * Author: Taj Morton
+ *
+ * Date: 27 November 2022
+ * Last Edited: 27 Novemner 2022
+ *
+ * This file is based on content that is:
+ * Copyright 1988-2007 University of Washington
+ * Copyright 2008-2009 Mark Crispin
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http:https://www.apache.org/licenses/LICENSE-2.0
+ *
+ */
+
+#include "tcp_unix.h" /* must be before osdep includes tcp.h */
+#include "mail.h"
+#include "osdep.h"
+#include <stdio.h>
+#include <sys/time.h>
+#include <sys/stat.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <ctype.h>
+#include <errno.h>
+extern int errno; /* just in case */
+#include <pwd.h>
+#include "misc.h"
+
+/* Stub of BSD gethostid() function.
+ * Returns a unique identifier for this machine.
+ */
+long gethostid (void)
+{
+ /* Return placeholder value. */
+ return 0xdeadbeef;
+}
+
+#include "fs_unix.c"
+#include "ftl_unix.c"
+#include "nl_unix.c"
+#include "env_unix.c"
+#define fork vfork
+#include "tcp_unix.c"
+#include "gr_waitp.c"
+#include "tz_sv4.c"
+#include "utime.c"
diff --git a/imap/src/osdep/unix/os_serenity.h b/imap/src/osdep/unix/os_serenity.h
new file mode 100644
index 0000000000000000000000000000000000000000..a1284105d9a25e9efe8b46e1440352e52df15928
--- /dev/null
+++ b/imap/src/osdep/unix/os_serenity.h
@@ -0,0 +1,62 @@
+/* ========================================================================
+ * Copyright 2022 Taj Morton
+ * ========================================================================
+ */
+
+/*
+ * Program: Operating-system dependent routines -- SerenityOS version
+ *
+ * Author: Taj Morton
+ *
+ * Date: 27 November 2022
+ * Last Edited: 27 Novemner 2022
+ *
+ * This file is based on content that is:
+ * Copyright 1988-2007 University of Washington
+ * Copyright 2008-2009 Mark Crispin
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http:https://www.apache.org/licenses/LICENSE-2.0
+ *
+ */
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/types.h>
+#include <syslog.h>
+#include <shadow.h>
+#include <dirent.h>
+#include <fcntl.h>
+#include <utime.h>
+#include <sys/select.h>
+#include <sys/file.h>
+#include <LibCrypt/crypt.h> /* crypt() prototype is here. */
+
+#define FNDELAY O_NONBLOCK
+#define setpgrp setpgid
+#define direct dirent
+
+#define L_SET SEEK_SET
+#define L_INCR SEEK_CUR
+#define L_XTND SEEK_END
+
+#ifndef htons
+#include <netinet/in.h> /* htons() prototypes are here. */
+#endif
+
+#ifndef gethostid
+long gethostid (void); /* Stub for function not yet implemented in libc. */
+#endif
+
+#define utime portable_utime
+int portable_utime (char *file, time_t timep[2]);
+
+#include "env_unix.h"
+#include "fs.h"
+#include "ftl.h"
+#include "nl.h"
+#include "tcp.h"
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taj Morton <[email protected]>
Date: Sat, 3 Dec 2022 08:46:22 -0800
Subject: [PATCH] Add Alpine system configuration file that specifies location
of CA certificates.

The system-certs-file configuration option is provided to
SSL_CTX_load_verify_locations() as the CAfile argument (via
imap/src/osdep/unix/ssl_unix.c).

system-certs-file and CAfile are used (as opposed to
system-certs-path and CApath, used to specify a directory)
because certificate files within the CApath directory must follow a
specific naming convention, where the filename matches the CA subject
name hash value.

See man 3 SSL_CTX_set_default_verify_paths for details on how OpenSSL
looks up CA certificates.
https://www.openssl.org/docs/man3.0/man3/SSL_CTX_set_default_verify_paths.html
---
pine-system.serenity.conf | 2 ++
1 file changed, 2 insertions(+)
create mode 100644 pine-system.serenity.conf

diff --git a/pine-system.serenity.conf b/pine-system.serenity.conf
new file mode 100644
index 0000000000000000000000000000000000000000..c20b30eeebdfa2e539663ae96bf4917f0824c3fe
--- /dev/null
+++ b/pine-system.serenity.conf
@@ -0,0 +1,2 @@
+system-certs-file = /etc/ssl/certs/ca-certificates.crt
+
30 changes: 30 additions & 0 deletions Ports/alpine/patches/ReadMe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Patches for alpine on SerenityOS

## `0001-Compiler-helpers-for-build-system-not-host.patch`

Compiler helpers for build system, not host.


## `0002-Add-serenity-as-OS-type-in-Alpine.patch`

Add serenity as OS type in Alpine.


## `0003-Add-Alpine-system-configuration-file-that-specifies-.patch`

Add Alpine system configuration file that specifies location of CA certificates.

The system-certs-file configuration option is provided to
SSL_CTX_load_verify_locations() as the CAfile argument (via
imap/src/osdep/unix/ssl_unix.c).

system-certs-file and CAfile are used (as opposed to
system-certs-path and CApath, used to specify a directory)
because certificate files within the CApath directory must follow a
specific naming convention, where the filename matches the CA subject
name hash value.

See man 3 SSL_CTX_set_default_verify_paths for details on how OpenSSL
looks up CA certificates.
https://www.openssl.org/docs/man3.0/man3/SSL_CTX_set_default_verify_paths.html

0 comments on commit 14baf35

Please sign in to comment.