XBPS can now be built on NetBSD (and probably any other BSD variant).

This commit is contained in:
Juan RP 2012-12-06 12:58:17 +01:00
parent d6a65a5a55
commit 2c1e4e502d
15 changed files with 145 additions and 158 deletions

78
configure vendored
View File

@ -7,6 +7,7 @@ VERSION=0.19
STRLCPY= STRLCPY=
STRLCAT= STRLCAT=
VASPRINTF= VASPRINTF=
HUMANIZE_NUMBER=
LIBFETCH= LIBFETCH=
PROPLIB= PROPLIB=
OS= OS=
@ -414,6 +415,52 @@ fi
echo "$STRLCAT." echo "$STRLCAT."
rm -f _$func.c _$func rm -f _$func.c _$func
#
# Check for humanize_number().
func=humanize_number
printf "Checking for $func() ... "
cat <<EOF > _$func.c
#include <stdio.h>
#include <util.h>
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 <<EOF > _$func.c
#include <sys/rbtree.h>
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(). # Check for libfetch's fetchIO_read().
# #
@ -564,8 +611,8 @@ fi
# #
# libarchive >= 2.8.0 with pkg-config support is required. # libarchive >= 2.8.0 with pkg-config support is required.
# #
printf "Checking for libarchive via pkg-config ... " printf "Checking for libarchive >= 3.0.2 via pkg-config ... "
if ! $PKGCONFIG_BIN --exists libarchive; then if ! $PKGCONFIG_BIN --atleast-version=3.0.2 libarchive; then
echo "libarchive.pc file not found, exiting." echo "libarchive.pc file not found, exiting."
exit 1 exit 1
else else
@ -592,8 +639,10 @@ else
fi fi
# #
# OpenSSL libssl with pkg-config support is required. # OpenSSL libssl with pkg-config support is required when building
# the static binaries.
# #
if [ "$BUILD_STATIC" = "yes" ]; then
printf "Checking for OpenSSL via pkg-config ... " printf "Checking for OpenSSL via pkg-config ... "
if ! $PKGCONFIG_BIN --exists libssl; then if ! $PKGCONFIG_BIN --exists libssl; then
echo "libssl.pc file not found, exiting." echo "libssl.pc file not found, exiting."
@ -605,6 +654,29 @@ else
echo "STATIC_LIBS += $($PKGCONFIG_BIN --libs --static libssl)" \ echo "STATIC_LIBS += $($PKGCONFIG_BIN --libs --static libssl)" \
>>$CONFIG_MK >>$CONFIG_MK
fi fi
else
func=SHA256
printf "Checking for OpenSSL $func() ... "
cat <<EOF > _$func.c
#include <openssl/sha.h>
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
# #
# If --with-static enabled, build static binaries. # If --with-static enabled, build static binaries.

View File

@ -3,7 +3,12 @@
#include <sys/types.h> #include <sys/types.h>
#include <stdarg.h> #include <stdarg.h>
#include "xbps_api_impl.h"
#if HAVE_VISIBILITY
#define HIDDEN __attribute__ ((visibility("hidden")))
#else
#define HIDDEN
#endif
#ifndef HAVE_STRLCAT #ifndef HAVE_STRLCAT
size_t HIDDEN strlcat(char *, const char *, size_t); 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 *); char HIDDEN *strcasestr(const char *, const char *);
#endif #endif
#if defined(HAVE_VASPRINTF) && !defined(_GNU_SOURCE) #if !defined(HAVE_VASPRINTF) && !defined(_GNU_SOURCE)
int HIDDEN vasprintf(char **, const char *, va_list); int HIDDEN vasprintf(char **, const char *, va_list);
#endif #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 */ #endif /* COMPAT_H */

View File

@ -38,11 +38,15 @@
#ifdef __cplusplus #ifdef __cplusplus
# ifndef __BEGIN_DECLS # ifndef __BEGIN_DECLS
# define __BEGIN_DECLS extern "C" { # define __BEGIN_DECLS extern "C" {
# endif
# ifndef __END_DECLS
# define __END_DECLS } # define __END_DECLS }
# endif # endif
#else #else
# ifndef __BEGIN_DECLS # ifndef __BEGIN_DECLS
# define __BEGIN_DECLS # define __BEGIN_DECLS
# endif
# ifndef __END_DECLS
# define __END_DECLS # define __END_DECLS
# endif # endif
#endif #endif

View File

@ -40,7 +40,6 @@
#define HIDDEN #define HIDDEN
#endif #endif
#include "compat.h"
#include "queue.h" #include "queue.h"
#include "fetch.h" #include "fetch.h"

View File

@ -7,9 +7,9 @@ LIBXBPS_SHLIB = libxbps.so.$(LIBXBPS_MAJOR).$(LIBXBPS_MINOR).$(LIBXBPS_MICRO)
LDFLAGS += $(LIBXBPS_LDFLAGS) -shared -Wl,-soname,libxbps.so.$(LIBXBPS_MAJOR) LDFLAGS += $(LIBXBPS_LDFLAGS) -shared -Wl,-soname,libxbps.so.$(LIBXBPS_MAJOR)
# portableproplib # 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_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_stack.o portableproplib/prop_string.o
LIBPROP_OBJS += portableproplib/prop_array_util.o portableproplib/prop_number.o LIBPROP_OBJS += portableproplib/prop_array_util.o portableproplib/prop_number.o
LIBPROP_OBJS += portableproplib/prop_dictionary_util.o portableproplib/prop_zlib.o LIBPROP_OBJS += portableproplib/prop_dictionary_util.o portableproplib/prop_zlib.o
@ -37,8 +37,7 @@ LIBFETCH_OBJS =
endif endif
# External code used by libxbps # External code used by libxbps
EXTOBJS = external/dewey.o external/fexec.o external/humanize_number.o EXTOBJS = external/dewey.o external/fexec.o external/mkpath.o
EXTOBJS += external/mkpath.o
# libxbps # libxbps
OBJS = package_configure.o package_config_files.o package_orphans.o OBJS = package_configure.o package_config_files.o package_orphans.o

