From 2c1e4e502d81c799e1bba775bd7bdd0ecee8dc40 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Thu, 6 Dec 2012 12:58:17 +0100 Subject: [PATCH] XBPS can now be built on NetBSD (and probably any other BSD variant). --- configure | 98 +++++++++++++++--- include/compat.h | 19 +++- include/xbps_api.h.in | 4 + include/xbps_api_impl.h | 1 - lib/Makefile | 7 +- lib/{external => compat}/humanize_number.c | 25 +---- lib/external/dewey.c | 3 + lib/portableproplib/prop/rbtree.h | 2 + lib/portableproplib/prop_array.c | 1 - lib/portableproplib/prop_dictionary.c | 1 - lib/portableproplib/prop_number.c | 1 - lib/portableproplib/prop_object.c | 11 +- lib/portableproplib/prop_object_impl.h | 5 +- lib/portableproplib/prop_rb_impl.h | 112 +-------------------- lib/util.c | 13 +++ 15 files changed, 145 insertions(+), 158 deletions(-) rename lib/{external => compat}/humanize_number.c (88%) diff --git a/configure b/configure index 61011912..adb9a955 100755 --- a/configure +++ b/configure @@ -7,6 +7,7 @@ VERSION=0.19 STRLCPY= STRLCAT= VASPRINTF= +HUMANIZE_NUMBER= LIBFETCH= PROPLIB= OS= @@ -414,6 +415,52 @@ fi echo "$STRLCAT." rm -f _$func.c _$func +# +# Check for humanize_number(). +func=humanize_number +printf "Checking for $func() ... " +cat < _$func.c +#include +#include + +int main(void) { + humanize_number(NULL, 0, 0, NULL, 0, 0); + return 0; +} +EOF +if $XCC -lutil _$func.c -o _$func 2>/dev/null; then + HUMANIZE_NUMBER=yes + echo "CPPFLAGS+= -DHAVE_HUMANIZE_NUMBER" >>$CONFIG_MK +else + HUMANIZE_NUMBER=no + echo "COMPAT_SRCS+= compat/humanize_number.o" >>$CONFIG_MK + echo "#include \"compat.h\"" >>$CONFIG_H +fi +echo "$HUMANIZE_NUMBER." +rm -f _$func.c _$func + +# +# Check for rbtree_ininit(). +# +func=rb_tree_init +printf "Checking for $func() ... " +cat < _$func.c +#include +int main(void) { + rb_tree_init(NULL, NULL); + return 0; +} +EOF +if $XCC _$func.c -o _$func 2>/dev/null; then + RBTREE=yes + echo "CPPFLAGS += -DHAVE_RBTREE" >>$CONFIG_MK +else + RBTREE=no + echo "LIBPROP_OBJS += portableproplib/rb.o" >>$CONFIG_MK +fi +echo "$RBTREE." +rm -f _$func.c _$func + # # Check for libfetch's fetchIO_read(). # @@ -564,13 +611,13 @@ fi # # libarchive >= 2.8.0 with pkg-config support is required. # -printf "Checking for libarchive via pkg-config ... " -if ! $PKGCONFIG_BIN --exists libarchive; then +printf "Checking for libarchive >= 3.0.2 via pkg-config ... " +if ! $PKGCONFIG_BIN --atleast-version=3.0.2 libarchive; then echo "libarchive.pc file not found, exiting." exit 1 else echo "found version $($PKGCONFIG_BIN --modversion libarchive)." - echo "CFLAGS += $($PKGCONFIG_BIN --cflags libarchive)" >>$CONFIG_MK + echo "CFLAGS += $($PKGCONFIG_BIN --cflags libarchive)" >>$CONFIG_MK echo "LDFLAGS += $($PKGCONFIG_BIN --libs libarchive)" >>$CONFIG_MK echo "STATIC_LIBS += $($PKGCONFIG_BIN --libs --static libarchive)" \ >>$CONFIG_MK @@ -592,18 +639,43 @@ else fi # -# OpenSSL libssl with pkg-config support is required. +# OpenSSL libssl with pkg-config support is required when building +# the static binaries. # -printf "Checking for OpenSSL via pkg-config ... " -if ! $PKGCONFIG_BIN --exists libssl; then - echo "libssl.pc file not found, exiting." - exit 1 +if [ "$BUILD_STATIC" = "yes" ]; then + printf "Checking for OpenSSL via pkg-config ... " + if ! $PKGCONFIG_BIN --exists libssl; then + echo "libssl.pc file not found, exiting." + exit 1 + else + echo "found version $($PKGCONFIG_BIN --modversion libssl)." + echo "CFLAGS += $($PKGCONFIG_BIN --cflags libssl)" >>$CONFIG_MK + echo "LDFLAGS += $($PKGCONFIG_BIN --libs libssl)" >>$CONFIG_MK + echo "STATIC_LIBS += $($PKGCONFIG_BIN --libs --static libssl)" \ + >>$CONFIG_MK + fi else - echo "found version $($PKGCONFIG_BIN --modversion libssl)." - echo "CFLAGS += $($PKGCONFIG_BIN --cflags libssl)" >>$CONFIG_MK - echo "LDFLAGS += $($PKGCONFIG_BIN --libs libssl)" >>$CONFIG_MK - echo "STATIC_LIBS += $($PKGCONFIG_BIN --libs --static libssl)" \ - >>$CONFIG_MK + func=SHA256 + printf "Checking for OpenSSL $func() ... " +cat < _$func.c +#include +int main(void) { + SHA256(NULL, NULL, 0); + return 0; +} +EOF + if $XCC -lcrypto _$func.c -o _$func 2>/dev/null; then + CRYPTO_SHA256=yes + echo "LDFLAGS += -lcrypto" >>$CONFIG_MK + else + CRYPTO_SHA256=no + fi + echo "$ZLIB." + rm -f _$func.c _$func + if [ "$CRYPTO_SHA256" = "no" ]; then + echo "Failed to link with your system's OpenSSL library, can't continue..." + exit 1 + fi fi # diff --git a/include/compat.h b/include/compat.h index 9d0085ff..9f057f95 100644 --- a/include/compat.h +++ b/include/compat.h @@ -3,7 +3,12 @@ #include #include -#include "xbps_api_impl.h" + +#if HAVE_VISIBILITY +#define HIDDEN __attribute__ ((visibility("hidden"))) +#else +#define HIDDEN +#endif #ifndef HAVE_STRLCAT size_t HIDDEN strlcat(char *, const char *, size_t); @@ -17,8 +22,18 @@ size_t HIDDEN strlcpy(char *, const char *, size_t); char HIDDEN *strcasestr(const char *, const char *); #endif -#if defined(HAVE_VASPRINTF) && !defined(_GNU_SOURCE) +#if !defined(HAVE_VASPRINTF) && !defined(_GNU_SOURCE) int HIDDEN vasprintf(char **, const char *, va_list); #endif +#ifndef HAVE_HUMANIZE_HUMBER +#define HN_DECIMAL 0x01 +#define HN_NOSPACE 0x02 +#define HN_B 0x04 +#define HN_DIVISOR_1000 0x08 +#define HN_GETSCALE 0x10 +#define HN_AUTOSCALE 0x20 +int HIDDEN humanize_number(char *, size_t, int64_t, const char *, int, int); +#endif + #endif /* COMPAT_H */ diff --git a/include/xbps_api.h.in b/include/xbps_api.h.in index d4f8fd50..694ae07e 100644 --- a/include/xbps_api.h.in +++ b/include/xbps_api.h.in @@ -38,11 +38,15 @@ #ifdef __cplusplus # ifndef __BEGIN_DECLS # define __BEGIN_DECLS extern "C" { +# endif +# ifndef __END_DECLS # define __END_DECLS } # endif #else # ifndef __BEGIN_DECLS # define __BEGIN_DECLS +# endif +# ifndef __END_DECLS # define __END_DECLS # endif #endif diff --git a/include/xbps_api_impl.h b/include/xbps_api_impl.h index 766bdee0..c5782f40 100644 --- a/include/xbps_api_impl.h +++ b/include/xbps_api_impl.h @@ -40,7 +40,6 @@ #define HIDDEN #endif -#include "compat.h" #include "queue.h" #include "fetch.h" diff --git a/lib/Makefile b/lib/Makefile index 30fc0644..39c4d910 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -7,9 +7,9 @@ LIBXBPS_SHLIB = libxbps.so.$(LIBXBPS_MAJOR).$(LIBXBPS_MINOR).$(LIBXBPS_MICRO) LDFLAGS += $(LIBXBPS_LDFLAGS) -shared -Wl,-soname,libxbps.so.$(LIBXBPS_MAJOR) # portableproplib -LIBPROP_OBJS = portableproplib/prop_array.o portableproplib/prop_bool.o +LIBPROP_OBJS += portableproplib/prop_array.o portableproplib/prop_bool.o LIBPROP_OBJS += portableproplib/prop_dictionary.o portableproplib/prop_ingest.o -LIBPROP_OBJS += portableproplib/prop_object.o portableproplib/rb.o +LIBPROP_OBJS += portableproplib/prop_object.o LIBPROP_OBJS += portableproplib/prop_stack.o portableproplib/prop_string.o LIBPROP_OBJS += portableproplib/prop_array_util.o portableproplib/prop_number.o LIBPROP_OBJS += portableproplib/prop_dictionary_util.o portableproplib/prop_zlib.o @@ -37,8 +37,7 @@ LIBFETCH_OBJS = endif # External code used by libxbps -EXTOBJS = external/dewey.o external/fexec.o external/humanize_number.o -EXTOBJS += external/mkpath.o +EXTOBJS = external/dewey.o external/fexec.o external/mkpath.o # libxbps OBJS = package_configure.o package_config_files.o package_orphans.o diff --git a/lib/external/humanize_number.c b/lib/compat/humanize_number.c similarity index 88% rename from lib/external/humanize_number.c rename to lib/compat/humanize_number.c index 9355cdfd..446c94b8 100644 --- a/lib/external/humanize_number.c +++ b/lib/compat/humanize_number.c @@ -37,16 +37,10 @@ #include #include -#include +#include "xbps_api_impl.h" +#include "compat.h" -#define HN_DECIMAL 0x01 -#define HN_NOSPACE 0x02 -#define HN_B 0x04 -#define HN_DIVISOR_1000 0x08 -#define HN_GETSCALE 0x10 -#define HN_AUTOSCALE 0x20 - -static int +int HIDDEN humanize_number(char *buf, size_t len, int64_t bytes, const char *suffix, int scale, int flags) { @@ -148,16 +142,3 @@ humanize_number(char *buf, size_t len, int64_t bytes, return (r); } - -/* - * Small wrapper for NetBSD's humanize_number(3) with some - * defaults set that we care about. - */ -int -xbps_humanize_number(char *buf, int64_t bytes) -{ - assert(buf != NULL); - - return humanize_number(buf, 7, bytes, "B", - HN_AUTOSCALE, HN_DECIMAL|HN_NOSPACE); -} diff --git a/lib/external/dewey.c b/lib/external/dewey.c index 49a2a877..c52ae23a 100644 --- a/lib/external/dewey.c +++ b/lib/external/dewey.c @@ -35,6 +35,9 @@ #include #include "xbps_api_impl.h" +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif #define PKG_PATTERN_MAX 1024 diff --git a/lib/portableproplib/prop/rbtree.h b/lib/portableproplib/prop/rbtree.h index b32307d4..349d7062 100644 --- a/lib/portableproplib/prop/rbtree.h +++ b/lib/portableproplib/prop/rbtree.h @@ -39,6 +39,8 @@ #include #include #endif +#include +#include #include #if __GNUC_PREREQ(2, 96) diff --git a/lib/portableproplib/prop_array.c b/lib/portableproplib/prop_array.c index 8c7c94f4..3baa1d92 100644 --- a/lib/portableproplib/prop_array.c +++ b/lib/portableproplib/prop_array.c @@ -34,7 +34,6 @@ #if !defined(_KERNEL) && !defined(_STANDALONE) #include -#define __unused /* empty */ #endif struct _prop_array { diff --git a/lib/portableproplib/prop_dictionary.c b/lib/portableproplib/prop_dictionary.c index 4c21fcb4..40db81d0 100644 --- a/lib/portableproplib/prop_dictionary.c +++ b/lib/portableproplib/prop_dictionary.c @@ -37,7 +37,6 @@ #if !defined(_KERNEL) && !defined(_STANDALONE) #include -#define __unused /* empty */ #endif /* diff --git a/lib/portableproplib/prop_number.c b/lib/portableproplib/prop_number.c index dfd5e42a..03f88228 100644 --- a/lib/portableproplib/prop_number.c +++ b/lib/portableproplib/prop_number.c @@ -41,7 +41,6 @@ #else #include #include -#define __unused /* empty */ #endif struct _prop_number { diff --git a/lib/portableproplib/prop_object.c b/lib/portableproplib/prop_object.c index 087110c2..3a7caef8 100644 --- a/lib/portableproplib/prop_object.c +++ b/lib/portableproplib/prop_object.c @@ -29,9 +29,6 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include -#include "prop_object_impl.h" - #include #include #include @@ -40,6 +37,9 @@ #include #include +#include +#include "prop_object_impl.h" + /* * _prop_object_init -- @@ -812,7 +812,10 @@ _prop_object_externalize_write_file(const char *fname, const char *xml, size_t len, bool do_compress) { gzFile gzf = NULL; - char tname[PATH_MAX], *otname; + char tname[PATH_MAX]; +#ifndef HAVE_STRLCAT + char *otname; +#endif int fd; int save_errno; mode_t myumask; diff --git a/lib/portableproplib/prop_object_impl.h b/lib/portableproplib/prop_object_impl.h index 6251709f..8be821f5 100644 --- a/lib/portableproplib/prop_object_impl.h +++ b/lib/portableproplib/prop_object_impl.h @@ -430,7 +430,10 @@ void * _prop_standalone_realloc(void *, size_t); #include #define _PROP_ARG_UNUSED __unused #else -#define _PROP_ARG_UNUSED /* delete */ +#ifndef __unused +#define __unused /* delete */ +#endif +#define _PROP_ARG_UNUSED /* delete */ #endif /* __NetBSD__ */ #endif /* _PROPLIB_PROP_OBJECT_IMPL_H_ */ diff --git a/lib/portableproplib/prop_rb_impl.h b/lib/portableproplib/prop_rb_impl.h index ee93451d..ae1df338 100644 --- a/lib/portableproplib/prop_rb_impl.h +++ b/lib/portableproplib/prop_rb_impl.h @@ -32,8 +32,11 @@ #ifndef _PROP_RB_IMPL_H_ #define _PROP_RB_IMPL_H_ -#if 1 +#ifdef __NetBSD__ +#include +#else #include +#endif /* * Define local names for common rb_tree functions. @@ -44,111 +47,4 @@ #define _prop_rb_tree_remove_node rb_tree_remove_node #define _prop_rb_tree_iterate rb_tree_iterate -#else /* __NetBSD__ */ - -#include -#include -#include - -struct rb_node { - struct rb_node *rb_nodes[3]; -#define RB_NODE_LEFT 0 -#define RB_NODE_RIGHT 1 -#define RB_NODE_OTHER 1 -#define RB_NODE_PARENT 2 -#define rb_left rb_nodes[RB_NODE_LEFT] -#define rb_right rb_nodes[RB_NODE_RIGHT] -#define rb_parent rb_nodes[RB_NODE_PARENT] - union { - struct { -#if BYTE_ORDER == LITTLE_ENDIAN - unsigned int : 28; - unsigned int s_root : 1; - unsigned int s_position : 1; - unsigned int s_color : 1; - unsigned int s_sentinel : 1; -#endif -#if BYTE_ORDER == BIG_ENDIAN - unsigned int s_sentinel : 1; - unsigned int s_color : 1; - unsigned int s_position : 1; - unsigned int s_root : 1; - unsigned int : 28; -#endif - } u_s; - unsigned int u_i; - } rb_u; -#define rb_root rb_u.u_s.s_root -#define rb_position rb_u.u_s.s_position -#define rb_color rb_u.u_s.s_color -#define rb_sentinel rb_u.u_s.s_sentinel -#define rb_properties rb_u.u_i -#define RB_SENTINEL_P(rb) ((rb)->rb_sentinel + 0) -#define RB_LEFT_SENTINEL_P(rb) ((rb)->rb_left->rb_sentinel + 0) -#define RB_RIGHT_SENTINEL_P(rb) ((rb)->rb_right->rb_sentinel + 0) -#define RB_PARENT_SENTINEL_P(rb) ((rb)->rb_parent->rb_sentinel + 0) -#define RB_CHILDLESS_P(rb) (RB_LEFT_SENTINEL_P(rb) \ - && RB_RIGHT_SENTINEL_P(rb)) -#define RB_TWOCHILDREN_P(rb) (!RB_LEFT_SENTINEL_P(rb) \ - && !RB_RIGHT_SENTINEL_P(rb)) -#define RB_ROOT_P(rb) ((rb)->rb_root != false) -#define RB_RED_P(rb) ((rb)->rb_color + 0) -#define RB_BLACK_P(rb) (!(rb)->rb_color) -#define RB_MARK_RED(rb) ((void)((rb)->rb_color = 1)) -#define RB_MARK_BLACK(rb) ((void)((rb)->rb_color = 0)) -#define RB_MARK_ROOT(rb) ((void)((rb)->rb_root = 1)) -#ifdef RBDEBUG - TAILQ_ENTRY(rb_node) rb_link; -#endif -}; - -#ifdef RBDEBUG -TAILQ_HEAD(rb_node_qh, rb_node); - -#define RB_TAILQ_REMOVE TAILQ_REMOVE -#define RB_TAILQ_INIT TAILQ_INIT -#define RB_TAILQ_INSERT_HEAD(a, b, c) TAILQ_INSERT_HEAD -#define RB_TAILQ_INSERT_BEFORE(a, b, c) TAILQ_INSERT_BEFORE -#define RB_TAILQ_INSERT_AFTER(a, b, c, d) TAILQ_INSERT_AFTER -#else -#define RB_TAILQ_REMOVE(a, b, c) do { } while (/*CONSTCOND*/0) -#define RB_TAILQ_INIT(a) do { } while (/*CONSTCOND*/0) -#define RB_TAILQ_INSERT_HEAD(a, b, c) do { } while (/*CONSTCOND*/0) -#define RB_TAILQ_INSERT_BEFORE(a, b, c) do { } while (/*CONSTCOND*/0) -#define RB_TAILQ_INSERT_AFTER(a, b, c, d) do { } while (/*CONSTCOND*/0) -#endif - -typedef int (*rb_compare_nodes_fn)(const struct rb_node *, - const struct rb_node *); -typedef int (*rb_compare_key_fn)(const struct rb_node *, const void *); - -struct rb_tree_ops { - rb_compare_nodes_fn rbto_compare_nodes; - rb_compare_key_fn rbto_compare_key; -}; - -struct rb_tree { - struct rb_node *rbt_root; -#ifdef RBDEBUG - struct rb_node_qh rbt_nodes; -#endif - const struct rb_tree_ops *rbt_ops; -#ifdef RBDEBUG - unsigned int rbt_count; -#endif -}; - -void _prop_rb_tree_init(struct rb_tree *, const struct rb_tree_ops *); -bool _prop_rb_tree_insert_node(struct rb_tree *, struct rb_node *); -struct rb_node * - _prop_rb_tree_find(struct rb_tree *, const void *); -void _prop_rb_tree_remove_node(struct rb_tree *, struct rb_node *); -#ifdef RBDEBUG -void _prop_rb_tree_check(const struct rb_tree *, bool); -#endif -struct rb_node * - _prop_rb_tree_iterate(struct rb_tree *, struct rb_node *, unsigned int); - -#endif /* __NetBSD__ */ - #endif /* _PROP_RB_IMPL_H_*/ diff --git a/lib/util.c b/lib/util.c index a7c98470..8f7422a5 100644 --- a/lib/util.c +++ b/lib/util.c @@ -312,3 +312,16 @@ xbps_pkgpattern_match(const char *pkg, const char *pattern) /* no match */ return 0; } + +/* + * Small wrapper for NetBSD's humanize_number(3) with some + * defaults set that we care about. + */ +int +xbps_humanize_number(char *buf, int64_t bytes) +{ + assert(buf != NULL); + + return humanize_number(buf, 7, bytes, "B", + HN_AUTOSCALE, HN_DECIMAL|HN_NOSPACE); +}