>From ca939c4cce2a03e13466777593a7c8b545034352 Mon Sep 17 00:00:00 2001
From: Mario Domenech Goulart <mario@parenteses.org>
Date: Thu, 12 Sep 2024 20:34:28 +0200
Subject: [PATCH 1/2] Create chicken-defaults.h and chicken-config.h atomically

Parallel builds might break if chichen-defaults.h and chicken-config.h
are not created atomically.

Makefile.mingw has been intentionally left untouched, as I cannot test
it.
---
 Makefile.aix               |  66 +++----
 Makefile.android           |  65 ++++---
 Makefile.bsd               |  68 +++----
 Makefile.cross-linux-mingw |  58 +++---
 Makefile.cygwin            |  70 +++----
 Makefile.haiku             |  66 +++----
 Makefile.hurd              |  68 +++----
 Makefile.ios               |  64 ++++---
 Makefile.linux             |  66 +++----
 Makefile.macosx            |  70 +++----
 Makefile.mingw-msys        |  58 +++---
 Makefile.solaris           |  62 +++---
 defaults.make              | 377 +++++++++++++++++++------------------
 13 files changed, 593 insertions(+), 565 deletions(-)

diff --git a/Makefile.aix b/Makefile.aix
index 3bf0ac32..782a6f46 100644
--- a/Makefile.aix
+++ b/Makefile.aix
@@ -66,39 +66,41 @@ CHICKEN_CONFIG_H = chicken-config.h
 include $(SRCDIR)/defaults.make
 
 chicken-config.h: chicken-defaults.h
-	echo "/* GENERATED */" >$@
-	echo "#define HAVE_DIRENT_H 1" >>$@
-	echo "#define HAVE_DLFCN_H 1" >>$@
-	echo "#define HAVE_INTTYPES_H 1" >>$@
-	echo "#define HAVE_LIMITS_H 1" >>$@
-	echo "#define HAVE_LONG_LONG 1" >>$@
-	echo "#define HAVE_MEMMOVE 1" >>$@
-	echo "#define HAVE_MEMORY_H 1" >>$@
-	echo "#define HAVE_SIGACTION 1" >>$@
-	echo "#define HAVE_SIGSETJMP 1" >>$@
-	echo "#define HAVE_STDINT_H 1" >>$@
-	echo "#define HAVE_STDLIB_H 1" >>$@
-	echo "#define HAVE_STRERROR 1" >>$@
-	echo "#define HAVE_STRINGS_H 1" >>$@
-	echo "#define HAVE_STRING_H 1" >>$@
-	echo "#define HAVE_STRTOLL 1" >>$@
-	echo "#define HAVE_STRTOQ 0" >>$@
-	echo "#define HAVE_SYS_STAT_H 1" >>$@
-	echo "#define HAVE_SYS_TYPES_H 1" >>$@
-	echo "#define HAVE_SETENV 1" >>$@
-	echo "#define HAVE_UNISTD_H 1" >>$@
-	echo "#define HAVE_UNSIGNED_LONG_LONG 1" >>$@
-	echo "#define STDC_HEADERS 1" >>$@
-	echo "#define HAVE_ALLOCA 1" >>$@
-	echo "#define HAVE_ALLOCA_H 1" >>$@
-	echo "#define HAVE_ERRNO_H 1" >>$@
-	echo "#define HAVE_SYSEXITS_H 1" >>$@
-	echo "#define SEARCH_EXE_PATH 1" >>$@
-	echo "#define C_STACK_GROWS_DOWNWARD 1" >>$@
+	echo "/* GENERATED */" >$@.tmp
+	echo "#define HAVE_DIRENT_H 1" >>$@.tmp
+	echo "#define HAVE_DLFCN_H 1" >>$@.tmp
+	echo "#define HAVE_INTTYPES_H 1" >>$@.tmp
+	echo "#define HAVE_LIMITS_H 1" >>$@.tmp
+	echo "#define HAVE_LONG_LONG 1" >>$@.tmp
+	echo "#define HAVE_MEMMOVE 1" >>$@.tmp
+	echo "#define HAVE_MEMORY_H 1" >>$@.tmp
+	echo "#define HAVE_SIGACTION 1" >>$@.tmp
+	echo "#define HAVE_SIGSETJMP 1" >>$@.tmp
+	echo "#define HAVE_STDINT_H 1" >>$@.tmp
+	echo "#define HAVE_STDLIB_H 1" >>$@.tmp
+	echo "#define HAVE_STRERROR 1" >>$@.tmp
+	echo "#define HAVE_STRINGS_H 1" >>$@.tmp
+	echo "#define HAVE_STRING_H 1" >>$@.tmp
+	echo "#define HAVE_STRTOLL 1" >>$@.tmp
+	echo "#define HAVE_STRTOQ 0" >>$@.tmp
+	echo "#define HAVE_SYS_STAT_H 1" >>$@.tmp
+	echo "#define HAVE_SYS_TYPES_H 1" >>$@.tmp
+	echo "#define HAVE_SETENV 1" >>$@.tmp
+	echo "#define HAVE_UNISTD_H 1" >>$@.tmp
+	echo "#define HAVE_UNSIGNED_LONG_LONG 1" >>$@.tmp
+	echo "#define STDC_HEADERS 1" >>$@.tmp
+	echo "#define HAVE_ALLOCA 1" >>$@.tmp
+	echo "#define HAVE_ALLOCA_H 1" >>$@.tmp
+	echo "#define HAVE_ERRNO_H 1" >>$@.tmp
+	echo "#define HAVE_SYSEXITS_H 1" >>$@.tmp
+	echo "#define SEARCH_EXE_PATH 1" >>$@.tmp
+	echo "#define C_STACK_GROWS_DOWNWARD 1" >>$@.tmp
 ifdef GCHOOKS
-	echo "#define C_GC_HOOKS" >>$@
+	echo "#define C_GC_HOOKS" >>$@.tmp
 endif
-	echo "#define C_USE_STD_FEATURE_MACROS" >>$@
-	cat chicken-defaults.h >>$@
+	echo "#define C_USE_STD_FEATURE_MACROS" >>$@.tmp
+	cat $@.tmp chicken-defaults.h >$@.tmp2
+	mv $@.tmp2 $@
+	rm $@.tmp
 
 include $(SRCDIR)/rules.make
diff --git a/Makefile.android b/Makefile.android
index fd997af8..0de986de 100644
--- a/Makefile.android
+++ b/Makefile.android
@@ -61,38 +61,41 @@ CHICKEN_CONFIG_H = chicken-config.h
 include $(SRCDIR)/defaults.make
 
 chicken-config.h: chicken-defaults.h
-	echo "/* GENERATED */" >$@
-	echo "#define HAVE_DIRENT_H 1" >>$@
-	echo "#define HAVE_DLFCN_H 1" >>$@
-	echo "#define HAVE_INTTYPES_H 1" >>$@
-	echo "#define HAVE_LIMITS_H 1" >>$@
-	echo "#define HAVE_LONG_LONG 1" >>$@
-	echo "#define HAVE_MEMMOVE 1" >>$@
-	echo "#define HAVE_MEMORY_H 1" >>$@
-	echo "#define HAVE_SIGACTION 1" >>$@
-	echo "#define HAVE_SIGSETJMP 1" >>$@
-	echo "#define HAVE_STDINT_H 1" >>$@
-	echo "#define HAVE_STDLIB_H 1" >>$@
-	echo "#define HAVE_STRERROR 1" >>$@
-	echo "#define HAVE_STRINGS_H 1" >>$@
-	echo "#define HAVE_STRING_H 1" >>$@
-	echo "#define HAVE_STRTOLL 1" >>$@
-	echo "#define HAVE_STRTOQ 1" >>$@
-	echo "#define HAVE_SYS_STAT_H 1" >>$@
-	echo "#define HAVE_SYS_TYPES_H 1" >>$@
-	echo "#define HAVE_SETENV 1" >>$@
-	echo "#define HAVE_UNISTD_H 1" >>$@
-	echo "#define HAVE_UNSIGNED_LONG_LONG 1" >>$@
-	echo "#define STDC_HEADERS 1" >>$@
-	echo "#define HAVE_ALLOCA 1" >>$@
-	echo "#define HAVE_ALLOCA_H 1" >>$@
-	echo "#define HAVE_ERRNO_H 1" >>$@
-	echo "#define SEARCH_EXE_PATH 1" >>$@
-	echo "#define C_STACK_GROWS_DOWNWARD 1" >>$@
+	echo "/* GENERATED */" >$@.tmp
+	echo "#define HAVE_DIRENT_H 1" >>$@.tmp
+	echo "#define HAVE_DLFCN_H 1" >>$@.tmp
+	echo "#define HAVE_INTTYPES_H 1" >>$@.tmp
+	echo "#define HAVE_LIMITS_H 1" >>$@.tmp
+	echo "#define HAVE_LONG_LONG 1" >>$@.tmp
+	echo "#define HAVE_MEMMOVE 1" >>$@.tmp
+	echo "#define HAVE_MEMORY_H 1" >>$@.tmp
+	echo "#define HAVE_SIGACTION 1" >>$@.tmp
+	echo "#define HAVE_SIGSETJMP 1" >>$@.tmp
+	echo "#define HAVE_STDINT_H 1" >>$@.tmp
+	echo "#define HAVE_STDLIB_H 1" >>$@.tmp
+	echo "#define HAVE_STRERROR 1" >>$@.tmp
+	echo "#define HAVE_STRINGS_H 1" >>$@.tmp
+	echo "#define HAVE_STRING_H 1" >>$@.tmp
+	echo "#define HAVE_STRTOLL 1" >>$@.tmp
+	echo "#define HAVE_STRTOQ 1" >>$@.tmp
+	echo "#define HAVE_SYS_STAT_H 1" >>$@.tmp
+	echo "#define HAVE_SYS_TYPES_H 1" >>$@.tmp
+	echo "#define HAVE_SETENV 1" >>$@.tmp
+	echo "#define HAVE_UNISTD_H 1" >>$@.tmp
+	echo "#define HAVE_UNSIGNED_LONG_LONG 1" >>$@.tmp
+	echo "#define STDC_HEADERS 1" >>$@.tmp
+	echo "#define HAVE_ALLOCA 1" >>$@.tmp
+	echo "#define HAVE_ALLOCA_H 1" >>$@.tmp
+	echo "#define HAVE_ERRNO_H 1" >>$@.tmp
+	echo "#define SEARCH_EXE_PATH 1" >>$@.tmp
+	echo "#define C_STACK_GROWS_DOWNWARD 1" >>$@.tmp
 ifdef GCHOOKS
-	echo "#define C_GC_HOOKS" >>$@
+	echo "#define C_GC_HOOKS" >>$@.tmp
 endif
-	echo "#define C_USE_STD_FEATURE_MACROS" >>$@
-	cat chicken-defaults.h >>$@
+	echo "#define C_USE_STD_FEATURE_MACROS" >>$@.tmp
+	cat $@.tmp chicken-defaults.h >$@.tmp2
+	rm $@.tmp
+	mv $@.tmp2 $@
+
 
 include $(SRCDIR)/rules.make
