> - If a file is not found, it will search for it and warn you.

With the attached patch, the alternative file will be cleaned if found.
--- deblob-2.6.30_orig	2009-06-12 18:37:42.000000000 +0200
+++ deblob-2.6.30	2009-09-03 09:49:18.511007256 +0200
@@ -2,6 +2,7 @@
 
 #    Copyright (C) 2008, 2009 Alexandre Oliva <[email protected]>
 #    Copyright (C) 2008 Jeff Moe
+#    Copyright (C) 2009 Rubén Rodríguez <[email protected]>
 #
 #    This program is free software; you can redistribute it and/or modify
 #    it under the terms of the GNU General Public License as published by
@@ -45,16 +46,24 @@
 # For each kver release, start extra with an empty string, then count
 # from 1 if changes are needed that require rebuilding the tarball.
 kver=2.6.30 extra=
+filelist=$(mktemp)
+rm $filelist
 
-fatal () {
-  echo "$@"
-  exit 1
-}
-
-case $1 in
---force) die () { echo ERROR: "$@": ignored >&2; }; forced=:; shift;;
-*) die () { fatal "$@"; }; forced=false;;
-esac
+if [ 1$1 = "1--force" ]; then
+    echo "WARNING: Using the force, ignored errors will be"
+    die () {
+        echo ERROR: "$@" >&2; 
+    }
+    forced=true
+    shift
+else
+    die () {
+        echo ERROR: "$@" >&2; 
+	echo Use --force to ignore
+	exit 1
+    }
+    forced=false
+fi
 
 check=`echo "$0" | sed 's,[^/]*$,,;s,^$,.,;s,/*$,,'`/deblob-check
 if [ ! -f $check ] ; then
@@ -68,6 +77,32 @@
   have_check=:
 fi
 
