git.mk 10.5 KB
Newer Older
1 2 3
# git.mk
#
# Copyright 2009, Red Hat, Inc.
Jasper St. Pierre's avatar
Jasper St. Pierre committed
4
# Copyright 2010,2011,2012,2013 Behdad Esfahbod
5 6 7
# Written by Behdad Esfahbod
#
# Copying and distribution of this file, with or without modification,
Jasper St. Pierre's avatar
Jasper St. Pierre committed
8
# is permitted in any medium without royalty provided the copyright
9 10
# notice and this notice are preserved.
#
Jasper St. Pierre's avatar
Jasper St. Pierre committed
11 12 13 14
# The latest version of this file can be downloaded from:
#   https://raw.github.com/behdad/git.mk/master/git.mk
# Bugs, etc, should be reported upstream at:
#   https://github.com/behdad/git.mk
15 16 17
#
# To use in your project, import this file in your git repo's toplevel,
# then do "make -f git.mk".  This modifies all Makefile.am files in
Jasper St. Pierre's avatar
Jasper St. Pierre committed
18 19 20
# your project to -include git.mk.  Remember to add that line to new
# Makefile.am files you create in your project, or just rerun the
# "make -f git.mk".
21 22 23 24 25 26 27 28 29
#
# This enables automatic .gitignore generation.  If you need to ignore
# more files, add them to the GITIGNOREFILES variable in your Makefile.am.
# But think twice before doing that.  If a file has to be in .gitignore,
# chances are very high that it's a generated file and should be in one
# of MOSTLYCLEANFILES, CLEANFILES, DISTCLEANFILES, or MAINTAINERCLEANFILES.
#
# The only case that you need to manually add a file to GITIGNOREFILES is
# when remove files in one of mostlyclean-local, clean-local, distclean-local,
Jasper St. Pierre's avatar
Jasper St. Pierre committed
30
# or maintainer-clean-local make targets.
31 32 33 34 35 36 37
#
# Note that for files like editor backup, etc, there are better places to
# ignore them.  See "man gitignore".
#
# If "make maintainer-clean" removes the files but they are not recognized
# by this script (that is, if "git status" shows untracked files still), send
# me the output of "git status" as well as your Makefile.am and Makefile for
Jasper St. Pierre's avatar
Jasper St. Pierre committed
38
# the directories involved and I'll diagnose.
39 40
#
# For a list of toplevel files that should be in MAINTAINERCLEANFILES, see
Jasper St. Pierre's avatar
Jasper St. Pierre committed
41
# Makefile.am.sample in the git.mk git repo.
42 43 44 45 46 47
#
# Don't EXTRA_DIST this file.  It is supposed to only live in git clones,
# not tarballs.  It serves no useful purpose in tarballs and clutters the
# build dir.
#
# This file knows how to handle autoconf, automake, libtool, gtk-doc,
Jasper St. Pierre's avatar
Jasper St. Pierre committed
48 49
# gnome-doc-utils, yelp.m4, mallard, intltool, gsettings, dejagnu, appdata,
# appstream.
50
#
Jasper St. Pierre's avatar
Jasper St. Pierre committed
51 52 53 54 55 56
# This makefile provides the following targets:
#
# - all: "make all" will build all gitignore files.
# - gitignore: makes all gitignore files in the current dir and subdirs.
# - .gitignore: make gitignore file for the current dir.
# - gitignore-recurse: makes all gitignore files in the subdirs.
57 58 59 60 61 62 63 64 65 66 67
#
# KNOWN ISSUES:
#
# - Recursive configure doesn't work as $(top_srcdir)/git.mk inside the
#   submodule doesn't find us.  If you have configure.{in,ac} files in
#   subdirs, add a proxy git.mk file in those dirs that simply does:
#   "include $(top_srcdir)/../git.mk".  Add more ..'s to your taste.
#   And add those files to git.  See vte/gnome-pty-helper/git.mk for
#   example.
#

