2009-08-28 Felix Zielcke
* conf/common.rmk (bin_UTILITIES): Add grub-mkrelpath. (grub_mkrelpath_SOURCES): New variable. * configure.ac (AC_CHECK_FUNCS): Add realpath. * util/grub-mkconfig_lib.in (make_system_path_relative_to_its_root): Use grub-mkrelpath. * util/grub-mkrelpath.c: New file. diff --git a/conf/common.rmk b/conf/common.rmk index 6d76746..9a2dc4c 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -55,6 +55,10 @@ grub_mkfont_CFLAGS = $(freetype_cflags) grub_mkfont_LDFLAGS = $(freetype_libs) endif +# For grub-mkrelpath. +bin_UTILITIES += grub-mkrelpath +grub_mkrelpath_SOURCES = util/grub-mkrelpath.c util/misc.c + # For the parser. grub_script.tab.c grub_script.tab.h: script/sh/parser.y $(YACC) -d -p grub_script_yy -b grub_script $(srcdir)/script/sh/parser.y diff --git a/configure.ac b/configure.ac index 549b35c..ee5ebb1 100644 --- a/configure.ac +++ b/configure.ac @@ -172,7 +172,7 @@ if test x$grub_cv_apple_cc = xyes ; then fi # Check for functions. -AC_CHECK_FUNCS(posix_memalign memalign asprintf) +AC_CHECK_FUNCS(posix_memalign memalign asprintf realpath) # # Check for target programs. diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in index 2385b08..c8d2736 100644 --- a/util/grub-mkconfig_lib.in +++ b/util/grub-mkconfig_lib.in @@ -32,49 +32,7 @@ grub_warn () make_system_path_relative_to_its_root () { - path=$1 - # abort if file doesn't exist - if test -e $path ; then : ;else - return 1 - fi - - # canonicalize - if path=`readlink -f $path` ; then : ; else - return 1 - fi - - # if not a directory, climb up to the directory containing it - if test -d $path ; then - dir=$path - else - dir=`echo $path | sed -e "s,/[^/]*$,,g"` - fi - - num=`stat -c %d $dir` - - # this loop sets $dir to the root directory of the filesystem we're inspecting - while : ; do - parent=`readlink -f $dir/..` - if [ "x`stat -c %d $parent`" = "x$num" ] ; then : ; else - # $parent is another filesystem; we found it. - break - fi - if [ "x$dir" = "x/" ] ; then - # / is our root. - break - fi - dir=$parent - done - - # This function never prints trailing slashes (so that its output can be - # appended a slash unconditionally). Each slash in $dir is considered a - # preceding slash, and therefore the root directory is an empty string. - if [ "$dir" = "/" ] ; then - dir="" - fi - - # XXX: This fails if $dir contains ','. - path=`echo "$path" | sed -e "s,^$dir,,g"` || return 1 + path = "`grub-mkrelpath $1`" case "`uname 2>/dev/null`" in CYGWIN*) diff --git a/util/grub-mkrelpath.c b/util/grub-mkrelpath.c index e69de29..7c9c678 100644 --- a/util/grub-mkrelpath.c +++ b/util/grub-mkrelpath.c @@ -0,0 +1,194 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2009 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see