diff --git a/Makefile.bsd b/Makefile.bsd
index d66d1f06..43b29b28 100644
--- a/Makefile.bsd
+++ b/Makefile.bsd
@@ -67,44 +67,46 @@ include $(SRCDIR)/defaults.make
 #LINKER_OPTIONS += -L/usr/pkg/lib -Wl,-R/usr/pkg/lib
 
 chicken-config.h: chicken-defaults.h
-	echo "/* GENERATED */" >$@
-	echo "#define HAVE_DIRENT_H 1" >>$@
-	echo "#define HAVE_DLFCN_H 1" >>$@
-	echo "#define HAVE_INTTYPES_H 1" >>$@
-	echo "#define HAVE_LIMITS_H 1" >>$@
-	echo "#define HAVE_LONG_LONG 1" >>$@
-	echo "#define HAVE_MEMMOVE 1" >>$@
-	echo "#define HAVE_MEMORY_H 1" >>$@
-	echo "#define HAVE_SIGACTION 1" >>$@
-	echo "#define HAVE_SIGSETJMP 1" >>$@
-	echo "#define HAVE_SIGPROCMASK 1" >>$@
-	echo "#define HAVE_STDINT_H 1" >>$@
-	echo "#define HAVE_STDLIB_H 1" >>$@
-	echo "#define HAVE_STRERROR 1" >>$@
-	echo "#define HAVE_STRINGS_H 1" >>$@
-	echo "#define HAVE_STRING_H 1" >>$@
-	echo "#define HAVE_STRLCAT 1" >>$@
-	echo "#define HAVE_STRLCPY 1" >>$@
-	echo "#define HAVE_STRTOLL 1" >>$@
-	echo "#define HAVE_STRTOQ 1" >>$@
-	echo "#define HAVE_SYS_STAT_H 1" >>$@
-	echo "#define HAVE_SYS_TYPES_H 1" >>$@
-	echo "#define HAVE_SETENV 1" >>$@
-	echo "#define HAVE_UNISTD_H 1" >>$@
-	echo "#define HAVE_UNSIGNED_LONG_LONG 1" >>$@
-	echo "#define STDC_HEADERS 1" >>$@
-	echo "#define HAVE_ALLOCA 1" >>$@
-	echo "#define HAVE_ERRNO_H 1" >>$@
-	echo "#define HAVE_SYSEXITS_H 1" >>$@
-	echo "#define SEARCH_EXE_PATH 1" >>$@
-	echo "#define C_STACK_GROWS_DOWNWARD 1" >>$@
+	echo "/* GENERATED */" >$@.tmp
+	echo "#define HAVE_DIRENT_H 1" >>$@.tmp
+	echo "#define HAVE_DLFCN_H 1" >>$@.tmp
+	echo "#define HAVE_INTTYPES_H 1" >>$@.tmp
+	echo "#define HAVE_LIMITS_H 1" >>$@.tmp
+	echo "#define HAVE_LONG_LONG 1" >>$@.tmp
+	echo "#define HAVE_MEMMOVE 1" >>$@.tmp
+	echo "#define HAVE_MEMORY_H 1" >>$@.tmp
+	echo "#define HAVE_SIGACTION 1" >>$@.tmp
+	echo "#define HAVE_SIGSETJMP 1" >>$@.tmp
+	echo "#define HAVE_SIGPROCMASK 1" >>$@.tmp
+	echo "#define HAVE_STDINT_H 1" >>$@.tmp
+	echo "#define HAVE_STDLIB_H 1" >>$@.tmp
+	echo "#define HAVE_STRERROR 1" >>$@.tmp
+	echo "#define HAVE_STRINGS_H 1" >>$@.tmp
+	echo "#define HAVE_STRING_H 1" >>$@.tmp
+	echo "#define HAVE_STRLCAT 1" >>$@.tmp
+	echo "#define HAVE_STRLCPY 1" >>$@.tmp
+	echo "#define HAVE_STRTOLL 1" >>$@.tmp
+	echo "#define HAVE_STRTOQ 1" >>$@.tmp
+	echo "#define HAVE_SYS_STAT_H 1" >>$@.tmp
+	echo "#define HAVE_SYS_TYPES_H 1" >>$@.tmp
+	echo "#define HAVE_SETENV 1" >>$@.tmp
+	echo "#define HAVE_UNISTD_H 1" >>$@.tmp
+	echo "#define HAVE_UNSIGNED_LONG_LONG 1" >>$@.tmp
+	echo "#define STDC_HEADERS 1" >>$@.tmp
+	echo "#define HAVE_ALLOCA 1" >>$@.tmp
+	echo "#define HAVE_ERRNO_H 1" >>$@.tmp
+	echo "#define HAVE_SYSEXITS_H 1" >>$@.tmp
+	echo "#define SEARCH_EXE_PATH 1" >>$@.tmp
+	echo "#define C_STACK_GROWS_DOWNWARD 1" >>$@.tmp
 ifdef GCHOOKS
-	echo "#define C_GC_HOOKS" >>$@
+	echo "#define C_GC_HOOKS" >>$@.tmp
 endif
 # Feature macros are unsupported on FreeBSD and DragonFly
 	echo "#if !defined(__FreeBSD__) && !defined(__DragonFly__)" >> $@
 	echo "# define C_USE_STD_FEATURE_MACROS" >> $@
 	echo "#endif" >> $@
-	cat chicken-defaults.h >>$@
+	cat $@.tmp chicken-defaults.h >$@.tmp2
+	rm $@.tmp
+	mv $@.tmp2 $@
 
 include $(SRCDIR)/rules.make
diff --git a/Makefile.cross-linux-mingw b/Makefile.cross-linux-mingw
index b51b676e..d6dcfa21 100644
--- a/Makefile.cross-linux-mingw
+++ b/Makefile.cross-linux-mingw
@@ -86,35 +86,37 @@ TARGETS = libchicken$(A) $(CHICKEN_PROGRAM)$(EXE) $(CSI_PROGRAM)$(EXE) \
 endif
 
 chicken-config.h: chicken-defaults.h
-	echo "/* GENERATED */" >$@
-	echo "#define HAVE_DIRENT_H 1" >>$@
-	echo "#define HAVE_INTTYPES_H 1" >>$@
-	echo "#define HAVE_LIMITS_H 1" >>$@
-	echo "#define HAVE_LONG_LONG 1" >>$@
-	echo "#define HAVE_MEMMOVE 1" >>$@
-	echo "#define HAVE_MEMORY_H 1" >>$@
-	echo "#define NO_POSIX_POLL 1" >>$@
-	echo "#define HAVE_STDINT_H 1" >>$@
-	echo "#define HAVE_STDLIB_H 1" >>$@
-	echo "#define HAVE_STRERROR 1" >>$@
-	echo "#define HAVE_STRINGS_H 1" >>$@
-	echo "#define HAVE_STRING_H 1" >>$@
-	echo "#define HAVE_STRTOLL 1" >>$@
-	echo "#define HAVE_SYS_STAT_H 1" >>$@
-	echo "#define HAVE_SYS_TYPES_H 1" >>$@
-	echo "#define HAVE_UNISTD_H 1" >>$@
-	echo "#define HAVE_UNSIGNED_LONG_LONG 1" >>$@
-	echo "#define STDC_HEADERS 1" >>$@
-	echo "#define HAVE_ALLOCA 1" >>$@
-	echo "#define HAVE_DIRECT_H 1" >>$@
-	echo "#define HAVE_ERRNO_H 1" >>$@
-	echo "#define HAVE_LOADLIBRARY 1" >>$@
-	echo "#define HAVE_GETPROCADDRESS 1" >>$@
-	echo "#define C_STACK_GROWS_DOWNWARD 1" >>$@
+	echo "/* GENERATED */" >$@.tmp
+	echo "#define HAVE_DIRENT_H 1" >>$@.tmp
+	echo "#define HAVE_INTTYPES_H 1" >>$@.tmp
+	echo "#define HAVE_LIMITS_H 1" >>$@.tmp
+	echo "#define HAVE_LONG_LONG 1" >>$@.tmp
+	echo "#define HAVE_MEMMOVE 1" >>$@.tmp
+	echo "#define HAVE_MEMORY_H 1" >>$@.tmp
+	echo "#define NO_POSIX_POLL 1" >>$@.tmp
+	echo "#define HAVE_STDINT_H 1" >>$@.tmp
+	echo "#define HAVE_STDLIB_H 1" >>$@.tmp
+	echo "#define HAVE_STRERROR 1" >>$@.tmp
+	echo "#define HAVE_STRINGS_H 1" >>$@.tmp
+	echo "#define HAVE_STRING_H 1" >>$@.tmp
+	echo "#define HAVE_STRTOLL 1" >>$@.tmp
+	echo "#define HAVE_SYS_STAT_H 1" >>$@.tmp
+	echo "#define HAVE_SYS_TYPES_H 1" >>$@.tmp
+	echo "#define HAVE_UNISTD_H 1" >>$@.tmp
+	echo "#define HAVE_UNSIGNED_LONG_LONG 1" >>$@.tmp
+	echo "#define STDC_HEADERS 1" >>$@.tmp
+	echo "#define HAVE_ALLOCA 1" >>$@.tmp
+	echo "#define HAVE_DIRECT_H 1" >>$@.tmp
+	echo "#define HAVE_ERRNO_H 1" >>$@.tmp
+	echo "#define HAVE_LOADLIBRARY 1" >>$@.tmp
+	echo "#define HAVE_GETPROCADDRESS 1" >>$@.tmp
+	echo "#define C_STACK_GROWS_DOWNWARD 1" >>$@.tmp
 ifdef GCHOOKS
-	echo "#define C_GC_HOOKS" >>$@
+	echo "#define C_GC_HOOKS" >>$@.tmp
 endif
-	echo "#define C_USE_STD_FEATURE_MACROS" >>$@
-	cat chicken-defaults.h >>$@
+	echo "#define C_USE_STD_FEATURE_MACROS" >>$@.tmp
+	cat $@.tmp chicken-defaults.h >$@.tmp2
+	rm $@.tmp
+	mv $@.tmp2 $@
 
 include $(SRCDIR)rules.make
diff --git a/Makefile.cygwin b/Makefile.cygwin
index 1ba7d7a8..b04652ea 100644
--- a/Makefile.cygwin
+++ b/Makefile.cygwin
@@ -78,41 +78,43 @@ include $(SRCDIR)/defaults.make
 LIBCHICKEN_SO_LIBRARIES = $(LIBRARIES)
 
 chicken-config.h: chicken-defaults.h
