build and use bundled libfetch natively

cute-signatures
Timo Teräs 2017-10-05 10:57:45 +03:00
parent 9dc6278c7b
commit 86436fce2f
10 changed files with 61 additions and 115 deletions

2
.gitignore vendored
View File

@ -6,6 +6,8 @@ test/repos.out
test/repos.stamp
test/test*.out
test/test*.ok
libfetch/*err.h
*.a
*.o
*.d
*.cmd

View File

@ -65,6 +65,7 @@ export FULL_VERSION RCS_FIND_IGNORE
CROSS_COMPILE ?=
CC := $(CROSS_COMPILE)gcc
AR := $(CROSS_COMPILE)ar
LD := $(CROSS_COMPILE)ld
INSTALL := install
INSTALLDIR := $(INSTALL) -d
@ -76,7 +77,7 @@ CFLAGS_ALL += $(CFLAGS)
LDFLAGS ?= -g
LDFLAGS_ALL += $(LDFLAGS)
export CC LD INSTALL INSTALLDIR CFLAGS_ALL LDFLAGS_ALL
export CC AR LD INSTALL INSTALLDIR CFLAGS_ALL LDFLAGS_ALL
build :=
@ -178,6 +179,10 @@ c_flags = -Wp,-MD,$(depfile) -Wp,-MT,$@ $(CPPFLAGS) \
$(CFLAGS_ALL) $(CFLAGS_EXTRA) $(CFLAGS_$(notdir $@))
ld_flags = $(LDFLAGS_ALL) $(LDFLAGS_EXTRA) $(LDFLAGS_$(notdir $@))
#####
# Generated targets
generate: $(addprefix $(obj)/,$(sort $(generate-y)))
#####
# Compile c-files.
quiet_cmd_cc_o_c = CC $@
@ -193,41 +198,60 @@ endef
$(obj)/%.o: override local-target-prereqs=%
$(obj)/%.o: $(src)/%.c FORCE
$(obj)/%.o: $(src)/%.c FORCE | generate
$(call if_changed_rule,cc_o_c)
#####
# Link static libraries
#
__arlibs := $(addprefix $(obj)/,$(sort $(libs-y)))
arobjs := $(addprefix $(obj)/,$(sort $(foreach m,$(libs-y),$($(m)-objs))))
# link shared library
quiet_cmd_ar = AR $@
cmd_ar = $(AR) rcs $@ $(addprefix $(obj)/,$($(@F)-objs))
$(__arlibs): override local-target-prereqs=$(addprefix $(obj)/,$($(*F)-objs))
$(__arlibs): $(obj)/%: $(arobjs) FORCE
$(call if_changed,ar)
targets += $(__arlibs) $(arobjs)
#####
# Link shared libraries
#
__shlibs := $(addprefix $(obj)/,$(sort $(shlibs-y)))
shobjs := $(addprefix $(obj)/,$(sort $(foreach m,$(shlibs-y),$($(m)-objs))))
shobjs := $(addprefix $(obj)/,$(sort $(foreach m,$(shlibs-y),$($(m)-objs)))) $(sort $(foreach m,$(shlibs-y),$($(m)-libs)))
# link shared library
quiet_cmd_shlib = LD -shared $@
cmd_shlib = $(CC) $(ld_flags) -shared -o $@ \
$(addprefix $(obj)/,$($(@F)-objs)) \
$($(@F)-libs) \
$(LIBS) $(LIBS_$(@F))
$(__shlibs): override local-target-prereqs=$(addprefix $(obj)/,$($(*F)-objs))
$(__shlibs): override local-target-prereqs=$(addprefix $(obj)/,$($(*F)-objs)) $($(*F)-libs)
$(__shlibs): $(obj)/%: $(shobjs) FORCE
$(call if_changed,shlib)
targets += $(__shlibs) $(shobjs)
#####
# Link programs
# Link an executable based on list of .o files, all plain c
# host-cmulti -> executable
__progs := $(addprefix $(obj)/,$(sort $(progs-y)))
cobjs := $(addprefix $(obj)/,$(sort $(foreach m,$(progs-y),$($(m)-objs))))
cobjs := $(addprefix $(obj)/,$(sort $(foreach m,$(progs-y),$($(m)-objs)))) $(sort $(foreach m,$(progs-y),$($(m)-libs)))
quiet_cmd_ld = LD $@
cmd_ld = $(CC) $(ld_flags) -o $@ \
$(addprefix $(obj)/,$($(@F)-objs)) \
$(addprefix $(obj)/,$($(@F)-objs)) $($(@F)-libs) \
$(LIBS) $(LIBS_$(@F))
$(__progs): override local-target-prereqs=$(addprefix $(obj)/,$($(*F)-objs))
$(__progs): override local-target-prereqs=$(addprefix $(obj)/,$($(*F)-objs)) $($(*F)-libs)
$(__progs): $(obj)/%: $(cobjs) FORCE
$(call if_changed,ld)
@ -263,18 +287,24 @@ endif
%/: FORCE
$(Q)$(MAKE) -f Make.rules build=$(build-dir) $(MAKECMDGOALS)
compile: $(targets)
compile: generate $(targets)
@:
install: $(targets) FORCE
generate:
clean: $(filter %/,$(targets))
ifeq ($(toplevelrun),yes)
$(Q)find . $(RCS_FIND_IGNORE) \
\( -name '*.[oas]' -o -name '.*.cmd' -o -name '.*.d' \) \
-type f -print | xargs rm -f
endif
$(Q)rm -rf $(addprefix $(obj)/,$(sort $(progs-y) $(progs-n) $(progs-) $(shlibs-y) $(shlibs-n) $(shlibs-)))
$(Q)rm -rf $(addprefix $(obj)/, \
$(sort $(progs-y) $(progs-n) $(progs-) \
$(shlibs-y) $(shlibs-n) $(shlibs-) \
$(libs-y) $(libs-n) $(libs-) \
$(generate-y) $(generate-n) $(generate-)))
ifeq ($(origin VERSION),command line)
DIST_VERSION=$(VERSION)

View File

@ -21,7 +21,7 @@ export DESTDIR SBINDIR LIBDIR CONFDIR MANDIR DOCDIR
##
# Top-level rules and targets
targets := src/
targets := libfetch/ src/
##
# Include all rules and stuff
@ -41,3 +41,5 @@ check test: FORCE
static:
$(Q)$(MAKE) STATIC=y
src/: libfetch/

View File

@ -1,45 +1,10 @@
# $NetBSD: Makefile,v 1.8 2016/10/27 10:05:38 joerg Exp $
CFLAGS_ALL += -DINET6 -DWITH_SSL -DFTP_COMBINE_CWDS
libs-y += libfetch.a
libfetch.a-objs := common.o fetch.o file.o ftp.o http.o
generate-y += ftperr.h httperr.h
LIB= fetch
SRCS= fetch.c common.c ftp.c http.c file.c
DPSRCS= ftperr.h httperr.h
INCS= fetch.h
MAN= fetch.3
CLEANFILES= ftperr.h httperr.h
MKLINT= no
MKPIC= no
MKPROFILE= no
quiet_cmd_generr = GENERR $@
cmd_generr = $(obj)/errlist.sh $(basename $(<F))_errlist $(shell echo $(basename $(<F)) | tr a-z A-Z) $< > $@
.include <bsd.own.mk>
CPPFLAGS+= -I.
CPPFLAGS+= -D_LARGEFILE_SOURCE -D_LARGE_FILES -D_FILE_OFFSET_BITS=64
FETCH_WITH_INET6?= no
FETCH_WITH_OPENSSL?= no
.if !empty(FETCH_WITH_INET6:M[yY][eE][sS])
CPPFLAGS+= -DINET6
.endif
.if !empty(FETCH_WITH_OPENSSL:M[yY][eE][sS])
CPPFLAGS+= -DWITH_SSL
LDADD= -lssl -lcrypto
.endif
CPPFLAGS+= -DFTP_COMBINE_CWDS
WARNS?= 4
ftp.o: ftperr.h
http.o: httperr.h
ftperr.h: ${.CURDIR}/ftp.errors ${.CURDIR}/Makefile ${.CURDIR}/errlist.sh
sh ${.CURDIR}/errlist.sh ftp_errlist FTP \
${.CURDIR}/ftp.errors > ${.TARGET}
httperr.h: ${.CURDIR}/http.errors ${.CURDIR}/Makefile ${.CURDIR}/errlist.sh
sh ${.CURDIR}/errlist.sh http_errlist HTTP \
${.CURDIR}/http.errors > ${.TARGET}
.include <bsd.lib.mk>
$(obj)/%err.h: $(obj)/%.errors
@$(call echo-cmd,generr) $(cmd_generr); $(cmd_generr)

View File

@ -33,32 +33,19 @@
#if HAVE_CONFIG_H
#include "config.h"
#endif
#ifndef NETBSD
#include <nbcompat.h>
#endif
#include <poll.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/uio.h>
#if HAVE_POLL_H
#include <poll.h>
#elif HAVE_SYS_POLL_H
#include <sys/poll.h>
#endif
#include <netinet/in.h>
#include <arpa/inet.h>
#include <ctype.h>
#include <errno.h>
#if defined(HAVE_INTTYPES_H) || defined(NETBSD)
#include <inttypes.h>
#endif
#ifndef NETBSD
#include <nbcompat/netdb.h>
#else
#include <netdb.h>
#endif
#include <pwd.h>
#include <stdarg.h>
#include <stdlib.h>

View File

@ -33,9 +33,6 @@
#if HAVE_CONFIG_H
#include "config.h"
#endif
#ifndef NETBSD
#include <nbcompat.h>
#endif
#include <ctype.h>
#include <errno.h>

View File

@ -33,9 +33,6 @@
#if HAVE_CONFIG_H
#include "config.h"
#endif
#ifndef NETBSD
#include <nbcompat.h>
#endif
#include <sys/stat.h>

View File

@ -57,17 +57,9 @@
*
*/
#ifdef __linux__
/* Keep this down to Linux, it can create surprises else where. */
#define _GNU_SOURCE
#endif
#if HAVE_CONFIG_H
#include "config.h"
#endif
#ifndef NETBSD
#include <nbcompat.h>
#endif
#include <sys/types.h>
#include <sys/socket.h>
@ -78,17 +70,10 @@
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#if defined(HAVE_INTTYPES_H) || defined(NETBSD)
#include <inttypes.h>
#endif
#include <stdarg.h>
#ifndef NETBSD
#include <nbcompat/netdb.h>
#include <nbcompat/stdio.h>
#else
#include <netdb.h>
#include <stdio.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <time.h>

