Skip to content

Commit

Permalink
sys-fs/dd-rescue: Fix building for musl.
Browse files Browse the repository at this point in the history
The original patch was written by gentoo developer Thomas Deutschmann
<whissi@gentoo.org>, but the patch needed to be rebased. I've added in
my secmem patch inside it (another musl fix for dd-rescue).

Closes: https://bugs.gentoo.org/829285
Signed-off-by: brahmajit das <listout@protonmail.com>
Closes: #26455
Signed-off-by: Sam James <sam@gentoo.org>
  • Loading branch information
listout authored and thesamesam committed Jul 23, 2023
1 parent 9469342 commit 3669e54
Show file tree
Hide file tree
Showing 3 changed files with 257 additions and 1 deletion.
107 changes: 107 additions & 0 deletions sys-fs/dd-rescue/dd-rescue-1.99.13-r1.ebuild
@@ -0,0 +1,107 @@
# Copyright 1999-2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

inherit autotools flag-o-matic toolchain-funcs

MY_PN="${PN/-/_}"
MY_P="${MY_PN}-${PV}"

DESCRIPTION="Similar to dd but can copy from source with errors"
HOMEPAGE="http://www.garloff.de/kurt/linux/ddrescue/"
SRC_URI="http://www.garloff.de/kurt/linux/ddrescue/${MY_P}.tar.bz2"

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="amd64 ~arm ~mips ~ppc ~ppc64 ~sparc x86 ~amd64-linux ~x86-linux ~ppc-macos"
IUSE="cpu_flags_x86_avx2 lzo cpu_flags_x86_sse4_2 static xattr"

RDEPEND="
lzo? ( dev-libs/lzo )
xattr? ( sys-apps/attr )
"
DEPEND="${RDEPEND}"

S="${WORKDIR}/${MY_P}"

PATCHES=(
"${FILESDIR}"/${PN}-1.99.13-musl.patch
)

src_prepare() {
default

if ! use cpu_flags_x86_sse4_2; then
sed -i \
-e 's:^CC_FLAGS_CHECK(-msse4.2,SSE42):#&:' \
configure.ac || die
fi

if ! use cpu_flags_x86_avx2; then
sed -i \
-e 's:^CC_FLAGS_CHECK(-mavx2,AVX2):#&:' \
configure.ac || die
fi

eautoreconf

sed -i \
-e 's:\(-ldl\):$(LDFLAGS) \1:' \
-e 's:\(-shared\):$(CFLAGS) $(LDFLAGS) \1:' \
Makefile || die
}

src_configure() {
use static && append-ldflags -static
# OpenSSL is only used by a random helper tool we don't install.
ac_cv_header_attr_xattr_h=$(usex xattr) \
ac_cv_header_openssl_evp_h=no \
ac_cv_lib_crypto_EVP_aes_192_ctr=no \
ac_cv_lib_lzo2_lzo1x_1_compress=$(usex lzo) \
ac_cv_header_lzo_lzo1x_h=$(usex lzo) \
econf
}

_emake() {
local arch
case ${ARCH} in
x86) arch=i386;;
amd64) arch=x86_64;;
arm) arch=arm;;
arm64) arch=aarch64;;
esac

local os=$(usex kernel_linux Linux IDK)

# The Makefile is a mess. Override a few vars rather than patch it.
emake \
MACH="${arch}" \
OS="${os}" \
HAVE_SSE42=$(usex cpu_flags_x86_sse4_2 1 0) \
HAVE_AVX2=$(usex cpu_flags_x86_avx2 1 0) \
RPM_OPT_FLAGS="${CFLAGS} ${CPPFLAGS}" \
CFLAGS_OPT='$(CFLAGS)' \
LDFLAGS="${LDFLAGS} -Wl,-rpath,${EPREFIX}/usr/$(get_libdir)/${PN}" \
CC="$(tc-getCC)" \
"$@"
}

src_compile() {
_emake
}

src_test() {
append-cflags -fcommon # bug #707796
_emake check
}

src_install() {
# easier to install by hand than trying to make sense of the Makefile.
dobin dd_rescue
dodir /usr/$(get_libdir)/${PN}
cp -pPR libddr_*.so "${ED}"/usr/$(get_libdir)/${PN}/ || die
dodoc README.dd_rescue
doman dd_rescue.1
use lzo && doman ddr_lzo.1
}
6 changes: 5 additions & 1 deletion sys-fs/dd-rescue/dd-rescue-1.99.13.ebuild
Expand Up @@ -14,7 +14,7 @@ SRC_URI="http://www.garloff.de/kurt/linux/ddrescue/${MY_P}.tar.bz2"

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="amd64 ~arm ~mips ~ppc ~ppc64 ~sparc x86 ~amd64-linux ~x86-linux ~ppc-macos"
KEYWORDS="~amd64 ~arm ~mips ~ppc ~ppc64 ~sparc ~x86 ~amd64-linux ~x86-linux ~ppc-macos"
IUSE="cpu_flags_x86_avx2 lzo cpu_flags_x86_sse4_2 static xattr"

RDEPEND="
Expand All @@ -25,6 +25,10 @@ DEPEND="${RDEPEND}"

S="${WORKDIR}/${MY_P}"

PATCHES=(
"${FILESDIR}"/${PN}-1.99.13-musl.patch
)