-	echo "/* GENERATED */" >$@
-	echo "#define C_INSTALL_RC_COMPILER \"$(RC_COMPILER)\"" >>$@
-	echo "#define C_TARGET_RC_COMPILER \"$(TARGET_RC_COMPILER)\"" >>$@
-	echo "#define HAVE_DIRENT_H 1" >>$@
-	echo "#define HAVE_INTTYPES_H 1" >>$@
-	echo "#define HAVE_LIMITS_H 1" >>$@
-	echo "#define HAVE_LONG_LONG 1" >>$@
-	echo "#define HAVE_MEMMOVE 1" >>$@
-	echo "#define HAVE_MEMORY_H 1" >>$@
-	echo "#define HAVE_SIGACTION 1" >>$@
-	echo "#define HAVE_STDINT_H 1" >>$@
-	echo "#define HAVE_STDLIB_H 1" >>$@
-	echo "#define HAVE_STRERROR 1" >>$@
-	echo "#define HAVE_STRINGS_H 1" >>$@
-	echo "#define HAVE_STRING_H 1" >>$@
-	echo "#define HAVE_STRLCAT 1" >>$@
-	echo "#define HAVE_STRLCPY 1" >>$@
-	echo "#define HAVE_STRTOLL 1" >>$@
-	echo "#define HAVE_STRTOQ 1" >>$@
-	echo "#define HAVE_SYS_STAT_H 1" >>$@
-	echo "#define HAVE_SYS_TYPES_H 1" >>$@
-	echo "#define HAVE_UNISTD_H 1" >>$@
-	echo "#define HAVE_UNSIGNED_LONG_LONG 1" >>$@
-	echo "#define STDC_HEADERS 1" >>$@
-	echo "#define HAVE_ALLOCA 1" >>$@
-	echo "#define HAVE_ALLOCA_H 1" >>$@
-	echo "#define HAVE_ERRNO_H 1" >>$@
-	echo "#define HAVE_SYSEXITS_H 1" >>$@
-	echo "#define HAVE_DLFCN_H 1" >>$@
-	echo "#define SEARCH_EXE_PATH 1" >>$@
-	echo "#define C_STACK_GROWS_DOWNWARD 1" >>$@
+	echo "/* GENERATED */" >$@.tmp
+	echo "#define C_INSTALL_RC_COMPILER \"$(RC_COMPILER)\"" >>$@.tmp
+	echo "#define C_TARGET_RC_COMPILER \"$(TARGET_RC_COMPILER)\"" >>$@.tmp
+	echo "#define HAVE_DIRENT_H 1" >>$@.tmp
+	echo "#define HAVE_INTTYPES_H 1" >>$@.tmp
+	echo "#define HAVE_LIMITS_H 1" >>$@.tmp
+	echo "#define HAVE_LONG_LONG 1" >>$@.tmp
+	echo "#define HAVE_MEMMOVE 1" >>$@.tmp
+	echo "#define HAVE_MEMORY_H 1" >>$@.tmp
+	echo "#define HAVE_SIGACTION 1" >>$@.tmp
+	echo "#define HAVE_STDINT_H 1" >>$@.tmp
+	echo "#define HAVE_STDLIB_H 1" >>$@.tmp
+	echo "#define HAVE_STRERROR 1" >>$@.tmp
+	echo "#define HAVE_STRINGS_H 1" >>$@.tmp
+	echo "#define HAVE_STRING_H 1" >>$@.tmp
+	echo "#define HAVE_STRLCAT 1" >>$@.tmp
+	echo "#define HAVE_STRLCPY 1" >>$@.tmp
+	echo "#define HAVE_STRTOLL 1" >>$@.tmp
+	echo "#define HAVE_STRTOQ 1" >>$@.tmp
+	echo "#define HAVE_SYS_STAT_H 1" >>$@.tmp
+	echo "#define HAVE_SYS_TYPES_H 1" >>$@.tmp
+	echo "#define HAVE_UNISTD_H 1" >>$@.tmp
+	echo "#define HAVE_UNSIGNED_LONG_LONG 1" >>$@.tmp
+	echo "#define STDC_HEADERS 1" >>$@.tmp
+	echo "#define HAVE_ALLOCA 1" >>$@.tmp
+	echo "#define HAVE_ALLOCA_H 1" >>$@.tmp
+	echo "#define HAVE_ERRNO_H 1" >>$@.tmp
+	echo "#define HAVE_SYSEXITS_H 1" >>$@.tmp
+	echo "#define HAVE_DLFCN_H 1" >>$@.tmp
+	echo "#define SEARCH_EXE_PATH 1" >>$@.tmp
+	echo "#define C_STACK_GROWS_DOWNWARD 1" >>$@.tmp
 ifdef GCHOOKS
-	echo "#define C_GC_HOOKS" >>$@
+	echo "#define C_GC_HOOKS" >>$@.tmp
 endif
-	echo "#define C_USE_STD_FEATURE_MACROS" >>$@
-	cat chicken-defaults.h >>$@
+	echo "#define C_USE_STD_FEATURE_MACROS" >>$@.tmp
+	cat $@.tmp chicken-defaults.h >$@.tmp2
+	rm $@.tmp
+	mv $@.tmp2 $@
 
 include $(SRCDIR)/rules.make
diff --git a/Makefile.haiku b/Makefile.haiku
index 679f355c..06b9d51a 100644
--- a/Makefile.haiku
+++ b/Makefile.haiku
@@ -58,39 +58,41 @@ CHICKEN_CONFIG_H = chicken-config.h
 include $(SRCDIR)/defaults.make
 
 chicken-config.h: chicken-defaults.h
-	echo "/* GENERATED */" >$@
-	echo "#define HAVE_DIRENT_H 1" >>$@
-	echo "#define HAVE_DLFCN_H 1" >>$@
-	echo "#define HAVE_INTTYPES_H 1" >>$@
-	echo "#define HAVE_LIMITS_H 1" >>$@
-	echo "#define HAVE_LONG_LONG 1" >>$@
-	echo "#define HAVE_MEMMOVE 1" >>$@
-	echo "#define HAVE_MEMORY_H 1" >>$@
-	echo "#define HAVE_SIGACTION 1" >>$@
-	echo "#define HAVE_SIGSETJMP 1" >>$@
-	echo "#define HAVE_SIGPROCMASK 1" >>$@
-	echo "#define HAVE_STDINT_H 1" >>$@
-	echo "#define HAVE_STDLIB_H 1" >>$@
-	echo "#define HAVE_STRERROR 1" >>$@
-	echo "#define HAVE_STRINGS_H 1" >>$@
-	echo "#define HAVE_STRING_H 1" >>$@
-	echo "#define HAVE_STRTOLL 1" >>$@
-	echo "#define HAVE_STRTOQ 1" >>$@
-	echo "#define HAVE_SYS_STAT_H 1" >>$@
-	echo "#define HAVE_SYS_TYPES_H 1" >>$@
-	echo "#define HAVE_SETENV 1" >>$@
-	echo "#define HAVE_UNISTD_H 1" >>$@
-	echo "#define HAVE_UNSIGNED_LONG_LONG 1" >>$@
-	echo "#define STDC_HEADERS 1" >>$@
-	echo "#define HAVE_ALLOCA 1" >>$@
-	echo "#define HAVE_ALLOCA_H 1" >>$@
-	echo "#define HAVE_ERRNO_H 1" >>$@
-	echo "#define C_STACK_GROWS_DOWNWARD 1" >>$@
-	echo "#define SIGIO 0" >>$@
+	echo "/* GENERATED */" >$@.tmp
+	echo "#define HAVE_DIRENT_H 1" >>$@.tmp
+	echo "#define HAVE_DLFCN_H 1" >>$@.tmp
+	echo "#define HAVE_INTTYPES_H 1" >>$@.tmp
+	echo "#define HAVE_LIMITS_H 1" >>$@.tmp
+	echo "#define HAVE_LONG_LONG 1" >>$@.tmp
+	echo "#define HAVE_MEMMOVE 1" >>$@.tmp
+	echo "#define HAVE_MEMORY_H 1" >>$@.tmp
+	echo "#define HAVE_SIGACTION 1" >>$@.tmp
+	echo "#define HAVE_SIGSETJMP 1" >>$@.tmp
+	echo "#define HAVE_SIGPROCMASK 1" >>$@.tmp
+	echo "#define HAVE_STDINT_H 1" >>$@.tmp
+	echo "#define HAVE_STDLIB_H 1" >>$@.tmp
+	echo "#define HAVE_STRERROR 1" >>$@.tmp
+	echo "#define HAVE_STRINGS_H 1" >>$@.tmp
+	echo "#define HAVE_STRING_H 1" >>$@.tmp
+	echo "#define HAVE_STRTOLL 1" >>$@.tmp
+	echo "#define HAVE_STRTOQ 1" >>$@.tmp
+	echo "#define HAVE_SYS_STAT_H 1" >>$@.tmp
+	echo "#define HAVE_SYS_TYPES_H 1" >>$@.tmp
+	echo "#define HAVE_SETENV 1" >>$@.tmp
+	echo "#define HAVE_UNISTD_H 1" >>$@.tmp
+	echo "#define HAVE_UNSIGNED_LONG_LONG 1" >>$@.tmp
+	echo "#define STDC_HEADERS 1" >>$@.tmp
+	echo "#define HAVE_ALLOCA 1" >>$@.tmp
+	echo "#define HAVE_ALLOCA_H 1" >>$@.tmp
+	echo "#define HAVE_ERRNO_H 1" >>$@.tmp
+	echo "#define C_STACK_GROWS_DOWNWARD 1" >>$@.tmp
+	echo "#define SIGIO 0" >>$@.tmp
 ifdef GCHOOKS
-	echo "#define C_GC_HOOKS" >>$@
+	echo "#define C_GC_HOOKS" >>$@.tmp
 endif
-	echo "#define C_USE_STD_FEATURE_MACROS" >>$@
-	cat chicken-defaults.h >>$@
+	echo "#define C_USE_STD_FEATURE_MACROS" >>$@.tmp
+	cat $@.tmp chicken-defaults.h >$@.tmp2
+	rm $@.tmp
+	mv $@.tmp2 $@
 
 include $(SRCDIR)/rules.make
diff --git a/Makefile.hurd b/Makefile.hurd
index 26cf28d8..5c3bcd8e 100644
--- a/Makefile.hurd
+++ b/Makefile.hurd
@@ -59,40 +59,42 @@ CHICKEN_CONFIG_H = chicken-config.h
 include $(SRCDIR)/defaults.make
 
 chicken-config.h: chicken-defaults.h
