aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRasmus Thomsen <oss@cogitri.dev>2020-03-16 15:25:02 +0200
committerTimo Teräs <timo.teras@iki.fi>2020-03-16 15:36:46 +0200
commit4966bc5edec37adcf4a9da692e57f38e02bac9fe (patch)
tree4e7ea811fbe4db259e7df8fca4120d2f3b374cc9
parent8b2efdd272862ae41d3e3aa2828f4d2c49e60abd (diff)
downloadaports-4966bc5edec37adcf4a9da692e57f38e02bac9fe.tar.bz2
aports-4966bc5edec37adcf4a9da692e57f38e02bac9fe.tar.xz
build: enable building of development package
- always create .so and .a with the apk libary code - create .pc file - install headers and above mentioned files Maintainers edit: merged commits, cleaned up sed script logic, and few other minor fixes.
-rw-r--r--.gitignore3
-rw-r--r--Make.rules32
-rw-r--r--Makefile10
-rw-r--r--src/Makefile106
4 files changed, 102 insertions, 49 deletions
diff --git a/.gitignore b/.gitignore
index 20d053e08b..7245856910 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,7 +11,8 @@ libfetch/*err.h
*.o
*.d
*.cmd
-*.so
+*.so*
*.5
*.8
+*.pc
config.mk
diff --git a/Make.rules b/Make.rules
index 09b78311f1..b07cf98514 100644
--- a/Make.rules
+++ b/Make.rules
@@ -69,7 +69,9 @@ CROSS_COMPILE ?=
CC := $(CROSS_COMPILE)gcc
AR := $(CROSS_COMPILE)ar
LD := $(CROSS_COMPILE)ld
+LN := ln -sf
SCDOC := scdoc
+SED := sed
INSTALL := install
INSTALLDIR := $(INSTALL) -d
@@ -80,7 +82,7 @@ CFLAGS_ALL += $(CFLAGS)
LDFLAGS ?= -g
LDFLAGS_ALL += $(LDFLAGS)
-export CC AR LD SCDOC INSTALL INSTALLDIR CFLAGS_ALL LDFLAGS_ALL
+export CC AR LD LN SCDOC SED INSTALL INSTALLDIR CFLAGS_ALL LDFLAGS_ALL
build :=
@@ -94,8 +96,8 @@ endif
ifneq ($(origin targets),file)
targets :=
endif
-ifneq ($(origin docs),file)
-docs :=
+ifneq ($(origin nontargets),file)
+nontargets :=
endif
src :=
@@ -274,11 +276,29 @@ quiet_cmd_scdoc = SCDOC $@
cmd_scdoc = $(SCDOC) < $< > $@
__scdocs := $(addprefix $(obj)/,$(sort $(scdocs-y)))
+nontargets += $(__scdocs)
docs += $(__scdocs)
$(__scdocs): $(obj)/%: $(src)/%.scd FORCE
$(call if_changed,scdoc)
+####
+# Template (.in) files
+
+quiet_cmd_sed = SED $@
+ cmd_sed = $(SED) \
+ -e "s|@EXEC_DIR@|$(SBINDIR)|" \
+ -e "s|@LIB_DIR@|$(LIBDIR)|" \
+ -e "s|@INCLUDE_DIR@|$(INCLUDEDIR)|" \
+ -e "s|@VERSION@|$(VERSION)|" \
+ $< > $@
+
+$(obj)/%: $(src)/%.in FORCE
+ $(call if_changed,sed)
+
+
+nontargets += $(addprefix $(obj)/,$(sort $(generate-y)))
+
###
# why - tell why a a target got build
ifeq ($(VERBOSE),2)
@@ -288,9 +308,9 @@ why = \
$(if $(strip $(any-prereq)),- due to: $(any-prereq), \
$(if $(arg-check), \
$(if $(cmd_$@),- due to command line change: $(arg-check), \
- $(if $(filter $@, $(targets) $(docs)), \
+ $(if $(filter $@, $(targets) $(nontargets)), \
- due to missing .cmd file, \
- - due to $(notdir $@) not in $$(targets) or $$(docs) \
+ - due to $(notdir $@) not in $$(targets) or $$(nontargets) \
) \
) \
) \
@@ -351,7 +371,7 @@ FORCE:
targets := $(wildcard $(sort $(targets)))
docs := $(wildcard $(sort $(docs)))
-cmd_files := $(wildcard $(foreach f,$(targets) $(docs),$(dir $(f)).$(notdir $(f)).cmd))
+cmd_files := $(wildcard $(foreach f,$(targets) $(nontargets),$(dir $(f)).$(notdir $(f)).cmd))
ifneq ($(cmd_files),)
include $(cmd_files)
diff --git a/Makefile b/Makefile
index e7cc0aa764..6ea5bc8330 100644
--- a/Makefile
+++ b/Makefile
@@ -6,6 +6,8 @@
PACKAGE := apk-tools
VERSION := 2.10.4
+export VERSION
+
##
# Default directories
@@ -15,8 +17,10 @@ LIBDIR := /lib
CONFDIR := /etc/apk
MANDIR := /usr/share/man
DOCDIR := /usr/share/doc/apk
+INCLUDEDIR := /usr/include/apk
+PKGCONFIGDIR := /usr/lib/pkgconfig
-export DESTDIR SBINDIR LIBDIR CONFDIR MANDIR DOCDIR
+export DESTDIR SBINDIR LIBDIR CONFDIR MANDIR DOCDIR INCLUDEDIR PKGCONFIGDIR
##
# Top-level subdirs
@@ -33,9 +37,9 @@ include Make.rules
install:
$(INSTALLDIR) $(DESTDIR)$(DOCDIR)
- $(INSTALL) README $(DESTDIR)$(DOCDIR)
+ $(INSTALL) README.md $(DESTDIR)$(DOCDIR)
-check test: FORCE
+check test: FORCE src/
$(Q)$(MAKE) TEST=y
$(Q)$(MAKE) -C test
diff --git a/src/Makefile b/src/Makefile
index 16b9f4c84b..6bf2ed023a 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -7,21 +7,50 @@ OPENSSL_LIBS := $(shell $(PKG_CONFIG) --libs openssl)
ZLIB_CFLAGS := $(shell $(PKG_CONFIG) --cflags zlib)
ZLIB_LIBS := $(shell $(PKG_CONFIG) --libs zlib)
-# lua module
+# Dynamic library
+libapk.so.$(VERSION)-objs := \
+ common.o database.o package.o commit.o solver.o \
+ version.o blob.o hash.o print.o \
+ io.o io_url.o io_gunzip.o io_archive.o
+
+libapk.so.$(VERSION)-libs := libfetch/libfetch.a
+
+libapk_soname := $(VERSION)
+shlibs-y += libapk.so.$(VERSION)
+LDFLAGS_libapk.so.$(VERSION) += -Wl,-soname,libapk.so.$(libapk_soname)
+
+libapk_so := $(obj)/libapk.so.$(VERSION)
+install-libapk_so := $(INSTALLDIR) $(DESTDIR)$(LIBDIR) && \
+ $(INSTALL) $(libapk_so) $(DESTDIR)$(LIBDIR)/libapk.so.$(VERSION) && \
+ $(INSTALL) $(obj)/libapk.so.$(libapk_soname) $(DESTDIR)$(LIBDIR) && \
+ $(INSTALL) $(obj)/libapk.so $(DESTDIR)$(LIBDIR)
+
+# Static library
+libapk.a-objs := $(libapk.so.$(VERSION)-objs)
+libapk.a-libs := $(libapk.so.$(VERSION)-libs)
+
+libs-y += libapk.a
+libapk_a := $(obj)/libapk.a
+
+install-libapk_a := $(INSTALLDIR) $(DESTDIR)$(LIBDIR) && \
+ $(INSTALL) $(libapk_a) $(DESTDIR)$(LIBDIR)
+apk-static-libs := $(libapk.a-libs) $(obj)/libapk.a
+
+# Lua module
ifneq ($(LUAAPK),)
LUA_VERSION ?= 5.3
LUA_PC ?= lua$(LUA_VERSION)
LUA_LIBDIR ?= /usr/lib/lua/$(LUA_VERSION)
-LIBAPK := YesPlease
shlibs-y += apk.so
apk.so-objs := lua-apk.o
CFLAGS_lua-apk.o := -DAPK_VERSION=\"$(FULL_VERSION)\" \
$(shell $(PKG_CONFIG) $(LUA_PC) --cflags)
-LUA_LIB-y := $(obj)/apk.so
-install-LUA_LIB-y := $(INSTALLDIR) $(DESTDIR)$(LUA_LIBDIR) && \
- $(INSTALL) $(LUA_LIB-y) $(DESTDIR)$(LUA_LIBDIR)
+apklua_so := $(obj)/apk.so
+install-apklua_so := $(INSTALLDIR) $(DESTDIR)$(LUA_LIBDIR) && \
+ $(INSTALL) $(apklua_so) $(DESTDIR)$(LUA_LIBDIR)
endif
+# Apk utility
progs-y += apk
apk-objs := apk.o \
app_add.o app_del.o app_fix.o app_update.o app_upgrade.o \
@@ -31,37 +60,9 @@ apk-objs := apk.o \
app_index.o app_fetch.o app_verify.o app_dot.o \
app_audit.o
-libapk.so-objs := common.o database.o package.o commit.o solver.o \
- version.o blob.o hash.o print.o \
- io.o io_url.o io_gunzip.o io_archive.o
-
-libapk.so-libs := libfetch/libfetch.a
-
-ifeq ($(TEST),y)
-progs-y += apk-test
-apk-test-objs := apk-test.o $(filter-out apk.o, $(apk-objs))
-endif
-
-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
LIBS_apk-test := -lapk
LIBS_apk.so := -L$(obj) -lapk
-endif
-
-ifneq ($(SHARED_LIBAPK),)
-shlibs-y += libapk.so
-LIBAPK-y := $(obj)/libapk.so
-install-LIBAPK-y := $(INSTALLDIR) $(DESTDIR)$(LIBDIR) && \
- $(INSTALL) $(LIBAPK-y) $(DESTDIR)$(LIBDIR)
-endif
CFLAGS_ALL += -D_ATFILE_SOURCE -Ilibfetch
CFLAGS_apk.o := -DAPK_VERSION=\"$(FULL_VERSION)\"
@@ -70,7 +71,7 @@ CFLAGS_apk-test.o := -DAPK_VERSION=\"$(FULL_VERSION)\" -DOPENSSL_NO_ENGINE -DTES
progs-$(STATIC) += apk.static
apk.static-objs := $(filter-out apk.o,$(apk-objs)) apk-static.o
-apk.static-libs := $(apk-libs)
+apk.static-libs := $(apk-static-libs)
LDFLAGS_apk.static := -static
LIBS_apk.static := -Wl,--as-needed -ldl -Wl,--no-as-needed
LDFLAGS_apk += -L$(obj)
@@ -81,13 +82,40 @@ LIBS := -Wl,--as-needed \
$(OPENSSL_LIBS) $(ZLIB_LIBS) \
-Wl,--no-as-needed
-$(obj)/apk: $(LIBAPK-y)
+# Test build
+ifeq ($(TEST),y)
+progs-y += apk-test
+apk-test-objs := apk-test.o $(filter-out apk.o, $(apk-objs))
+endif
+
+$(obj)/apk: $(libapk_so)
+
+$(obj)/apk-test: $(libapk_so)
+
+$(obj)/apk.so: $(libapk_so)
+
+ifneq ($(libapk_soname), $(VERSION))
+generate-y += libapk.so.$(libapk_soname)
+
+$(obj)/libapk.so.$(libapk_soname):
+ $(LN) libapk.so.$(VERSION) $(obj)/libapk.so.$(libapk_soname)
+endif
+
+generate-y += libapk.so
+
+$(obj)/libapk.so:
+ $(LN) libapk.so.$(libapk_soname) $(obj)/libapk.so
-$(obj)/apk.so: $(LIBAPK-y)
+generate-y += apk.pc
-install: $(obj)/apk $(LIBAPK-y) $(LUA_LIB-y)
+install: $(obj)/apk $(libapk_so) $(libapk_a) $(apklua_so)
$(INSTALLDIR) $(DESTDIR)$(SBINDIR)
$(INSTALL) $(obj)/apk $(DESTDIR)$(SBINDIR)
- $(install-LIBAPK-y)
- $(install-LUA_LIB-y)
+ $(install-libapk_so)
+ $(install-libapk_a)
+ $(install-apklua_so)
+ $(INSTALLDIR) $(DESTDIR)$(INCLUDEDIR)
+ $(INSTALL) -m644 src/*.h $(DESTDIR)$(INCLUDEDIR)
+ $(INSTALLDIR) $(DESTDIR)$(PKGCONFIGDIR)
+ $(INSTALL) -m644 $(obj)/apk.pc $(DESTDIR)$(PKGCONFIGDIR)