Properly build shared/static libxbps and utils.

xbps-fetch: added -v flag to see verbose messages in libfetch.

--HG--
extra : convert_revision : xtraeme%40gmail.com-20091030111726-axf9paz2k01ntqzz
This commit is contained in:
Juan RP 2009-10-30 12:17:26 +01:00
parent 79f9f34775
commit 3905c2106c
16 changed files with 145 additions and 66 deletions

View File

@ -4,9 +4,27 @@ SUBDIRS = lib bin
.PHONY: all
all:
for dir in $(SUBDIRS); do \
$(MAKE) -C $$dir; \
done
@echo
@echo "********************************"
@echo "*** Building shared libxbps ***"
@echo "********************************"
@echo
$(MAKE) -C lib
@echo
@echo "********************************"
@echo "*** Building shared binaries ***"
@echo "********************************"
@echo
$(MAKE) -C bin
@echo
@echo "********************************"
@echo "*** Building static binaries ***"
@echo "********************************"
@echo
$(MAKE) -C lib clean
$(MAKE) -C bin clean
$(MAKE) STATIC=1 -C lib
$(MAKE) STATIC=1 -C bin
.PHONY: install
install:

View File

@ -3,7 +3,6 @@ include $(TOPDIR)/vars.mk
BIN = xbps-bin
OBJS = check.o install.o main.o remove.o show-deps.o ../xbps-repo/util.o
STATIC_LIBS += -lz -lacl -lbz2 -llzma
include $(TOPDIR)/prog.mk

View File