View File

@ -63,24 +63,12 @@
* SUCH DAMAGE.
*/
#if defined(__linux__) || defined(__MINT__) || defined(__FreeBSD_kernel__)
/* Keep this down to Linux or MiNT, it can create surprises elsewhere. */
/*
__FreeBSD_kernel__ is defined for GNU/kFreeBSD.
See http://glibc-bsd.alioth.debian.org/porting/PORTING .
*/
#define _GNU_SOURCE
#endif
/* Needed for gmtime_r on Interix */
#define _REENTRANT
#if HAVE_CONFIG_H
#include "config.h"
#endif
#ifndef NETBSD
#include <nbcompat.h>
#endif
#include <sys/types.h>
#include <sys/socket.h>
@ -89,11 +77,7 @@
#include <errno.h>
#include <locale.h>
#include <stdarg.h>
#ifndef NETBSD
#include <nbcompat/stdio.h>
#else
#include <stdio.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <time.h>
@ -101,13 +85,7 @@
#include <netinet/in.h>
#include <netinet/tcp.h>
#ifndef NETBSD
#include <nbcompat/netdb.h>
#else
#include <netdb.h>
#endif
#include <arpa/inet.h>
#include "fetch.h"

View File

@ -7,8 +7,6 @@ OPENSSL_LIBS := $(shell $(PKG_CONFIG) --libs openssl)
ZLIB_CFLAGS := $(shell $(PKG_CONFIG) --cflags zlib)
ZLIB_LIBS := $(shell $(PKG_CONFIG) --libs zlib)
FETCH_LIBS := $(shell $(CC) -print-file-name=libfetch.a)
# lua module
ifneq ($(LUAAPK),)
LUA_VERSION ?= 5.2
@ -32,6 +30,7 @@ apk-objs := apk.o add.o del.o fix.o update.o info.o \
libapk.so-objs := common.o database.o package.o archive.o \
version.o io.o url.o gunzip.o blob.o hash.o print.o \
commit.o solver.o
libapk.so-libs := libfetch/libfetch.a
ifeq ($(TEST),y)
progs-y += apk-test
@ -42,6 +41,9 @@ ifeq ($(SHARED_LIBAPK),)
apk-objs += $(libapk.so-objs)
apk-test-objs += $(libapk.so-objs)
apk.so-objs += $(libapk.so-objs)
apk-libs += $(libapk.so-libs)
apk-test-libs += $(libapk.so-libs)
apk.so-libs += $(libapk.so-libs)
else
LIBAPK := YesPlease
LIBS_apk := -lapk
@ -56,13 +58,14 @@ install-LIBAPK-y := $(INSTALLDIR) $(DESTDIR)$(LIBDIR) && \
$(INSTALL) $(LIBAPK-y) $(DESTDIR)$(LIBDIR)
endif
CFLAGS_ALL += -D_ATFILE_SOURCE
CFLAGS_ALL += -D_ATFILE_SOURCE -Ilibfetch
CFLAGS_apk.o := -DAPK_VERSION=\"$(FULL_VERSION)\"
CFLAGS_apk-static.o := -DAPK_VERSION=\"$(FULL_VERSION)\" -DOPENSSL_NO_ENGINE
CFLAGS_apk-test.o := -DAPK_VERSION=\"$(FULL_VERSION)\" -DOPENSSL_NO_ENGINE -DTEST_MODE
progs-$(STATIC) += apk.static
apk.static-objs := $(filter-out apk.o,$(apk-objs)) apk-static.o
apk.static-libs := $(apk-libs)
LDFLAGS_apk.static := -static
LIBS_apk.static := -Wl,--as-needed -ldl -Wl,--no-as-needed
LDFLAGS_apk += -L$(obj)
@ -70,7 +73,7 @@ LDFLAGS_apk-test += -L$(obj)
CFLAGS_ALL += $(OPENSSL_CFLAGS) $(ZLIB_CFLAGS)
LIBS := -Wl,--as-needed \
$(FETCH_LIBS) $(OPENSSL_LIBS) $(ZLIB_LIBS) \
$(OPENSSL_LIBS) $(ZLIB_LIBS) \
-Wl,--no-as-needed
$(obj)/apk: $(LIBAPK-y)