-	echo "/* GENERATED */" >$@
-	echo "#define HAVE_DIRENT_H 1" >>$@
-	echo "#define HAVE_DLFCN_H 1" >>$@
-	echo "#define HAVE_INTTYPES_H 1" >>$@
-	echo "#define HAVE_LIMITS_H 1" >>$@
-	echo "#define HAVE_LONG_LONG 1" >>$@
-	echo "#define HAVE_MEMMOVE 1" >>$@
-	echo "#define HAVE_MEMORY_H 1" >>$@
-	echo "#define HAVE_SIGACTION 1" >>$@
-	echo "#define HAVE_SIGSETJMP 1" >>$@
-	echo "#define HAVE_SIGPROCMASK 1" >>$@
-	echo "#define HAVE_STDINT_H 1" >>$@
-	echo "#define HAVE_STDLIB_H 1" >>$@
-	echo "#define HAVE_STRERROR 1" >>$@
-	echo "#define HAVE_STRINGS_H 1" >>$@
-	echo "#define HAVE_STRING_H 1" >>$@
-	echo "#define HAVE_STRTOLL 1" >>$@
-	echo "#define HAVE_STRTOQ 1" >>$@
-	echo "#define HAVE_SYS_STAT_H 1" >>$@
-	echo "#define HAVE_SYS_TYPES_H 1" >>$@
-	echo "#define HAVE_SETENV 1" >>$@
-	echo "#define HAVE_UNISTD_H 1" >>$@
-	echo "#define HAVE_UNSIGNED_LONG_LONG 1" >>$@
-	echo "#define STDC_HEADERS 1" >>$@
-	echo "#define HAVE_ALLOCA 1" >>$@
-	echo "#define HAVE_ALLOCA_H 1" >>$@
-	echo "#define HAVE_ERRNO_H 1" >>$@
-	echo "#define HAVE_SYSEXITS_H 1" >>$@
-	echo "#define SEARCH_EXE_PATH 1" >>$@
-	echo "#define C_STACK_GROWS_DOWNWARD 1" >>$@
+	echo "/* GENERATED */" >$@.tmp
+	echo "#define HAVE_DIRENT_H 1" >>$@.tmp
+	echo "#define HAVE_DLFCN_H 1" >>$@.tmp
+	echo "#define HAVE_INTTYPES_H 1" >>$@.tmp
+	echo "#define HAVE_LIMITS_H 1" >>$@.tmp
+	echo "#define HAVE_LONG_LONG 1" >>$@.tmp
+	echo "#define HAVE_MEMMOVE 1" >>$@.tmp
+	echo "#define HAVE_MEMORY_H 1" >>$@.tmp
+	echo "#define HAVE_SIGACTION 1" >>$@.tmp
+	echo "#define HAVE_SIGSETJMP 1" >>$@.tmp
+	echo "#define HAVE_SIGPROCMASK 1" >>$@.tmp
+	echo "#define HAVE_STDINT_H 1" >>$@.tmp
+	echo "#define HAVE_STDLIB_H 1" >>$@.tmp
+	echo "#define HAVE_STRERROR 1" >>$@.tmp
+	echo "#define HAVE_STRINGS_H 1" >>$@.tmp
+	echo "#define HAVE_STRING_H 1" >>$@.tmp
+	echo "#define HAVE_STRTOLL 1" >>$@.tmp
+	echo "#define HAVE_STRTOQ 1" >>$@.tmp
+	echo "#define HAVE_SYS_STAT_H 1" >>$@.tmp
+	echo "#define HAVE_SYS_TYPES_H 1" >>$@.tmp
+	echo "#define HAVE_SETENV 1" >>$@.tmp
+	echo "#define HAVE_UNISTD_H 1" >>$@.tmp
+	echo "#define HAVE_UNSIGNED_LONG_LONG 1" >>$@.tmp
+	echo "#define STDC_HEADERS 1" >>$@.tmp
+	echo "#define HAVE_ALLOCA 1" >>$@.tmp
+	echo "#define HAVE_ALLOCA_H 1" >>$@.tmp
+	echo "#define HAVE_ERRNO_H 1" >>$@.tmp
+	echo "#define HAVE_SYSEXITS_H 1" >>$@.tmp
+	echo "#define SEARCH_EXE_PATH 1" >>$@.tmp
+	echo "#define C_STACK_GROWS_DOWNWARD 1" >>$@.tmp
 ifdef GCHOOKS
-	echo "#define C_GC_HOOKS" >>$@
+	echo "#define C_GC_HOOKS" >>$@.tmp
 endif
-	echo "#define C_USE_STD_FEATURE_MACROS" >>$@
-	cat chicken-defaults.h >>$@
+	echo "#define C_USE_STD_FEATURE_MACROS" >>$@.tmp
+	cat $@.tmp chicken-defaults.h >$@.tmp2
+	rm $@.tmp
+	mv $@.tmp2 $@
 
 include $(SRCDIR)/rules.make
diff --git a/Makefile.ios b/Makefile.ios
index e5495703..71843009 100644
--- a/Makefile.ios
+++ b/Makefile.ios
@@ -65,39 +65,41 @@ CHICKEN_CONFIG_H = chicken-config.h
 include $(SRCDIR)/defaults.make
 
 chicken-config.h: chicken-defaults.h
-	echo "/* GENERATED */" >$@
-	echo "#define STATICBUILD 1" >>$@
-	echo "#define HAVE_DIRENT_H 1" >>$@
-	echo "#define HAVE_INTTYPES_H 1" >>$@
-	echo "#define HAVE_LIMITS_H 1" >>$@
-	echo "#define HAVE_LONG_LONG 1" >>$@
-	echo "#define HAVE_MEMMOVE 1" >>$@
-	echo "#define HAVE_MEMORY_H 1" >>$@
-	echo "#define HAVE_SIGACTION 1" >>$@
-	echo "#define HAVE_SIGSETJMP 1" >>$@
-	echo "#define HAVE_SIGPROCMASK 1" >>$@
-	echo "#define HAVE_STDINT_H 1" >>$@
-	echo "#define HAVE_STDLIB_H 1" >>$@
-	echo "#define HAVE_STRERROR 1" >>$@
-	echo "#define HAVE_STRINGS_H 1" >>$@
-	echo "#define HAVE_STRING_H 1" >>$@
-	echo "#define HAVE_STRTOLL 1" >>$@
-	echo "#define HAVE_STRTOQ 1" >>$@
-	echo "#define HAVE_SYS_STAT_H 1" >>$@
-	echo "#define HAVE_SYS_TYPES_H 1" >>$@
-	echo "#define HAVE_UNISTD_H 1" >>$@
-	echo "#define HAVE_UNSIGNED_LONG_LONG 1" >>$@
-	echo "#define STDC_HEADERS 1" >>$@
-	echo "#define HAVE_ALLOCA 1" >>$@
-	echo "#define HAVE_ALLOCA_H 1" >>$@
-	echo "#define HAVE_ERRNO_H 1" >>$@
-	echo "#define HAVE_SYSEXITS_H 1" >>$@
+	echo "/* GENERATED */" >$@.tmp
+	echo "#define STATICBUILD 1" >>$@.tmp
+	echo "#define HAVE_DIRENT_H 1" >>$@.tmp
+	echo "#define HAVE_INTTYPES_H 1" >>$@.tmp
+	echo "#define HAVE_LIMITS_H 1" >>$@.tmp
+	echo "#define HAVE_LONG_LONG 1" >>$@.tmp
+	echo "#define HAVE_MEMMOVE 1" >>$@.tmp
+	echo "#define HAVE_MEMORY_H 1" >>$@.tmp
+	echo "#define HAVE_SIGACTION 1" >>$@.tmp
+	echo "#define HAVE_SIGSETJMP 1" >>$@.tmp
+	echo "#define HAVE_SIGPROCMASK 1" >>$@.tmp
+	echo "#define HAVE_STDINT_H 1" >>$@.tmp
+	echo "#define HAVE_STDLIB_H 1" >>$@.tmp
+	echo "#define HAVE_STRERROR 1" >>$@.tmp
+	echo "#define HAVE_STRINGS_H 1" >>$@.tmp
+	echo "#define HAVE_STRING_H 1" >>$@.tmp
+	echo "#define HAVE_STRTOLL 1" >>$@.tmp
+	echo "#define HAVE_STRTOQ 1" >>$@.tmp
+	echo "#define HAVE_SYS_STAT_H 1" >>$@.tmp
+	echo "#define HAVE_SYS_TYPES_H 1" >>$@.tmp
+	echo "#define HAVE_UNISTD_H 1" >>$@.tmp
+	echo "#define HAVE_UNSIGNED_LONG_LONG 1" >>$@.tmp
+	echo "#define STDC_HEADERS 1" >>$@.tmp
+	echo "#define HAVE_ALLOCA 1" >>$@.tmp
+	echo "#define HAVE_ALLOCA_H 1" >>$@.tmp
+	echo "#define HAVE_ERRNO_H 1" >>$@.tmp
+	echo "#define HAVE_SYSEXITS_H 1" >>$@.tmp
 # TODO: Use MacOS exe path mechanism?
-	echo "#define SEARCH_EXE_PATH 1" >>$@
-	echo "#define C_STACK_GROWS_DOWNWARD 1" >>$@
+	echo "#define SEARCH_EXE_PATH 1" >>$@.tmp
+	echo "#define C_STACK_GROWS_DOWNWARD 1" >>$@.tmp
 ifdef GCHOOKS
-	echo "#define C_GC_HOOKS" >>$@
+	echo "#define C_GC_HOOKS" >>$@.tmp
 endif
-	cat chicken-defaults.h >>$@
+	cat $@.tmp chicken-defaults.h >$@.tmp2
+	rm $@.tmp
+	mv $@.tmp2 $@
 
 include $(SRCDIR)/rules.make
diff --git a/Makefile.linux b/Makefile.linux
index 77d59b88..a48e252f 100644
--- a/Makefile.linux
+++ b/Makefile.linux
@@ -66,39 +66,41 @@ CHICKEN_CONFIG_H = chicken-config.h
 include $(SRCDIR)/defaults.make
 
 chicken-config.h: chicken-defaults.h
-	echo "/* GENERATED */" >$@
-	echo "#define HAVE_DIRENT_H 1" >>$@
-	echo "#define HAVE_DLFCN_H 1" >>$@
-	echo "#define HAVE_INTTYPES_H 1" >>$@
-	echo "#define HAVE_LIMITS_H 1" >>$@
-	echo "#define HAVE_LONG_LONG 1" >>$@
-	echo "#define HAVE_MEMMOVE 1" >>$@
-	echo "#define HAVE_MEMORY_H 1" >>$@
-	echo "#define HAVE_SIGACTION 1" >>$@
-	echo "#define HAVE_SIGSETJMP 1" >>$@
-	echo "#define HAVE_SIGPROCMASK 1" >>$@
-	echo "#define HAVE_STDINT_H 1" >>$@
-	echo "#define HAVE_STDLIB_H 1" >>$@
-	echo "#define HAVE_STRERROR 1" >>$@
-	echo "#define HAVE_STRINGS_H 1" >>$@
-	echo "#define HAVE_STRING_H 1" >>$@
-	echo "#define HAVE_STRTOLL 1" >>$@
-	echo "#define HAVE_STRTOQ 1" >>$@
-	echo "#define HAVE_SYS_STAT_H 1" >>$@
-	echo "#define HAVE_SYS_TYPES_H 1" >>$@
-	echo "#define HAVE_SETENV 1" >>$@
-	echo "#define HAVE_UNISTD_H 1" >>$@
-	echo "#define HAVE_UNSIGNED_LONG_LONG 1" >>$@
-	echo "#define STDC_HEADERS 1" >>$@
-	echo "#define HAVE_ALLOCA 1" >>$@
-	echo "#define HAVE_ALLOCA_H 1" >>$@
-	echo "#define HAVE_ERRNO_H 1" >>$@
-	echo "#define HAVE_SYSEXITS_H 1" >>$@
-	echo "#define C_STACK_GROWS_DOWNWARD 1" >>$@
+	echo "/* GENERATED */" >$@.tmp
+	echo "#define HAVE_DIRENT_H 1" >>$@.tmp
+	echo "#define HAVE_DLFCN_H 1" >>$@.tmp
+	echo "#define HAVE_INTTYPES_H 1" >>$@.tmp
+	echo "#define HAVE_LIMITS_H 1" >>$@.tmp
+	echo "#define HAVE_LONG_LONG 1" >>$@.tmp
+	echo "#define HAVE_MEMMOVE 1" >>$@.tmp
+	echo "#define HAVE_MEMORY_H 1" >>$@.tmp
+	echo "#define HAVE_SIGACTION 1" >>$@.tmp
+	echo "#define HAVE_SIGSETJMP 1" >>$@.tmp
+	echo "#define HAVE_SIGPROCMASK 1" >>$@.tmp
+	echo "#define HAVE_STDINT_H 1" >>$@.tmp
+	echo "#define HAVE_STDLIB_H 1" >>$@.tmp
+	echo "#define HAVE_STRERROR 1" >>$@.tmp
+	echo "#define HAVE_STRINGS_H 1" >>$@.tmp
+	echo "#define HAVE_STRING_H 1" >>$@.tmp
+	echo "#define HAVE_STRTOLL 1" >>$@.tmp
+	echo "#define HAVE_STRTOQ 1" >>$@.tmp
+	echo "#define HAVE_SYS_STAT_H 1" >>$@.tmp
+	echo "#define HAVE_SYS_TYPES_H 1" >>$@.tmp
+	echo "#define HAVE_SETENV 1" >>$@.tmp
+	echo "#define HAVE_UNISTD_H 1" >>$@.tmp
+	echo "#define HAVE_UNSIGNED_LONG_LONG 1" >>$@.tmp
+	echo "#define STDC_HEADERS 1" >>$@.tmp
+	echo "#define HAVE_ALLOCA 1" >>$@.tmp
+	echo "#define HAVE_ALLOCA_H 1" >>$@.tmp
+	echo "#define HAVE_ERRNO_H 1" >>$@.tmp
+	echo "#define HAVE_SYSEXITS_H 1" >>$@.tmp
+	echo "#define C_STACK_GROWS_DOWNWARD 1" >>$@.tmp
 ifdef GCHOOKS
-	echo "#define C_GC_HOOKS" >>$@
+	echo "#define C_GC_HOOKS" >>$@.tmp
 endif
-	echo "#define C_USE_STD_FEATURE_MACROS" >>$@
-	cat chicken-defaults.h >>$@
+	echo "#define C_USE_STD_FEATURE_MACROS" >>$@.tmp
+	cat $@.tmp chicken-defaults.h >$@.tmp2
+	rm $@.tmp
+	mv $@.tmp2 $@
 
 include $(SRCDIR)/rules.make
diff --git a/Makefile.macosx b/Makefile.macosx
index 05d8813b..6a431f1e 100644
--- a/Makefile.macosx
+++ b/Makefile.macosx
@@ -85,41 +85,43 @@ endif
 include $(SRCDIR)/defaults.make
 
 chicken-config.h: chicken-defaults.h
-	echo "/* GENERATED */" >$@
-	echo "#define HAVE_DIRENT_H 1" >>$@
-	echo "#define HAVE_DLFCN_H 1" >>$@
-	echo "#define HAVE_INTTYPES_H 1" >>$@
-	echo "#define HAVE_LIMITS_H 1" >>$@
-	echo "#define HAVE_LONG_LONG 1" >>$@
-	echo "#define HAVE_MEMMOVE 1" >>$@
-	echo "#define HAVE_MEMORY_H 1" >>$@
-	echo "#define HAVE_SIGACTION 1" >>$@
-	echo "#define HAVE_SIGSETJMP 1" >>$@
-	echo "#define HAVE_SIGPROCMASK 1" >>$@
-	echo "#define HAVE_STDINT_H 1" >>$@
-	echo "#define HAVE_STDLIB_H 1" >>$@
-	echo "#define HAVE_STRERROR 1" >>$@
-	echo "#define HAVE_STRINGS_H 1" >>$@
-	echo "#define HAVE_STRING_H 1" >>$@
-	echo "#define HAVE_STRLCAT 1" >>$@
-	echo "#define HAVE_STRLCPY 1" >>$@
-	echo "#define HAVE_STRTOLL 1" >>$@
-	echo "#define HAVE_STRTOQ 1" >>$@
-	echo "#define HAVE_SYS_STAT_H 1" >>$@
-	echo "#define HAVE_SYS_TYPES_H 1" >>$@
-	echo "#define HAVE_SETENV 1" >>$@
-	echo "#define HAVE_UNISTD_H 1" >>$@
-	echo "#define HAVE_UNSIGNED_LONG_LONG 1" >>$@
-	echo "#define STDC_HEADERS 1" >>$@
-	echo "#define HAVE_ALLOCA 1" >>$@
-	echo "#define HAVE_ALLOCA_H 1" >>$@
-	echo "#define HAVE_CRT_EXTERNS_H 1" >>$@
-	echo "#define HAVE_ERRNO_H 1" >>$@
-	echo "#define HAVE_SYSEXITS_H 1" >>$@
-	echo "#define C_STACK_GROWS_DOWNWARD 1" >>$@
+	echo "/* GENERATED */" >$@.tmp
+	echo "#define HAVE_DIRENT_H 1" >>$@.tmp
+	echo "#define HAVE_DLFCN_H 1" >>$@.tmp
+	echo "#define HAVE_INTTYPES_H 1" >>$@.tmp
+	echo "#define HAVE_LIMITS_H 1" >>$@.tmp
+	echo "#define HAVE_LONG_LONG 1" >>$@.tmp
+	echo "#define HAVE_MEMMOVE 1" >>$@.tmp
+	echo "#define HAVE_MEMORY_H 1" >>$@.tmp
+	echo "#define HAVE_SIGACTION 1" >>$@.tmp
+	echo "#define HAVE_SIGSETJMP 1" >>$@.tmp
+	echo "#define HAVE_SIGPROCMASK 1" >>$@.tmp
+	echo "#define HAVE_STDINT_H 1" >>$@.tmp
+	echo "#define HAVE_STDLIB_H 1" >>$@.tmp
+	echo "#define HAVE_STRERROR 1" >>$@.tmp
+	echo "#define HAVE_STRINGS_H 1" >>$@.tmp
+	echo "#define HAVE_STRING_H 1" >>$@.tmp
+	echo "#define HAVE_STRLCAT 1" >>$@.tmp
+	echo "#define HAVE_STRLCPY 1" >>$@.tmp
+	echo "#define HAVE_STRTOLL 1" >>$@.tmp
+	echo "#define HAVE_STRTOQ 1" >>$@.tmp
+	echo "#define HAVE_SYS_STAT_H 1" >>$@.tmp
+	echo "#define HAVE_SYS_TYPES_H 1" >>$@.tmp
+	echo "#define HAVE_SETENV 1" >>$@.tmp
+	echo "#define HAVE_UNISTD_H 1" >>$@.tmp
+	echo "#define HAVE_UNSIGNED_LONG_LONG 1" >>$@.tmp
+	echo "#define STDC_HEADERS 1" >>$@.tmp
+	echo "#define HAVE_ALLOCA 1" >>$@.tmp
+	echo "#define HAVE_ALLOCA_H 1" >>$@.tmp
+	echo "#define HAVE_CRT_EXTERNS_H 1" >>$@.tmp
+	echo "#define HAVE_ERRNO_H 1" >>$@.tmp
+	echo "#define HAVE_SYSEXITS_H 1" >>$@.tmp
+	echo "#define C_STACK_GROWS_DOWNWARD 1" >>$@.tmp
 ifdef GCHOOKS
-	echo "#define C_GC_HOOKS" >>$@
+	echo "#define C_GC_HOOKS" >>$@.tmp
 endif
-	cat chicken-defaults.h >>$@
+	cat $@.tmp chicken-defaults.h >$@.tmp2
+	rm $@.tmp
+	mv $@.tmp2 $@
 
 include $(SRCDIR)/rules.make
diff --git a/Makefile.mingw-msys b/Makefile.mingw-msys
index e6698cbe..db4bf2a7 100644
--- a/Makefile.mingw-msys
+++ b/Makefile.mingw-msys
@@ -78,35 +78,37 @@ POSIXFILE = posixwin
 include $(SRCDIR)/defaults.make
 
 chicken-config.h: chicken-defaults.h
-	echo "/* GENERATED */" >$@
-	echo "#define HAVE_DIRENT_H 1" >>$@
-	echo "#define HAVE_INTTYPES_H 1" >>$@
-	echo "#define HAVE_LIMITS_H 1" >>$@
-	echo "#define HAVE_LONG_LONG 1" >>$@
-	echo "#define HAVE_MEMMOVE 1" >>$@
-	echo "#define HAVE_MEMORY_H 1" >>$@
-	echo "#define NO_POSIX_POLL 1" >>$@
-	echo "#define HAVE_STDINT_H 1" >>$@
-	echo "#define HAVE_STDLIB_H 1" >>$@
-	echo "#define HAVE_STRERROR 1" >>$@
-	echo "#define HAVE_STRINGS_H 1" >>$@
-	echo "#define HAVE_STRING_H 1" >>$@
-	echo "#define HAVE_STRTOLL 1" >>$@
-	echo "#define HAVE_SYS_STAT_H 1" >>$@
-	echo "#define HAVE_SYS_TYPES_H 1" >>$@
-	echo "#define HAVE_UNISTD_H 1" >>$@
-	echo "#define HAVE_UNSIGNED_LONG_LONG 1" >>$@
-	echo "#define STDC_HEADERS 1" >>$@
-	echo "#define HAVE_DIRECT_H 1" >>$@
-	echo "#define HAVE_ERRNO_H 1" >>$@
-	echo "#define HAVE_LOADLIBRARY 1" >>$@
-	echo "#define HAVE_GETPROCADDRESS 1" >>$@
-	echo "#define C_WINDOWS_SHELL 1" >>$@
-	echo "#define C_STACK_GROWS_DOWNWARD 1" >>$@
+	echo "/* GENERATED */" >$@.tmp
+	echo "#define HAVE_DIRENT_H 1" >>$@.tmp
+	echo "#define HAVE_INTTYPES_H 1" >>$@.tmp
+	echo "#define HAVE_LIMITS_H 1" >>$@.tmp
+	echo "#define HAVE_LONG_LONG 1" >>$@.tmp
+	echo "#define HAVE_MEMMOVE 1" >>$@.tmp
+	echo "#define HAVE_MEMORY_H 1" >>$@.tmp
+	echo "#define NO_POSIX_POLL 1" >>$@.tmp
+	echo "#define HAVE_STDINT_H 1" >>$@.tmp
+	echo "#define HAVE_STDLIB_H 1" >>$@.tmp
+	echo "#define HAVE_STRERROR 1" >>$@.tmp
+	echo "#define HAVE_STRINGS_H 1" >>$@.tmp
+	echo "#define HAVE_STRING_H 1" >>$@.tmp
+	echo "#define HAVE_STRTOLL 1" >>$@.tmp
+	echo "#define HAVE_SYS_STAT_H 1" >>$@.tmp
+	echo "#define HAVE_SYS_TYPES_H 1" >>$@.tmp
+	echo "#define HAVE_UNISTD_H 1" >>$@.tmp
+	echo "#define HAVE_UNSIGNED_LONG_LONG 1" >>$@.tmp
+	echo "#define STDC_HEADERS 1" >>$@.tmp
+	echo "#define HAVE_DIRECT_H 1" >>$@.tmp
+	echo "#define HAVE_ERRNO_H 1" >>$@.tmp
+	echo "#define HAVE_LOADLIBRARY 1" >>$@.tmp
+	echo "#define HAVE_GETPROCADDRESS 1" >>$@.tmp
+	echo "#define C_WINDOWS_SHELL 1" >>$@.tmp
+	echo "#define C_STACK_GROWS_DOWNWARD 1" >>$@.tmp
 ifdef GCHOOKS
-	echo "#define C_GC_HOOKS" >>$@
+	echo "#define C_GC_HOOKS" >>$@.tmp
 endif
-	echo "#define C_USE_STD_FEATURE_MACROS" >>$@
-	cat chicken-defaults.h >>$@
+	echo "#define C_USE_STD_FEATURE_MACROS" >>$@.tmp
+	cat $@.tmp chicken-defaults.h >$@.tmp2
+	rm $@.tmp
+	mv $@.tmp2 $@
 
 include $(SRCDIR)/rules.make
diff --git a/Makefile.solaris b/Makefile.solaris
index a3bbe8a0..a18086c6 100644
--- a/Makefile.solaris
+++ b/Makefile.solaris
@@ -90,37 +90,39 @@ CHICKEN_CONFIG_H = chicken-config.h
 include $(SRCDIR)/defaults.make
 
 chicken-config.h: chicken-defaults.h
-	echo "/* END OF FILE */" >$@
-	echo "#define HAVE_DIRENT_H 1" >>$@
-	echo "#define HAVE_DLFCN_H 1" >>$@
-	echo "#define HAVE_INTTYPES_H 1" >>$@
-	echo "#define HAVE_LIMITS_H 1" >>$@
-	echo "#define HAVE_LONG_LONG 1" >>$@
-	echo "#define HAVE_MEMMOVE 1" >>$@
-	echo "#define HAVE_MEMORY_H 1" >>$@
-	echo "#define HAVE_SIGACTION 1" >>$@
-	echo "#define HAVE_STDINT_H 1" >>$@
-	echo "#define HAVE_STDLIB_H 1" >>$@
-	echo "#define HAVE_STRERROR 1" >>$@
-	echo "#define HAVE_STRINGS_H 1" >>$@
-	echo "#define HAVE_STRING_H 1" >>$@
-	echo "#define HAVE_STRLCAT 1" >>$@
-	echo "#define HAVE_STRLCPY 1" >>$@
-	echo "#define HAVE_STRTOLL 1" >>$@
-	echo "#define HAVE_SYS_STAT_H 1" >>$@
-	echo "#define HAVE_SYS_TYPES_H 1" >>$@
-	echo "#define HAVE_SETENV 1" >>$@
-	echo "#define HAVE_UNISTD_H 1" >>$@
-	echo "#define HAVE_UNSIGNED_LONG_LONG 1" >>$@
-	echo "#define STDC_HEADERS 1" >>$@
-	echo "#define HAVE_ALLOCA_H 1" >>$@
-	echo "#define HAVE_ALLOCA 1" >>$@
-	echo "#define HAVE_ERRNO_H 1" >>$@
-	echo "#define HAVE_SYSEXITS_H 1" >>$@
-	echo "#define C_STACK_GROWS_DOWNWARD 1" >>$@
+	echo "/* END OF FILE */" >$@.tmp
+	echo "#define HAVE_DIRENT_H 1" >>$@.tmp
+	echo "#define HAVE_DLFCN_H 1" >>$@.tmp
+	echo "#define HAVE_INTTYPES_H 1" >>$@.tmp
+	echo "#define HAVE_LIMITS_H 1" >>$@.tmp
+	echo "#define HAVE_LONG_LONG 1" >>$@.tmp
+	echo "#define HAVE_MEMMOVE 1" >>$@.tmp
+	echo "#define HAVE_MEMORY_H 1" >>$@.tmp
+	echo "#define HAVE_SIGACTION 1" >>$@.tmp
+	echo "#define HAVE_STDINT_H 1" >>$@.tmp
+	echo "#define HAVE_STDLIB_H 1" >>$@.tmp
+	echo "#define HAVE_STRERROR 1" >>$@.tmp
+	echo "#define HAVE_STRINGS_H 1" >>$@.tmp
+	echo "#define HAVE_STRING_H 1" >>$@.tmp
+	echo "#define HAVE_STRLCAT 1" >>$@.tmp
+	echo "#define HAVE_STRLCPY 1" >>$@.tmp
+	echo "#define HAVE_STRTOLL 1" >>$@.tmp
+	echo "#define HAVE_SYS_STAT_H 1" >>$@.tmp
+	echo "#define HAVE_SYS_TYPES_H 1" >>$@.tmp
+	echo "#define HAVE_SETENV 1" >>$@.tmp
+	echo "#define HAVE_UNISTD_H 1" >>$@.tmp
+	echo "#define HAVE_UNSIGNED_LONG_LONG 1" >>$@.tmp
+	echo "#define STDC_HEADERS 1" >>$@.tmp
+	echo "#define HAVE_ALLOCA_H 1" >>$@.tmp
+	echo "#define HAVE_ALLOCA 1" >>$@.tmp
+	echo "#define HAVE_ERRNO_H 1" >>$@.tmp
+	echo "#define HAVE_SYSEXITS_H 1" >>$@.tmp
+	echo "#define C_STACK_GROWS_DOWNWARD 1" >>$@.tmp
 ifdef GCHOOKS
-	echo "#define C_GC_HOOKS" >>$@
+	echo "#define C_GC_HOOKS" >>$@.tmp
 endif
-	cat chicken-defaults.h >>$@
+	cat $@.tmp chicken-defaults.h >$@.tmp2
+	rm $@.tmp
+	mv $@.tmp2 $@
 
 include $(SRCDIR)/rules.make
diff --git a/defaults.make b/defaults.make
index e471c3f0..703e1cf1 100644
--- a/defaults.make
+++ b/defaults.make
@@ -337,208 +337,211 @@ all: $(TARGETS)
 
 chicken-defaults.h:
 ifdef OPTIMIZE_FOR_SPEED
-	$(call echo, >,$@, /* (this build was optimized for speed) */)
+	$(call echo, >,$@.tmp, /* (this build was optimized for speed) */)
 endif
 ifdef DEBUGBUILD
-	$(call echo, >>, $@,#define DEBUGBUILD 1)
+	$(call echo, >>, $@.tmp,#define DEBUGBUILD 1)
 endif
 ifdef STATICBUILD
-	$(call echo, >>, $@,#define STATICBUILD 1)
+	$(call echo, >>, $@.tmp,#define STATICBUILD 1)
 endif
-	$(call echo, >>, $@,#define C_CHICKEN_PROGRAM "$(CHICKEN_PROGRAM)$(EXE)")
-	$(call echo, >>, $@,#ifndef C_INSTALL_CC)
-	$(call echo, >>, $@,# define C_INSTALL_CC "$(C_COMPILER)")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_INSTALL_CXX)
-	$(call echo, >>, $@,# define C_INSTALL_CXX "$(CXX_COMPILER)")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_INSTALL_POSTINSTALL_PROGRAM)
-	$(call echo, >>, $@,# define C_INSTALL_POSTINSTALL_PROGRAM "$(POSTINSTALL_PROGRAM)")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_INSTALL_RC_COMPILER)
-	$(call echo, >>, $@,# define C_INSTALL_RC_COMPILER "$(RC_COMPILER)")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_INSTALL_CFLAGS)
-	$(call echo, >>, $@,# define C_INSTALL_CFLAGS "$(C_COMPILER_OPTIONS) $(C_COMPILER_OPTIMIZATION_OPTIONS)")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_INSTALL_LDFLAGS)
-	$(call echo, >>, $@,# define C_INSTALL_LDFLAGS "$(LINKER_OPTIONS) $(LINKER_OPTIMIZATION_OPTIONS)")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_INSTALL_PREFIX)
-	$(call echo, >>, $@,# define C_INSTALL_PREFIX "$(PREFIX)")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_INSTALL_SHARE_HOME)
-	$(call echo, >>, $@,# define C_INSTALL_SHARE_HOME "$(DATADIR)")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_INSTALL_BIN_HOME)
-	$(call echo, >>, $@,# define C_INSTALL_BIN_HOME "$(BINDIR)")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_INSTALL_EGG_HOME)
-	$(call echo, >>, $@,# define C_INSTALL_EGG_HOME "$(EGGDIR)")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_INSTALL_LIB_HOME)
-	$(call echo, >>, $@,# define C_INSTALL_LIB_HOME "$(LIBDIR)")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_INSTALL_LIB_NAME)
-	$(call echo, >>, $@,# define C_INSTALL_LIB_NAME "$(INSTALL_LIB_NAME)")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_INSTALL_STATIC_LIB_HOME)
-	$(call echo, >>, $@,# define C_INSTALL_STATIC_LIB_HOME "$(LIBDIR)")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_INSTALL_INCLUDE_HOME)
-	$(call echo, >>, $@,# define C_INSTALL_INCLUDE_HOME "$(CHICKENINCDIR)")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_INSTALL_MORE_LIBS)
-	$(call echo, >>, $@,# define C_INSTALL_MORE_LIBS "$(LIBRARIES)")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_INSTALL_MORE_STATIC_LIBS)
-	$(call echo, >>, $@,# define C_INSTALL_MORE_STATIC_LIBS "$(LIBRARIES)")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_STACK_GROWS_DOWNWARD)
-	$(call echo, >>, $@,# define C_STACK_GROWS_DOWNWARD $(STACKDIRECTION))
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_TARGET_MORE_LIBS)
-	$(call echo, >>, $@,# define C_TARGET_MORE_LIBS "$(TARGET_LIBRARIES)")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_TARGET_MORE_STATIC_LIBS)
-	$(call echo, >>, $@,# define C_TARGET_MORE_STATIC_LIBS "$(TARGET_LIBRARIES)")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_TARGET_CC)
-	$(call echo, >>, $@,# define C_TARGET_CC "$(TARGET_C_COMPILER)")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_TARGET_CXX)
-	$(call echo, >>, $@,# define C_TARGET_CXX "$(TARGET_CXX_COMPILER)")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_TARGET_RC_COMPILER)
-	$(call echo, >>, $@,# define C_TARGET_RC_COMPILER "$(TARGET_RC_COMPILER)")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_TARGET_LIBRARIAN)
-	$(call echo, >>, $@,# define C_TARGET_LIBRARIAN "$(TARGET_LIBRARIAN)")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_TARGET_INSTALL_PROGRAM)
-	$(call echo, >>, $@,# define C_TARGET_INSTALL_PROGRAM "$(INSTALL_PROGRAM)")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_TARGET_CFLAGS)
-	$(call echo, >>, $@,# define C_TARGET_CFLAGS "$(TARGET_C_COMPILER_OPTIONS) $(TARGET_C_COMPILER_OPTIMIZATION_OPTIONS)")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_TARGET_LIBRARIAN_FLAGS)
-	$(call echo, >>, $@,# define C_TARGET_LIBRARIAN_FLAGS "$(TARGET_LIBRARIAN_OPTIONS)")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_TARGET_LDFLAGS)
-	$(call echo, >>, $@,# define C_TARGET_LDFLAGS "$(TARGET_LINKER_OPTIONS) $(TARGET_LINKER_OPTIMIZATION_OPTIONS)")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_TARGET_INSTALL_PROGRAM_EXECUTABLE_OPTIONS)
-	$(call echo, >>, $@,# define C_TARGET_INSTALL_PROGRAM_EXECUTABLE_OPTIONS "$(INSTALL_PROGRAM_EXECUTABLE_OPTIONS)")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_TARGET_INSTALL_PROGRAM_FILE_OPTIONS)
-	$(call echo, >>, $@,# define C_TARGET_INSTALL_PROGRAM_FILE_OPTIONS "$(INSTALL_PROGRAM_FILE_OPTIONS)")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_TARGET_FEATURES)
-	$(call echo, >>, $@,# define C_TARGET_FEATURES "$(TARGET_FEATURES)")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_CROSS_CHICKEN)
-	$(call echo, >>, $@,# define C_CROSS_CHICKEN $(CROSS_CHICKEN))
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_TARGET_PREFIX)
-	$(call echo, >>, $@,# define C_TARGET_PREFIX "$(TARGET_PREFIX)")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_TARGET_BIN_HOME)
-	$(call echo, >>, $@,# define C_TARGET_BIN_HOME "$(TARGET_PREFIX)/bin")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_TARGET_LIB_HOME)
-	$(call echo, >>, $@,# define C_TARGET_LIB_HOME "$(TARGET_PREFIX)/lib")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_TARGET_LIB_NAME)
-	$(call echo, >>, $@,# define C_TARGET_LIB_NAME "$(TARGET_LIB_NAME)")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_TARGET_RUN_LIB_HOME)
+	$(call echo, >>, $@.tmp,#define C_CHICKEN_PROGRAM "$(CHICKEN_PROGRAM)$(EXE)")
+	$(call echo, >>, $@.tmp,#ifndef C_INSTALL_CC)
+	$(call echo, >>, $@.tmp,# define C_INSTALL_CC "$(C_COMPILER)")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_INSTALL_CXX)
+	$(call echo, >>, $@.tmp,# define C_INSTALL_CXX "$(CXX_COMPILER)")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_INSTALL_POSTINSTALL_PROGRAM)
+	$(call echo, >>, $@.tmp,# define C_INSTALL_POSTINSTALL_PROGRAM "$(POSTINSTALL_PROGRAM)")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_INSTALL_RC_COMPILER)
+	$(call echo, >>, $@.tmp,# define C_INSTALL_RC_COMPILER "$(RC_COMPILER)")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_INSTALL_CFLAGS)
+	$(call echo, >>, $@.tmp,# define C_INSTALL_CFLAGS "$(C_COMPILER_OPTIONS) $(C_COMPILER_OPTIMIZATION_OPTIONS)")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_INSTALL_LDFLAGS)
+	$(call echo, >>, $@.tmp,# define C_INSTALL_LDFLAGS "$(LINKER_OPTIONS) $(LINKER_OPTIMIZATION_OPTIONS)")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_INSTALL_PREFIX)
+	$(call echo, >>, $@.tmp,# define C_INSTALL_PREFIX "$(PREFIX)")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_INSTALL_SHARE_HOME)
+	$(call echo, >>, $@.tmp,# define C_INSTALL_SHARE_HOME "$(DATADIR)")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_INSTALL_BIN_HOME)
+	$(call echo, >>, $@.tmp,# define C_INSTALL_BIN_HOME "$(BINDIR)")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_INSTALL_EGG_HOME)
+	$(call echo, >>, $@.tmp,# define C_INSTALL_EGG_HOME "$(EGGDIR)")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_INSTALL_LIB_HOME)
+	$(call echo, >>, $@.tmp,# define C_INSTALL_LIB_HOME "$(LIBDIR)")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_INSTALL_LIB_NAME)
+	$(call echo, >>, $@.tmp,# define C_INSTALL_LIB_NAME "$(INSTALL_LIB_NAME)")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_INSTALL_STATIC_LIB_HOME)
+	$(call echo, >>, $@.tmp,# define C_INSTALL_STATIC_LIB_HOME "$(LIBDIR)")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_INSTALL_INCLUDE_HOME)
+	$(call echo, >>, $@.tmp,# define C_INSTALL_INCLUDE_HOME "$(CHICKENINCDIR)")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_INSTALL_MORE_LIBS)
+	$(call echo, >>, $@.tmp,# define C_INSTALL_MORE_LIBS "$(LIBRARIES)")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_INSTALL_MORE_STATIC_LIBS)
+	$(call echo, >>, $@.tmp,# define C_INSTALL_MORE_STATIC_LIBS "$(LIBRARIES)")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_STACK_GROWS_DOWNWARD)
+	$(call echo, >>, $@.tmp,# define C_STACK_GROWS_DOWNWARD $(STACKDIRECTION))
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_TARGET_MORE_LIBS)
+	$(call echo, >>, $@.tmp,# define C_TARGET_MORE_LIBS "$(TARGET_LIBRARIES)")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_TARGET_MORE_STATIC_LIBS)
+	$(call echo, >>, $@.tmp,# define C_TARGET_MORE_STATIC_LIBS "$(TARGET_LIBRARIES)")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_TARGET_CC)
+	$(call echo, >>, $@.tmp,# define C_TARGET_CC "$(TARGET_C_COMPILER)")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_TARGET_CXX)
+	$(call echo, >>, $@.tmp,# define C_TARGET_CXX "$(TARGET_CXX_COMPILER)")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_TARGET_RC_COMPILER)
+	$(call echo, >>, $@.tmp,# define C_TARGET_RC_COMPILER "$(TARGET_RC_COMPILER)")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_TARGET_LIBRARIAN)
+	$(call echo, >>, $@.tmp,# define C_TARGET_LIBRARIAN "$(TARGET_LIBRARIAN)")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_TARGET_INSTALL_PROGRAM)
+	$(call echo, >>, $@.tmp,# define C_TARGET_INSTALL_PROGRAM "$(INSTALL_PROGRAM)")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_TARGET_CFLAGS)
+	$(call echo, >>, $@.tmp,# define C_TARGET_CFLAGS "$(TARGET_C_COMPILER_OPTIONS) $(TARGET_C_COMPILER_OPTIMIZATION_OPTIONS)")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_TARGET_LIBRARIAN_FLAGS)
+	$(call echo, >>, $@.tmp,# define C_TARGET_LIBRARIAN_FLAGS "$(TARGET_LIBRARIAN_OPTIONS)")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_TARGET_LDFLAGS)
+	$(call echo, >>, $@.tmp,# define C_TARGET_LDFLAGS "$(TARGET_LINKER_OPTIONS) $(TARGET_LINKER_OPTIMIZATION_OPTIONS)")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_TARGET_INSTALL_PROGRAM_EXECUTABLE_OPTIONS)
+	$(call echo, >>, $@.tmp,# define C_TARGET_INSTALL_PROGRAM_EXECUTABLE_OPTIONS "$(INSTALL_PROGRAM_EXECUTABLE_OPTIONS)")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_TARGET_INSTALL_PROGRAM_FILE_OPTIONS)
+	$(call echo, >>, $@.tmp,# define C_TARGET_INSTALL_PROGRAM_FILE_OPTIONS "$(INSTALL_PROGRAM_FILE_OPTIONS)")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_TARGET_FEATURES)
+	$(call echo, >>, $@.tmp,# define C_TARGET_FEATURES "$(TARGET_FEATURES)")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_CROSS_CHICKEN)
+	$(call echo, >>, $@.tmp,# define C_CROSS_CHICKEN $(CROSS_CHICKEN))
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_TARGET_PREFIX)
+	$(call echo, >>, $@.tmp,# define C_TARGET_PREFIX "$(TARGET_PREFIX)")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_TARGET_BIN_HOME)
+	$(call echo, >>, $@.tmp,# define C_TARGET_BIN_HOME "$(TARGET_PREFIX)/bin")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_TARGET_LIB_HOME)
+	$(call echo, >>, $@.tmp,# define C_TARGET_LIB_HOME "$(TARGET_PREFIX)/lib")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_TARGET_LIB_NAME)
+	$(call echo, >>, $@.tmp,# define C_TARGET_LIB_NAME "$(TARGET_LIB_NAME)")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_TARGET_RUN_LIB_HOME)
 ifdef DLLSINPATH
-	$(call echo, >>, $@,# define C_TARGET_RUN_LIB_HOME "$(TARGET_RUN_PREFIX)/bin")
+	$(call echo, >>, $@.tmp,# define C_TARGET_RUN_LIB_HOME "$(TARGET_RUN_PREFIX)/bin")
 else
-	$(call echo, >>, $@,# define C_TARGET_RUN_LIB_HOME "$(TARGET_RUN_PREFIX)/lib")
+	$(call echo, >>, $@.tmp,# define C_TARGET_RUN_LIB_HOME "$(TARGET_RUN_PREFIX)/lib")
 endif
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_TARGET_SHARE_HOME)
-	$(call echo, >>, $@,# define C_TARGET_SHARE_HOME "$(TARGET_PREFIX)/share/chicken")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_TARGET_INCLUDE_HOME)
-	$(call echo, >>, $@,# define C_TARGET_INCLUDE_HOME "$(TARGET_PREFIX)/include/chicken")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_TARGET_STATIC_LIB_HOME)
-	$(call echo, >>, $@,# define C_TARGET_STATIC_LIB_HOME "$(TARGET_PREFIX)/lib")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_CHICKEN_PROGRAM)
-	$(call echo, >>, $@,# define C_CHICKEN_PROGRAM "$(CHICKEN_PROGRAM)")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_CSC_PROGRAM)
-	$(call echo, >>, $@,# define C_CSC_PROGRAM "$(CSC_PROGRAM)")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_CSI_PROGRAM)
-	$(call echo, >>, $@,# define C_CSI_PROGRAM "$(CSI_PROGRAM)")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_CHICKEN_DO_PROGRAM)
-	$(call echo, >>, $@,# define C_CHICKEN_DO_PROGRAM "$(CHICKEN_DO_PROGRAM)")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_CHICKEN_INSTALL_PROGRAM)
-	$(call echo, >>, $@,# define C_CHICKEN_INSTALL_PROGRAM "$(CHICKEN_INSTALL_PROGRAM)")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_CHICKEN_UNINSTALL_PROGRAM)
-	$(call echo, >>, $@,# define C_CHICKEN_UNINSTALL_PROGRAM "$(CHICKEN_UNINSTALL_PROGRAM)")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_CHICKEN_STATUS_PROGRAM)
-	$(call echo, >>, $@,# define C_CHICKEN_STATUS_PROGRAM "$(CHICKEN_STATUS_PROGRAM)")
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_WINDOWS_SHELL)
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_TARGET_SHARE_HOME)
+	$(call echo, >>, $@.tmp,# define C_TARGET_SHARE_HOME "$(TARGET_PREFIX)/share/chicken")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_TARGET_INCLUDE_HOME)
+	$(call echo, >>, $@.tmp,# define C_TARGET_INCLUDE_HOME "$(TARGET_PREFIX)/include/chicken")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_TARGET_STATIC_LIB_HOME)
+	$(call echo, >>, $@.tmp,# define C_TARGET_STATIC_LIB_HOME "$(TARGET_PREFIX)/lib")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_CHICKEN_PROGRAM)
+	$(call echo, >>, $@.tmp,# define C_CHICKEN_PROGRAM "$(CHICKEN_PROGRAM)")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_CSC_PROGRAM)
+	$(call echo, >>, $@.tmp,# define C_CSC_PROGRAM "$(CSC_PROGRAM)")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_CSI_PROGRAM)
+	$(call echo, >>, $@.tmp,# define C_CSI_PROGRAM "$(CSI_PROGRAM)")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_CHICKEN_DO_PROGRAM)
+	$(call echo, >>, $@.tmp,# define C_CHICKEN_DO_PROGRAM "$(CHICKEN_DO_PROGRAM)")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_CHICKEN_INSTALL_PROGRAM)
+	$(call echo, >>, $@.tmp,# define C_CHICKEN_INSTALL_PROGRAM "$(CHICKEN_INSTALL_PROGRAM)")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_CHICKEN_UNINSTALL_PROGRAM)
+	$(call echo, >>, $@.tmp,# define C_CHICKEN_UNINSTALL_PROGRAM "$(CHICKEN_UNINSTALL_PROGRAM)")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_CHICKEN_STATUS_PROGRAM)
+	$(call echo, >>, $@.tmp,# define C_CHICKEN_STATUS_PROGRAM "$(CHICKEN_STATUS_PROGRAM)")
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_WINDOWS_SHELL)
 ifdef WINDOWS_SHELL
-	$(call echo, >>, $@,# define C_WINDOWS_SHELL 1)
+	$(call echo, >>, $@.tmp,# define C_WINDOWS_SHELL 1)
 else
-	$(call echo, >>, $@,# define C_WINDOWS_SHELL 0)
+	$(call echo, >>, $@.tmp,# define C_WINDOWS_SHELL 0)
 endif
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_BINARY_VERSION)
-	$(call echo, >>, $@,# define C_BINARY_VERSION $(BINARYVERSION))
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,#ifndef C_USES_SONAME)
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_BINARY_VERSION)
+	$(call echo, >>, $@.tmp,# define C_BINARY_VERSION $(BINARYVERSION))
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,#ifndef C_USES_SONAME)
 ifdef USES_SONAME
-	$(call echo, >>, $@,# define C_USES_SONAME 1)
+	$(call echo, >>, $@.tmp,# define C_USES_SONAME 1)
 else
-	$(call echo, >>, $@,# define C_USES_SONAME 0)
+	$(call echo, >>, $@.tmp,# define C_USES_SONAME 0)
 endif
-	$(call echo, >>, $@,#endif)
-	$(call echo, >>, $@,/* END OF FILE */)
+	$(call echo, >>, $@.tmp,#endif)
+	$(call echo, >>, $@.tmp,/* END OF FILE */)
+	mv $@.tmp $@
 
 chicken-install.rc:
-	$(call echo, >, $@,/* GENERATED */)
-	$(call echo, >>, $@,1 24 MOVEABLE PURE)
-	$(call echo, >>, $@,BEGIN)
-	$(call echo, >>, $@,  "<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes""?>\r\n")
-	$(call echo, >>, $@,  "<assembly xmlns=""urn:schemas-microsoft-com:asm.v1"" manifestVersion=""1.0"">\r\n")
-	$(call echo, >>, $@,  "  <assemblyIdentity version=""1.0.0.0"" processorArchitecture=""*"" name=""$(PROGRAM_PREFIX)chicken-install$(PROGRAM_SUFFIX)"" type=""win32""/>\r\n")
-	$(call echo, >>, $@,  "  <ms_asmv2:trustInfo xmlns:ms_asmv2=""urn:schemas-microsoft-com:asm.v2"">\r\n")
-	$(call echo, >>, $@,  "    <ms_asmv2:security>\r\n")
-	$(call echo, >>, $@,  "      <ms_asmv2:requestedPrivileges>\r\n")
-	$(call echo, >>, $@,  "        <ms_asmv2:requestedExecutionLevel level=""asInvoker"" uiAccess=""false""/>\r\n")
-	$(call echo, >>, $@,  "      </ms_asmv2:requestedPrivileges>\r\n")
-	$(call echo, >>, $@,  "    </ms_asmv2:security>\r\n")
-	$(call echo, >>, $@,  "  </ms_asmv2:trustInfo>\r\n")
-	$(call echo, >>, $@,  "</assembly>\r\n")
-	$(call echo, >>, $@,END)
-	$(call echo, >>, $@,/* END OF FILE */)
+	$(call echo, >, $@.tmp,/* GENERATED */)
+	$(call echo, >>, $@.tmp,1 24 MOVEABLE PURE)
+	$(call echo, >>, $@.tmp,BEGIN)
+	$(call echo, >>, $@.tmp,  "<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes""?>\r\n")
+	$(call echo, >>, $@.tmp,  "<assembly xmlns=""urn:schemas-microsoft-com:asm.v1"" manifestVersion=""1.0"">\r\n")
+	$(call echo, >>, $@.tmp,  "  <assemblyIdentity version=""1.0.0.0"" processorArchitecture=""*"" name=""$(PROGRAM_PREFIX)chicken-install$(PROGRAM_SUFFIX)"" type=""win32""/>\r\n")
+	$(call echo, >>, $@.tmp,  "  <ms_asmv2:trustInfo xmlns:ms_asmv2=""urn:schemas-microsoft-com:asm.v2"">\r\n")
+	$(call echo, >>, $@.tmp,  "    <ms_asmv2:security>\r\n")
+	$(call echo, >>, $@.tmp,  "      <ms_asmv2:requestedPrivileges>\r\n")
+	$(call echo, >>, $@.tmp,  "        <ms_asmv2:requestedExecutionLevel level=""asInvoker"" uiAccess=""false""/>\r\n")
+	$(call echo, >>, $@.tmp,  "      </ms_asmv2:requestedPrivileges>\r\n")
+	$(call echo, >>, $@.tmp,  "    </ms_asmv2:security>\r\n")
+	$(call echo, >>, $@.tmp,  "  </ms_asmv2:trustInfo>\r\n")
+	$(call echo, >>, $@.tmp,  "</assembly>\r\n")
+	$(call echo, >>, $@.tmp,END)
+	$(call echo, >>, $@.tmp,/* END OF FILE */)
+	mv $@.tmp $@
 
 chicken-uninstall.rc:
-	$(call echo, >, $@,/* GENERATED */)
-	$(call echo, >>, $@,1 24 MOVEABLE PURE)
-	$(call echo, >>, $@,BEGIN)
-	$(call echo, >>, $@,  "<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes""?>\r\n")
-	$(call echo, >>, $@,  "<assembly xmlns=""urn:schemas-microsoft-com:asm.v1"" manifestVersion=""1.0"">\r\n")
-	$(call echo, >>, $@,  "  <assemblyIdentity version=""1.0.0.0"" processorArchitecture=""*"" name=""$(PROGRAM_PREFIX)chicken-uninstall$(PROGRAM_SUFFIX)"" type=""win32""/>\r\n")
-	$(call echo, >>, $@,  "  <ms_asmv2:trustInfo xmlns:ms_asmv2=""urn:schemas-microsoft-com:asm.v2"">\r\n")
-	$(call echo, >>, $@,  "    <ms_asmv2:security>\r\n")
-	$(call echo, >>, $@,  "      <ms_asmv2:requestedPrivileges>\r\n")
-	$(call echo, >>, $@,  "        <ms_asmv2:requestedExecutionLevel level=""asInvoker"" uiAccess=""false""/>\r\n")
-	$(call echo, >>, $@,  "      </ms_asmv2:requestedPrivileges>\r\n")
-	$(call echo, >>, $@,  "    </ms_asmv2:security>\r\n")
-	$(call echo, >>, $@,  "  </ms_asmv2:trustInfo>\r\n")
-	$(call echo, >>, $@,  "</assembly>\r\n")
-	$(call echo, >>, $@,END)
-	$(call echo, >>, $@,/* END OF FILE */)
+	$(call echo, >, $@.tmp,/* GENERATED */)
+	$(call echo, >>, $@.tmp,1 24 MOVEABLE PURE)
+	$(call echo, >>, $@.tmp,BEGIN)
+	$(call echo, >>, $@.tmp,  "<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes""?>\r\n")
+	$(call echo, >>, $@.tmp,  "<assembly xmlns=""urn:schemas-microsoft-com:asm.v1"" manifestVersion=""1.0"">\r\n")
+	$(call echo, >>, $@.tmp,  "  <assemblyIdentity version=""1.0.0.0"" processorArchitecture=""*"" name=""$(PROGRAM_PREFIX)chicken-uninstall$(PROGRAM_SUFFIX)"" type=""win32""/>\r\n")
+	$(call echo, >>, $@.tmp,  "  <ms_asmv2:trustInfo xmlns:ms_asmv2=""urn:schemas-microsoft-com:asm.v2"">\r\n")
+	$(call echo, >>, $@.tmp,  "    <ms_asmv2:security>\r\n")
+	$(call echo, >>, $@.tmp,  "      <ms_asmv2:requestedPrivileges>\r\n")
+	$(call echo, >>, $@.tmp,  "        <ms_asmv2:requestedExecutionLevel level=""asInvoker"" uiAccess=""false""/>\r\n")
+	$(call echo, >>, $@.tmp,  "      </ms_asmv2:requestedPrivileges>\r\n")
+	$(call echo, >>, $@.tmp,  "    </ms_asmv2:security>\r\n")
+	$(call echo, >>, $@.tmp,  "  </ms_asmv2:trustInfo>\r\n")
+	$(call echo, >>, $@.tmp,  "</assembly>\r\n")
+	$(call echo, >>, $@.tmp,END)
+	$(call echo, >>, $@.tmp,/* END OF FILE */)
+	mv $@.tmp $@
-- 
2.39.2