@ -164,7 +164,7 @@ download_package_list(prop_object_iterator_t iter)
}
printf("Downloading %s-%s binary package ...\n",
pkgname, version);
rv = xbps_fetch_file(binfile, savedir);
rv = xbps_fetch_file(binfile, savedir, NULL);
free(savedir);
free(binfile);
if (rv != 0) {

View File

@ -1,21 +1,40 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <xbps_api.h>
#include "fetch.h"
static void
usage(void)
{
printf("usage: xbps-fetch [-v] URL\n");
exit(EXIT_FAILURE);
}
int
main(int argc, char **argv)
{
int rv = 0;
char flags[8];
int c, rv = 0;
if (argc != 2) {
printf("Usage: xbps-fetch [options] URL\n");
exit(EXIT_FAILURE);
while ((c = getopt(argc, argv, "v")) != -1) {
switch (c) {
case 'v':
strcat(flags, "v");
break;
default:
usage();
}
}
argc -= optind;
argv += optind;
rv = xbps_fetch_file(argv[1], ".");
if (argc != 1)
usage();
rv = xbps_fetch_file(argv[0], ".", flags);
if (rv != 0) {
printf("xbps-fetch: couldn't download %s!\n", argv[1]);
printf("xbps-fetch: %s\n", xbps_fetch_error_string());
printf("%s: %s\n", argv[0], xbps_fetch_error_string());
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);

View File

@ -3,6 +3,5 @@ include $(TOPDIR)/vars.mk
BIN = xbps-repo
OBJS = main.o util.o index.o
STATIC_LIBS += -lz -lbz2 -lacl -llzma
include $(TOPDIR)/prog.mk

View File

@ -26,16 +26,26 @@ http://code.google.com/p/portableproplib/
I'm also the human maintaining the portable proplib package. I'd suggest you
to install it into /usr/local to avoid issues with your distribution packages.
To build the xbps utils, you'll need:
To build the xbps utils, you'll need for both shared and dynamic:
* asciidoc (to build the manpages)
* libarchive (devel pkg)
* proplib (devel pkg)
* openssl (devel pkg)
If you only want to build the static binaries, you can pass STATIC=1
to the make command. You'll need development packages for the ones
mentioned above as well as the following:
* attr (devel pkg with static lib)
* acl (devel pkg with static lib)
* zlib (devel pkg with static lib)
* bzip2 (devel pkg with static lib)
* xz (devel pkg with static lib)
* libarchive (devel pkg with static lib, all features built in)
* proplib (devel pkg with static lib, see above)
* openssl (devel pkg with static lib)
Please note that when building the static binaries, the static libs
must match the requirements! please make sure that your installed
libarchive has all features built in (acl, zlib, bzip2, xz and openssl).
------------------------------------------------------------------------------
HOW TO USE IT

View File

@ -44,8 +44,8 @@ typedef struct _SHA256_CTX {
uint8_t buffer[SHA256_BLOCK_LENGTH];
} SHA256_CTX;
int SHA256_Init(SHA256_CTX *);
int SHA256_Update(SHA256_CTX *, const uint8_t *, size_t);
char *SHA256_End(SHA256_CTX *, uint8_t *);
int XBPS_SHA256_Init(SHA256_CTX *);
int XBPS_SHA256_Update(SHA256_CTX *, const uint8_t *, size_t);
char *XBPS_SHA256_End(SHA256_CTX *, uint8_t *);
#endif /* !_SHA2_DIGEST_H_ */

View File

@ -82,7 +82,7 @@ int SYMEXPORT xbps_configure_all_pkgs(void);
int SYMEXPORT xbps_cmpver(const char *, const char *);
/* From lib/download.c */
int SYMEXPORT xbps_fetch_file(const char *, const char *);
int SYMEXPORT xbps_fetch_file(const char *, const char *, const char *);
void SYMEXPORT (*xbps_fetch_start_cb)(const char *, off_t *, off_t *);
void SYMEXPORT (*xbps_fetch_update_cb)(off_t *);
void SYMEXPORT (*xbps_fetch_end_cb)(void);

View File

@ -1,27 +1,10 @@
include ../vars.mk
INET6 ?= yes
SSL ?= yes
LIBS = -larchive -lprop
ifdef SSL
CPPFLAGS += -DWITH_SSL
LIBS += -lssl -lcrypto
endif
ifdef INET6
CPPFLAGS += -DINET6
endif
ifdef DEBUG
CPPFLAGS += -DDEBUG
endif
LIBMAJOR = 0
LIBMINOR = 0
LIBMICRO = 0
LIBXBPS_SHLIB = libxbps.so.$(LIBMAJOR).$(LIBMINOR).$(LIBMICRO)
LIBXBPS_LDFLAGS = $(LIBS) -shared -Wl,-soname,libxbps.so.$(LIBMAJOR)
LIBXBPS_LDFLAGS = -shared -Wl,-soname,libxbps.so.$(LIBMAJOR)
# libfetch
OBJS = fetch/common.o fetch/fetch.o fetch/file.o fetch/ftp.o fetch/http.o
@ -32,14 +15,25 @@ OBJS += humanize_number.o orphans.o plist.o purge.o register.o remove.o
OBJS += repository.o requiredby.o sha256.o sortdeps.o state.o
OBJS += sync_remote_pkgidx.o unpack.o util.o
ifdef STATIC
all: libfetch libxbps.a
else
LDFLAGS = -lprop -larchive
ifdef WITH_SSL
LDFLAGS += -lssl -lcrypto
endif
all: libfetch libxbps.so libxbps.a
endif
.PHONY: all
libfetch:
$(MAKE) -C fetch
%.o: %.c
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -c $<
libxbps.so: $(OBJS)
$(CC) $(LIBXBPS_LDFLAGS) $^ -o $(LIBXBPS_SHLIB)
$(CC) $(LDFLAGS) $(LIBXBPS_LDFLAGS) $^ -o $(LIBXBPS_SHLIB)
-ln -sf $(LIBXBPS_SHLIB) libxbps.so.$(LIBMAJOR)
-ln -sf $(LIBXBPS_SHLIB) libxbps.so
@ -50,7 +44,9 @@ libxbps.a: $(OBJS)
.PHONY: install
install: all
install -d $(LIBDIR)
ifdef STATIC
install -m 644 libxbps.a $(LIBDIR)
endif
install -m 644 $(LIBXBPS_SHLIB) $(LIBDIR)
cp -a libxbps.so $(LIBDIR)
cp -a libxbps.so.$(LIBMAJOR) $(LIBDIR)

View File

@ -171,7 +171,7 @@ xbps_fetch_error_string(void)
}
int SYMEXPORT
xbps_fetch_file(const char *uri, const char *outputdir)
xbps_fetch_file(const char *uri, const char *outputdir, const char *flags)
{
struct stat st;
struct xferstat xs;
@ -181,7 +181,7 @@ xbps_fetch_file(const char *uri, const char *outputdir)
struct timeval tv[2];
ssize_t bytes_read, bytes_written;
off_t bytes_dld = -1;
char buf[32768], *filename, *destfile = NULL;
char buf[32768], *filename, *destfile = NULL, fetchflags[8];
int fd = -1, rv = 0;
bool restart = false;
@ -221,7 +221,12 @@ xbps_fetch_file(const char *uri, const char *outputdir)
goto out;
}
if ((rv = fetchStat(url, &url_st, "i")) == -1) {
memset(&fetchflags, 0, sizeof(fetchflags));
if (flags != NULL)
strcat(fetchflags, flags);
strcat(fetchflags, "i");
if ((rv = fetchStat(url, &url_st, fetchflags)) == -1) {
rv = fetchLastErrCode;
goto out;
}
@ -234,7 +239,7 @@ xbps_fetch_file(const char *uri, const char *outputdir)
if (restart)
url->offset = st.st_size;
fio = fetchXGet(url, &url_st, "i");
fio = fetchXGet(url, &url_st, fetchflags);
if (fio == NULL) {
rv = fetchLastErrCode;
goto out;

View File

@ -4,6 +4,22 @@ include $(TOPDIR)/vars.mk
CFLAGS += -Wno-unused-macros -Wno-conversion
CPPFLAGS += -DFTP_COMBINE_CWDS -DNETBSD -I$(TOPDIR)/include
ifdef WITH_INET6
CPPFLAGS += -DINET6
endif
ifdef WITH_SSL
CPPFLAGS += -DWITH_SSL
endif
ifdef WITH_DEBUG
CPPFLAGS += -DDEBUG
endif
ifdef STATIC
CFLAGS += -static
endif
OBJS= fetch.o common.o ftp.o http.o file.o
INCS= common.h
GEN = ftperr.h httperr.h
@ -12,7 +28,7 @@ GEN = ftperr.h httperr.h
all: $(OBJS)
%.o: %.c $(INCS) $(GEN)
$(CC) $(CPPFLAGS) $(CFLAGS) -c $<
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -c $<
ftperr.h: ftp.errors
./errlist.sh ftp_errlist FTP ftp.errors > $@

View File

@ -123,7 +123,7 @@ static const uint32_t sha256_initial_hash_value[8] = {
/*** SHA-256: *********************************************************/
int
SHA256_Init(SHA256_CTX *context)
XBPS_SHA256_Init(SHA256_CTX *context)
{
if (context == NULL)
return 1;
@ -220,7 +220,7 @@ SHA256_Transform(SHA256_CTX *context, const uint32_t *data)
#else /* SHA2_UNROLL_TRANSFORM */
void
static void
SHA256_Transform(SHA256_CTX *context, const uint32_t *data)
{
uint32_t a, b, c, d, e, f, g, h, s0, s1;
@ -298,7 +298,7 @@ SHA256_Transform(SHA256_CTX *context, const uint32_t *data)
#endif /* SHA2_UNROLL_TRANSFORM */
int
SHA256_Update(SHA256_CTX *context, const uint8_t *data, size_t len)
XBPS_SHA256_Update(SHA256_CTX *context, const uint8_t *data, size_t len)
{
unsigned int freespace, usedspace;
@ -441,7 +441,7 @@ SHA256_Final(uint8_t digest[], SHA256_CTX *context)
static const char sha2_hex_digits[] = "0123456789abcdef";
char *
SHA256_End(SHA256_CTX *ctx, uint8_t *buffer)
XBPS_SHA256_End(SHA256_CTX *ctx, uint8_t *buffer)
{
uint8_t digest[SHA256_DIGEST_LENGTH], *d = digest;
uint8_t *ret;

View File

@ -133,7 +133,7 @@ xbps_sync_repository_pkg_index(const char *uri)
free(lrepodir);
return errno;
}
rv = xbps_fetch_file(rpidx, lrepodir);
rv = xbps_fetch_file(rpidx, lrepodir, NULL);
free(rpidx);
free(lrepodir);

View File

@ -53,10 +53,10 @@ xbps_get_file_hash(const char *file)
if ((fd = open(file, O_RDONLY)) == -1)
return NULL;
SHA256_Init(&ctx);
XBPS_SHA256_Init(&ctx);
while ((bytes = read(fd, buf, sizeof(buf))) > 0)
SHA256_Update(&ctx, buf, (size_t)bytes);
hash = strdup(SHA256_End(&ctx, digest));
XBPS_SHA256_Update(&ctx, buf, (size_t)bytes);
hash = strdup(XBPS_SHA256_End(&ctx, digest));
(void)close(fd);
return hash;

23
prog.mk
View File

@ -1,29 +1,35 @@
BIN_STATIC ?= $(BIN).static
OBJS ?= main.o
MAN ?= $(BIN).8
all: $(BIN) $(BIN_STATIC) $(MAN)
ifdef STATIC
all: $(BIN).static
else
LDFLAGS = -lxbps
all: $(BIN) $(MAN)
endif
.PHONY: all
$(MAN):
a2x -f manpage $(MAN).txt
$(BIN_STATIC): $(OBJS)
$(CC) -static $^ $(LDFLAGS) $(STATIC_LIBS) -o $@
$(BIN).static: $(OBJS)
$(CC) $^ -static -lxbps $(LDFLAGS) -o $@
$(BIN): $(OBJS)
$(CC) $^ $(LDFLAGS) -o $@
.PHONY: clean
clean:
-rm -f $(BIN) $(BIN_STATIC) $(MAN)
-rm -f $(BIN) $(MAN)
-rm -f $(BIN).static
-rm -f $(OBJS)
.PHONY: install
install: $(BIN) $(BIN_STATIC) $(MAN)
install: $(BIN) $(MAN)
install -d $(SBINDIR)
install $(INSTALL_STRIPPED) -m 755 $(BIN) $(SBINDIR)
install $(INSTALL_STRIPPED) -m 755 $(BIN_STATIC) $(SBINDIR)
install $(INSTALL_STRIPPED) -m 755 $(BIN).static $(SBINDIR)
ifdef MAN
install -d $(MANDIR)
install -m 644 $(MAN) $(MANDIR)
@ -31,4 +37,5 @@ endif
.PHONY: uninstall
uninstall:
-rm -f $(SBINDIR)/$(BIN) $(SBINDIR)/$(BIN_STATIC)
-rm -f $(SBINDIR)/$(BIN)
-rm -f $(SBINDIR)/$(BIN).static

20
vars.mk
View File

@ -1,5 +1,8 @@
# Common variables.
WITH_INET6 = yes
WITH_SSL = yes
PREFIX ?= /usr/local
SBINDIR ?= $(DESTDIR)$(PREFIX)/sbin
LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
@ -12,12 +15,19 @@ INSTALL_STRIPPED=
DEBUG_FLAGS = -g
endif
STATIC_LIBS ?= -lprop -lpthread -larchive
LDFLAGS += -L$(TOPDIR)/lib -L$(PREFIX)/lib -lxbps
LDFLAGS = -L$(TOPDIR)/lib
CPPFLAGS += -I$(TOPDIR)/include -D_XOPEN_SOURCE=600 -D_GNU_SOURCE
CPPFLAGS += -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGE_FILES
WARNFLAGS ?= -pedantic -std=c99 -Wall -Wextra -Werror -Wshadow -Wformat=2
WARNFLAGS += -Wmissing-declarations -Wcomment -Wunused-macros -Wendif-labels
WARNFLAGS += -Wcast-qual -Wcast-align -Wstack-protector
CFLAGS = $(DEBUG_FLAGS) $(WARNFLAGS) -fstack-protector-all -O2 -fPIC -DPIC
CFLAGS += -fvisibility=hidden
WARNFLAGS += -Wcast-qual -Wcast-align
CFLAGS = $(DEBUG_FLAGS) $(WARNFLAGS)
ifdef STATIC
CFLAGS += -static
LDFLAGS += -lprop -lpthread -larchive -lssl -lcrypto -ldl -lacl \
-lattr -lcrypto -llzma -lbz2 -lz
else
CFLAGS += -fvisibility=hidden -fstack-protector-all -fPIC -DPIC
CPPFLAGS += -Wstack-protector
endif