src_prepare() {
default

Expand Down
145 changes: 145 additions & 0 deletions sys-fs/dd-rescue/files/dd-rescue-1.99.13-musl.patch
@@ -0,0 +1,145 @@
# Original patch was created by Thomas Deutschmann <whissi@gentoo.org>, but the
# patch needed to be rebased. Mainly configure.ac instead of configure.in.
# The only additional included part is secmem patch.
#
# Closes: https://bugs.gentoo.org/829285
From 69c3974670f5a8ee0f2258f10a9228b39025b464 Mon Sep 17 00:00:00 2001
From: Thomas Deutschmann <whissi@gentoo.org>
Date: Wed, 13 Dec 2017 01:02:12 +0100
Subject: [PATCH] loff_t and __WORDSIZE includes for MUSL

Rewrite of Justin Keogh's patch [Link 1] to fix build problems
on ARM.

Link 1: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=5f5abc0f1b036921d6eb5b0f434c960ed280619f
Fixes: https://bugs.gentoo.org/616364
--- a/configure.ac
+++ b/configure.ac
@@ -11,7 +11,7 @@ AC_C_INLINE

#AC_PROG_INSTALL
#CFLAGS="$CFLAGS -DHAVE_CONFIG_H"
-AC_CHECK_HEADERS([fallocate.h dlfcn.h unistd.h sys/xattr.h attr/xattr.h sys/acl.h sys/ioctl.h endian.h linux/fs.h linux/fiemap.h stdint.h lzo/lzo1x.h openssl/evp.h linux/random.h sys/random.h malloc.h sched.h sys/statvfs.h sys/resource.h sys/endian.h linux/swab.h])
+AC_CHECK_HEADERS([fallocate.h dlfcn.h unistd.h sys/xattr.h attr/xattr.h sys/acl.h sys/ioctl.h sys/reg.h endian.h linux/fs.h linux/fiemap.h stdint.h lzo/lzo1x.h openssl/evp.h linux/random.h sys/random.h malloc.h sched.h sys/statvfs.h sys/resource.h sys/endian.h linux/swab.h])
AC_CHECK_FUNCS([ffs ffsl basename fallocate64 splice getopt_long open64 pread pread64 lseek64 stat64 posix_fadvise posix_fadvise64 __builtin_prefetch htonl htobe64 feof_unlocked getline getentropy getrandom posix_memalign valloc sched_yield fstatvfs __builtin_cpu_supports getrlimit aligned_alloc])
AC_CHECK_LIB(dl,dlsym)
AC_CHECK_LIB(fallocate,linux_fallocate64)
--- a/ddr_ctrl.h
+++ b/ddr_ctrl.h
@@ -7,6 +7,9 @@
* License: GNU GPLv2 or v3
*/

+#define _GNU_SOURCE
+#include <fcntl.h>
+
#ifndef _DDR_CTRL_H
#define _DDR_CTRL_H

--- a/ffs.h
+++ b/ffs.h
@@ -28,6 +28,9 @@
#include <endian.h>
#endif

+#ifdef HAVE_SYS_REG_H
+#include <sys/reg.h>
+#endif

#ifdef HAVE_FFS
# define myffs(x) ffs(x)

--- a/fiemap.h
+++ b/fiemap.h
@@ -29,5 +29,9 @@

#endif /* HAVE_LINUX_FS_H */

+#ifdef HAVE_SYS_REG_H
+#include <sys/reg.h>
+#endif
+
#endif /* _FIEMAPH */

--- a/fmt_no.h
+++ b/fmt_no.h
@@ -1,4 +1,6 @@
/** Decl for int to str conversion with highlighting */
+#define _GNU_SOURCE
+#include <fcntl.h>

#ifndef _FMT_NO_H
#define _FMT_NO_H

--- a/fstrim.h
+++ b/fstrim.h
@@ -1,3 +1,6 @@
+#define _GNU_SOURCE
+#include <fcntl.h>
+
#ifndef _FSTRIM_H
#define _FSTRIM_H

--- a/libddr_hash.c
+++ b/libddr_hash.c
@@ -34,6 +34,10 @@
#include <unistd.h>
#include <fcntl.h>

+#ifdef HAVE_SYS_REG_H
+#include <sys/reg.h>
+#endif
+
#include <netinet/in.h> /* For ntohl/htonl */
#include <endian.h>

--- a/libddr_lzo.c
+++ b/libddr_lzo.c
@@ -16,6 +16,9 @@
#include "ddr_plugin.h"
#include "ddr_ctrl.h"

+#ifdef HAVE_SYS_REG_H
+#include <sys/reg.h>
+#endif
#include <stdlib.h>
#include <string.h>
#include <stdint.h>

--- a/libddr_null.c
+++ b/libddr_null.c
@@ -10,6 +10,9 @@
#include "ddr_ctrl.h"
#include <string.h>
#include <stdlib.h>
+#ifdef HAVE_SYS_REG_H
+#include <sys/reg.h>
+#endif

/* fwd decl */
extern ddr_plugin_t ddr_plug;

--- a/sha512.h
+++ b/sha512.h
@@ -3,6 +3,10 @@

#include "hash.h"

+#ifdef HAVE_SYS_REG_H
+#include <sys/reg.h>
+#endif
+
void sha512_init(hash_t *ctx);
void sha384_init(hash_t *ctx);
void sha512_128(const uint8_t* msg, hash_t* ctx);

--- a/secmem.c
+++ b/secmem.c
@@ -15,6 +15,7 @@
#endif
#ifdef HAVE_SYS_RESOURCE_H
# include <sys/resource.h>
+# include <stddef.h>
#endif

static unsigned char *optr;

0 comments on commit 3669e54

Please sign in to comment.