diff --git a/pkgs/os-specific/darwin/apple-source-releases/mail_cmds/meson.build.in b/pkgs/os-specific/darwin/apple-source-releases/mail_cmds/meson.build.in new file mode 100644 index 000000000000..cacd64bb7b55 --- /dev/null +++ b/pkgs/os-specific/darwin/apple-source-releases/mail_cmds/meson.build.in @@ -0,0 +1,72 @@ +# Build settings based on the upstream Xcode project. +# See: https://github.com/apple-oss-distributions/mail_cmds/blob/main/mail_cmds.xcodeproj/project.pbxproj + +# Project settings +project('mail_cmds', 'c', version : '@version@') + + +# Dependencies +cc = meson.get_compiler('c') + + +# Compatibility tests +utimensat_test = ''' +#include +#include +#include +int main(int argc, char* argv[]) { + return utimensat(AT_FDCWD, NULL, NULL, 0); +} +''' + +has_utimensat = cc.compiles(utimensat_test, name : 'supports utimensat') +utimensat_c_args = has_utimensat ? [ ] : [ '-include', 'time_compat.h', '-I' + meson.source_root() + '/compat' ] +utimensat_sources = has_utimensat ? [ ] : [ 'compat/time_compat.c' ] + +compat_link_args = not has_utimensat ? [ '-Wl,-undefined,dynamic_lookup' ] : [ ] + +# Binaries +executable( + 'mail', + c_args : utimensat_c_args, + install : true, + link_args : compat_link_args, + sources : [ + 'mail/cmd1.c', + 'mail/cmd2.c', + 'mail/cmd3.c', + 'mail/cmdtab.c', + 'mail/collect.c', + 'mail/edit.c', + 'mail/fio.c', + 'mail/getname.c', + 'mail/head.c', + 'mail/lex.c', + 'mail/list.c', + 'mail/main.c', + 'mail/names.c', + 'mail/popen.c', + 'mail/quit.c', + 'mail/send.c', + 'mail/strings.c', + 'mail/temp.c', + 'mail/tty.c', + 'mail/util.c', + 'mail/v7.local.c', + 'mail/vars.c', + 'mail/version.c', + utimensat_sources, + ], +) +install_man('mail/mail.1') + +install_symlink( + 'mailx', + install_dir : get_option('bindir'), + pointing_to : 'mail', +) +install_symlink( + 'mailx.1', + install_dir : get_option('mandir') / 'man1', + pointing_to : 'mail.1', +) diff --git a/pkgs/os-specific/darwin/apple-source-releases/mail_cmds/package.nix b/pkgs/os-specific/darwin/apple-source-releases/mail_cmds/package.nix new file mode 100644 index 000000000000..b4bbf77a21d9 --- /dev/null +++ b/pkgs/os-specific/darwin/apple-source-releases/mail_cmds/package.nix @@ -0,0 +1,29 @@ +{ + lib, + apple-sdk, + file_cmds, + mkAppleDerivation, + pkg-config, +}: + +mkAppleDerivation { + releaseName = "mail_cmds"; + + outputs = [ + "out" + "man" + ]; + + xcodeHash = "sha256-6rBflDgQkqWDc8XPLgKIO703bMamg2QlhUnP71hBX3I="; + + patches = [ + # Add implementations of missing functions for older SDKs + ./patches/0003-Add-implementations-of-missing-APIs-for-older-SDKs.patch + ]; + + postPatch = '' + cp '${file_cmds.src}/gzip/futimens.c' compat/futimens.c + ''; + + meta.description = "Traditional mail command for Darwin"; +} diff --git a/pkgs/os-specific/darwin/apple-source-releases/mail_cmds/patches/0003-Add-implementations-of-missing-APIs-for-older-SDKs.patch b/pkgs/os-specific/darwin/apple-source-releases/mail_cmds/patches/0003-Add-implementations-of-missing-APIs-for-older-SDKs.patch new file mode 100644 index 000000000000..7838aa2b7fe9 --- /dev/null +++ b/pkgs/os-specific/darwin/apple-source-releases/mail_cmds/patches/0003-Add-implementations-of-missing-APIs-for-older-SDKs.patch @@ -0,0 +1,113 @@ +From 9d21ed4cb6b56966a7962227a33c0e1986996cb1 Mon Sep 17 00:00:00 2001 +From: Randy Eckenrode +Date: Sun, 8 Sep 2024 09:46:49 -0400 +Subject: [PATCH 3/3] Add implementations of missing APIs for older SDKs + +--- + compat/rpmatch_compat.c | 10 ++++++++++ + compat/rpmatch_compat.h | 6 ++++++ + compat/time_compat.c | 38 ++++++++++++++++++++++++++++++++++++++ + compat/time_compat.h | 16 ++++++++++++++++ + 4 files changed, 70 insertions(+) + create mode 100644 compat/rpmatch_compat.c + create mode 100644 compat/rpmatch_compat.h + create mode 100644 compat/time_compat.c + create mode 100644 compat/time_compat.h + +diff --git a/compat/rpmatch_compat.c b/compat/rpmatch_compat.c +new file mode 100644 +index 0000000..8eb99c3 +--- /dev/null ++++ b/compat/rpmatch_compat.c +@@ -0,0 +1,10 @@ ++// SPDX-License-Identifier: APSL-2.0 ++// utimensat written by Randy Eckenrode © 2024 ++ ++#include "rpmatch_compat.h" ++ ++#include ++ ++int rpmatch(const char *response) { ++ return response != NULL && (response[0] == 'y' || response[0] == 'Y'); ++} +diff --git a/compat/rpmatch_compat.h b/compat/rpmatch_compat.h +new file mode 100644 +index 0000000..a13b64b +--- /dev/null ++++ b/compat/rpmatch_compat.h +@@ -0,0 +1,6 @@ ++// SPDX-License-Identifier: APSL-2.0 ++// utimensat written by Randy Eckenrode © 2024 ++ ++#pragma once ++ ++extern int rpmatch(const char *response); +diff --git a/compat/time_compat.c b/compat/time_compat.c +new file mode 100644 +index 0000000..becf778 +--- /dev/null ++++ b/compat/time_compat.c +@@ -0,0 +1,38 @@ ++// SPDX-License-Identifier: APSL-2.0 ++// utimensat written by Randy Eckenrode © 2024 ++ ++#include "time_compat.h" ++ ++#define futimens gzip_futimens ++#include "compat/futimens.c" ++#undef futimens ++ ++#include ++#include ++ ++#if __MAC_OS_X_VERSION_MIN_REQUIRED < 101300 ++extern int utimensat(int dirfd, const char* pathname, const struct timespec times[_Nullable 2], int flags); ++extern int futimens(int fd, const struct timespec times[_Nullable 2]); ++#endif ++ ++int compat_utimensat(int dirfd, const char* pathname, const struct timespec times[_Nullable 2], int flags) { ++ if (__builtin_available(macOS 10.13, *)) { ++ return utimensat(dirfd, pathname, times, flags); ++ } else { ++ int fd = openat(dirfd, pathname, flags); ++ if (fd == -1) { return -1; } ++ ++ int retval = compat_futimens(fd, times); ++ if (close(fd) == -1) { return -1; } ++ ++ return retval; ++ } ++} ++ ++int compat_futimens(int fd, const struct timespec times[_Nullable 2]) { ++ if (__builtin_available(macOS 10.13, *)) { ++ return futimens(fd, times); ++ } else { ++ return gzip_futimens(fd, times); ++ } ++} +diff --git a/compat/time_compat.h b/compat/time_compat.h +new file mode 100644 +index 0000000..f07a7ed +--- /dev/null ++++ b/compat/time_compat.h +@@ -0,0 +1,16 @@ ++// SPDX-License-Identifier: APSL-2.0 ++// utimensat written by Randy Eckenrode © 2024 ++ ++#pragma once ++ ++#include ++ ++// https://github.com/apple-oss-distributions/xnu/blob/94d3b452840153a99b38a3a9659680b2a006908e/bsd/sys/stat.h#L578-L579 ++#define UTIME_NOW -1 ++#define UTIME_OMIT -2 ++ ++#define utimensat compat_utimensat ++#define futimens compat_futimens ++ ++extern int compat_utimensat(int dirfd, const char* pathname, const struct timespec times[_Nullable 2], int flags); ++extern int compat_futimens(int fd, const struct timespec times[_Nullable 2]); +-- +2.46.0 + diff --git a/pkgs/os-specific/darwin/apple-source-releases/versions.json b/pkgs/os-specific/darwin/apple-source-releases/versions.json index 86d45066ea54..913698993a04 100644 --- a/pkgs/os-specific/darwin/apple-source-releases/versions.json +++ b/pkgs/os-specific/darwin/apple-source-releases/versions.json @@ -67,6 +67,10 @@ "hash": "sha256-tUsl22Z0HUVSkSoohFXkhicNFCW+RARvpTS0q6yaQFk=", "version": "72" }, + "mail_cmds": { + "hash": "sha256-ET1nga9nwgBtN7fuvsPs1yqe5OhQ62PVl7LxqbsAPqU=", + "version": "38.0.1" + }, "network_cmds": { "hash": "sha256-PChAbC/4cHa0lbojElR2PHOUo+cDvsoNdiorle0IXss=", "version": "606.40.2"