+filetest () {
+	export FILE=$1
+	if ! [ -f $1 ]
+	then	
+		if [ $( basename $1) = Makefile ] || [ $( basename $1) = Kconfig ]
+		then
+			die File not found: $1
+			return 1
+		fi
+		
+		file=$( basename $1)
+		[ -f $filelist ] || find > $filelist
+		if alternatives=$(egrep  /$file$ $filelist)
+		then
+			die File not found: $1
+			echo WARNING: alternative\(s\) to $1 found: $alternatives
+			export FILE=$(echo $alternatives | cut -d ' ' -f 1)
+			echo WARNING: Deblobbing the first alternative: $FILE
+			return 0
+		else
+			die File not found: $1, no alternatives found
+		fi
+		return 1
+	fi
+}
+
 announce () {
 	echo
 	echo "$@"
@@ -75,45 +110,41 @@
 
 clean_file () {
 	#$1 = filename
-	if test ! -f $1; then
-		die $1 does not exist, something is wrong
-	fi
-	rm $1
-	echo $1: removed
+	filetest $1 || return
+	rm $FILE
+	echo $FILE: removed
 }
 
 check_changed () {
-	if test ! -f $1; then
-		die $1 does not exist, something is wrong
-	elif cmp $1.deblob $1 > /dev/null; then
-		die $1 did not change, something is wrong
+	#$1 = filename
+	if cmp $1.deblob $1 > /dev/null; then
+		rm $1.deblob
+		die $1 did not change, something is wrong && return 1
 	fi
-	mv $1.deblob $1
+		mv $1.deblob $1
+		return 0
 }
 
 clean_blob () {
 	#$1 = filename
+	filetest $1 || return
 	if $have_check; then
-	    if test ! -f $1; then
-		die $1 does not exist, something is wrong
-	    fi
-	    name=$1
+	    name=$FILE
 	    set fnord "$@" -d
 	    shift 2
 	    $check "$@" -i linux-$kver $name > $name.deblob
-	    echo $name: removed blobs
-	    check_changed $name
+	    check_changed $name && echo $name: removed blobs
 	else
-	    clean_file $1
+	    clean_file $FILE
 	fi
 }
 
 dummy_blob () {
 	#$1 = filename
 	if test -f $1; then
-	    die $1 exists, something is wrong
+	    die $1 exists, something is wrong && return
 	elif test ! -f firmware/Makefile; then
-	    die firmware/Makefile does not exist, something is wrong
+	    die firmware/Makefile does not exist, something is wrong && return
 	fi
 
 	clean_sed "s,`echo $1 | sed s,^firmware/,,`,\$(DEBLOBBED),g" \
@@ -122,23 +153,21 @@
 
 clean_fw () {
 	#$1 = firmware text input, $2 = firmware output
-	if test ! -f $1; then
-		die $1 does not exist, something is wrong
-	elif test -f $2; then
-		die $2 exists, something is wrong
+	filetest $1 || return
+	if test -f $2; then
+		die $2 exists, something is wrong && return
 	fi
-	clean_blob $1 -s 4
+	clean_blob $FILE -s 4
 	dummy_blob $2
 }
 
 drop_fw_file () {
 	#$1 = firmware text input, $2 = firmware output
-	if test ! -f $1; then
-		die $1 does not exist, something is wrong
-	elif test -f $2; then
-		die $2 exists, something is wrong
+	filetest $1 || return
+	if test -f $2; then
+		die $2 exists, something is wrong && return
 	fi
-	clean_file $1
+	clean_file $FILE
 	dummy_blob $2
 }
 
@@ -154,11 +183,11 @@
 		fi
 		;;
 	esac
+	filetest $1 || return
 	sed "/^config \\($2\\)\$/{p;i\
 	depends on NONFREE
-d;}" $1 > $1.deblob
-	echo $1: marked config $2 as depending on NONFREE
-	check_changed $1
+d;}" $FILE > $FILE.deblob
+	check_changed $FILE && echo $FILE: marked config $2 as depending on NONFREE
 }
 
 clean_mk () {
@@ -167,32 +196,40 @@
 	# sed -i "/\\($1\\)/d" $2
 	# echo $2: removed $1 support
 	# check_changed $2
-	if sed -n "/\\($1\\)/p" $2 | grep . > /dev/null; then
+	filetest $2 || return
+	if sed -n "/\\($1\\)/p" $FILE | grep . > /dev/null; then
 	    :
 	else
-	    die $2 does not contain matches for $1
+	    die $FILE does not contain matches for $1
+	    if alternatives=$(grep Makefile $filelist | xargs grep $1)
+	    then
+		    echo WARNING: alternative matches found at $alternatives
+	    fi
+	
 	fi
 }
 
 clean_sed () {
 	#$1 = sed-script $2 = file $3 = comment
-	sed -e "$1" "$2" > "$2".deblob
-	echo $2: ${3-applied sed script $1}
-	check_changed "$2"
+	filetest $2 || return
+	sed -e "$1" "$FILE" > "$FILE".deblob
+	check_changed $FILE && echo $FILE: ${3-applied sed script $1} 
 }
 
 reject_firmware () {
 	#$1 = file
+	filetest $1 || return
 	clean_sed '
 s,request\(_ihex\)\?_firmware\(_nowait\)\?,reject_firmware\2,g
-' "$1" 'disabled non-Free firmware-loading machinery'
+' "$FILE" 'disabled non-Free firmware-loading machinery'
 }
 
 maybe_reject_firmware () {
 	#$1 = file
+	filetest $1 || return
 	clean_sed '
 s,request_firmware\(_nowait\)\?,maybe_reject_firmware\1,g
-' "$1" 'retain Free firmware-loading machinery, disabling non-Free one'
+' "$FILE" 'retain Free firmware-loading machinery, disabling non-Free one'
 }
 
 undefine_macro () {
@@ -255,18 +292,17 @@
     sound/pci/cs46xx/imgs/cwcdma.asp \
 ; do
   if test ! $f; then
-    die $f is not present, something is amiss
+    die $f is not present, something is amiss && return
   fi
 done
 
 # Identify the tarball.
-clean_sed "
-s,^EXTRAVERSION.*,&-libre$extra,
+grep -q EXTRAVERSION.*libre.* Makefile || clean_sed "s,^EXTRAVERSION.*,&-libre$extra,
 " Makefile 'added -libre to EXTRAVERSION'
 
 # Add reject_firmware and maybe_reject_firmware
-clean_sed '
-$i\
+grep -q LINUX_LIBRE include/linux/firmware.h || clean_sed '$i\
+#define dev_name(dev) ((dev)->bus_id) /* Undefined in kernels prior to 2.6.25 */\
 #ifndef _LINUX_LIBRE_FIRMWARE_H\
 #define _LINUX_LIBRE_FIRMWARE_H\
 \
@@ -1953,4 +1989,5 @@
 clean_blob firmware/README.AddingFirmware
 clean_blob firmware/WHENCE
 
+[ -f $filelist ] && rm $filelist
 exit 0
_______________________________________________
linux-libre mailing list
[email protected]
http://www.fsfla.org/cgi-bin/mailman/listinfo/linux-libre

Reply via email to