blob: bd39ae10d5acc6e526f66ff9c940a5b7ad34764c [file] [log] [blame]
Behdad Esfahbod23e4fac2015-08-31 19:41:01 +01001# git.mk, a small Makefile to autogenerate .gitignore files
2# for autotools-based projects.
Behdad Esfahbod29aa4002009-11-02 16:28:39 -05003#
4# Copyright 2009, Red Hat, Inc.
Behdad Esfahbod22c625a2013-03-04 20:56:15 -05005# Copyright 2010,2011,2012,2013 Behdad Esfahbod
Behdad Esfahbod29aa4002009-11-02 16:28:39 -05006# Written by Behdad Esfahbod
7#
8# Copying and distribution of this file, with or without modification,
Behdad Esfahbod6efe1ec2012-07-11 15:30:08 -04009# is permitted in any medium without royalty provided the copyright
Behdad Esfahbod29aa4002009-11-02 16:28:39 -050010# notice and this notice are preserved.
11#
Behdad Esfahbod22c625a2013-03-04 20:56:15 -050012# The latest version of this file can be downloaded from:
Behdad Esfahbodd1466782015-02-26 13:52:50 -080013GIT_MK_URL = https://raw.githubusercontent.com/behdad/git.mk/master/git.mk
14#
Behdad Esfahbod22c625a2013-03-04 20:56:15 -050015# Bugs, etc, should be reported upstream at:
16# https://github.com/behdad/git.mk
Behdad Esfahbod29aa4002009-11-02 16:28:39 -050017#
18# To use in your project, import this file in your git repo's toplevel,
19# then do "make -f git.mk". This modifies all Makefile.am files in
Behdad Esfahbodbee74ef2012-01-27 02:14:08 -050020# your project to -include git.mk. Remember to add that line to new
21# Makefile.am files you create in your project, or just rerun the
22# "make -f git.mk".
Behdad Esfahbod29aa4002009-11-02 16:28:39 -050023#
24# This enables automatic .gitignore generation. If you need to ignore
25# more files, add them to the GITIGNOREFILES variable in your Makefile.am.
26# But think twice before doing that. If a file has to be in .gitignore,
27# chances are very high that it's a generated file and should be in one
28# of MOSTLYCLEANFILES, CLEANFILES, DISTCLEANFILES, or MAINTAINERCLEANFILES.
29#
30# The only case that you need to manually add a file to GITIGNOREFILES is
31# when remove files in one of mostlyclean-local, clean-local, distclean-local,
Behdad Esfahbodbee74ef2012-01-27 02:14:08 -050032# or maintainer-clean-local make targets.
Behdad Esfahbod29aa4002009-11-02 16:28:39 -050033#
34# Note that for files like editor backup, etc, there are better places to
35# ignore them. See "man gitignore".
36#
37# If "make maintainer-clean" removes the files but they are not recognized
38# by this script (that is, if "git status" shows untracked files still), send
39# me the output of "git status" as well as your Makefile.am and Makefile for
Behdad Esfahbodbee74ef2012-01-27 02:14:08 -050040# the directories involved and I'll diagnose.
Behdad Esfahbod29aa4002009-11-02 16:28:39 -050041#
42# For a list of toplevel files that should be in MAINTAINERCLEANFILES, see
Behdad Esfahbodbee74ef2012-01-27 02:14:08 -050043# Makefile.am.sample in the git.mk git repo.
Behdad Esfahbod29aa4002009-11-02 16:28:39 -050044#
45# Don't EXTRA_DIST this file. It is supposed to only live in git clones,
46# not tarballs. It serves no useful purpose in tarballs and clutters the
47# build dir.
48#
49# This file knows how to handle autoconf, automake, libtool, gtk-doc,
Behdad Esfahbodd1466782015-02-26 13:52:50 -080050# gnome-doc-utils, yelp.m4, mallard, intltool, gsettings, dejagnu, appdata,
51# appstream.
Behdad Esfahbod29aa4002009-11-02 16:28:39 -050052#
Behdad Esfahbod6efe1ec2012-07-11 15:30:08 -040053# This makefile provides the following targets:
54#
55# - all: "make all" will build all gitignore files.
56# - gitignore: makes all gitignore files in the current dir and subdirs.
57# - .gitignore: make gitignore file for the current dir.
58# - gitignore-recurse: makes all gitignore files in the subdirs.
Behdad Esfahbod29aa4002009-11-02 16:28:39 -050059#
60# KNOWN ISSUES:
61#
62# - Recursive configure doesn't work as $(top_srcdir)/git.mk inside the
63# submodule doesn't find us. If you have configure.{in,ac} files in
64# subdirs, add a proxy git.mk file in those dirs that simply does:
65# "include $(top_srcdir)/../git.mk". Add more ..'s to your taste.
66# And add those files to git. See vte/gnome-pty-helper/git.mk for
67# example.
68#
69
Behdad Esfahbod22c625a2013-03-04 20:56:15 -050070
71
72###############################################################################
73# Variables user modules may want to add to toplevel MAINTAINERCLEANFILES:
74###############################################################################
75
76#
77# Most autotools-using modules should be fine including this variable in their
78# toplevel MAINTAINERCLEANFILES:
79GITIGNORE_MAINTAINERCLEANFILES_TOPLEVEL = \
80 $(srcdir)/aclocal.m4 \
81 $(srcdir)/autoscan.log \
Behdad Esfahbod22c625a2013-03-04 20:56:15 -050082 $(srcdir)/configure.scan \
Behdad Esfahboddddf9902013-08-26 17:58:25 -040083 `AUX_DIR=$(srcdir)/$$(cd $(top_srcdir); $(AUTOCONF) --trace 'AC_CONFIG_AUX_DIR:$$1' ./configure.ac); \
Behdad Esfahbod627af692013-08-06 16:53:56 -040084 test "x$$AUX_DIR" = "x$(srcdir)/" && AUX_DIR=$(srcdir); \
85 for x in \
Behdad Esfahbod72225272013-08-06 15:19:23 -040086 ar-lib \
87 compile \
88 config.guess \
89 config.sub \
90 depcomp \
91 install-sh \
92 ltmain.sh \
93 missing \
94 mkinstalldirs \
Behdad Esfahbod6b4fdde2013-09-30 13:48:19 -040095 test-driver \
Behdad Esfahbodd1466782015-02-26 13:52:50 -080096 ylwrap \
Behdad Esfahbod72225272013-08-06 15:19:23 -040097 ; do echo "$$AUX_DIR/$$x"; done` \
Behdad Esfahboddddf9902013-08-26 17:58:25 -040098 `cd $(top_srcdir); $(AUTOCONF) --trace 'AC_CONFIG_HEADERS:$$1' ./configure.ac | \
Behdad Esfahbod72225272013-08-06 15:19:23 -040099 head -n 1 | while read f; do echo "$(srcdir)/$$f.in"; done`
Behdad Esfahbod22c625a2013-03-04 20:56:15 -0500100#
101# All modules should also be fine including the following variable, which
102# removes automake-generated Makefile.in files:
103GITIGNORE_MAINTAINERCLEANFILES_MAKEFILE_IN = \
Behdad Esfahboddddf9902013-08-26 17:58:25 -0400104 `cd $(top_srcdir); $(AUTOCONF) --trace 'AC_CONFIG_FILES:$$1' ./configure.ac | \
Behdad Esfahbod22c625a2013-03-04 20:56:15 -0500105 while read f; do \
106 case $$f in Makefile|*/Makefile) \
107 test -f "$(srcdir)/$$f.am" && echo "$(srcdir)/$$f.in";; esac; \
108 done`
109#
Behdad Esfahbod6b4fdde2013-09-30 13:48:19 -0400110# Modules that use libtool and use AC_CONFIG_MACRO_DIR() may also include this,
111# though it's harmless to include regardless.
Behdad Esfahbod22c625a2013-03-04 20:56:15 -0500112GITIGNORE_MAINTAINERCLEANFILES_M4_LIBTOOL = \
Behdad Esfahbod6b4fdde2013-09-30 13:48:19 -0400113 `MACRO_DIR=$(srcdir)/$$(cd $(top_srcdir); $(AUTOCONF) --trace 'AC_CONFIG_MACRO_DIR:$$1' ./configure.ac); \
114 if test "x$$MACRO_DIR" != "x$(srcdir)/"; then \
115 for x in \
116 libtool.m4 \
117 ltoptions.m4 \
118 ltsugar.m4 \
119 ltversion.m4 \
120 lt~obsolete.m4 \
121 ; do echo "$$MACRO_DIR/$$x"; done; \
122 fi`
Behdad Esfahbod22c625a2013-03-04 20:56:15 -0500123
124
125
126###############################################################################
127# Default rule is to install ourselves in all Makefile.am files:
128###############################################################################
129
Behdad Esfahbod29aa4002009-11-02 16:28:39 -0500130git-all: git-mk-install
131
132git-mk-install:
Behdad Esfahbod36a661c2013-04-11 13:38:37 -0400133 @echo "Installing git makefile"
Behdad Esfahbodbee74ef2012-01-27 02:14:08 -0500134 @any_failed=; \
135 find "`test -z "$(top_srcdir)" && echo . || echo "$(top_srcdir)"`" -name Makefile.am | while read x; do \
Behdad Esfahbod29aa4002009-11-02 16:28:39 -0500136 if grep 'include .*/git.mk' $$x >/dev/null; then \
Behdad Esfahbod36a661c2013-04-11 13:38:37 -0400137 echo "$$x already includes git.mk"; \
Behdad Esfahbod29aa4002009-11-02 16:28:39 -0500138 else \
139 failed=; \
140 echo "Updating $$x"; \
141 { cat $$x; \
142 echo ''; \
143 echo '-include $$(top_srcdir)/git.mk'; \
144 } > $$x.tmp || failed=1; \
145 if test x$$failed = x; then \
146 mv $$x.tmp $$x || failed=1; \
147 fi; \
148 if test x$$failed = x; then : else \
Behdad Esfahbod36a661c2013-04-11 13:38:37 -0400149 echo "Failed updating $$x"; >&2 \
Behdad Esfahbod29aa4002009-11-02 16:28:39 -0500150 any_failed=1; \
151 fi; \
152 fi; done; test -z "$$any_failed"
153
Behdad Esfahbodd1466782015-02-26 13:52:50 -0800154git-mk-update:
155 wget $(GIT_MK_URL) -O $(top_srcdir)/git.mk
156
157.PHONY: git-all git-mk-install git-mk-update
Behdad Esfahbod29aa4002009-11-02 16:28:39 -0500158
159
Behdad Esfahbod22c625a2013-03-04 20:56:15 -0500160
161###############################################################################
162# Actual .gitignore generation:
163###############################################################################
Behdad Esfahbod29aa4002009-11-02 16:28:39 -0500164
165$(srcdir)/.gitignore: Makefile.am $(top_srcdir)/git.mk
Behdad Esfahbod72225272013-08-06 15:19:23 -0400166 @echo "git.mk: Generating $@"
167 @{ \
Behdad Esfahbod29aa4002009-11-02 16:28:39 -0500168 if test "x$(DOC_MODULE)" = x -o "x$(DOC_MAIN_SGML_FILE)" = x; then :; else \
169 for x in \
170 $(DOC_MODULE)-decl-list.txt \
171 $(DOC_MODULE)-decl.txt \
172 tmpl/$(DOC_MODULE)-unused.sgml \
173 "tmpl/*.bak" \
Behdad Esfahbod23e4fac2015-08-31 19:41:01 +0100174 $(REPORT_FILES) \
175 $(DOC_MODULE).pdf \
Behdad Esfahbod29aa4002009-11-02 16:28:39 -0500176 xml html \
Behdad Esfahbod36a661c2013-04-11 13:38:37 -0400177 ; do echo "/$$x"; done; \
Behdad Esfahboddddf9902013-08-26 17:58:25 -0400178 FLAVOR=$$(cd $(top_srcdir); $(AUTOCONF) --trace 'GTK_DOC_CHECK:$$2' ./configure.ac); \
179 case $$FLAVOR in *no-tmpl*) echo /tmpl;; esac; \
Behdad Esfahbod23e4fac2015-08-31 19:41:01 +0100180 if echo "$(SCAN_OPTIONS)" | grep -q "\-\-rebuild-types"; then \
181 echo "/$(DOC_MODULE).types"; \
182 fi; \
183 if echo "$(SCAN_OPTIONS)" | grep -q "\-\-rebuild-sections"; then \
184 echo "/$(DOC_MODULE)-sections.txt"; \
185 fi; \
186 if test "$(abs_srcdir)" != "$(abs_builddir)" ; then \
187 for x in \
188 $(SETUP_FILES) \
189 $(DOC_MODULE).types \
190 ; do echo "/$$x"; done; \
191 fi; \
Behdad Esfahbod29aa4002009-11-02 16:28:39 -0500192 fi; \
Behdad Esfahbodbee74ef2012-01-27 02:14:08 -0500193 if test "x$(DOC_MODULE)$(DOC_ID)" = x -o "x$(DOC_LINGUAS)" = x; then :; else \
Behdad Esfahbod6efe1ec2012-07-11 15:30:08 -0400194 for lc in $(DOC_LINGUAS); do \
195 for x in \
196 $(if $(DOC_MODULE),$(DOC_MODULE).xml) \
197 $(DOC_PAGES) \
198 $(DOC_INCLUDES) \
Behdad Esfahbod36a661c2013-04-11 13:38:37 -0400199 ; do echo "/$$lc/$$x"; done; \
Behdad Esfahbod6efe1ec2012-07-11 15:30:08 -0400200 done; \
Behdad Esfahbod29aa4002009-11-02 16:28:39 -0500201 for x in \
Behdad Esfahbod29aa4002009-11-02 16:28:39 -0500202 $(_DOC_OMF_ALL) \
203 $(_DOC_DSK_ALL) \
204 $(_DOC_HTML_ALL) \
Behdad Esfahbodbee74ef2012-01-27 02:14:08 -0500205 $(_DOC_MOFILES) \
Behdad Esfahbodbee74ef2012-01-27 02:14:08 -0500206 $(DOC_H_FILE) \
Behdad Esfahbod29aa4002009-11-02 16:28:39 -0500207 "*/.xml2po.mo" \
208 "*/*.omf.out" \
209 ; do echo /$$x; done; \
210 fi; \
Behdad Esfahbodbee74ef2012-01-27 02:14:08 -0500211 if test "x$(HELP_ID)" = x -o "x$(HELP_LINGUAS)" = x; then :; else \
Behdad Esfahbod6efe1ec2012-07-11 15:30:08 -0400212 for lc in $(HELP_LINGUAS); do \
213 for x in \
214 $(HELP_FILES) \
215 "$$lc.stamp" \
216 "$$lc.mo" \
Behdad Esfahbod36a661c2013-04-11 13:38:37 -0400217 ; do echo "/$$lc/$$x"; done; \
Behdad Esfahbod6efe1ec2012-07-11 15:30:08 -0400218 done; \
Behdad Esfahbodbee74ef2012-01-27 02:14:08 -0500219 fi; \
220 if test "x$(gsettings_SCHEMAS)" = x; then :; else \
221 for x in \
222 $(gsettings_SCHEMAS:.xml=.valid) \
223 $(gsettings__enum_file) \
Behdad Esfahbod36a661c2013-04-11 13:38:37 -0400224 ; do echo "/$$x"; done; \
Behdad Esfahbodbee74ef2012-01-27 02:14:08 -0500225 fi; \
Behdad Esfahbodd1466782015-02-26 13:52:50 -0800226 if test "x$(appdata_XML)" = x; then :; else \
227 for x in \
228 $(appdata_XML:.xml=.valid) \
229 ; do echo "/$$x"; done; \
230 fi; \
231 if test "x$(appstream_XML)" = x; then :; else \
232 for x in \
233 $(appstream_XML:.xml=.valid) \
234 ; do echo "/$$x"; done; \
235 fi; \
Behdad Esfahbod29aa4002009-11-02 16:28:39 -0500236 if test -f $(srcdir)/po/Makefile.in.in; then \
237 for x in \
238 po/Makefile.in.in \
Behdad Esfahbod72225272013-08-06 15:19:23 -0400239 po/Makefile.in.in~ \
Behdad Esfahbod29aa4002009-11-02 16:28:39 -0500240 po/Makefile.in \
241 po/Makefile \
Behdad Esfahbod72225272013-08-06 15:19:23 -0400242 po/Makevars.template \
Behdad Esfahbod29aa4002009-11-02 16:28:39 -0500243 po/POTFILES \
Behdad Esfahbod72225272013-08-06 15:19:23 -0400244 po/Rules-quot \
Behdad Esfahbod29aa4002009-11-02 16:28:39 -0500245 po/stamp-it \
246 po/.intltool-merge-cache \
247 "po/*.gmo" \
Behdad Esfahbod72225272013-08-06 15:19:23 -0400248 "po/*.header" \
Behdad Esfahbod29aa4002009-11-02 16:28:39 -0500249 "po/*.mo" \
Behdad Esfahbod72225272013-08-06 15:19:23 -0400250 "po/*.sed" \
251 "po/*.sin" \
Behdad Esfahbod29aa4002009-11-02 16:28:39 -0500252 po/$(GETTEXT_PACKAGE).pot \
253 intltool-extract.in \
254 intltool-merge.in \
255 intltool-update.in \
Behdad Esfahbod36a661c2013-04-11 13:38:37 -0400256 ; do echo "/$$x"; done; \
Behdad Esfahbod29aa4002009-11-02 16:28:39 -0500257 fi; \
258 if test -f $(srcdir)/configure; then \
259 for x in \
260 autom4te.cache \
261 configure \
262 config.h \
263 stamp-h1 \
264 libtool \
265 config.lt \
Behdad Esfahbod36a661c2013-04-11 13:38:37 -0400266 ; do echo "/$$x"; done; \
Behdad Esfahbod29aa4002009-11-02 16:28:39 -0500267 fi; \
Behdad Esfahbod6efe1ec2012-07-11 15:30:08 -0400268 if test "x$(DEJATOOL)" = x; then :; else \
269 for x in \
270 $(DEJATOOL) \
Behdad Esfahbod36a661c2013-04-11 13:38:37 -0400271 ; do echo "/$$x.sum"; echo "/$$x.log"; done; \
Behdad Esfahbod6efe1ec2012-07-11 15:30:08 -0400272 echo /site.exp; \
273 fi; \
Behdad Esfahbod36a661c2013-04-11 13:38:37 -0400274 if test "x$(am__dirstamp)" = x; then :; else \
275 echo "$(am__dirstamp)"; \
276 fi; \
Behdad Esfahbodd1466782015-02-26 13:52:50 -0800277 if test "x$(LTCOMPILE)" = x -a "x$(LTCXXCOMPILE)" = x -a "x$(GTKDOC_RUN)" = x; then :; else \
Behdad Esfahbod36a661c2013-04-11 13:38:37 -0400278 for x in \
279 "*.lo" \
280 ".libs" "_libs" \
281 ; do echo "$$x"; done; \
282 fi; \
Behdad Esfahbod29aa4002009-11-02 16:28:39 -0500283 for x in \
284 .gitignore \
285 $(GITIGNOREFILES) \
286 $(CLEANFILES) \
Behdad Esfahbod6efe1ec2012-07-11 15:30:08 -0400287 $(PROGRAMS) $(check_PROGRAMS) $(EXTRA_PROGRAMS) \
288 $(LIBRARIES) $(check_LIBRARIES) $(EXTRA_LIBRARIES) \
289 $(LTLIBRARIES) $(check_LTLIBRARIES) $(EXTRA_LTLIBRARIES) \
Behdad Esfahbod29aa4002009-11-02 16:28:39 -0500290 so_locations \
Behdad Esfahbod29aa4002009-11-02 16:28:39 -0500291 $(MOSTLYCLEANFILES) \
Behdad Esfahboddddf9902013-08-26 17:58:25 -0400292 $(TEST_LOGS) \
293 $(TEST_LOGS:.log=.trs) \
294 $(TEST_SUITE_LOG) \
Behdad Esfahbodd1466782015-02-26 13:52:50 -0800295 $(TESTS:=.test) \
296 "*.gcda" \
297 "*.gcno" \
Behdad Esfahbod29aa4002009-11-02 16:28:39 -0500298 $(DISTCLEANFILES) \
299 $(am__CONFIG_DISTCLEAN_FILES) \
300 $(CONFIG_CLEAN_FILES) \
301 TAGS ID GTAGS GRTAGS GSYMS GPATH tags \
302 "*.tab.c" \
303 $(MAINTAINERCLEANFILES) \
304 $(BUILT_SOURCES) \
Behdad Esfahboddddf9902013-08-26 17:58:25 -0400305 $(patsubst %.vala,%.c,$(filter %.vala,$(SOURCES))) \
306 $(filter %_vala.stamp,$(DIST_COMMON)) \
307 $(filter %.vapi,$(DIST_COMMON)) \
Behdad Esfahbodd1466782015-02-26 13:52:50 -0800308 $(filter $(addprefix %,$(notdir $(patsubst %.vapi,%.h,$(filter %.vapi,$(DIST_COMMON))))),$(DIST_COMMON)) \
Behdad Esfahbod29aa4002009-11-02 16:28:39 -0500309 Makefile \
310 Makefile.in \
311 "*.orig" \
312 "*.rej" \
313 "*.bak" \
314 "*~" \
315 ".*.sw[nop]" \
Behdad Esfahbodbee74ef2012-01-27 02:14:08 -0500316 ".dirstamp" \
Behdad Esfahbod36a661c2013-04-11 13:38:37 -0400317 ; do echo "/$$x"; done; \
Behdad Esfahbodd1466782015-02-26 13:52:50 -0800318 for x in \
319 "*.$(OBJEXT)" \
320 $(DEPDIR) \
321 ; do echo "$$x"; done; \
Behdad Esfahbod29aa4002009-11-02 16:28:39 -0500322 } | \
323 sed "s@^/`echo "$(srcdir)" | sed 's/\(.\)/[\1]/g'`/@/@" | \
324 sed 's@/[.]/@/@g' | \
325 LC_ALL=C sort | uniq > $@.tmp && \
326 mv $@.tmp $@;
327
328all: $(srcdir)/.gitignore gitignore-recurse-maybe
Behdad Esfahbod6efe1ec2012-07-11 15:30:08 -0400329gitignore: $(srcdir)/.gitignore gitignore-recurse
330
Behdad Esfahbod29aa4002009-11-02 16:28:39 -0500331gitignore-recurse-maybe:
Behdad Esfahbodbee74ef2012-01-27 02:14:08 -0500332 @for subdir in $(DIST_SUBDIRS); do \
333 case " $(SUBDIRS) " in \
334 *" $$subdir "*) :;; \
Behdad Esfahbod72225272013-08-06 15:19:23 -0400335 *) test "$$subdir" = . -o -e "$$subdir/.git" || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) gitignore || echo "Skipping $$subdir");; \
Behdad Esfahbodbee74ef2012-01-27 02:14:08 -0500336 esac; \
Behdad Esfahbod29aa4002009-11-02 16:28:39 -0500337 done
Behdad Esfahbod6efe1ec2012-07-11 15:30:08 -0400338gitignore-recurse:
339 @for subdir in $(DIST_SUBDIRS); do \
Behdad Esfahbod72225272013-08-06 15:19:23 -0400340 test "$$subdir" = . -o -e "$$subdir/.git" || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) gitignore || echo "Skipping $$subdir"); \
Behdad Esfahbod6efe1ec2012-07-11 15:30:08 -0400341 done
Behdad Esfahbod29aa4002009-11-02 16:28:39 -0500342
343maintainer-clean: gitignore-clean
344gitignore-clean:
345 -rm -f $(srcdir)/.gitignore
346
347.PHONY: gitignore-clean gitignore gitignore-recurse gitignore-recurse-maybe