diff --git a/.gitignore b/.gitignore index 4370544..ca391f4 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,8 @@ test/repos.out test/repos.stamp test/test*.out test/test*.ok +libfetch/*err.h +*.a *.o *.d *.cmd diff --git a/Make.rules b/Make.rules index 6457d6f..7f33e0a 100644 --- a/Make.rules +++ b/Make.rules @@ -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)) \ + $(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) diff --git a/Makefile b/Makefile index 52c2c00..e8892fd 100644 --- a/Makefile +++ b/Makefile @@ -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/ diff --git a/libfetch/Makefile b/libfetch/Makefile index cfcef4b..6b183cb 100644 --- a/libfetch/Makefile +++ b/libfetch/Makefile @@ -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 $( $@ -.include - -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 +$(obj)/%err.h: $(obj)/%.errors + @$(call echo-cmd,generr) $(cmd_generr); $(cmd_generr) diff --git a/libfetch/common.c b/libfetch/common.c index c1e1587..1fbd0d4 100644 --- a/libfetch/common.c +++ b/libfetch/common.c @@ -33,32 +33,19 @@ #if HAVE_CONFIG_H #include "config.h" #endif -#ifndef NETBSD -#include -#endif +#include #include #include #include #include -#if HAVE_POLL_H -#include -#elif HAVE_SYS_POLL_H -#include -#endif #include #include #include #include -#if defined(HAVE_INTTYPES_H) || defined(NETBSD) #include -#endif -#ifndef NETBSD -#include -#else #include -#endif #include #include #include diff --git a/libfetch/fetch.c b/libfetch/fetch.c index c287097..78cec71 100644 --- a/libfetch/fetch.c +++ b/libfetch/fetch.c @@ -33,9 +33,6 @@ #if HAVE_CONFIG_H #include "config.h" #endif -#ifndef NETBSD -#include -#endif #include #include diff --git a/libfetch/file.c b/libfetch/file.c index b092fdf..a18d94c 100644 --- a/libfetch/file.c +++ b/libfetch/file.c @@ -33,9 +33,6 @@ #if HAVE_CONFIG_H #include "config.h" #endif -#ifndef NETBSD -#include -#endif #include diff --git a/libfetch/ftp.c b/libfetch/ftp.c index 79dcbbc..af6a964 100644 --- a/libfetch/ftp.c +++ b/libfetch/ftp.c @@ -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 -#endif #include #include @@ -78,17 +70,10 @@ #include #include #include -#if defined(HAVE_INTTYPES_H) || defined(NETBSD) #include -#endif #include -#ifndef NETBSD -#include -#include -#else #include #include -#endif #include #include #include diff --git a/libfetch/http.c b/libfetch/http.c index d0882e2..6cf5aac 100644 --- a/libfetch/http.c +++ b/libfetch/http.c @@ -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 -#endif #include #include @@ -89,11 +77,7 @@ #include #include #include -#ifndef NETBSD -#include -#else #include -#endif #include #include #include @@ -101,13 +85,7 @@ #include #include - -#ifndef NETBSD -#include -#else #include -#endif - #include #include "fetch.h" diff --git a/src/Makefile b/src/Makefile index 5fe2bc8..c891bca 100644 --- a/src/Makefile +++ b/src/Makefile @@ -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)