Jasper St. Pierre's avatar
Jasper St. Pierre committed
68 69 70 71 72 73 74 75 76 77 78 79 80


###############################################################################
# Variables user modules may want to add to toplevel MAINTAINERCLEANFILES:
###############################################################################

#
# Most autotools-using modules should be fine including this variable in their
# toplevel MAINTAINERCLEANFILES:
GITIGNORE_MAINTAINERCLEANFILES_TOPLEVEL = \
	$(srcdir)/aclocal.m4 \
	$(srcdir)/autoscan.log \
	$(srcdir)/configure.scan \
Jasper St. Pierre's avatar
Jasper St. Pierre committed
81 82 83
	`AUX_DIR=$(srcdir)/$$(cd $(top_srcdir); $(AUTOCONF) --trace 'AC_CONFIG_AUX_DIR:$$1' ./configure.ac); \
	 test "x$$AUX_DIR" = "x$(srcdir)/" && AUX_DIR=$(srcdir); \
	 for x in \
84 85 86 87
		ar-lib \
		compile \
		config.guess \
		config.sub \
88
		config.rpath \
89 90 91 92 93
		depcomp \
		install-sh \
		ltmain.sh \
		missing \
		mkinstalldirs \
Jasper St. Pierre's avatar
Jasper St. Pierre committed
94
		test-driver \
Jasper St. Pierre's avatar
Jasper St. Pierre committed
95
		ylwrap \
96
	 ; do echo "$$AUX_DIR/$$x"; done` \
Jasper St. Pierre's avatar
Jasper St. Pierre committed
97
	`cd $(top_srcdir); $(AUTOCONF) --trace 'AC_CONFIG_HEADERS:$$1' ./configure.ac | \
98
	head -n 1 | while read f; do echo "$(srcdir)/$$f.in"; done`
Jasper St. Pierre's avatar
Jasper St. Pierre committed
99 100 101 102
#
# All modules should also be fine including the following variable, which
# removes automake-generated Makefile.in files:
GITIGNORE_MAINTAINERCLEANFILES_MAKEFILE_IN = \
Jasper St. Pierre's avatar
Jasper St. Pierre committed
103
	`cd $(top_srcdir); $(AUTOCONF) --trace 'AC_CONFIG_FILES:$$1' ./configure.ac | \
Jasper St. Pierre's avatar
Jasper St. Pierre committed
104 105 106 107 108
	while read f; do \
	  case $$f in Makefile|*/Makefile) \
	    test -f "$(srcdir)/$$f.am" && echo "$(srcdir)/$$f.in";; esac; \
	done`
#
Jasper St. Pierre's avatar
Jasper St. Pierre committed
109 110
# Modules that use libtool and use  AC_CONFIG_MACRO_DIR() may also include this,
# though it's harmless to include regardless.
Jasper St. Pierre's avatar
Jasper St. Pierre committed
111
GITIGNORE_MAINTAINERCLEANFILES_M4_LIBTOOL = \
Jasper St. Pierre's avatar
Jasper St. Pierre committed
112 113 114 115 116 117 118 119 120 121
	`MACRO_DIR=$(srcdir)/$$(cd $(top_srcdir); $(AUTOCONF) --trace 'AC_CONFIG_MACRO_DIR:$$1' ./configure.ac); \
	 if test "x$$MACRO_DIR" != "x$(srcdir)/"; then \
		for x in \
			libtool.m4 \
			ltoptions.m4 \
			ltsugar.m4 \
			ltversion.m4 \
			lt~obsolete.m4 \
		; do echo "$$MACRO_DIR/$$x"; done; \
	 fi`
Jasper St. Pierre's avatar
Jasper St. Pierre committed
122 123 124 125 126 127 128



###############################################################################
# Default rule is to install ourselves in all Makefile.am files:
###############################################################################

129 130 131
git-all: git-mk-install

git-mk-install:
Jasper St. Pierre's avatar
Jasper St. Pierre committed
132
	@echo "Installing git makefile"
