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

98
configure vendored
View File

@ -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 <<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().
#
@ -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 <<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
#

View File

@ -3,7 +3,12 @@
#include <sys/types.h>
#include <stdarg.h>
#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 */

View File

@ -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

View File

@ -40,7 +40,6 @@
#define HIDDEN
#endif
#include "compat.h"
#include "queue.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)
# 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

View File

@ -37,16 +37,10 @@
#include <string.h>
#include <locale.h>
#include <xbps_api.h>
#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);
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -29,9 +29,6 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <prop/prop_object.h>
#include "prop_object_impl.h"
#include <sys/mman.h>
#include <sys/stat.h>
#include <errno.h>
@ -40,6 +37,9 @@
#include <unistd.h>
#include <zlib.h>
#include <prop/prop_object.h>
#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;

View File

@ -430,7 +430,10 @@ void * _prop_standalone_realloc(void *, size_t);
#include <sys/cdefs.h>
#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_ */

View File

@ -32,8 +32,11 @@
#ifndef _PROP_RB_IMPL_H_
#define _PROP_RB_IMPL_H_
#if 1
#ifdef __NetBSD__
#include <sys/rbtree.h>
#else
#include <prop/rbtree.h>
#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 <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_*/

View File

@ -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);
}