• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, hotdoc.
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.rpath \
90		config.sub \
91		depcomp \
92		install-sh \
93		ltmain.sh \
94		missing \
95		mkinstalldirs \
96		test-driver \
97		ylwrap \
98	 ; do echo "$$AUX_DIR/$$x"; done` \
99	`cd $(top_srcdir); $(AUTOCONF) --trace 'AC_CONFIG_HEADERS:$$1' ./configure.ac | \
100	head -n 1 | while read f; do echo "$(srcdir)/$$f.in"; done`
101#
102# All modules should also be fine including the following variable, which
103# removes automake-generated Makefile.in files:
104GITIGNORE_MAINTAINERCLEANFILES_MAKEFILE_IN = \
105	`cd $(top_srcdir); $(AUTOCONF) --trace 'AC_CONFIG_FILES:$$1' ./configure.ac | \
106	while read f; do \
107	  case $$f in Makefile|*/Makefile) \
108	    test -f "$(srcdir)/$$f.am" && echo "$(srcdir)/$$f.in";; esac; \
109	done`
110#
111# Modules that use libtool and use  AC_CONFIG_MACRO_DIR() may also include this,
112# though it's harmless to include regardless.
113GITIGNORE_MAINTAINERCLEANFILES_M4_LIBTOOL = \
114	`MACRO_DIR=$(srcdir)/$$(cd $(top_srcdir); $(AUTOCONF) --trace 'AC_CONFIG_MACRO_DIR:$$1' ./configure.ac); \
115	 if test "x$$MACRO_DIR" != "x$(srcdir)/"; then \
116		for x in \
117			libtool.m4 \
118			ltoptions.m4 \
119			ltsugar.m4 \
120			ltversion.m4 \
121			lt~obsolete.m4 \
122		; do echo "$$MACRO_DIR/$$x"; done; \
123	 fi`
124#
125# Modules that use gettext and use  AC_CONFIG_MACRO_DIR() may also include this,
126# though it's harmless to include regardless.
127GITIGNORE_MAINTAINERCLEANFILES_M4_GETTEXT = \
128	`MACRO_DIR=$(srcdir)/$$(cd $(top_srcdir); $(AUTOCONF) --trace 'AC_CONFIG_MACRO_DIR:$$1' ./configure.ac); \
129	if test "x$$MACRO_DIR" != "x$(srcdir)/"; then	\
130		for x in				\
131			codeset.m4			\
132			extern-inline.m4		\
133			fcntl-o.m4			\
134			gettext.m4			\
135			glibc2.m4			\
136			glibc21.m4			\
137			iconv.m4			\
138			intdiv0.m4			\
139			intl.m4				\
140			intldir.m4			\
141			intlmacosx.m4			\
142			intmax.m4			\
143			inttypes-pri.m4			\
144			inttypes_h.m4			\
145			lcmessage.m4			\
146			lib-ld.m4			\
147			lib-link.m4			\
148			lib-prefix.m4			\
149			lock.m4				\
150			longlong.m4			\
151			nls.m4				\
152			po.m4				\
153			printf-posix.m4			\
154			progtest.m4			\
155			size_max.m4			\
156			stdint_h.m4			\
157			threadlib.m4			\
158			uintmax_t.m4			\
159			visibility.m4			\
160			wchar_t.m4			\
161			wint_t.m4			\
162			xsize.m4			\
163		; do echo "$$MACRO_DIR/$$x"; done; \
164	fi`
165
166
167
168###############################################################################
169# Default rule is to install ourselves in all Makefile.am files:
170###############################################################################
171
172git-all: git-mk-install
173
174git-mk-install:
175	@echo "Installing git makefile"
176	@any_failed=; \
177		find "`test -z "$(top_srcdir)" && echo . || echo "$(top_srcdir)"`" -name Makefile.am | while read x; do \
178		if grep 'include .*/git.mk' $$x >/dev/null; then \
179			echo "$$x already includes git.mk"; \
180		else \
181			failed=; \
182			echo "Updating $$x"; \
183			{ cat $$x; \
184			  echo ''; \
185			  echo '-include $$(top_srcdir)/git.mk'; \
186			} > $$x.tmp || failed=1; \
187			if test x$$failed = x; then \
188				mv $$x.tmp $$x || failed=1; \
189			fi; \
190			if test x$$failed = x; then : else \
191				echo "Failed updating $$x"; >&2 \
192				any_failed=1; \
193			fi; \
194	fi; done; test -z "$$any_failed"
195
196git-mk-update:
197	wget $(GIT_MK_URL) -O $(top_srcdir)/git.mk
198
199.PHONY: git-all git-mk-install git-mk-update
200
201
202
203###############################################################################
204# Actual .gitignore generation:
205###############################################################################
206
207$(srcdir)/.gitignore: Makefile.am $(top_srcdir)/git.mk
208	@echo "git.mk: Generating $@"
209	@{ \
210		if test "x$(DOC_MODULE)" = x -o "x$(DOC_MAIN_SGML_FILE)" = x; then :; else \
211			for x in \
212				$(DOC_MODULE)-decl-list.txt \
213				$(DOC_MODULE)-decl.txt \
214				tmpl/$(DOC_MODULE)-unused.sgml \
215				"tmpl/*.bak" \
216				$(REPORT_FILES) \
217				$(DOC_MODULE).pdf \
218				xml html \
219			; do echo "/$$x"; done; \
220			FLAVOR=$$(cd $(top_srcdir); $(AUTOCONF) --trace 'GTK_DOC_CHECK:$$2' ./configure.ac); \
221			case $$FLAVOR in *no-tmpl*) echo /tmpl;; esac; \
222			if echo "$(SCAN_OPTIONS)" | grep -q "\-\-rebuild-types"; then \
223				echo "/$(DOC_MODULE).types"; \
224			fi; \
225			if echo "$(SCAN_OPTIONS)" | grep -q "\-\-rebuild-sections"; then \
226				echo "/$(DOC_MODULE)-sections.txt"; \
227			fi; \
228			if test "$(abs_srcdir)" != "$(abs_builddir)" ; then \
229				for x in \
230					$(SETUP_FILES) \
231					$(DOC_MODULE).types \
232				; do echo "/$$x"; done; \
233			fi; \
234		fi; \
235		if test "x$(DOC_MODULE)$(DOC_ID)" = x -o "x$(DOC_LINGUAS)" = x; then :; else \
236			for lc in $(DOC_LINGUAS); do \
237				for x in \
238					$(if $(DOC_MODULE),$(DOC_MODULE).xml) \
239					$(DOC_PAGES) \
240					$(DOC_INCLUDES) \
241				; do echo "/$$lc/$$x"; done; \
242			done; \
243			for x in \
244				$(_DOC_OMF_ALL) \
245				$(_DOC_DSK_ALL) \
246				$(_DOC_HTML_ALL) \
247				$(_DOC_MOFILES) \
248				$(DOC_H_FILE) \
249				"*/.xml2po.mo" \
250				"*/*.omf.out" \
251			; do echo /$$x; done; \
252		fi; \
253		if test "x$(HOTDOC)" = x; then :; else \
254			$(foreach project, $(HOTDOC_PROJECTS),echo "/$(call HOTDOC_TARGET,$(project))"; \
255				echo "/$(shell $(call HOTDOC_PROJECT_COMMAND,$(project)) --get-conf-path output)" ; \
256				echo "/$(shell $(call HOTDOC_PROJECT_COMMAND,$(project)) --get-private-folder)" ; \
257			) \
258			for x in \
259				.hotdoc.d \
260			; do echo "/$$x"; done; \
261		fi; \
262		if test "x$(HELP_ID)" = x -o "x$(HELP_LINGUAS)" = x; then :; else \
263			for lc in $(HELP_LINGUAS); do \
264				for x in \
265					$(HELP_FILES) \
266					"$$lc.stamp" \
267					"$$lc.mo" \
268				; do echo "/$$lc/$$x"; done; \
269			done; \
270		fi; \
271		if test "x$(gsettings_SCHEMAS)" = x; then :; else \
272			for x in \
273				$(gsettings_SCHEMAS:.xml=.valid) \
274				$(gsettings__enum_file) \
275			; do echo "/$$x"; done; \
276		fi; \
277		if test "x$(appdata_XML)" = x; then :; else \
278			for x in \
279				$(appdata_XML:.xml=.valid) \
280			; do echo "/$$x"; done; \
281		fi; \
282		if test "x$(appstream_XML)" = x; then :; else \
283			for x in \
284				$(appstream_XML:.xml=.valid) \
285			; do echo "/$$x"; done; \
286		fi; \
287		if test -f $(srcdir)/po/Makefile.in.in; then \
288			for x in \
289				ABOUT-NLS \
290				po/Makefile.in.in \
291				po/Makefile.in.in~ \
292				po/Makefile.in \
293				po/Makefile \
294				po/Makevars.template \
295				po/POTFILES \
296				po/Rules-quot \
297				po/stamp-it \
298				po/stamp-po \
299				po/.intltool-merge-cache \
300				"po/*.gmo" \
301				"po/*.header" \
302				"po/*.mo" \
303				"po/*.sed" \
304				"po/*.sin" \
305				po/$(GETTEXT_PACKAGE).pot \
306				intltool-extract.in \
307				intltool-merge.in \
308				intltool-update.in \
309			; do echo "/$$x"; done; \
310		fi; \
311		if test -f $(srcdir)/configure; then \
312			for x in \
313				autom4te.cache \
314				configure \
315				config.h \
316				stamp-h1 \
317				libtool \
318				config.lt \
319			; do echo "/$$x"; done; \
320		fi; \
321		if test "x$(DEJATOOL)" = x; then :; else \
322			for x in \
323				$(DEJATOOL) \
324			; do echo "/$$x.sum"; echo "/$$x.log"; done; \
325			echo /site.exp; \
326		fi; \
327		if test "x$(am__dirstamp)" = x; then :; else \
328			echo "$(am__dirstamp)"; \
329		fi; \
330		if test "x$(findstring libtool,$(LTCOMPILE))" = x -a "x$(findstring libtool,$(LTCXXCOMPILE))" = x -a "x$(GTKDOC_RUN)" = x; then :; else \
331			for x in \
332				"*.lo" \
333				".libs" "_libs" \
334			; do echo "$$x"; done; \
335		fi; \
336		for x in \
337			.gitignore \
338			$(GITIGNOREFILES) \
339			$(CLEANFILES) \
340			$(PROGRAMS) $(check_PROGRAMS) $(EXTRA_PROGRAMS) \
341			$(LIBRARIES) $(check_LIBRARIES) $(EXTRA_LIBRARIES) \
342			$(LTLIBRARIES) $(check_LTLIBRARIES) $(EXTRA_LTLIBRARIES) \
343			so_locations \
344			$(MOSTLYCLEANFILES) \
345			$(TEST_LOGS) \
346			$(TEST_LOGS:.log=.trs) \
347			$(TEST_SUITE_LOG) \
348			$(TESTS:=.test) \
349			"*.gcda" \
350			"*.gcno" \
351			$(DISTCLEANFILES) \
352			$(am__CONFIG_DISTCLEAN_FILES) \
353			$(CONFIG_CLEAN_FILES) \
354			TAGS ID GTAGS GRTAGS GSYMS GPATH tags \
355			"*.tab.c" \
356			$(MAINTAINERCLEANFILES) \
357			$(BUILT_SOURCES) \
358			$(patsubst %.vala,%.c,$(filter %.vala,$(SOURCES))) \
359			$(filter %_vala.stamp,$(DIST_COMMON)) \
360			$(filter %.vapi,$(DIST_COMMON)) \
361			$(filter $(addprefix %,$(notdir $(patsubst %.vapi,%.h,$(filter %.vapi,$(DIST_COMMON))))),$(DIST_COMMON)) \
362			Makefile \
363			Makefile.in \
364			"*.orig" \
365			"*.rej" \
366			"*.bak" \
367			"*~" \
368			".*.sw[nop]" \
369			".dirstamp" \
370		; do echo "/$$x"; done; \
371		for x in \
372			"*.$(OBJEXT)" \
373			$(DEPDIR) \
374		; do echo "$$x"; done; \
375	} | \
376	sed "s@^/`echo "$(srcdir)" | sed 's/\(.\)/[\1]/g'`/@/@" | \
377	sed 's@/[.]/@/@g' | \
378	LC_ALL=C sort | uniq > $@.tmp && \
379	mv $@.tmp $@;
380
381all: $(srcdir)/.gitignore gitignore-recurse-maybe
382gitignore: $(srcdir)/.gitignore gitignore-recurse
383
384gitignore-recurse-maybe:
385	@for subdir in $(DIST_SUBDIRS); do \
386	  case " $(SUBDIRS) " in \
387	    *" $$subdir "*) :;; \
388	    *) test "$$subdir" = . -o -e "$$subdir/.git" || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) gitignore || echo "Skipping $$subdir");; \
389	  esac; \
390	done
391gitignore-recurse:
392	@for subdir in $(DIST_SUBDIRS); do \
393	    test "$$subdir" = . -o -e "$$subdir/.git" || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) gitignore || echo "Skipping $$subdir"); \
394	done
395
396maintainer-clean: gitignore-clean
397gitignore-clean:
398	-rm -f $(srcdir)/.gitignore
399
400.PHONY: gitignore-clean gitignore gitignore-recurse gitignore-recurse-maybe
401