Jasper St. Pierre's avatar
Jasper St. Pierre committed
133 134
	@any_failed=; \
		find "`test -z "$(top_srcdir)" && echo . || echo "$(top_srcdir)"`" -name Makefile.am | while read x; do \
135
		if grep 'include .*/git.mk' $$x >/dev/null; then \
Jasper St. Pierre's avatar
Jasper St. Pierre committed
136
			echo "$$x already includes git.mk"; \
137 138 139 140 141 142 143 144 145 146 147
		else \
			failed=; \
			echo "Updating $$x"; \
			{ cat $$x; \
			  echo ''; \
			  echo '-include $$(top_srcdir)/git.mk'; \
			} > $$x.tmp || failed=1; \
			if test x$$failed = x; then \
				mv $$x.tmp $$x || failed=1; \
			fi; \
			if test x$$failed = x; then : else \
Jasper St. Pierre's avatar
Jasper St. Pierre committed
148
				echo "Failed updating $$x"; >&2 \
149 150 151 152 153 154 155
				any_failed=1; \
			fi; \
	fi; done; test -z "$$any_failed"

.PHONY: git-all git-mk-install


Jasper St. Pierre's avatar
Jasper St. Pierre committed
156 157 158 159

###############################################################################
# Actual .gitignore generation:
###############################################################################
160 161

$(srcdir)/.gitignore: Makefile.am $(top_srcdir)/git.mk
Jasper St. Pierre's avatar
Jasper St. Pierre committed
162 163
	@echo "git.mk: Generating $@"
	@{ \
164 165 166 167 168 169 170
		if test "x$(DOC_MODULE)" = x -o "x$(DOC_MAIN_SGML_FILE)" = x; then :; else \
			for x in \
				$(DOC_MODULE)-decl-list.txt \
				$(DOC_MODULE)-decl.txt \
				tmpl/$(DOC_MODULE)-unused.sgml \
				"tmpl/*.bak" \
				xml html \
Jasper St. Pierre's avatar
Jasper St. Pierre committed
171
			; do echo "/$$x"; done; \
Jasper St. Pierre's avatar
Jasper St. Pierre committed
172 173
			FLAVOR=$$(cd $(top_srcdir); $(AUTOCONF) --trace 'GTK_DOC_CHECK:$$2' ./configure.ac); \
			case $$FLAVOR in *no-tmpl*) echo /tmpl;; esac; \
174
		fi; \
Jasper St. Pierre's avatar
Jasper St. Pierre committed
175 176 177 178 179 180
		if test "x$(DOC_MODULE)$(DOC_ID)" = x -o "x$(DOC_LINGUAS)" = x; then :; else \
			for lc in $(DOC_LINGUAS); do \
				for x in \
					$(if $(DOC_MODULE),$(DOC_MODULE).xml) \
					$(DOC_PAGES) \
					$(DOC_INCLUDES) \
Jasper St. Pierre's avatar
Jasper St. Pierre committed
181
				; do echo "/$$lc/$$x"; done; \
Jasper St. Pierre's avatar
Jasper St. Pierre committed
182
			done; \
183 184 185 186
			for x in \
				$(_DOC_OMF_ALL) \
				$(_DOC_DSK_ALL) \
				$(_DOC_HTML_ALL) \
Jasper St. Pierre's avatar
Jasper St. Pierre committed
187 188
				$(_DOC_MOFILES) \
				$(DOC_H_FILE) \
189 190 191 192
				"*/.xml2po.mo" \
				"*/*.omf.out" \
			; do echo /$$x; done; \
		fi; \
Jasper St. Pierre's avatar
Jasper St. Pierre committed
193 194 195 196 197 198
		if test "x$(HELP_ID)" = x -o "x$(HELP_LINGUAS)" = x; then :; else \
			for lc in $(HELP_LINGUAS); do \
				for x in \
					$(HELP_FILES) \
					"$$lc.stamp" \
					"$$lc.mo" \
