From 77c1b7e352ecd2716aa7f70eaeebf3648dc6c7ae Mon Sep 17 00:00:00 2001
From: Alexandre Julliard <julliard@winehq.org>
Date: Fri, 26 Feb 2016 18:06:25 +0900
Subject: [PATCH] makefiles: Generate the top-level .gitignore and the
 distclean rules.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
---
 Makefile.in     |  2 +-
 aclocal.m4      | 28 +++--------------
 configure       | 80 ++++++++++---------------------------------------
 configure.ac    | 30 +------------------
 tools/makedep.c |  9 ++++--
 5 files changed, 28 insertions(+), 121 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index 8c2d8562366..d34acf198ff 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -96,6 +96,7 @@ LIBWINE_INSTALL_DEV = @LIBWINE_INSTALL_DEV@
 LIBWINE_LDFLAGS     = @LIBWINE_LDFLAGS@
 LIBWINE_DEPENDS     = @LIBWINE_DEPENDS@
 ALL_TEST_RESOURCES  = @ALL_TEST_RESOURCES@
+CONFIGURE_TARGETS   = @CONFIGURE_TARGETS@
 @ALL_VARS_RULES@
 @SET_MAKE@
 
@@ -117,7 +118,6 @@ include/stamp-h: $(srcdir)/include/config.h.in config.status
 
 clean:: __clean__
 distclean:: clean
-	$(RM) config.* configure.lineno TAGS tags include/config.h include/stamp-h Makefile Make.tmp .gitignore
 	$(RM) -r autom4te.cache documentation/html documentation/api-guide documentation/api-guide-xml documentation/man$(api_manext)
 
 # Rules for uninstalling
diff --git a/aclocal.m4 b/aclocal.m4
index abe5ca44874..81e6a44ad9b 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -199,8 +199,8 @@ dnl
 AC_DEFUN([WINE_CONFIG_HELPERS],
 [wine_rules_file=conf$$rules.make
 rm -f $wine_rules_file
-GITIGNORE="# Automatically generated by configure; DO NOT EDIT!!"
 AC_SUBST(SUBDIRS,"")
+AC_SUBST(CONFIGURE_TARGETS,"")
 AC_SUBST(ALL_TEST_RESOURCES,"")
 
 wine_fn_append_file ()
@@ -208,15 +208,6 @@ wine_fn_append_file ()
     AS_VAR_APPEND($[1]," \\$as_nl	$[2]")
 }
 
-wine_fn_ignore_file ()
-{
-    case "$[1]" in
-      */*) AS_VAR_APPEND([GITIGNORE],"$as_nl$[1]") ;;
-      \**) AS_VAR_APPEND([GITIGNORE],"$as_nl$[1]") ;;
-      *)   AS_VAR_APPEND([GITIGNORE],"$as_nl/$[1]") ;;
-    esac
-}
-
 wine_fn_append_rule ()
 {
     AS_ECHO("$[1]") >>$wine_rules_file
@@ -454,15 +445,6 @@ __uninstall__: $ac_dir/uninstall"
 $ac_file.cross.a: $srcdir/$ac_dir/$ac_name.spec \$(WINEBUILD)
 	\$(WINEBUILD) \$(CROSSTARGET:%=-b %)$ac_implibflags -w --implib -o \$[@] --export $srcdir/$ac_dir/$ac_name.spec"
         fi
-
-        if test "$ac_name" != "$ac_implib"
-        then
-            wine_fn_ignore_file "dlls/lib$ac_implib.$IMPLIBEXT"
-            if test -n "$CROSSTARGET" -a -z "$ac_implibflags"
-            then
-                wine_fn_ignore_file "dlls/lib$ac_implib.cross.a"
-            fi
-        fi
     fi
 }
 
@@ -594,10 +576,8 @@ wine_fn_config_symlink ()
     ac_links=$[@]
     wine_fn_append_rule \
 "$ac_links:
-	@./config.status \$[@]
-distclean::
-	\$(RM) $ac_links"
-    for f in $ac_links; do wine_fn_ignore_file $f; done
+	@./config.status \$[@]"
+    for f in $ac_links; do wine_fn_append_file CONFIGURE_TARGETS $f; done
     test -n "$ac_linkdir" || return
     wine_fn_append_rule "$ac_linkdir/depend: $ac_links"
 }])
@@ -692,7 +672,7 @@ dnl
 dnl Usage: WINE_IGNORE_FILE(file,enable)
 dnl
 AC_DEFUN([WINE_IGNORE_FILE],[AC_REQUIRE([WINE_CONFIG_HELPERS])dnl
-m4_ifval([$2],[test "x$[$2]" = xno || ])wine_fn_ignore_file $1])
+m4_ifval([$2],[test "x$[$2]" = xno || ])wine_fn_append_file CONFIGURE_TARGETS $1])
 
 dnl **** Add a message to the list displayed at the end ****
 dnl
diff --git a/configure b/configure
index 06c68322eb7..eddf07ba9c3 100755
--- a/configure
+++ b/configure
@@ -716,6 +716,7 @@ SOCKET_LIBS
 DLLTOOL
 WINELOADER_PROGRAMS
 ALL_TEST_RESOURCES
+CONFIGURE_TARGETS
 SUBDIRS
 READELF
 OTOOL
@@ -7414,9 +7415,10 @@ fi
 
 wine_rules_file=conf$$rules.make
 rm -f $wine_rules_file
-GITIGNORE="# Automatically generated by configure; DO NOT EDIT!!"
 SUBDIRS=""
 
+CONFIGURE_TARGETS=""
+
 ALL_TEST_RESOURCES=""
 
 
@@ -7425,15 +7427,6 @@ wine_fn_append_file ()
     as_fn_append $1 " \\$as_nl	$2"
 }
 
-wine_fn_ignore_file ()
-{
-    case "$1" in
-      */*) as_fn_append GITIGNORE "$as_nl$1" ;;
-      \**) as_fn_append GITIGNORE "$as_nl$1" ;;
-      *)   as_fn_append GITIGNORE "$as_nl/$1" ;;
-    esac
-}
-
 wine_fn_append_rule ()
 {
     $as_echo "$1" >>$wine_rules_file
@@ -7681,15 +7674,6 @@ __uninstall__: $ac_dir/uninstall"
 $ac_file.cross.a: $srcdir/$ac_dir/$ac_name.spec \$(WINEBUILD)
 	\$(WINEBUILD) \$(CROSSTARGET:%=-b %)$ac_implibflags -w --implib -o \$@ --export $srcdir/$ac_dir/$ac_name.spec"
         fi
-
-        if test "$ac_name" != "$ac_implib"
-        then
-            wine_fn_ignore_file "dlls/lib$ac_implib.$IMPLIBEXT"
-            if test -n "$CROSSTARGET" -a -z "$ac_implibflags"
-            then
-                wine_fn_ignore_file "dlls/lib$ac_implib.cross.a"
-            fi
-        fi
     fi
 }
 
@@ -7827,10 +7811,8 @@ wine_fn_config_symlink ()
     ac_links=$@
     wine_fn_append_rule \
 "$ac_links:
-	@./config.status \$@
-distclean::
-	\$(RM) $ac_links"
-    for f in $ac_links; do wine_fn_ignore_file $f; done
+	@./config.status \$@"
+    for f in $ac_links; do wine_fn_append_file CONFIGURE_TARGETS $f; done
     test -n "$ac_linkdir" || return
     wine_fn_append_rule "$ac_linkdir/depend: $ac_links"
 }
@@ -14949,7 +14931,7 @@ case $host_os in
   linux*)
     case $host_cpu in
       *i[3456789]86*|x86_64*)
-        test "$wine_binary" = wine || wine_fn_ignore_file "loader/wine-preloader"
+        test "$wine_binary" = wine || wine_fn_append_file CONFIGURE_TARGETS "loader/wine-preloader"
         WINELOADER_PROGRAMS="$WINELOADER_PROGRAMS $wine_binary-preloader"
         ;;
     esac
@@ -17263,10 +17245,6 @@ Makefile: $srcdir/Makefile.in config.status \$(MAKEDEP)
 depend: \$(MAKEDEP) dummy
 	\$(MAKEDEP)"
 
-test "$srcdir" = . && wine_fn_append_rule "all: .gitignore
-.gitignore: config.status
-	@./config.status .gitignore"
-
 test -n "$CROSSTARGET" || wine_fn_append_rule "crosstest:
 	@echo \"crosstest is not supported (mingw not installed?)\" && false"
 
@@ -18259,22 +18237,18 @@ zh_TW"
 
 
 
-wine_fn_ignore_file ".gitignore"
-wine_fn_ignore_file "Makefile"
-wine_fn_ignore_file "TAGS"
-wine_fn_ignore_file "tags"
-wine_fn_ignore_file "autom4te.cache"
-wine_fn_ignore_file "config.cache"
-wine_fn_ignore_file "config.log"
-wine_fn_ignore_file "config.status"
-wine_fn_ignore_file "configure.lineno"
-wine_fn_ignore_file "include/config.h"
-wine_fn_ignore_file "include/stamp-h"
-test "$wine_binary" = wine || wine_fn_ignore_file "loader/wine"
+wine_fn_append_file CONFIGURE_TARGETS "TAGS"
+wine_fn_append_file CONFIGURE_TARGETS "tags"
+wine_fn_append_file CONFIGURE_TARGETS "autom4te.cache"
+wine_fn_append_file CONFIGURE_TARGETS "config.log"
+wine_fn_append_file CONFIGURE_TARGETS "config.status"
+wine_fn_append_file CONFIGURE_TARGETS "include/config.h"
+wine_fn_append_file CONFIGURE_TARGETS "include/stamp-h"
+test "$wine_binary" = wine || wine_fn_append_file CONFIGURE_TARGETS "loader/wine"
 
 if test "x$enable_tools" != xno
 then
-    wine_fn_ignore_file "tools/makedep$ac_exeext"
+    wine_fn_append_file CONFIGURE_TARGETS "tools/makedep$ac_exeext"
     ac_config_commands="$ac_config_commands tools/makedep"
 
 fi
@@ -18298,18 +18272,11 @@ fi
 
 test "$MSGFMT" != false || LINGUAS=
 
-for i in $LINGUAS
-do
-    wine_fn_ignore_file "po/$i.mo"
-done
-
 if test "x$enable_tools" != xno
 then
     wine_fn_append_rule "tools/makedep$ac_exeext: $srcdir/tools/makedep.c include/config.h config.status
 	@./config.status tools/makedep
-Makefile: tools/makedep$ac_exeext
-distclean:: clean
-	\$(RM) tools/makedep$ac_exeext"
+Makefile: tools/makedep$ac_exeext"
 else
     wine_fn_append_rule "\$(MAKEDEP):
 	@echo \"You need to run make in $TOOLSDIR first\" && false"
@@ -18342,12 +18309,6 @@ uninstall::
     esac
 fi
 
-if test "$srcdir" = .
-then
-    ac_config_commands="$ac_config_commands .gitignore"
-
-fi
-
 $as_echo " done" >&6
 cat >confcache <<\_ACEOF
 # This file is a shell script that caches the results of configure
@@ -19054,13 +19015,6 @@ wine_fn_output_makefile ()
 _WINE_EOF
     as_fn_error $? "could not create Makefile" "$LINENO" 5
 }
-wine_fn_output_gitignore ()
-{
-    sort <<\_WINE_EOF >\$tmp/gitignore && mv -f \$tmp/gitignore \$1 && return
-$GITIGNORE
-_WINE_EOF
-    as_fn_error $? "could not create .gitignore" "$LINENO" 5
-}
 
 _ACEOF
 
@@ -19084,7 +19038,6 @@ do
     "tools/makedep") CONFIG_COMMANDS="$CONFIG_COMMANDS tools/makedep" ;;
     "Makefile") CONFIG_COMMANDS="$CONFIG_COMMANDS Makefile" ;;
     "Make.tmp") CONFIG_FILES="$CONFIG_FILES Make.tmp:Makefile.in" ;;
-    ".gitignore") CONFIG_COMMANDS="$CONFIG_COMMANDS .gitignore" ;;
 
   *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
   esac
@@ -19670,7 +19623,6 @@ $as_echo "$as_me: executing $ac_file commands" >&6;}
     "include/stamp-h":C) echo timestamp > include/stamp-h ;;
     "tools/makedep":C) wine_fn_output_makedep || as_fn_exit $? ;;
     "Makefile":C) wine_fn_output_makefile Makefile ;;
-    ".gitignore":C) wine_fn_output_gitignore .gitignore ;;
 
   esac
 done # for ac_tag
diff --git a/configure.ac b/configure.ac
index 9e0dcd96446..73e4140e74b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2616,11 +2616,6 @@ Makefile: $srcdir/Makefile.in config.status \$(MAKEDEP)
 depend: \$(MAKEDEP) dummy
 	\$(MAKEDEP)])
 
-test "$srcdir" = . && WINE_APPEND_RULE(
-[all: .gitignore
-.gitignore: config.status
-	@./config.status .gitignore])
-
 test -n "$CROSSTARGET" || WINE_APPEND_RULE(
 [crosstest:
 	@echo \"crosstest is not supported (mingw not installed?)\" && false])
@@ -3602,15 +3597,11 @@ dnl End of auto-generated output commands
 
 dnl Main ignore file
 
-WINE_IGNORE_FILE(".gitignore")
-WINE_IGNORE_FILE("Makefile")
 WINE_IGNORE_FILE("TAGS")
 WINE_IGNORE_FILE("tags")
 WINE_IGNORE_FILE("autom4te.cache")
-WINE_IGNORE_FILE("config.cache")
 WINE_IGNORE_FILE("config.log")
 WINE_IGNORE_FILE("config.status")
-WINE_IGNORE_FILE("configure.lineno")
 WINE_IGNORE_FILE("include/config.h")
 WINE_IGNORE_FILE("include/stamp-h")
 test "$wine_binary" = wine || WINE_IGNORE_FILE("loader/wine")
@@ -3652,19 +3643,12 @@ fi
 
 test "$MSGFMT" != false || LINGUAS=
 
-for i in $LINGUAS
-do
-    WINE_IGNORE_FILE("po/$i.mo")
-done
-
 if test "x$enable_tools" != xno
 then
     WINE_APPEND_RULE(
 [tools/makedep$ac_exeext: $srcdir/tools/makedep.c include/config.h config.status
 	@./config.status tools/makedep
-Makefile: tools/makedep$ac_exeext
-distclean:: clean
-	\$(RM) tools/makedep$ac_exeext])
+Makefile: tools/makedep$ac_exeext])
 else
     WINE_APPEND_RULE(
 [\$(MAKEDEP):
@@ -3700,18 +3684,6 @@ uninstall::
     esac
 fi
 
-if test "$srcdir" = .
-then
-    AC_CONFIG_COMMANDS([.gitignore], [wine_fn_output_gitignore .gitignore],
-[wine_fn_output_gitignore ()
-{
-    sort <<\_WINE_EOF >\$tmp/gitignore && mv -f \$tmp/gitignore \$[]1 && return
-$GITIGNORE
-_WINE_EOF
-    AS_ERROR([could not create .gitignore])
-}])
-fi
-
 AS_ECHO(" done") >&AS_MESSAGE_FD
 AC_OUTPUT
 
diff --git a/tools/makedep.c b/tools/makedep.c
index 27fc99793a0..db7a42d6b72 100644
--- a/tools/makedep.c
+++ b/tools/makedep.c
@@ -3044,8 +3044,10 @@ static struct strarray output_sources( const struct makefile *make )
     {
         struct strarray build_deps = empty_strarray;
         struct strarray makefile_deps = empty_strarray;
-        struct strarray distclean_files = empty_strarray;
+        struct strarray distclean_files = get_expanded_make_var_array( make, "CONFIGURE_TARGETS" );
 
+        strarray_add( &distclean_files, obj_dir_path( make, output_makefile_name ));
+        if (!make->src_dir) strarray_add( &distclean_files, obj_dir_path( make, ".gitignore" ));
         for (i = 0; i < make->subdirs.count; i++)
         {
             const struct makefile *submake = make->submakes[i];
@@ -3103,6 +3105,8 @@ static struct strarray output_sources( const struct makefile *make )
         output( "\n" );
     }
 
+    if (!make->base_dir)
+        strarray_addall( &clean_files, get_expanded_make_var_array( make, "CONFIGURE_TARGETS" ));
     return clean_files;
 }
 
@@ -3317,8 +3321,7 @@ static void output_dependencies( const struct makefile *make )
         strarray_add( &ignore_files, "testlist.c" );
     }
     strarray_addall( &ignore_files, targets );
-    if (!make->src_dir && make->base_dir)
-        output_gitignore( base_dir_path( make, ".gitignore" ), ignore_files );
+    if (!make->src_dir) output_gitignore( base_dir_path( make, ".gitignore" ), ignore_files );
 
     create_file_directories( make, targets );
 
-- 
GitLab