* [PATCH] Check -DXXH_INLINE_ALL works, otherwise link against libxxhash
@ 2022-11-03 16:28 Mark Wielaard
2022-11-03 22:11 ` Mark Wielaard
0 siblings, 1 reply; 2+ messages in thread
From: Mark Wielaard @ 2022-11-03 16:28 UTC (permalink / raw)
To: dwz; +Cc: Mark Wielaard
Because we don't have a real configure script this does a Makefile
shell trick trying to compile with XXH_INLINE_ALL defined when
including xxhash.h. If that fails (like on oldstable debian) it
doesn't add -DXXH_INLINE_ALL=1 to CFLAGS and does add -lxxhash
to LIBS.
---
Makefile | 13 ++++++++++++-
dwz.c | 14 ++++++++------
2 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/Makefile b/Makefile
index 591a0f6..7becde9 100644
--- a/Makefile
+++ b/Makefile
@@ -8,7 +8,15 @@ CFLAGS = -O2 -g
DWZ_VERSION := $(shell cat $(srcdir)/VERSION)
CFLAGS_VERSION = -DDWZ_VERSION='"$(DWZ_VERSION)"'
CFLAGS_COPYRIGHT = $(shell cat $(srcdir)/COPYRIGHT_YEARS)
-CFLAGS_COMMON = -Wall -W -D_FILE_OFFSET_BITS=64 -DXXH_INLINE_ALL=1
+CFLAGS_COMMON = -Wall -W -D_FILE_OFFSET_BITS=64
+XXH_INLINE_ALL_WORKS = $(shell printf "\#define XXH_INLINE_ALL 1;\n \
+ \#include <xxhash.h>" \
+ | $(CC) -xc -c - -o /dev/null 2>/dev/null \
+ && echo -n 1)
+ifeq "$(XXH_INLINE_ALL_WORKS)" "1"
+ CFLAGS_COMMON += -DXXH_INLINE_ALL=1
+endif
+
override CFLAGS += $(CFLAGS_COMMON) $(CFLAGS_VERSION) $(CFLAGS_COPYRIGHT)
prefix = /usr
@@ -18,6 +26,9 @@ datarootdir = $(prefix)/share
mandir = $(datarootdir)/man
OBJECTS = args.o dwz.o hashtab.o pool.o sha1.o dwarfnames.o
LIBS=-lelf
+ifneq "$(XXH_INLINE_ALL_WORKS)" "1"
+LIBS += -lxxhash
+endif
dwz: $(OBJECTS)
$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
args.o: native.o
diff --git a/dwz.c b/dwz.c
index 51c5dd6..3bc6038 100644
--- a/dwz.c
+++ b/dwz.c
@@ -114,20 +114,20 @@
# define NT_GNU_BUILD_ID 3
#endif
-/* xxHash state object. */
-static XXH64_state_t state;
+/* xxHash state object. Init in main. */
+static XXH64_state_t *state;
/* Clear xxHash state to zero. */
-#define hash_init_state() XXH64_reset(&state, 0)
+#define hash_init_state() XXH64_reset(state, 0)
/* Update hash STATE with VALUE. */
-#define hash_update_state_object(value) XXH64_update(&state, &value, sizeof value)
+#define hash_update_state_object(value) XXH64_update(state, &value, sizeof value)
/* Update hash STATE with OBJECT that has a provided SIZE. */
-#define hash_update_state(object, size) XXH64_update(&state, object, size)
+#define hash_update_state(object, size) XXH64_update(state, object, size)
/* Get digest once we are done with a state. */
-#define hash_digest() XXH64_digest(&state)
+#define hash_digest() XXH64_digest(state)
/* Shorthand for hashing something with an intrinsic size. */
#define hash(IN,LEN) XXH64(IN, LEN, 0)
@@ -16834,6 +16834,8 @@ main (int argc, char *argv[])
int nr_files;
char **files;
+ state = XXH64_createState ();
+
if (elf_version (EV_CURRENT) == EV_NONE)
error (1, 0, "library out of date");
--
2.18.4
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Check -DXXH_INLINE_ALL works, otherwise link against libxxhash
2022-11-03 16:28 [PATCH] Check -DXXH_INLINE_ALL works, otherwise link against libxxhash Mark Wielaard
@ 2022-11-03 22:11 ` Mark Wielaard
0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2022-11-03 22:11 UTC (permalink / raw)
To: dwz
[-- Attachment #1: Type: text/plain, Size: 474 bytes --]
On Thu, Nov 03, 2022 at 05:28:38PM +0100, Mark Wielaard wrote:
> Because we don't have a real configure script this does a Makefile
> shell trick trying to compile with XXH_INLINE_ALL defined when
> including xxhash.h. If that fails (like on oldstable debian) it
> doesn't add -DXXH_INLINE_ALL=1 to CFLAGS and does add -lxxhash
> to LIBS.
After testing a bit more on different systems I pushed this variant
which does the string escaping slightly different.
Cheers,
Mark
[-- Attachment #2: 0001-Check-DXXH_INLINE_ALL-works-otherwise-link-against-l.patch --]
[-- Type: text/x-diff, Size: 2952 bytes --]
From 7aae87b5dff6128c46fc7fb2ccd1eae2c6fa11ba Mon Sep 17 00:00:00 2001
From: Mark Wielaard <mark@klomp.org>
Date: Thu, 3 Nov 2022 23:08:50 +0100
Subject: [PATCH] Check -DXXH_INLINE_ALL works, otherwise link against
libxxhash
Because we don't have a real configure script this does a Makefile
shell trick trying to compile with XXH_INLINE_ALL defined when
including xxhash.h. If that fails (like on oldstable debian) it
doesn't add -DXXH_INLINE_ALL=1 to CFLAGS and does add -lxxhash
to LIBS.
---
Makefile | 13 ++++++++++++-
dwz.c | 14 ++++++++------
2 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/Makefile b/Makefile
index 591a0f6..8b7cf76 100644
--- a/Makefile
+++ b/Makefile
@@ -8,7 +8,15 @@ CFLAGS = -O2 -g
DWZ_VERSION := $(shell cat $(srcdir)/VERSION)
CFLAGS_VERSION = -DDWZ_VERSION='"$(DWZ_VERSION)"'
CFLAGS_COPYRIGHT = $(shell cat $(srcdir)/COPYRIGHT_YEARS)
-CFLAGS_COMMON = -Wall -W -D_FILE_OFFSET_BITS=64 -DXXH_INLINE_ALL=1
+CFLAGS_COMMON = -Wall -W -D_FILE_OFFSET_BITS=64
+XXH_PROG = "\#define XXH_INLINE_ALL 1\n\#include <xxhash.h>\n"
+XXH_INLINE_ALL_WORKS = $(shell printf $(XXH_PROG) \
+ | $(CC) -xc -c - -o /dev/null 2>/dev/null \
+ && echo -n 1)
+ifeq "$(XXH_INLINE_ALL_WORKS)" "1"
+ CFLAGS_COMMON += -DXXH_INLINE_ALL=1
+endif
+
override CFLAGS += $(CFLAGS_COMMON) $(CFLAGS_VERSION) $(CFLAGS_COPYRIGHT)
prefix = /usr
@@ -18,6 +26,9 @@ datarootdir = $(prefix)/share
mandir = $(datarootdir)/man
OBJECTS = args.o dwz.o hashtab.o pool.o sha1.o dwarfnames.o
LIBS=-lelf
+ifneq "$(XXH_INLINE_ALL_WORKS)" "1"
+LIBS += -lxxhash
+endif
dwz: $(OBJECTS)
$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
args.o: native.o
diff --git a/dwz.c b/dwz.c
index 51c5dd6..3bc6038 100644
--- a/dwz.c
+++ b/dwz.c
@@ -114,20 +114,20 @@
# define NT_GNU_BUILD_ID 3
#endif
-/* xxHash state object. */
-static XXH64_state_t state;
+/* xxHash state object. Init in main. */
+static XXH64_state_t *state;
/* Clear xxHash state to zero. */
-#define hash_init_state() XXH64_reset(&state, 0)
+#define hash_init_state() XXH64_reset(state, 0)
/* Update hash STATE with VALUE. */
-#define hash_update_state_object(value) XXH64_update(&state, &value, sizeof value)
+#define hash_update_state_object(value) XXH64_update(state, &value, sizeof value)
/* Update hash STATE with OBJECT that has a provided SIZE. */
-#define hash_update_state(object, size) XXH64_update(&state, object, size)
+#define hash_update_state(object, size) XXH64_update(state, object, size)
/* Get digest once we are done with a state. */
-#define hash_digest() XXH64_digest(&state)
+#define hash_digest() XXH64_digest(state)
/* Shorthand for hashing something with an intrinsic size. */
#define hash(IN,LEN) XXH64(IN, LEN, 0)
@@ -16834,6 +16834,8 @@ main (int argc, char *argv[])
int nr_files;
char **files;
+ state = XXH64_createState ();
+
if (elf_version (EV_CURRENT) == EV_NONE)
error (1, 0, "library out of date");
--
2.30.2
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-11-03 22:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-03 16:28 [PATCH] Check -DXXH_INLINE_ALL works, otherwise link against libxxhash Mark Wielaard
2022-11-03 22:11 ` Mark Wielaard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).