projects/package-update-indicator

view Makefile @ 52:707e9e3deeac

Do not hardcode pkg-config

Using a macro allows passing a different executable in case of
cross-compilation.
author Helmut Grohne <helmut@subdivi.de>
date Sat Dec 12 01:08:21 2020 -0500 (11 months ago)
parents 0d4bb2f8908a
children
line source
1 #
2 # Copyright (C) 2018 Guido Berhoerster <guido+pui@berhoerster.name>
3 #
4 # Permission is hereby granted, free of charge, to any person obtaining
5 # a copy of this software and associated documentation files (the
6 # "Software"), to deal in the Software without restriction, including
7 # without limitation the rights to use, copy, modify, merge, publish,
8 # distribute, sublicense, and/or sell copies of the Software, and to
9 # permit persons to whom the Software is furnished to do so, subject to
10 # the following conditions:
11 #
12 # The above copyright notice and this permission notice shall be included
13 # in all copies or substantial portions of the Software.
14 #
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 #
24 PACKAGE = package-update-indicator
25 APPLICATION_ID = org.guido-berhoerster.code.package-update-indicator
26 PREFS_APPLICATION_ID = org.guido-berhoerster.code.package-update-indicator.preferences
27 VERSION = 7
28 DISTNAME = $(PACKAGE)-$(VERSION)
29 AUTHOR = Guido Berhoerster
30 BUG_ADDRESS = guido+pui@berhoerster.name
32 # gcc, clang, icc, Sun/Solaris Studio
33 CC := $(CC) -std=c99
34 COMPILE.c = $(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(XCPPFLAGS) $(TARGET_ARCH) -c
35 # gcc, clang, icc
36 MAKEDEPEND.c = $(CC) -MM $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(XCPPFLAGS)
37 # Sun/Solaris Studio
38 #MAKEDEPEND.c = $(CC) -xM1 $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(XCPPFLAGS)
39 # X makedepend
40 #MAKEDEPEND.c = makedepend -f- -Y -- $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(XCPPFLAGS) --
41 LINK.c = $(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(XCPPFLAGS) $(LDFLAGS) $(XLDFLAGS) $(TARGET_ARCH)
42 LINK.o = $(CC) $(LDFLAGS) $(XLDFLAGS) $(TARGET_ARCH)
43 CP := cp
44 INSTALL := install
45 INSTALL.exec := $(INSTALL) -D -m 0755
46 INSTALL.data := $(INSTALL) -D -m 0644
47 INSTALL.link := $(CP) -f -P
48 PAX := pax
49 GZIP := gzip
50 SED := sed
51 PKG_CONFIG := pkg-config
52 GLIB_COMPILE_SCHEMAS := $(shell $(PKG_CONFIG) --variable=glib_compile_schemas gio-2.0)
53 GLIB_COMPILE_RESOURCES := $(shell $(PKG_CONFIG) --variable=glib_compile_resources gio-2.0)
54 GLIB_MKENUMS := $(shell $(PKG_CONFIG) --variable=glib_mkenums glib-2.0)
55 XSLTPROC := xsltproc
56 DOCBOOK5_MANPAGES_STYLESHEET = http://docbook.sourceforge.net/release/xsl-ns/current/manpages/docbook.xsl
57 DOCBOOK5_MANPAGES_FLAGS = --stringparam man.authors.section.enabled 0 \
58 --stringparam man.copyright.section.enabled 0
59 MSGFMT = msgfmt
60 MSGMERGE = msgmerge
61 XGETTEXT = xgettext
62 XGETTEXT_OPTIONS = --copyright-holder "$(AUTHOR)" \
63 --package-name '$(PACKAGE)' \
64 --package-version '$(VERSION)' \
65 --msgid-bugs-address '$(BUG_ADDRESS)' \
66 --default-domain '$(PACKAGE)' \
67 --from-code UTF-8 \
68 --keyword=_ \
69 --keyword=N_ \
70 --keyword=C_:1c,2 \
71 --keyword=NC_:1c,2 \
72 --keyword=g_dngettext:2,3 \
73 --add-comments
74 INDICATOR_LIB := $(or \
75 $(shell $(PKG_CONFIG) --exists appindicator3-0.1 && \
76 printf '%s\\\n' appindicator3-0.1), \
77 $(shell $(PKG_CONFIG) --exists ayatana-appindicator3-0.1 && \
78 printf '%s\\\n' ayatana-appindicator3-0.1), \
79 appindicator3-0.1)
80 INDICATOR_FLAG := $(if $(findstring ayatana,$(INDICATOR_LIB)), \
81 -DHAVE_AYATANA_APPINDICATOR,)
83 define generate-manpage-rule =
84 %.$1: %.$(addsuffix .xml,$1) docbook-update-source-data.xsl
85 $$(XSLTPROC) \
86 --xinclude \
87 --stringparam package $$(PACKAGE) \
88 --stringparam version $$(VERSION) \
89 docbook-update-source-data.xsl $$< | \
90 $$(XSLTPROC) \
91 --xinclude \
92 --output $$@ \
93 $$(DOCBOOK5_MANPAGES_FLAGS) \
94 $$(DOCBOOK5_MANPAGES_STYLESHEET) \
95 -
96 endef
98 DESTDIR ?=
99 prefix ?= /usr/local
100 bindir ?= $(prefix)/bin
101 datadir ?= $(prefix)/share
102 mandir ?= $(datadir)/man
103 localedir ?= $(datadir)/locale
104 sysconfdir ?= /etc
105 xdgautostartdir ?= $(sysconfdir)/xdg/autostart
106 xdgapplicationsdir ?= $(datadir)/applications
108 OS_NAME := $(shell uname -s)
109 OS_RELEASE := $(shell uname -r)
111 $(PACKAGE)_OBJS = package-update-indicator.o \
112 pui-application.o \
113 pui-backend.o \
114 pui-get-updates.o \
115 pui-settings.o \
116 pui-types.o \
117 pui-resources.o
119 $(PACKAGE)-prefs_OBJS = package-update-indicator-prefs.o \
120 pui-prefs-application.o \
121 pui-settings.o \
122 pui-prefs-resources.o
124 OBJS = $($(PACKAGE)_OBJS) $($(PACKAGE)-prefs_OBJS)
126 ENUM_DEPS = pui-backend.h \
127 pui-application.h
129 ENUM_HEADER = pui-types.h
131 ENUM_FILES = $(ENUM_HEADER) \
132 pui-types.c
134 GSETTINGS_SCHEMAS = $(APPLICATION_ID).gschema.xml
136 GRESOURCE_FILES = pui-prefs.gresource.xml
138 AUTOSTART_FILE = $(APPLICATION_ID).desktop
140 DESKTOP_FILES = $(PREFS_APPLICATION_ID).desktop
142 LINGUAS := $(shell sed 's/\#.*//' po/LINGUAS)
143 MOFILES := $(patsubst %,po/%.mo,$(LINGUAS))
144 POTFILES_IN := $(shell sed 's/\#.*//' po/POTFILES.in)
145 POTFILE = po/$(PACKAGE).pot
147 MANPAGES = $(PACKAGE).1 $(PACKAGE)-prefs.1
149 .DEFAULT_TARGET = all
151 .PHONY: all pot update-po clean clobber dist install
153 all: $(PACKAGE) $(PACKAGE)-prefs $(AUTOSTART_FILE) $(DESKTOP_FILES) $(MOFILES) $(MANPAGES)
155 $(PACKAGE): XCPPFLAGS = -DPACKAGE=\"$(PACKAGE)\" \
156 -DAPPLICATION_ID=\"$(APPLICATION_ID)\" \
157 -DVERSION=\"$(VERSION)\" \
158 -DG_LOG_DOMAIN=\"$(PACKAGE)\" \
159 -DPACKAGE_LOCALE_DIR="\"$(localedir)\"" \
160 -DGETTEXT_PACKAGE=\"$(PACKAGE)\" \
161 -DSETTINGS_SCHEMA_ID=\"$(APPLICATION_ID)\" \
162 -DI_KNOW_THE_PACKAGEKIT_GLIB2_API_IS_SUBJECT_TO_CHANGE \
163 $(INDICATOR_FLAG)
164 $(PACKAGE): XCFLAGS = $(shell $(PKG_CONFIG) --cflags gtk+-3.0 \
165 $(INDICATOR_LIB) packagekit-glib2 \
166 polkit-gobject-1 upower-glib)
167 $(PACKAGE): LDLIBS = $(shell $(PKG_CONFIG) --libs gtk+-3.0 \
168 $(INDICATOR_LIB) packagekit-glib2 \
169 polkit-gobject-1 upower-glib)
171 $(PACKAGE)-prefs: XCPPFLAGS = -DPACKAGE=\"$(PACKAGE)\" \
172 -DAPPLICATION_ID=\"$(PREFS_APPLICATION_ID)\" \
173 -DVERSION=\"$(VERSION)\" \
174 -DG_LOG_DOMAIN=\"$(PACKAGE)\" \
175 -DPACKAGE_LOCALE_DIR="\"$(localedir)\"" \
176 -DGETTEXT_PACKAGE=\"$(PACKAGE)\" \
177 -DSETTINGS_SCHEMA_ID=\"$(APPLICATION_ID)\"
178 $(PACKAGE)-prefs: XCFLAGS = $(shell $(PKG_CONFIG) --cflags gtk+-3.0)
179 $(PACKAGE)-prefs: LDLIBS = $(shell $(PKG_CONFIG) --libs gtk+-3.0)
181 ifneq ($(findstring $(OS_NAME),FreeBSD DragonFly OpenBSD),)
182 $(PACKAGE): XCPPFLAGS += -I/usr/local/include
183 $(PACKAGE): XLDFLAGS += -L/usr/local/lib
184 else ifeq ($(OS_NAME),NetBSD)
185 $(PACKAGE): XCPPFLAGS += -I/usr/pkg/include
186 $(PACKAGE): XLDFLAGS += -L/usr/pkg/lib
187 endif
188 ifeq ($(findstring $(OS_NAME),FreeBSD DragonFly NetBSD OpenBSD),)
189 $(PACKAGE): XCPPFLAGS += -D_XOPEN_SOURCE=600
190 endif
192 $(PACKAGE): $($(PACKAGE)_OBJS)
193 $(LINK.o) $^ $(LDLIBS) -o $@
195 $(PACKAGE)-prefs: $($(PACKAGE)-prefs_OBJS)
196 $(LINK.o) $^ $(LDLIBS) -o $@
198 $(OBJS): $(ENUM_HEADER)
200 %-types.h: %-types.h.in $(ENUM_DEPS)
201 $(GLIB_MKENUMS) --template $< >$@ $(filter-out $<,$^)
203 %-types.c: %-types.c.in $(ENUM_DEPS)
204 $(GLIB_MKENUMS) --template $< >$@ $(filter-out $<,$^)
206 %-resources.c: %.gresource.xml
207 $(GLIB_COMPILE_RESOURCES) --generate-dependencies $< | \
208 while read -r resource_file; do \
209 printf '%s: %s\n' $@ "$${resource_file}"; \
210 done
211 $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=. --generate-source $<
213 $(POTFILE): po/POTFILES.in $(POTFILES_IN)
214 $(XGETTEXT) $(XGETTEXT_OPTIONS) --files-from $< --output $@
216 pot: $(POTFILE)
218 update-po: $(POTFILE)
219 for pofile in $(patsubst %.mo,%.po,$(MOFILES)); do \
220 $(MSGMERGE) --update --backup off $$pofile $<; \
221 done
223 %.mo: %.po
224 $(MSGFMT) --output $@ $<
226 %.desktop: %.desktop.in
227 $(MSGFMT) --desktop --keyword 'Keywords' --template $< -d po --output $@
229 $(foreach section,1 2 3 4 5 6 7 8 9,$(eval $(call generate-manpage-rule,$(section))))
231 %.o: %.c
232 $(MAKEDEPEND.c) $< | $(SED) -f deps.sed >$*.d
233 $(COMPILE.c) -o $@ $<
235 install: all
236 $(INSTALL.exec) $(PACKAGE) "$(DESTDIR)$(bindir)/$(PACKAGE)"
237 $(INSTALL.exec) $(PACKAGE)-prefs \
238 "$(DESTDIR)$(bindir)/$(PACKAGE)-prefs"
239 for schema in $(GSETTINGS_SCHEMAS); do \
240 $(INSTALL.data) $${schema} \
241 $(DESTDIR)$(datadir)/glib-2.0/schemas/$${schema}; \
242 done
243 if [ -n "$(GSETTINGS_SCHEMAS)" ] && [ -z "$(DESTDIR)" ]; then \
244 $(GLIB_COMPILE_SCHEMAS) $(datadir)/glib-2.0/schemas; \
245 fi
246 $(INSTALL.data) $(AUTOSTART_FILE) \
247 $(DESTDIR)$(xdgautostartdir)/$(AUTOSTART_FILE)
248 for desktop_file in $(DESKTOP_FILES); do \
249 $(INSTALL.data) $${desktop_file} \
250 $(DESTDIR)$(xdgapplicationsdir)/$${desktop_file}; \
251 done
252 for lang in $(LINGUAS); do \
253 $(INSTALL.data) po/$${lang}.mo \
254 $(DESTDIR)$(localedir)/$${lang}/LC_MESSAGES/$(PACKAGE).mo; \
255 done
256 for manpage in $(MANPAGES); do \
257 $(INSTALL.data) $${manpage} \
258 "$(DESTDIR)$(mandir)/man$${manpage##*.}/$${manpage##*/}"; \
259 done
261 clean:
262 rm -f $(PACKAGE) $(OBJS) $(ENUM_FILES) $(AUTOSTART_FILE) \
263 $(DESKTOP_FILES) $(POTFILE) $(MOFILES) $(MANPAGES)
265 clobber: clean
266 rm -f $(patsubst %.o,%.d,$(OBJS))
268 dist: clobber
269 $(PAX) -w -x ustar -s ',.*/\..*,,' -s ',./[^/]*\.tar\.gz,,' \
270 -s ',^\.$$,,' -s ',\./,$(DISTNAME)/,' . | \
271 $(GZIP) > $(DISTNAME).tar.gz
273 -include local.mk
275 -include $(patsubst %.o,%.d,$(OBJS))
276 -include $(patsubst %.gresource.xml,%.gresource.d,$(GRESOURCE_FILES))