Jasper St. Pierre's avatar
Jasper St. Pierre committed
199
				; do echo "/$$lc/$$x"; done; \
Jasper St. Pierre's avatar
Jasper St. Pierre committed
200 201 202 203 204 205
			done; \
		fi; \
		if test "x$(gsettings_SCHEMAS)" = x; then :; else \
			for x in \
				$(gsettings_SCHEMAS:.xml=.valid) \
				$(gsettings__enum_file) \
Jasper St. Pierre's avatar
Jasper St. Pierre committed
206
			; do echo "/$$x"; done; \
Jasper St. Pierre's avatar
Jasper St. Pierre committed
207
		fi; \
Jasper St. Pierre's avatar
Jasper St. Pierre committed
208 209 210 211 212
		if test "x$(appdata_XML)" = x; then :; else \
			for x in \
				$(appdata_XML:.xml=.valid) \
			; do echo "/$$x"; done; \
		fi; \
Jasper St. Pierre's avatar
Jasper St. Pierre committed
213 214 215 216 217
		if test "x$(appstream_XML)" = x; then :; else \
			for x in \
				$(appstream_XML:.xml=.valid) \
			; do echo "/$$x"; done; \
		fi; \
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
		for tdir in po $(GITIGNORE_TRANSLATION_DIRS); do \
			if test -f "$(srcdir)/$$tdir/Makefile.in.in"; then \
				for x in \
					$$tdir/Makefile.in.in \
					$$tdir/Makefile.in.in~ \
					$$tdir/Makefile.in \
					$$tdir/Makefile \
					$$tdir/Makevars.template \
					$$tdir/POTFILES \
					$$tdir/Rules-quot \
					$$tdir/stamp-it \
					$$tdir/stamp-po \
					$$tdir/.intltool-merge-cache \
					"$$tdir/*.gmo" \
					"$$tdir/*.header" \
					"$$tdir/*.mo" \
					"$$tdir/*.sed" \
					"$$tdir/*.sin" \
					$$tdir/$(GETTEXT_PACKAGE).pot \
				; do echo "/$$x"; done; \
			fi; \
239
			for x in \
240
				ABOUT-NLS \
241 242 243
				intltool-extract.in \
				intltool-merge.in \
				intltool-update.in \
Jasper St. Pierre's avatar
Jasper St. Pierre committed
244
			; do echo "/$$x"; done; \
245
		done; \
246 247 248 249 250 251 252 253
		if test -f $(srcdir)/configure; then \
			for x in \
				autom4te.cache \
				configure \
				config.h \
				stamp-h1 \
				libtool \
				config.lt \
Jasper St. Pierre's avatar
Jasper St. Pierre committed
254
			; do echo "/$$x"; done; \
255
		fi; \
Jasper St. Pierre's avatar
Jasper St. Pierre committed
256 257 258
		if test "x$(DEJATOOL)" = x; then :; else \
			for x in \
				$(DEJATOOL) \
Jasper St. Pierre's avatar
Jasper St. Pierre committed
259
			; do echo "/$$x.sum"; echo "/$$x.log"; done; \
Jasper St. Pierre's avatar
Jasper St. Pierre committed
260 261
			echo /site.exp; \
		fi; \
Jasper St. Pierre's avatar
Jasper St. Pierre committed
262 263 264
		if test "x$(am__dirstamp)" = x; then :; else \
			echo "$(am__dirstamp)"; \
		fi; \
Jasper St. Pierre's avatar
Jasper St. Pierre committed
265
		if test "x$(LTCOMPILE)" = x -a "x$(LTCXXCOMPILE)" = x -a "x$(GTKDOC_RUN)" = x; then :; else \
Jasper St. Pierre's avatar
Jasper St. Pierre committed
266 267 268 269 270
			for x in \
				"*.lo" \
				".libs" "_libs" \
			; do echo "$$x"; done; \
		fi; \
271 272 273 274
		for x in \
			.gitignore \
			$(GITIGNOREFILES) \
			$(CLEANFILES) \
