1# git.mk, a small Makefile to autogenerate .gitignore files
2# for autotools-based projects.
3#
4# Copyright 2009, Red Hat, Inc.
5# Copyright 2010,2011,2012,2013 Behdad Esfahbod
6# Written by Behdad Esfahbod
7#
8# Copying and distribution of this file, with or without modification,
9# is permitted in any medium without royalty provided the copyright
10# notice and this notice are preserved.
11#
12# The latest version of this file can be downloaded from:
13GIT_MK_URL = https://raw.githubusercontent.com/behdad/git.mk/master/git.mk
14#
15# Bugs, etc, should be reported upstream at:
16#   https://github.com/behdad/git.mk
17#
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
20# 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".
23#
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,
32# or maintainer-clean-local make targets.
33#
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
40# the directories involved and I'll diagnose.
41#
42# For a list of toplevel files that should be in MAINTAINERCLEANFILES, see
43# Makefile.am.sample in the git.mk git repo.
44#
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,
50# gnome-doc-utils, yelp.m4, mallard, intltool, gsettings, dejagnu, appdata,
51# appstream.
52#
53# 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.
59#
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
70
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 \
82	$(srcdir)/configure.scan \
83	`AUX_DIR=$(srcdir)/$$(cd $(top_srcdir); $(AUTOCONF) --trace 'AC_CONFIG_AUX_DIR:$$1' ./configure.ac); \
84	 test "x$$AUX_DIR" = "x$(srcdir)/" && AUX_DIR=$(srcdir); \
85	 for x in \
86		ar-lib \
87		compile \
88		config.guess \
89		config.sub \
90		depcomp \
91		install-sh \
92		ltmain.sh \
93		missing \
94		mkinstalldirs \
95		test-driver \
96		ylwrap \
97	 ; do echo "$$AUX_DIR/$$x"; done` \
98	`cd $(top_srcdir); $(AUTOCONF) --trace 'AC_CONFIG_HEADERS:$$1' ./configure.ac | \
99	head -n 1 | while read f; do echo "$(srcdir)/$$f.in"; done`
100#
101# All modules should also be fine including the following variable, which
102# removes automake-generated Makefile.in files:
103GITIGNORE_MAINTAINERCLEANFILES_MAKEFILE_IN = \
104	`cd $(top_srcdir); $(AUTOCONF) --trace 'AC_CONFIG_FILES:$$1' ./configure.ac | \
105	while read f; do \
106	  case $$f in Makefile|*/Makefile) \
107	    test -f "$(srcdir)/$$f.am" && echo "$(srcdir)/$$f.in";; esac; \
108	done`
109#
110# Modules that use libtool and use  AC_CONFIG_MACRO_DIR() may also include this,
111# though it's harmless to include regardless.
112GITIGNORE_MAINTAINERCLEANFILES_M4_LIBTOOL = \
113	`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`
123
124
125
126###############################################################################
127# Default rule is to install ourselves in all Makefile.am files:
128###############################################################################
129
130git-all: git-mk-install
131
132git-mk-install:
133	@echo "Installing git makefile"
134	@any_failed=; \
135		find "`test -z "$(top_srcdir)" && echo . || echo "$(top_srcdir)"`" -name Makefile.am | while read x; do \
136		if grep 'include .*/git.mk' $$x >/dev/null; then \
137			echo "$$x already includes git.mk"; \
138		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 \
149				echo "Failed updating $$x"; >&2 \
150				any_failed=1; \
151			fi; \
152	fi; done; test -z "$$any_failed"
153
154git-mk-update:
155	wget $(GIT_MK_URL) -O $(top_srcdir)/git.mk
156
157.PHONY: git-all git-mk-install git-mk-update
158
159
160
161###############################################################################
162# Actual .gitignore generation:
163###############################################################################
164
165$(srcdir)/.gitignore: Makefile.am $(top_srcdir)/git.mk
166	@echo "git.mk: Generating $@"
167	@{ \
168		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" \
174				$(REPORT_FILES) \
175				$(DOC_MODULE).pdf \
176				xml html \
177			; do echo "/$$x"; done; \
178			FLAVOR=$$(cd $(top_srcdir); $(AUTOCONF) --trace 'GTK_DOC_CHECK:$$2' ./configure.ac); \
179			case $$FLAVOR in *no-tmpl*) echo /tmpl;; esac; \
180			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; \
192		fi; \
193		if test "x$(DOC_MODULE)$(DOC_ID)" = x -o "x$(DOC_LINGUAS)" = x; then :; else \
194			for lc in $(DOC_LINGUAS); do \
195				for x in \
196					$(if $(DOC_MODULE),$(DOC_MODULE).xml) \
197					$(DOC_PAGES) \
198					$(DOC_INCLUDES) \
199				; do echo "/$$lc/$$x"; done; \
200			done; \
201			for x in \
202				$(_DOC_OMF_ALL) \
203				$(_DOC_DSK_ALL) \
204				$(_DOC_HTML_ALL) \
205				$(_DOC_MOFILES) \
206				$(DOC_H_FILE) \
207				"*/.xml2po.mo" \
208				"*/*.omf.out" \
209			; do echo /$$x; done; \
210		fi; \
211		if test "x$(HELP_ID)" = x -o "x$(HELP_LINGUAS)" = x; then :; else \
212			for lc in $(HELP_LINGUAS); do \
213				for x in \
214					$(HELP_FILES) \
215					"$$lc.stamp" \
216					"$$lc.mo" \
217				; do echo "/$$lc/$$x"; done; \
218			done; \
219		fi; \
220		if test "x$(gsettings_SCHEMAS)" = x; then :; else \
221			for x in \
222				$(gsettings_SCHEMAS:.xml=.valid) \
223				$(gsettings__enum_file) \
224			; do echo "/$$x"; done; \
225		fi; \
226		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; \
236		if test -f $(srcdir)/po/Makefile.in.in; then \
237			for x in \
238				po/Makefile.in.in \
239				po/Makefile.in.in~ \
240				po/Makefile.in \
241				po/Makefile \
242				po/Makevars.template \
243				po/POTFILES \
244				po/Rules-quot \
245				po/stamp-it \
246				po/.intltool-merge-cache \
247				"po/*.gmo" \
248				"po/*.header" \
249				"po/*.mo" \
250				"po/*.sed" \
251				"po/*.sin" \
252				po/$(GETTEXT_PACKAGE).pot \
253				intltool-extract.in \
254				intltool-merge.in \
255				intltool-update.in \
256			; do echo "/$$x"; done; \
257		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 \
266			; do echo "/$$x"; done; \
267		fi; \
268		if test "x$(DEJATOOL)" = x; then :; else \
269			for x in \
270				$(DEJATOOL) \
271			; do echo "/$$x.sum"; echo "/$$x.log"; done; \
272			echo /site.exp; \
273		fi; \
274		if test "x$(am__dirstamp)" = x; then :; else \
275			echo "$(am__dirstamp)"; \
276		fi; \
277		if test "x$(LTCOMPILE)" = x -a "x$(LTCXXCOMPILE)" = x -a "x$(GTKDOC_RUN)" = x; then :; else \
278			for x in \
279				"*.lo" \
280				".libs" "_libs" \
281			; do echo "$$x"; done; \
282		fi; \
283		for x in \
284			.gitignore \
285			$(GITIGNOREFILES) \
286			$(CLEANFILES) \
287			$(PROGRAMS) $(check_PROGRAMS) $(EXTRA_PROGRAMS) \
288			$(LIBRARIES) $(check_LIBRARIES) $(EXTRA_LIBRARIES) \
289			$(LTLIBRARIES) $(check_LTLIBRARIES) $(EXTRA_LTLIBRARIES) \
290			so_locations \
291			$(MOSTLYCLEANFILES) \
292			$(TEST_LOGS) \
293			$(TEST_LOGS:.log=.trs) \
294			$(TEST_SUITE_LOG) \
295			$(TESTS:=.test) \
296			"*.gcda" \
297			"*.gcno" \
298			$(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) \
305			$(patsubst %.vala,%.c,$(filter %.vala,$(SOURCES))) \
306			$(filter %_vala.stamp,$(DIST_COMMON)) \
307			$(filter %.vapi,$(DIST_COMMON)) \
308			$(filter $(addprefix %,$(notdir $(patsubst %.vapi,%.h,$(filter %.vapi,$(DIST_COMMON))))),$(DIST_COMMON)) \
309			Makefile \
310			Makefile.in \
311			"*.orig" \
312			"*.rej" \
313			"*.bak" \
314			"*~" \
315			".*.sw[nop]" \
316			".dirstamp" \
317		; do echo "/$$x"; done; \
318		for x in \
319			"*.$(OBJEXT)" \
320			$(DEPDIR) \
321		; do echo "$$x"; done; \
322	} | \
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
329gitignore: $(srcdir)/.gitignore gitignore-recurse
330
331gitignore-recurse-maybe:
332	@for subdir in $(DIST_SUBDIRS); do \
333	  case " $(SUBDIRS) " in \
334	    *" $$subdir "*) :;; \
335	    *) test "$$subdir" = . -o -e "$$subdir/.git" || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) gitignore || echo "Skipping $$subdir");; \
336	  esac; \
337	done
338gitignore-recurse:
339	@for subdir in $(DIST_SUBDIRS); do \
340	    test "$$subdir" = . -o -e "$$subdir/.git" || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) gitignore || echo "Skipping $$subdir"); \
341	done
342
343maintainer-clean: gitignore-clean
344gitignore-clean:
345	-rm -f $(srcdir)/.gitignore
346
347.PHONY: gitignore-clean gitignore gitignore-recurse gitignore-recurse-maybe
348