View File

@ -37,16 +37,10 @@
#include <string.h> #include <string.h>
#include <locale.h> #include <locale.h>
#include <xbps_api.h> #include "xbps_api_impl.h"
#include "compat.h"
#define HN_DECIMAL 0x01 int HIDDEN
#define HN_NOSPACE 0x02
#define HN_B 0x04
#define HN_DIVISOR_1000 0x08
#define HN_GETSCALE 0x10
#define HN_AUTOSCALE 0x20
static int
humanize_number(char *buf, size_t len, int64_t bytes, humanize_number(char *buf, size_t len, int64_t bytes,
const char *suffix, int scale, int flags) const char *suffix, int scale, int flags)
{ {
@ -148,16 +142,3 @@ humanize_number(char *buf, size_t len, int64_t bytes,
return (r); 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);
}

View File

@ -35,6 +35,9 @@
#include <ctype.h> #include <ctype.h>
#include "xbps_api_impl.h" #include "xbps_api_impl.h"
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#define PKG_PATTERN_MAX 1024 #define PKG_PATTERN_MAX 1024

View File

@ -39,6 +39,8 @@
#include <stdbool.h> #include <stdbool.h>
#include <inttypes.h> #include <inttypes.h>
#endif #endif
#include <sys/types.h>
#include <sys/cdefs.h>
#include <queue.h> #include <queue.h>
#if __GNUC_PREREQ(2, 96) #if __GNUC_PREREQ(2, 96)

View File

@ -34,7 +34,6 @@
#if !defined(_KERNEL) && !defined(_STANDALONE) #if !defined(_KERNEL) && !defined(_STANDALONE)
#include <errno.h> #include <errno.h>
#define __unused /* empty */
#endif #endif
struct _prop_array { struct _prop_array {

View File

@ -37,7 +37,6 @@
#if !defined(_KERNEL) && !defined(_STANDALONE) #if !defined(_KERNEL) && !defined(_STANDALONE)
#include <errno.h> #include <errno.h>
#define __unused /* empty */
#endif #endif
/* /*

View File

@ -41,7 +41,6 @@
#else #else
#include <errno.h> #include <errno.h>
#include <stdlib.h> #include <stdlib.h>
#define __unused /* empty */
#endif #endif
struct _prop_number { struct _prop_number {

View File

@ -29,9 +29,6 @@
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <prop/prop_object.h>
#include "prop_object_impl.h"
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <errno.h> #include <errno.h>
@ -40,6 +37,9 @@
#include <unistd.h> #include <unistd.h>
#include <zlib.h> #include <zlib.h>
#include <prop/prop_object.h>
#include "prop_object_impl.h"
/* /*
* _prop_object_init -- * _prop_object_init --
@ -812,7 +812,10 @@ _prop_object_externalize_write_file(const char *fname, const char *xml,
size_t len, bool do_compress) size_t len, bool do_compress)
{ {
gzFile gzf = NULL; gzFile gzf = NULL;
char tname[PATH_MAX], *otname; char tname[PATH_MAX];
#ifndef HAVE_STRLCAT
char *otname;
#endif
int fd; int fd;
int save_errno; int save_errno;
mode_t myumask; mode_t myumask;

View File

@ -430,6 +430,9 @@ void * _prop_standalone_realloc(void *, size_t);
#include <sys/cdefs.h> #include <sys/cdefs.h>
#define _PROP_ARG_UNUSED __unused #define _PROP_ARG_UNUSED __unused
#else #else
#ifndef __unused
#define __unused /* delete */
#endif
#define _PROP_ARG_UNUSED /* delete */ #define _PROP_ARG_UNUSED /* delete */
#endif /* __NetBSD__ */ #endif /* __NetBSD__ */

View File

@ -32,8 +32,11 @@
#ifndef _PROP_RB_IMPL_H_ #ifndef _PROP_RB_IMPL_H_
#define _PROP_RB_IMPL_H_ #define _PROP_RB_IMPL_H_
#if 1 #ifdef __NetBSD__
#include <sys/rbtree.h>
#else
#include <prop/rbtree.h> #include <prop/rbtree.h>
#endif
/* /*
* Define local names for common rb_tree functions. * 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_remove_node rb_tree_remove_node
#define _prop_rb_tree_iterate rb_tree_iterate #define _prop_rb_tree_iterate rb_tree_iterate
#else /* __NetBSD__ */
#include <sys/types.h>
#include <sys/queue.h>
#include <machine/endian.h>
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_*/ #endif /* _PROP_RB_IMPL_H_*/

View File

@ -312,3 +312,16 @@ xbps_pkgpattern_match(const char *pkg, const char *pattern)
/* no match */ /* no match */
return 0; 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);
}