Jasper St. Pierre's avatar
Jasper St. Pierre committed
275 276 277
			$(PROGRAMS) $(check_PROGRAMS) $(EXTRA_PROGRAMS) \
			$(LIBRARIES) $(check_LIBRARIES) $(EXTRA_LIBRARIES) \
			$(LTLIBRARIES) $(check_LTLIBRARIES) $(EXTRA_LTLIBRARIES) \
278 279
			so_locations \
			$(MOSTLYCLEANFILES) \
Jasper St. Pierre's avatar
Jasper St. Pierre committed
280 281 282 283 284
			$(TEST_LOGS) \
			$(TEST_LOGS:.log=.trs) \
			$(TEST_SUITE_LOG) \
			"*.gcda" \
			"*.gcno" \
285 286 287 288 289 290 291
			$(DISTCLEANFILES) \
			$(am__CONFIG_DISTCLEAN_FILES) \
			$(CONFIG_CLEAN_FILES) \
			TAGS ID GTAGS GRTAGS GSYMS GPATH tags \
			"*.tab.c" \
			$(MAINTAINERCLEANFILES) \
			$(BUILT_SOURCES) \
Jasper St. Pierre's avatar
Jasper St. Pierre committed
292 293 294 295
			$(patsubst %.vala,%.c,$(filter %.vala,$(SOURCES))) \
			$(filter %_vala.stamp,$(DIST_COMMON)) \
			$(filter %.vapi,$(DIST_COMMON)) \
			$(filter $(addprefix %,$(notdir $(patsubst %.vapi,%.h,$(filter %.vapi,$(DIST_COMMON))))),$(DIST_COMMON)) \
296 297 298 299 300 301 302
			Makefile \
			Makefile.in \
			"*.orig" \
			"*.rej" \
			"*.bak" \
			"*~" \
			".*.sw[nop]" \
Jasper St. Pierre's avatar
Jasper St. Pierre committed
303
			".dirstamp" \
Jasper St. Pierre's avatar
Jasper St. Pierre committed
304
		; do echo "/$$x"; done; \
Jasper St. Pierre's avatar
Jasper St. Pierre committed
305 306 307 308
		for x in \
			"*.$(OBJEXT)" \
			$(DEPDIR) \
		; do echo "$$x"; done; \
309 310 311
	} | \
	sed "s@^/`echo "$(srcdir)" | sed 's/\(.\)/[\1]/g'`/@/@" | \
	sed 's@/[.]/@/@g' | \
312
	LC_ALL=C sort | uniq > $@.tmp && \
313 314 315
	mv $@.tmp $@;

all: $(srcdir)/.gitignore gitignore-recurse-maybe
Jasper St. Pierre's avatar
Jasper St. Pierre committed
316 317
gitignore: $(srcdir)/.gitignore gitignore-recurse

318
gitignore-recurse-maybe:
319 320 321
	@for subdir in $(DIST_SUBDIRS); do \
	  case " $(SUBDIRS) " in \
	    *" $$subdir "*) :;; \
Jasper St. Pierre's avatar
Jasper St. Pierre committed
322
	    *) test "$$subdir" = . -o -e "$$subdir/.git" || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) gitignore || echo "Skipping $$subdir");; \
323
	  esac; \
324
	done
Jasper St. Pierre's avatar
Jasper St. Pierre committed
325 326
gitignore-recurse:
	@for subdir in $(DIST_SUBDIRS); do \
Jasper St. Pierre's avatar
Jasper St. Pierre committed
327
	    test "$$subdir" = . -o -e "$$subdir/.git" || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) gitignore || echo "Skipping $$subdir"); \
Jasper St. Pierre's avatar
Jasper St. Pierre committed
328
	done
329 330 331 332 333 334

maintainer-clean: gitignore-clean
gitignore-clean:
	-rm -f $(srcdir)/.gitignore

.PHONY: gitignore-clean gitignore gitignore-recurse gitignore-recurse-maybe