1 # git.mk, a small Makefile to autogenerate .gitignore files
2 # for autotools-based projects.
4 # Copyright 2009, Red Hat, Inc.
5 # Copyright 2010,2011,2012,2013 Behdad Esfahbod
6 # Written by Behdad Esfahbod
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.
12 # The latest version of this file can be downloaded from:
13 GIT_MK_URL = https://raw.githubusercontent.com/behdad/git.mk/master/git.mk
15 # Bugs, etc, should be reported upstream at:
16 # https://github.com/behdad/git.mk
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
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.
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.
34 # Note that for files like editor backup, etc, there are better places to
35 # ignore them. See "man gitignore".
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.
42 # For a list of toplevel files that should be in MAINTAINERCLEANFILES, see
43 # Makefile.am.sample in the git.mk git repo.
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
49 # This file knows how to handle autoconf, automake, libtool, gtk-doc,
50 # gnome-doc-utils, yelp.m4, mallard, intltool, gsettings, dejagnu, appdata,
53 # This makefile provides the following targets:
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.
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
72 ###############################################################################
73 # Variables user modules may want to add to toplevel MAINTAINERCLEANFILES:
74 ###############################################################################
77 # Most autotools-using modules should be fine including this variable in their
78 # toplevel MAINTAINERCLEANFILES:
79 GITIGNORE_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); \
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`
101 # All modules should also be fine including the following variable, which
102 # removes automake-generated Makefile.in files:
103 GITIGNORE_MAINTAINERCLEANFILES_MAKEFILE_IN = \
104 `cd $(top_srcdir); $(AUTOCONF) --trace 'AC_CONFIG_FILES:$$1' ./configure.ac | \
106 case $$f in Makefile|*/Makefile) \
107 test -f "$(srcdir)/$$f.am" && echo "$(srcdir)/$$f.in";; esac; \
110 # Modules that use libtool and use AC_CONFIG_MACRO_DIR() may also include this,
111 # though it's harmless to include regardless.
112 GITIGNORE_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 \
121 ; do echo "$$MACRO_DIR/$$x"; done; \
126 ###############################################################################
127 # Default rule is to install ourselves in all Makefile.am files:
128 ###############################################################################
130 git-all: git-mk-install
133 @echo "Installing git makefile"
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"; \
140 echo "Updating $$x"; \
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; \
148 if test x$$failed = x; then : else \
149 echo "Failed updating $$x"; >&2 \
152 fi; done; test -z "$$any_failed"
155 wget $(GIT_MK_URL) -O $(top_srcdir)/git.mk
157 .PHONY: git-all git-mk-install git-mk-update
161 ###############################################################################
162 # Actual .gitignore generation:
163 ###############################################################################
165 $(srcdir)/.gitignore: Makefile.am $(top_srcdir)/git.mk
166 @echo "git.mk: Generating $@"
168 if test "x$(DOC_MODULE)" = x -o "x$(DOC_MAIN_SGML_FILE)" = x; then :; else \
170 $(DOC_MODULE)-decl-list.txt \
171 $(DOC_MODULE)-decl.txt \
172 tmpl/$(DOC_MODULE)-unused.sgml \
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"; \
183 if echo "$(SCAN_OPTIONS)" | grep -q "\-\-rebuild-sections"; then \
184 echo "/$(DOC_MODULE)-sections.txt"; \
186 if test "$(abs_srcdir)" != "$(abs_builddir)" ; then \
189 $(DOC_MODULE).types \
190 ; do echo "/$$x"; done; \
193 if test "x$(DOC_MODULE)$(DOC_ID)" = x -o "x$(DOC_LINGUAS)" = x; then :; else \
194 for lc in $(DOC_LINGUAS); do \
196 $(if $(DOC_MODULE),$(DOC_MODULE).xml) \
199 ; do echo "/$$lc/$$x"; done; \
209 ; do echo /$$x; done; \
211 if test "x$(HELP_ID)" = x -o "x$(HELP_LINGUAS)" = x; then :; else \
212 for lc in $(HELP_LINGUAS); do \
217 ; do echo "/$$lc/$$x"; done; \
220 if test "x$(gsettings_SCHEMAS)" = x; then :; else \
222 $(gsettings_SCHEMAS:.xml=.valid) \
223 $(gsettings__enum_file) \
224 ; do echo "/$$x"; done; \
226 if test "x$(appdata_XML)" = x; then :; else \
228 $(appdata_XML:.xml=.valid) \
229 ; do echo "/$$x"; done; \
231 if test "x$(appstream_XML)" = x; then :; else \
233 $(appstream_XML:.xml=.valid) \
234 ; do echo "/$$x"; done; \
236 if test -f $(srcdir)/po/Makefile.in.in; then \
242 po/Makevars.template \
247 po/.intltool-merge-cache \
253 po/$(GETTEXT_PACKAGE).pot \
254 intltool-extract.in \
257 ; do echo "/$$x"; done; \
259 if test -f $(srcdir)/configure; then \
267 ; do echo "/$$x"; done; \
269 if test "x$(DEJATOOL)" = x; then :; else \
272 ; do echo "/$$x.sum"; echo "/$$x.log"; done; \
275 if test "x$(am__dirstamp)" = x; then :; else \
276 echo "$(am__dirstamp)"; \
278 if test "x$(findstring libtool,$(LTCOMPILE))" = x -a "x$(findstring libtool,$(LTCXXCOMPILE))" = x -a "x$(GTKDOC_RUN)" = x; then :; else \
282 ; do echo "$$x"; done; \
288 $(PROGRAMS) $(check_PROGRAMS) $(EXTRA_PROGRAMS) \
289 $(LIBRARIES) $(check_LIBRARIES) $(EXTRA_LIBRARIES) \
290 $(LTLIBRARIES) $(check_LTLIBRARIES) $(EXTRA_LTLIBRARIES) \
292 $(MOSTLYCLEANFILES) \
294 $(TEST_LOGS:.log=.trs) \
300 $(am__CONFIG_DISTCLEAN_FILES) \
301 $(CONFIG_CLEAN_FILES) \
302 TAGS ID GTAGS GRTAGS GSYMS GPATH tags \
304 $(MAINTAINERCLEANFILES) \
306 $(patsubst %.vala,%.c,$(filter %.vala,$(SOURCES))) \
307 $(filter %_vala.stamp,$(DIST_COMMON)) \
308 $(filter %.vapi,$(DIST_COMMON)) \
309 $(filter $(addprefix %,$(notdir $(patsubst %.vapi,%.h,$(filter %.vapi,$(DIST_COMMON))))),$(DIST_COMMON)) \
318 ; do echo "/$$x"; done; \
322 ; do echo "$$x"; done; \
324 sed "s@^/`echo "$(srcdir)" | sed 's/\(.\)/[\1]/g'`/@/@" | \
325 sed 's@/[.]/@/@g' | \
326 LC_ALL=C sort | uniq > $@.tmp && \
329 all: $(srcdir)/.gitignore gitignore-recurse-maybe
330 gitignore: $(srcdir)/.gitignore gitignore-recurse
332 gitignore-recurse-maybe:
333 @for subdir in $(DIST_SUBDIRS); do \
334 case " $(SUBDIRS) " in \
335 *" $$subdir "*) :;; \
336 *) test "$$subdir" = . -o -e "$$subdir/.git" || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) gitignore || echo "Skipping $$subdir");; \
340 @for subdir in $(DIST_SUBDIRS); do \
341 test "$$subdir" = . -o -e "$$subdir/.git" || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) gitignore || echo "Skipping $$subdir"); \
344 maintainer-clean: gitignore-clean
346 -rm -f $(srcdir)/.gitignore
348 .PHONY: gitignore-clean gitignore gitignore-recurse gitignore-recurse-maybe