#!/bin/sh -e

# 04_make_minus_j_fix.dpatch by Steve Kowalik and Colm Buckley

# DP: Fix building with 'make -j'.

. debian/patches/patch-opts

if [ $# -ne 1 ]; then
    echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
    exit 1
fi

case "$1" in
       -patch) patch $patch_opts -p1 < $0;;
       -unpatch) patch $patch_opts -p1 -R < $0;;
        *)
                echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
                exit 1;;
esac

exit 0

@DPATCH@

diff -urNad alsa-driver/Rules.make~ alsa-driver/Rules.make
--- alsa-driver/Rules.make~	2003-05-09 20:56:13.000000000 -0400
+++ alsa-driver/Rules.make	2003-05-09 23:20:38.000000000 -0400
@@ -240,7 +240,7 @@
 	genksyms_smp_prefix := 
 endif
 
-$(MODINCL)/$(MODPREFIX)%.ver: %.c
+$(MODINCL)/$(MODPREFIX)%.ver: %.c update-sndvers
 	@if [ ! -r $(MODINCL)/$(MODPREFIX)$*.stamp -o $(MODINCL)/$(MODPREFIX)$*.stamp -ot $< ]; then \
 		echo '$(CC) -D__KERNEL__ $(CFLAGS) $(EXTRA_CFLAGS) -E -D__GENKSYMS__ $<'; \
 		echo '| $(GENKSYMS) $(genksyms_smp_prefix) > $@.tmp'; \
@@ -258,7 +258,8 @@
 endif # export-objs 
 
 define update-sndvers
-	@(echo "#ifndef _LINUX_SNDVERSIONS_H"; \
+	(tmpfile=`mktemp $(SNDVERSIONS).XXXXXXXXXXXX`; \
+	(echo "#ifndef _LINUX_SNDVERSIONS_H"; \
 	  echo "#define _LINUX_SNDVERSIONS_H"; \
 	  echo "#include <linux/modsetver.h>"; \
 	  cd $(TOPDIR)/include/modules; \
@@ -266,14 +267,14 @@
 	    if [ -f $$f ]; then echo "#include \"modules/$${f}\""; fi; \
 	  done; \
 	  echo "#endif"; \
-	) > $(SNDVERSIONS).tmp
-	@if [ -r $(SNDVERSIONS) ] && cmp -s $(SNDVERSIONS) $(SNDVERSIONS).tmp; then \
+	) > $${tmpfile}; \
+	if [ -r $(SNDVERSIONS) ] && cmp -s $(SNDVERSIONS) $${tmpfile}; then \
 		echo $(SNDVERSIONS) was not updated; \
-		rm -f $(SNDVERSIONS).tmp; \
+		rm -f $${tmpfile}; \
 	else \
 		echo $(SNDVERSIONS) was updated; \
-		mv -f $(SNDVERSIONS).tmp $(SNDVERSIONS); \
-	fi
+		mv -f $${tmpfile} $(SNDVERSIONS); \
+	fi)
 endef
 
 $(SNDVERSIONS):
