Robert Millan wrote:
On Thu, Jul 24, 2008 at 10:19:17PM +0200, Christian Franke wrote:
+  case "`uname 2>/dev/null`" in
+    CYGWIN*)

Could this be done at build time instead? (when generating update-grub
from update-grub.in)


Yes, of course. Some alternatives:

1.)
The method used by AM_CONDITIONAL from GNU automake is simple and works with config.status without any extra 'shell preprocessor'.

Looks ugly, but may be OK if there are only few changes. See attached patch for a working example.


2.)
Use some shell-preprocessor. A primitive version can be configured by above method:

update-grub.in:
@ifdef CYGWIN
...
@else CYGWIN
...
@endif CYGWIN

shellpp.sh.in:
@CYGWIN_TRUE@  sed '/[EMAIL PROTECTED] CYGWIN/,/[EMAIL PROTECTED] 
CYGWIN/d;/[EMAIL PROTECTED] CYGWIN/d'
@CYGWIN_FALSE@ sed '/[EMAIL PROTECTED] CYGWIN/d;/[EMAIL PROTECTED] 
CYGWIN/,/[EMAIL PROTECTED] CYGWIN/d'



3.)
Move platform specific code to functions in update-grub_lib, e.g. 'check_user_root()' in this case.

Let 'update-grub_lib' include optional platform specific scripts (e.g. 'update-grub-_lib-i386-pc-cygwin'). The existence of the script can be checked by configure. This script can then replace the default implementations if necessary:

Example:

update-grub.in:

check_user_root || exit 1


update-grub-lib.in:

check_user_root()
{
... default implementation, test EUID==0
}

[EMAIL PROTECTED]@
test -z "${platform_lib}" || . "${libdir}/${platform_lib}"


update-grub-_lib-i386-pc-cygwin:

check_user_root()
{
... Cygwin specific implementation ...
}


Any method would also help to implement 'make_system_path_relative_to_its_root()' without the need for 'grub-probe -t prefix'.

Christian

diff --git a/aclocal.m4 b/aclocal.m4
index ee6c4db..8c44678 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -414,3 +414,17 @@ else
   AC_MSG_RESULT([no])
 [fi]
 ])
+
+dnl Set conditional for target dependend sections in scripts.
+dnl Similar to AM_CONDITIONAL from GNU automake.
+AC_DEFUN([grub_CONDITIONAL],[
+AC_SUBST([$1_TRUE])
+AC_SUBST([$1_FALSE])
+if $2 ; then
+  $1_TRUE=
+  $1_FALSE="#"
+else
+  $1_TRUE="#"
+  $1_FALSE=
+fi
+])
diff --git a/configure.ac b/configure.ac
index 7a5938a..def656d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -351,6 +351,9 @@ CPPFLAGS="$tmp_CPPFLAGS"
 LDFLAGS="$tmp_LDFLAGS"
 LIBS="$tmp_LIBS"
 
+# Set conditionals for target dependend sections in scripts.
+grub_CONDITIONAL(CYGWIN, [test "$target_os" = cygwin])
+
 #
 # Check for options.
 #
diff --git a/util/update-grub.in b/util/update-grub.in
index c78444e..55aab75 100644
--- a/util/update-grub.in
+++ b/util/update-grub.in
@@ -73,8 +73,21 @@ if [ "x$EUID" = "x" ] ; then
 fi
 
 if [ "$EUID" != 0 ] ; then
-  echo "$0: You must run this as root" >&2
-  exit 1
[EMAIL PROTECTED]@  # Begin Cygwin specific.
[EMAIL PROTECTED]@  # Assume root if member of admin group.
[EMAIL PROTECTED]@  root=f
[EMAIL PROTECTED]@  for g in `id -G 2>/dev/null` ; do
[EMAIL PROTECTED]@    case $g in
[EMAIL PROTECTED]@      0|544) root=t ;;
[EMAIL PROTECTED]@    esac
[EMAIL PROTECTED]@  done
[EMAIL PROTECTED]@  if [ $root != t ] ; then
[EMAIL PROTECTED]@    echo "$0: You must have admin rights to run this" >&2
[EMAIL PROTECTED]@    exit 1
[EMAIL PROTECTED]@  fi
[EMAIL PROTECTED]@  # End Cygwin specific.
[EMAIL PROTECTED]@  echo "$0: You must run this as root" >&2
[EMAIL PROTECTED]@  exit 1
 fi
 
 set $grub_mkdevicemap dummy
@@ -154,6 +167,7 @@ export GRUB_DEVICE GRUB_DEVICE_UUID GRUB_DEVICE_BOOT GRUB_DEVICE_BOOT_UUID GRUB_
 # These are optional, user-defined variables.
 export GRUB_DEFAULT GRUB_TIMEOUT GRUB_DISTRIBUTOR GRUB_CMDLINE_LINUX GRUB_CMDLINE_LINUX_DEFAULT GRUB_TERMINAL GRUB_SERIAL_COMMAND GRUB_DISABLE_LINUX_UUID
 
+rm -f ${grub_cfg}.new
 exec > ${grub_cfg}.new
 
 # Allow this to fail, since /boot/grub/ might need to be fatfs to support some
@@ -187,6 +201,6 @@ for i in ${update_grub_dir}/* ; do
 done
 
 # none of the children aborted with error, install the new grub.cfg
-mv ${grub_cfg}.new ${grub_cfg}
+mv -f ${grub_cfg}.new ${grub_cfg}
 
 echo "done" >&2
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to