Commit 86436fce authored by Timo Teräs's avatar Timo Teräs

build and use bundled libfetch natively

parent 9dc6278c
...@@ -6,6 +6,8 @@ test/repos.out ...@@ -6,6 +6,8 @@ test/repos.out
test/repos.stamp test/repos.stamp
test/test*.out test/test*.out
test/test*.ok test/test*.ok
libfetch/*err.h
*.a
*.o *.o
*.d *.d
*.cmd *.cmd
......
...@@ -65,6 +65,7 @@ export FULL_VERSION RCS_FIND_IGNORE ...@@ -65,6 +65,7 @@ export FULL_VERSION RCS_FIND_IGNORE
CROSS_COMPILE ?= CROSS_COMPILE ?=
CC := $(CROSS_COMPILE)gcc CC := $(CROSS_COMPILE)gcc
AR := $(CROSS_COMPILE)ar
LD := $(CROSS_COMPILE)ld LD := $(CROSS_COMPILE)ld
INSTALL := install INSTALL := install
INSTALLDIR := $(INSTALL) -d INSTALLDIR := $(INSTALL) -d
...@@ -76,7 +77,7 @@ CFLAGS_ALL += $(CFLAGS) ...@@ -76,7 +77,7 @@ CFLAGS_ALL += $(CFLAGS)
LDFLAGS ?= -g LDFLAGS ?= -g
LDFLAGS_ALL += $(LDFLAGS) LDFLAGS_ALL += $(LDFLAGS)
export CC LD INSTALL INSTALLDIR CFLAGS_ALL LDFLAGS_ALL export CC AR LD INSTALL INSTALLDIR CFLAGS_ALL LDFLAGS_ALL
build := build :=
...@@ -178,6 +179,10 @@ c_flags = -Wp,-MD,$(depfile) -Wp,-MT,$@ $(CPPFLAGS) \ ...@@ -178,6 +179,10 @@ c_flags = -Wp,-MD,$(depfile) -Wp,-MT,$@ $(CPPFLAGS) \
$(CFLAGS_ALL) $(CFLAGS_EXTRA) $(CFLAGS_$(notdir $@)) $(CFLAGS_ALL) $(CFLAGS_EXTRA) $(CFLAGS_$(notdir $@))
ld_flags = $(LDFLAGS_ALL) $(LDFLAGS_EXTRA) $(LDFLAGS_$(notdir $@)) ld_flags = $(LDFLAGS_ALL) $(LDFLAGS_EXTRA) $(LDFLAGS_$(notdir $@))
#####
# Generated targets
generate: $(addprefix $(obj)/,$(sort $(generate-y)))
##### #####
# Compile c-files. # Compile c-files.
quiet_cmd_cc_o_c = CC $@ quiet_cmd_cc_o_c = CC $@
...@@ -193,41 +198,60 @@ endef ...@@ -193,41 +198,60 @@ endef
$(obj)/%.o: override local-target-prereqs=% $(obj)/%.o: override local-target-prereqs=%
$(obj)/%.o: $(src)/%.c FORCE $(obj)/%.o: $(src)/%.c FORCE | generate
$(call if_changed_rule,cc_o_c) $(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 # Link shared libraries
# #
__shlibs := $(addprefix $(obj)/,$(sort $(shlibs-y))) __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 # link shared library
quiet_cmd_shlib = LD -shared $@ quiet_cmd_shlib = LD -shared $@
cmd_shlib = $(CC) $(ld_flags) -shared -o $@ \ cmd_shlib = $(CC) $(ld_flags) -shared -o $@ \
$(addprefix $(obj)/,$($(@F)-objs)) \ $(addprefix $(obj)/,$($(@F)-objs)) \
$($(@F)-libs) \
$(LIBS) $(LIBS_$(@F)) $(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 $(__shlibs): $(obj)/%: $(shobjs) FORCE
$(call if_changed,shlib) $(call if_changed,shlib)
targets += $(__shlibs) $(shobjs) targets += $(__shlibs) $(shobjs)
##### #####
# Link programs # Link programs
# Link an executable based on list of .o files, all plain c # Link an executable based on list of .o files, all plain c
# host-cmulti -> executable # host-cmulti -> executable
__progs := $(addprefix $(obj)/,$(sort $(progs-y))) __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 $@ quiet_cmd_ld = LD $@
cmd_ld = $(CC) $(ld_flags) -o $@ \ cmd_ld = $(CC) $(ld_flags) -o $@ \
$(addprefix $(obj)/,$($(@F)-objs)) \ $(addprefix $(obj)/,$($(@F)-objs)) $($(@F)-libs) \
$(LIBS) $(LIBS_$(@F)) $(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 $(__progs): $(obj)/%: $(cobjs) FORCE
$(call if_changed,ld) $(call if_changed,ld)
...@@ -263,18 +287,24 @@ endif ...@@ -263,18 +287,24 @@ endif
%/: FORCE %/: FORCE
$(Q)$(MAKE) -f Make.rules build=$(build-dir) $(MAKECMDGOALS) $(Q)$(MAKE) -f Make.rules build=$(build-dir) $(MAKECMDGOALS)
compile: $(targets) compile: generate $(targets)
@: @:
install: $(targets) FORCE install: $(targets) FORCE
generate:
clean: $(filter %/,$(targets)) clean: $(filter %/,$(targets))
ifeq ($(toplevelrun),yes) ifeq ($(toplevelrun),yes)
$(Q)find . $(RCS_FIND_IGNORE) \ $(Q)find . $(RCS_FIND_IGNORE) \
\( -name '*.[oas]' -o -name '.*.cmd' -o -name '.*.d' \) \ \( -name '*.[oas]' -o -name '.*.cmd' -o -name '.*.d' \) \
-type f -print | xargs rm -f -type f -print | xargs rm -f
endif 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) ifeq ($(origin VERSION),command line)
DIST_VERSION=$(VERSION) DIST_VERSION=$(VERSION)
......
...@@ -21,7 +21,7 @@ export DESTDIR SBINDIR LIBDIR CONFDIR MANDIR DOCDIR ...@@ -21,7 +21,7 @@ export DESTDIR SBINDIR LIBDIR CONFDIR MANDIR DOCDIR
## ##
# Top-level rules and targets # Top-level rules and targets
targets := src/ targets := libfetch/ src/
## ##
# Include all rules and stuff # Include all rules and stuff
...@@ -41,3 +41,5 @@ check test: FORCE ...@@ -41,3 +41,5 @@ check test: FORCE
static: static:
$(Q)$(MAKE) STATIC=y $(Q)$(MAKE) STATIC=y
src/: libfetch/
# $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 quiet_cmd_generr = GENERR $@
SRCS= fetch.c common.c ftp.c http.c file.c cmd_generr = $(obj)/errlist.sh $(basename $(<F))_errlist $(shell echo $(basename $(<F)) | tr a-z A-Z) $< > $@
DPSRCS= ftperr.h httperr.h
INCS= fetch.h
MAN= fetch.3
CLEANFILES= ftperr.h httperr.h
MKLINT= no
MKPIC= no
MKPROFILE= no
.include <bsd.own.mk> $(obj)/%err.h: $(obj)/%.errors
@$(call echo-cmd,generr) $(cmd_generr); $(cmd_generr)
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>
...@@ -33,32 +33,19 @@ ...@@ -33,32 +33,19 @@
#if HAVE_CONFIG_H #if HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
#ifndef NETBSD
#include <nbcompat.h>
#endif
#include <poll.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/uio.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 <netinet/in.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
#if defined(HAVE_INTTYPES_H) || defined(NETBSD)
#include <inttypes.h> #include <inttypes.h>
#endif
#ifndef NETBSD
#include <nbcompat/netdb.h>
#else
#include <netdb.h> #include <netdb.h>
#endif
#include <pwd.h> #include <pwd.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdlib.h> #include <stdlib.h>
......
...@@ -33,9 +33,6 @@ ...@@ -33,9 +33,6 @@
#if HAVE_CONFIG_H #if HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
#ifndef NETBSD
#include <nbcompat.h>
#endif
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
......
...@@ -33,9 +33,6 @@ ...@@ -33,9 +33,6 @@
#if HAVE_CONFIG_H #if HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
#ifndef NETBSD
#include <nbcompat.h>
#endif
#include <sys/stat.h> #include <sys/stat.h>
......
...@@ -57,17 +57,9 @@ ...@@ -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 #if HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
#ifndef NETBSD
#include <nbcompat.h>
#endif
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
...@@ -78,17 +70,10 @@ ...@@ -78,17 +70,10 @@
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#if defined(HAVE_INTTYPES_H) || defined(NETBSD)
#include <inttypes.h> #include <inttypes.h>
#endif
#include <stdarg.h> #include <stdarg.h>
#ifndef NETBSD
#include <nbcompat/netdb.h>
#include <nbcompat/stdio.h>
#else
#include <netdb.h> #include <netdb.h>
#include <stdio.h> #include <stdio.h>
#endif
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
......
...@@ -63,24 +63,12 @@ ...@@ -63,24 +63,12 @@
* SUCH DAMAGE. * 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 */ /* Needed for gmtime_r on Interix */
#define _REENTRANT #define _REENTRANT
#if HAVE_CONFIG_H #if HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
#ifndef NETBSD
#include <nbcompat.h>
#endif
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
...@@ -89,11 +77,7 @@ ...@@ -89,11 +77,7 @@
#include <errno.h> #include <errno.h>
#include <locale.h> #include <locale.h>
#include <stdarg.h> #include <stdarg.h>
#ifndef NETBSD
#include <nbcompat/stdio.h>
#else
#include <stdio.h> #include <stdio.h>
#endif
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
...@@ -101,13 +85,7 @@ ...@@ -101,13 +85,7 @@
#include <netinet/in.h> #include <netinet/in.h>
#include <netinet/tcp.h> #include <netinet/tcp.h>
#ifndef NETBSD
#include <nbcompat/netdb.h>
#else
#include <netdb.h> #include <netdb.h>
#endif
#include <arpa/inet.h> #include <arpa/inet.h>
#include "fetch.h" #include "fetch.h"
......
...@@ -7,8 +7,6 @@ OPENSSL_LIBS := $(shell $(PKG_CONFIG) --libs openssl) ...@@ -7,8 +7,6 @@ OPENSSL_LIBS := $(shell $(PKG_CONFIG) --libs openssl)
ZLIB_CFLAGS := $(shell $(PKG_CONFIG) --cflags zlib) ZLIB_CFLAGS := $(shell $(PKG_CONFIG) --cflags zlib)
ZLIB_LIBS := $(shell $(PKG_CONFIG) --libs zlib) ZLIB_LIBS := $(shell $(PKG_CONFIG) --libs zlib)
FETCH_LIBS := $(shell $(CC) -print-file-name=libfetch.a)
# lua module # lua module
ifneq ($(LUAAPK),) ifneq ($(LUAAPK),)
LUA_VERSION ?= 5.2 LUA_VERSION ?= 5.2
...@@ -32,6 +30,7 @@ apk-objs := apk.o add.o del.o fix.o update.o info.o \ ...@@ -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 \ 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 \ version.o io.o url.o gunzip.o blob.o hash.o print.o \
commit.o solver.o commit.o solver.o
libapk.so-libs := libfetch/libfetch.a
ifeq ($(TEST),y) ifeq ($(TEST),y)
progs-y += apk-test progs-y += apk-test
...@@ -42,6 +41,9 @@ ifeq ($(SHARED_LIBAPK),) ...@@ -42,6 +41,9 @@ ifeq ($(SHARED_LIBAPK),)
apk-objs += $(libapk.so-objs) apk-objs += $(libapk.so-objs)
apk-test-objs += $(libapk.so-objs) apk-test-objs += $(libapk.so-objs)
apk.so-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 else
LIBAPK := YesPlease LIBAPK := YesPlease
LIBS_apk := -lapk LIBS_apk := -lapk
...@@ -56,13 +58,14 @@ install-LIBAPK-y := $(INSTALLDIR) $(DESTDIR)$(LIBDIR) && \ ...@@ -56,13 +58,14 @@ install-LIBAPK-y := $(INSTALLDIR) $(DESTDIR)$(LIBDIR) && \
$(INSTALL) $(LIBAPK-y) $(DESTDIR)$(LIBDIR) $(INSTALL) $(LIBAPK-y) $(DESTDIR)$(LIBDIR)
endif endif
CFLAGS_ALL += -D_ATFILE_SOURCE CFLAGS_ALL += -D_ATFILE_SOURCE -Ilibfetch
CFLAGS_apk.o := -DAPK_VERSION=\"$(FULL_VERSION)\" CFLAGS_apk.o := -DAPK_VERSION=\"$(FULL_VERSION)\"
CFLAGS_apk-static.o := -DAPK_VERSION=\"$(FULL_VERSION)\" -DOPENSSL_NO_ENGINE CFLAGS_apk-static.o := -DAPK_VERSION=\"$(FULL_VERSION)\" -DOPENSSL_NO_ENGINE
CFLAGS_apk-test.o := -DAPK_VERSION=\"$(FULL_VERSION)\" -DOPENSSL_NO_ENGINE -DTEST_MODE CFLAGS_apk-test.o := -DAPK_VERSION=\"$(FULL_VERSION)\" -DOPENSSL_NO_ENGINE -DTEST_MODE
progs-$(STATIC) += apk.static progs-$(STATIC) += apk.static
apk.static-objs := $(filter-out apk.o,$(apk-objs)) apk-static.o apk.static-objs := $(filter-out apk.o,$(apk-objs)) apk-static.o
apk.static-libs := $(apk-libs)
LDFLAGS_apk.static := -static LDFLAGS_apk.static := -static
LIBS_apk.static := -Wl,--as-needed -ldl -Wl,--no-as-needed LIBS_apk.static := -Wl,--as-needed -ldl -Wl,--no-as-needed
LDFLAGS_apk += -L$(obj) LDFLAGS_apk += -L$(obj)
...@@ -70,7 +73,7 @@ LDFLAGS_apk-test += -L$(obj) ...@@ -70,7 +73,7 @@ LDFLAGS_apk-test += -L$(obj)
CFLAGS_ALL += $(OPENSSL_CFLAGS) $(ZLIB_CFLAGS) CFLAGS_ALL += $(OPENSSL_CFLAGS) $(ZLIB_CFLAGS)
LIBS := -Wl,--as-needed \ LIBS := -Wl,--as-needed \
$(FETCH_LIBS) $(OPENSSL_LIBS) $(ZLIB_LIBS) \ $(OPENSSL_LIBS) $(ZLIB_LIBS) \
-Wl,--no-as-needed -Wl,--no-as-needed
$(obj)/apk: $(LIBAPK-y) $(obj)/apk: $(LIBAPK-y)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment