From d2d44f76c4d86017ccbe6f70ef6318d71947e6d7 Mon Sep 17 00:00:00 2001
From: Paul Smith <psmith@gnu.org>
Date: Sat, 21 Sep 2013 17:37:59 -0400
Subject: [PATCH] Invert the #define for output-sync: turn it off with
 NO_OUTPUT_SYNC

---
 ChangeLog             | 14 ++++++++++++++
 config.ami.template   |  3 +++
 config.h-vms.template |  3 +++
 config.h.W32.template |  2 --
 configh.dos.template  |  4 ++--
 configure.ac          |  1 -
 job.c                 | 12 ++++++------
 job.h                 | 13 ++++++-------
 main.c                | 12 ++++++++----
 makeint.h             |  4 ----
 output.c              | 16 ++++++++++------
 output.h              |  2 +-
 12 files changed, 53 insertions(+), 33 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index cc9ed4ee..5adb84c9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
 2013-09-21  Paul Smith  <psmith@gnu.org>
 
+	Invert the output-sync #define to NO_OUTPUT_SYNC
+
+	* configure.ac: Don't set OUTPUT_SYNC.
+	* makeint.h: Ditto.
+	* main.c: Use NO_OUTPUT_SYNC instead of OUTPUT_SYNC.
+	* output.c: Ditto.
+	* output.h: Ditto.
+	* job.h: Ditto.
+	* job.c: Ditto.
+	* config.ami.template: Set NO_OUTPUT_SYNC.
+	* config.h-vms.template: Ditto.
+	* config.h.W32.template: Ditto.
+	* configh.dos.template: Ditto.
+
 	Output generated while reading makefiles should be synced.
 
 	* main.c (make_sync): Define a context for syncing while reading
diff --git a/config.ami.template b/config.ami.template
index c31eea4e..d9163c05 100644
--- a/config.ami.template
+++ b/config.ami.template
@@ -321,6 +321,9 @@ this program.  If not, see <http://www.gnu.org/licenses/>.  */
 /* Define if you have the sun library (-lsun).  */
 /* #undef HAVE_LIBSUN */
 
+/* Output sync sypport */
+#define NO_OUTPUT_SYNC
+
 /* Define for Case Insensitve behavior */
 #define HAVE_CASE_INSENSITIVE_FS
 
diff --git a/config.h-vms.template b/config.h-vms.template
index 7b180cc5..3b4bd3b5 100644
--- a/config.h-vms.template
+++ b/config.h-vms.template
@@ -411,5 +411,8 @@ this program.  If not, see <http://www.gnu.org/licenses/>.  */
 #define alloca(n)       __ALLOCA(n)
 #endif
 
+/* Output sync sypport */
+#define NO_OUTPUT_SYNC
+
 /* Build host information. */
 #define MAKE_HOST "VMS"
diff --git a/config.h.W32.template b/config.h.W32.template
index dc041bd3..f7aed900 100644
--- a/config.h.W32.template
+++ b/config.h.W32.template
@@ -523,5 +523,3 @@ this program.  If not, see <http://www.gnu.org/licenses/>.  */
 #ifdef HAVE_CYGWIN_SHELL
 #undef BATCH_MODE_ONLY_SHELL
 #endif
-
-#define OUTPUT_SYNC
diff --git a/configh.dos.template b/configh.dos.template
index 63af880e..797e234d 100644
--- a/configh.dos.template
+++ b/configh.dos.template
@@ -100,8 +100,8 @@ this program.  If not, see <http://www.gnu.org/licenses/>.  */
 /* Define to the version of this package. */
 #define PACKAGE_VERSION "%VERSION%"
 
-/* Define to 1 if the C compiler supports function prototypes. */
-#define PROTOTYPES 1
+/* Output sync sypport */
+#define NO_OUTPUT_SYNC
 
 /* Version number of package */
 #define VERSION "%VERSION%"
diff --git a/configure.ac b/configure.ac
index 09b5ce25..893ef0cf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -428,7 +428,6 @@ AS_CASE([$host],
    [AM_CONDITIONAL([WINDOWSENV], [true])
     w32_target_env=yes
     AC_DEFINE([WINDOWS32], [1], [Use platform specific coding])
-    AC_DEFINE([OUTPUT_SYNC], [1], [Support synchronized output])
     AC_DEFINE([HAVE_DOS_PATHS], [1], [Use platform specific coding])
   ])
 
diff --git a/job.c b/job.c
index 79d25ee3..12b0ff65 100644
--- a/job.c
+++ b/job.c
@@ -894,7 +894,7 @@ reap_children (int block, int err)
                 }
               else
                 {
-#ifdef OUTPUT_SYNC
+#ifndef NO_OUTPUT_SYNC
                   /* If we're sync'ing per line, write the previous line's
                      output before starting the next one.  */
                   if (output_sync == OUTPUT_SYNC_LINE)
@@ -930,10 +930,10 @@ reap_children (int block, int err)
 
       /* When we get here, all the commands for c->file are finished.  */
 
-#ifdef OUTPUT_SYNC
+#ifndef NO_OUTPUT_SYNC
       /* Synchronize any remaining parallel output.  */
       output_dump (&c->output);
-#endif /* OUTPUT_SYNC */
+#endif
 
       /* At this point c->file->update_status is success or failed.  But
          c->file->command_state is still cs_running if all the commands
@@ -1267,12 +1267,12 @@ start_job_command (struct child *child)
 
   OUTPUT_SET (&child->output);
 
-#ifdef OUTPUT_SYNC
+#ifndef NO_OUTPUT_SYNC
   if (! child->output.syncout)
     /* We don't want to sync this command: to avoid misordered
        output ensure any already-synced content is written.  */
     output_dump (&child->output);
-#endif /* OUTPUT_SYNC */
+#endif
 
   /* Print the command if appropriate.  */
   if (just_print_flag || trace_flag
@@ -1592,7 +1592,7 @@ start_job_command (struct child *child)
       /* make sure CreateProcess() has Path it needs */
       sync_Path_environment ();
 
-#ifdef OUTPUT_SYNC
+#ifndef NO_OUTPUT_SYNC
           /* Divert child output if output_sync in use.  Don't capture
              recursive make output unless we are synchronizing "make" mode.  */
           if (child->output.syncout)
diff --git a/job.h b/job.h
index c9cb7fa3..29652fce 100644
--- a/job.h
+++ b/job.h
@@ -37,7 +37,11 @@ this program.  If not, see <http://www.gnu.org/licenses/>.  */
 # define CLOSE_ON_EXEC(_d) (void) fcntl ((_d), F_SETFD, FD_CLOEXEC)
 #endif
 
-#ifdef OUTPUT_SYNC
+#ifdef NO_OUTPUT_SYNC
+# define RECORD_SYNC_MUTEX(m) \
+    error (NILF, \
+           _("-O[TYPE] (--output-sync[=TYPE]) is not configured for this build."));
+#else
 # ifdef WINDOWS32
 /* For emulations in w32/compat/posixfcn.c.  */
 #  define F_GETFD 1
@@ -69,7 +73,6 @@ int same_stream (FILE *f1, FILE *f2);
 #  define RECORD_SYNC_MUTEX(m) record_sync_mutex(m)
 void record_sync_mutex (const char *str);
 void prepare_mutex_handle_string (intptr_t hdl);
-
 # else  /* !WINDOWS32 */
 
 typedef int sync_handle_t;      /* file descriptor */
@@ -77,11 +80,7 @@ typedef int sync_handle_t;      /* file descriptor */
 #  define RECORD_SYNC_MUTEX(m) (void)(m)
 
 # endif
-#else /* !OUTPUT_SYNC */
-#define RECORD_SYNC_MUTEX(m) \
-   error (NILF, \
-         _("-O[TYPE] (--output-sync[=TYPE]) is not configured for this build."));
-#endif  /* OUTPUT_SYNC */
+#endif  /* !OUTPUT_SYNC */
 
 /* Structure describing a running or dead child process.  */
 
diff --git a/main.c b/main.c
index f0a7174d..a180ee9c 100644
--- a/main.c
+++ b/main.c
@@ -789,7 +789,7 @@ decode_output_sync_flags (void)
 
 #ifdef WINDOWS32
 
-#ifdef OUTPUT_SYNC
+#ifndef NO_OUTPUT_SYNC
 
 /* This is called from start_job_command when it detects that
    output_sync option is in effect.  The handle to the synchronization
@@ -814,7 +814,7 @@ prepare_mutex_handle_string (sync_handle_t handle)
     }
 }
 
-#endif	/* OUTPUT_SYNC */
+#endif  /* NO_OUTPUT_SYNC */
 
 /*
  * HANDLE runtime exceptions by avoiding a requestor on the GUI. Capture
@@ -1263,7 +1263,7 @@ main (int argc, char **argv, char **envp)
 #ifdef MAKE_JOBSERVER
                            " jobserver"
 #endif
-#ifdef OUTPUT_SYNC
+#ifndef NO_OUTPUT_SYNC
                            " output-sync"
 #endif
 #ifdef MAKE_SYMLINKS
@@ -1560,7 +1560,11 @@ main (int argc, char **argv, char **envp)
             error (NILF, _("warning: -jN forced in submake: disabling jobserver mode."));
         }
 #ifndef WINDOWS32
-#define FD_OK(_f) ((fcntl ((_f), F_GETFD) != -1) || (errno != EBADF))
+#ifdef HAVE_FCNTL
+# define FD_OK(_f) ((fcntl ((_f), F_GETFD) != -1) || (errno != EBADF))
+#else
+# define FD_OK(_f) 1
+#endif
       /* Create a duplicate pipe, that will be closed in the SIGCHLD
          handler.  If this fails with EBADF, the parent has closed the pipe
          on us because it didn't think we were a submake.  If so, print a
diff --git a/makeint.h b/makeint.h
index dac58587..f48c0873 100644
--- a/makeint.h
+++ b/makeint.h
@@ -556,10 +556,6 @@ int strncasecmp (const char *s1, const char *s2, int n);
 # endif
 #endif
 
-#ifdef POSIX
-# define OUTPUT_SYNC
-#endif
-
 #define OUTPUT_SYNC_NONE    0
 #define OUTPUT_SYNC_LINE    1
 #define OUTPUT_SYNC_TARGET  2
diff --git a/output.c b/output.c
index 32334ebd..f58b8166 100644
--- a/output.c
+++ b/output.c
@@ -42,6 +42,12 @@ unsigned int stdio_traced = 0;
 
 #define OUTPUT_ISSET(_out) ((_out)->out >= 0 || (_out)->err >= 0)
 
+#ifdef HAVE_FCNTL
+# define STREAM_OK(_s)    ((fcntl (fileno (_s), F_GETFD) != -1) || (errno != EBADF))
+#else
+# define STREAM_OK(_s)    1
+#endif
+
 /* I really want to move to gnulib.  However, this is a big undertaking
    especially for non-UNIX platforms: how to get bootstrapping to work, etc.
    I don't want to take the time to do it right now.  Use a hack to get a
@@ -178,13 +184,11 @@ set_append_mode (int fd)
 }
 
 
-#ifdef OUTPUT_SYNC
+#ifndef NO_OUTPUT_SYNC
 
 /* Semaphore for use in -j mode with output_sync. */
 static sync_handle_t sync_handle = -1;
 
-#define STREAM_OK(_s)    ((fcntl (fileno (_s), F_GETFD) != -1) || (errno != EBADF))
-
 #define FD_NOT_EMPTY(_f) ((_f) != OUTPUT_NONE && lseek ((_f), 0, SEEK_END) > 0)
 
 /* Set up the sync handle.  Disables output_sync on error.  */
@@ -409,7 +413,7 @@ output_dump (struct output *out)
         }
     }
 }
-#endif /* OUTPUT_SYNC */
+#endif /* NO_OUTPUT_SYNC */
 
 
 /* Provide support for temporary files.  */
@@ -555,7 +559,7 @@ output_close (struct output *out)
       return;
     }
 
-#ifdef OUTPUT_SYNC
+#ifndef NO_OUTPUT_SYNC
   output_dump (out);
 #endif
 
@@ -571,7 +575,7 @@ output_close (struct output *out)
 void
 output_start ()
 {
-#ifdef OUTPUT_SYNC
+#ifndef NO_OUTPUT_SYNC
   if (output_context && output_context->syncout && ! OUTPUT_ISSET(output_context))
     setup_tmpfile (output_context);
 #endif
diff --git a/output.h b/output.h
index 5fef436c..e0d5daaa 100644
--- a/output.h
+++ b/output.h
@@ -44,7 +44,7 @@ void output_start (void);
 /* Show a message on stdout or stderr.  Will start the output if needed.  */
 void outputs (int is_err, const char *msg);
 
-#ifdef OUTPUT_SYNC
+#ifndef NO_OUTPUT_SYNC
 int output_tmpfd (void);
 /* Dump any child output content to stdout, and reset it.  */
 void output_dump (struct output *out);