aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2025-04-25 03:42:40 +0000
committerLaurent Bercot <ska@appnovation.com>2025-04-25 03:42:40 +0000
commit7cada88937b8f7edead691a462d3339834674ec9 (patch)
tree0d9934aff03081ed35949a3e0bbabcf324d49705 /Makefile
parent15583497da174dd17b7b44701dcb000f46c235ed (diff)
downloadexecline-7cada88937b8f7edead691a462d3339834674ec9.tar.gz
First version of pkg-config support
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile58
1 files changed, 37 insertions, 21 deletions
diff --git a/Makefile b/Makefile
index c9f20d3..38a14f9 100644
--- a/Makefile
+++ b/Makefile
@@ -12,34 +12,51 @@ ifeq "" "$(strip $(filter $(make_need), $(firstword $(sort $(make_need) $(MAKE_V
fail := $(error Your make ($(MAKE_VERSION)) is too old. You need $(make_need) or newer)
endif
+uniq = $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1)))
+
CC = $(error Please use ./configure first)
STATIC_LIBS :=
SHARED_LIBS :=
INTERNAL_LIBS :=
EXTRA_TARGETS :=
+PC_TARGETS :=
LIB_DEFS :=
BIN_SYMLINKS :=
-PC_DEFS :=
define library_definition
-name := $(lastword $(subst =, ,$(1)))
-LIB$(firstword $(subst =, ,$(1))) := lib$(lastword $(subst =, ,$(1))).$(if $(DO_ALLSTATIC),a,so).xyzzy
+LIB$(1) := lib$(2).$(if $(DO_ALLSTATIC),a,so).xyzzy
ifdef DO_SHARED
-SHARED_LIBS += lib$(lastword $(subst =, ,$(1))).so.xyzzy
+SHARED_LIBS += lib$(2).so.xyzzy
endif
ifdef DO_STATIC
-STATIC_LIBS += lib$(lastword $(subst =, ,$(1))).a.xyzzy
+STATIC_LIBS += lib$(2).a.xyzzy
+endif
+ifdef DO_PKGCONFIG
+PC_TARGETS += lib$(2).pc
endif
-PC_DEFS += $(lastword $(subst =, ,$(1)))
-$(lastword $(subst =, ,$(1))).pc: $(if $(DO_SHARED),lib$(lastword $(subst =, ,$(1))).so.xyzzy,) $(if $(DO_STATIC),lib$(lastword $(subst =, ,$(1))).a.xyzzy,)
- ./tools/gen-dotpc.sh $(lastword $(subst =, ,$(1))) $(if $(DO_SHARED),true,false) $(if $(DO_STATIC),true,false) "$$($(lastword $(subst =, ,$(1)))_description)" "$(includedir)" "$(dynlibdir)" "$(libdir)" "$$($(lastword $(subst =, ,$(1)))_dependencies)"
+lib$(2).pc:
+ exec env \
+ library="$(2)" \
+ includedir="$(includedir)" \
+ dynlibdir="$(dynlibdir)" \
+ libdir="$(libdir)" \
+ buildtime_includedirs="$(buildtime_includedirs)" \
+ buildtime_dynlibdirs="$(buildtime_dynlibdirs)" \
+ buildtime_libdirs="$(buildtime_libdirs)" \
+ extra_libs="$$(strip $$(EXTRA_LIBS))" \
+ requires="$$($(1)_REQUIRES)" \
+ requires_private="$$($(1)_REQUIRES_PRIVATE)" \
+ description="$$($(1)_DESCRIPTION)" \
+ ldlibs="$(LDLIBS)" \
+ ./tools/gen-dotpc.sh > $$@.tmp
+ exec mv -f $$@.tmp $$@
endef
define binary_installation_rule
-$(DESTDIR)$(1)/$(2): $(2) package/modes
+$(DESTDIR)$(1)/$(2): ./$(2) package/modes
exec $(INSTALL) -D -m 600 $$< $$@
grep -- ^$$(@F) < package/modes | { read name mode owner && \
if [ x$$$$owner != x ] ; then chown -- $$$$owner $$@ ; fi && \
@@ -54,7 +71,7 @@ endef
-include config.mak
include package/targets.mak
-$(foreach var,$(LIB_DEFS),$(eval $(call library_definition,$(var))))
+$(foreach var,$(LIB_DEFS),$(eval $(call library_definition,$(firstword $(subst =, ,$(var))),$(lastword $(subst =, ,$(var))))))
include package/deps.mak
@@ -74,7 +91,7 @@ RANLIB := $(CROSS_COMPILE)ranlib
STRIP := $(CROSS_COMPILE)strip
INSTALL := ./tools/install.sh
-$(foreach var,$(filter-out define,$(BIN_TARGETS)),$(eval $(call binary_installation_rule,$(bindir),$(var))))
+$(foreach var,$(BIN_TARGETS),$(eval $(call binary_installation_rule,$(bindir),$(var))))
$(foreach var,$(LIBEXEC_TARGETS),$(eval $(call binary_installation_rule,$(libexecdir),$(var))))
$(foreach var,$(BIN_SYMLINKS),$(eval $(call symlink_installation_rule,$(bindir),$(var))))
@@ -82,10 +99,10 @@ ALL_BINS := $(LIBEXEC_TARGETS) $(BIN_TARGETS)
ALL_LIBS := $(SHARED_LIBS) $(STATIC_LIBS) $(INTERNAL_LIBS)
ALL_INCLUDES := $(wildcard src/include/$(package)/*.h)
-all: $(ALL_LIBS) $(ALL_BINS) $(ALL_INCLUDES) $(EXTRA_INCLUDES)
+all: $(ALL_LIBS) $(ALL_BINS) $(ALL_INCLUDES) $(EXTRA_INCLUDES) $(PC_TARGETS)
clean:
- @exec rm -f $(ALL_LIBS) $(ALL_BINS) $(wildcard src/*/*.o src/*/*.lo) $(EXTRA_TARGETS)
+ @exec rm -f $(ALL_LIBS) $(ALL_BINS) $(wildcard src/*/*.o src/*/*.lo) $(PC_TARGETS) $(EXTRA_TARGETS)
distclean: clean
@exec rm -f config.mak src/include/$(package)/config.h
@@ -106,13 +123,14 @@ ifneq ($(strip $(ALL_BINS)$(SHARED_LIBS)),)
exec $(STRIP) -R .note -R .comment $(ALL_BINS) $(SHARED_LIBS)
endif
-install: install-dynlib install-libexec install-bin install-symlinks install-lib install-include
+install: install-dynlib install-libexec install-bin install-symlinks install-lib install-include install-pkgconfig
install-dynlib: $(SHARED_LIBS:lib%.so.xyzzy=$(DESTDIR)$(dynlibdir)/lib%.so)
install-libexec: $(LIBEXEC_TARGETS:%=$(DESTDIR)$(libexecdir)/%)
install-bin: $(BIN_TARGETS:%=$(DESTDIR)$(bindir)/%)
install-symlinks: $(BIN_SYMLINKS:%=$(DESTDIR)$(bindir)/%)
install-lib: $(STATIC_LIBS:lib%.a.xyzzy=$(DESTDIR)$(libdir)/lib%.a)
install-include: $(ALL_INCLUDES:src/include/$(package)/%.h=$(DESTDIR)$(includedir)/$(package)/%.h) $(EXTRA_INCLUDES:src/include/%.h=$(DESTDIR)$(includedir)/%.h)
+install-pkgconfig: $(PC_TARGETS:%=$(DESTDIR)$(pkgconfdir)/%)
ifneq ($(exthome),)
@@ -147,27 +165,25 @@ $(DESTDIR)$(includedir)/$(package)/%.h: src/include/$(package)/%.h
$(DESTDIR)$(includedir)/%.h: src/include/%.h
exec $(INSTALL) -D -m 644 $< $@
+$(DESTDIR)$(pkgconfdir)/lib%.pc: lib%.pc
+ exec $(INSTALL) -D -m 644 $< $@
+
%.o: %.c
exec $(CC) $(CPPFLAGS_ALL) $(CFLAGS_ALL) -c -o $@ $<
%.lo: %.c
exec $(CC) $(CPPFLAGS_ALL) $(CFLAGS_ALL) $(CFLAGS_SHARED) -c -o $@ $<
-ifdef DO_ALLSTATIC
-$(ALL_BINS): -lskarnet
- exec $(CC) -o $@ $(CFLAGS_ALL) $(LDFLAGS_ALL) $(LDFLAGS_NOSHARED) $^ $(EXTRA_LIBS) $(LDLIBS)
-else
$(ALL_BINS):
exec $(CC) -o $@ $(CFLAGS_ALL) $(LDFLAGS_ALL) $(LDFLAGS_NOSHARED) $^ $(EXTRA_LIBS) $(LDLIBS)
-endif
lib%.a.xyzzy:
exec $(AR) rc $@ $^
exec $(RANLIB) $@
lib%.so.xyzzy:
- exec $(CC) -o $@ $(CFLAGS_ALL) $(CFLAGS_SHARED) $(LDFLAGS_ALL) $(LDFLAGS_SHARED) -Wl,-soname,$(patsubst lib%.so.xyzzy,lib%.so.$(version_M),$@) $^ $(EXTRA_LIBS) $(LDLIBS)
+ exec $(CC) -o $@ $(CFLAGS_ALL) $(CFLAGS_SHARED) $(LDFLAGS_ALL) $(LDFLAGS_SHARED) -Wl,-soname,$(patsubst lib%.so.xyzzy,lib%.so.$(version_M),$@) -Wl,-rpath=$(dynlibdir) $^ $(EXTRA_LIBS) $(LDLIBS)
-.PHONY: it all clean distclean tgz strip install install-dynlib install-bin install-lib install-include
+.PHONY: it all clean distclean tgz strip install install-dynlib install-bin install-lib install-include install-pkgconfig
.DELETE_ON_ERROR: