patch to compile grub2 in msys/mingw environment
PATCH 1/1 patch to compile grub2 in msys/mingw environment
Hi,
There are three issue related to msys/mingw environment.
1, no nanosleep in mingw, although, the windows API Sleep support millisecond.
2, Use stat on device like //./PHYSICALDRIVE0 would fail. It should use utility function grub_util_get_disk_size in read_device_map.
3, The ln command in msys can't handle symbol link properly, which causes AC_CONFIG_LINKS to fail. This patch add new test grub_CHECK_LINK_DIR, which is used to decide whether to call AC_CONFIG_LINKS or copy directory itself.
2009-03-14 Bean <[email protected]>
* util/hostdisk.c (read_device_map): Use grub_util_get_disk_size to instead of stat in mingw environment.
* util/misc.c (grub_millisleep): New function in environment.
* aclocal.m4 (grub_CHECK_LINK_DIR): New function.
* configure.ac: Use grub_CHECK_LINK_DIR to determine whether to use AC_CONFIG_LINKS.
Signature · 1 line
Bean
aclocal.m4 +18 -0
@@ -448,3 +448,21 @@ else AC_MSG_RESULT([no]) [fi] ]) + +dnl Check if ln can handle directories properly (mingw). +AC_DEFUN(grub_CHECK_LINK_DIR,[ +AC_MSG_CHECKING([whether ln can handle directories properly]) +[mkdir testdir 2>/dev/null +case $srcdir in +[\\/$]* | ?:[\\/]* ) reldir=$srcdir/include/grub/util ;; + *) reldir=../$srcdir/include/grub/util ;; +esac +if ln -s $reldir testdir/util 2>/dev/null ; then] + AC_MSG_RESULT([yes]) + [link_dir=yes +else + link_dir=no] + AC_MSG_RESULT([no]) +[fi +rm -rf testdir] +])
configure.ac +10 -1
@@ -474,8 +474,17 @@ AC_SUBST([freetype_cflags]) AC_SUBST([freetype_libs]) # Output files. -AC_CONFIG_LINKS([include/grub/cpu:include/grub/$target_cpu +grub_CHECK_LINK_DIR +if test x"$link_dir" = xyes ; then + AC_CONFIG_LINKS([include/grub/cpu:include/grub/$target_cpu include/grub/machine:include/grub/$target_cpu/$platform]) +else + mkdir -p include/grub 2>/dev/null + rm -rf include/grub/cpu + cp -rp $srcdir/include/grub/$target_cpu include/grub/cpu 2>/dev/null + rm -rf include/grub/machine + cp -rp $srcdir/include/grub/$target_cpu/$platform include/grub/machine 2>/dev/null +fi AC_CONFIG_FILES([Makefile gensymlist.sh genkernsyms.sh]) AC_CONFIG_FILES([stamp-h], [echo timestamp > stamp-h]) AC_OUTPUT
util/hostdisk.c +5 -0
@@ -555,7 +555,12 @@ read_device_map (const char *dev_map) e++; *e ='\0' ; +#ifdef __MINGW32__ + (void ) st; +if (grub_util_get_disk_size (p) ==-1LL ) +#else if (stat (p, &st) == -1) +#endif {free (map[drive].drive); map[drive].drive =NULL ;
util/misc.c +8 -0
@@ -311,6 +311,7 @@ grub_get_time_ms (void)return (tv.tv_sec *1000 + tv.tv_usec /1000 ); } +#ifndef __MINGW32__void grub_millisleep (grub_uint32_t ms) {
@@ -320,6 +321,7 @@ grub_millisleep (grub_uint32_t ms) ts.tv_nsec = (ms %1000 ) *1000000 ;nanosleep (&ts,NULL ); } +#endif void grub_arch_sync_caches (void *address __attribute__ ((unused)),
@@ -361,6 +363,12 @@ void sleep (int s)Sleep (s *1000 ); } +void +grub_millisleep (grub_uint32_t ms) +{ +Sleep (ms); +} +grub_int64_t grub_util_get_disk_size (char *name) {
Quoted 19 lines · Bean
Hi,
There are three issue related to msys/mingw environment.
1, no nanosleep in mingw, although, the windows API Sleep support millisecond.
2, Use stat on device like //./PHYSICALDRIVE0 would fail. It should use utility function
grub_util_get_disk_sizeinread_device_map.3, The ln command in msys can't handle symbol link properly, which causes
AC_CONFIG_LINKSto fail. This patch add new testgrub_CHECK_LINK_DIR, which is used to decide whether to callAC_CONFIG_LINKSor copy directory itself.2009-03-14 Bean <[email protected]>
*
util/hostdisk.c(read_device_map): Usegrub_util_get_disk_sizeto instead of stat in mingw environment.
Quoted 6 lines
*
util/misc.c(grub_millisleep): New function in environment.* aclocal.m4 (
grub_CHECK_LINK_DIR): New function.* configure.ac: Use
grub_CHECK_LINK_DIRto determine whether to useAC_CONFIG_LINKS.
It seems you defined the mingw32 version of grub_millisleep unconditionally.
Btw, would be nice if you could send patches as inline attachments, without the base64 encoding. Then I'd have been able to reply using the patch as context.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Quoted 20 lines · Robert Millan
Quoted 19 lines · Bean
Hi,
There are three issue related to msys/mingw environment.
1, no nanosleep in mingw, although, the windows API Sleep support millisecond.
2, Use stat on device like //./PHYSICALDRIVE0 would fail. It should use utility function
grub_util_get_disk_sizeinread_device_map.3, The ln command in msys can't handle symbol link properly, which causes
AC_CONFIG_LINKSto fail. This patch add new testgrub_CHECK_LINK_DIR, which is used to decide whether to callAC_CONFIG_LINKSor copy directory itself.2009-03-14 Bean <[email protected]>
*
util/hostdisk.c(read_device_map): Usegrub_util_get_disk_sizeto instead of stat in mingw environment.
Quoted 8 lines
Quoted 6 lines
*
util/misc.c(grub_millisleep): New function in environment.* aclocal.m4 (
grub_CHECK_LINK_DIR): New function.* configure.ac: Use
grub_CHECK_LINK_DIRto determine whether to useAC_CONFIG_LINKS.It seems you defined the mingw32 version of
grub_millisleepunconditionally.
Hi,
Are you suggesting adding some test in configure.ac ? Although grub_millisleep for mingw32 uses Windows API Sleep, I guess it's safe to assume it's present.
Quoted 4 lines
Btw, would be nice if you could send patches as inline attachments, without the base64 encoding. Then I'd have been able to reply using the patch as context.
Ok, here it is.
aclocal.m4 +18 -0
@@ -448,3 +448,21 @@ else AC_MSG_RESULT([no]) [fi] ]) + +dnl Check if ln can handle directories properly (mingw). +AC_DEFUN(grub_CHECK_LINK_DIR,[ +AC_MSG_CHECKING([whether ln can handle directories properly]) +[mkdir testdir 2>/dev/null +case $srcdir in +[\\/$]* | ?:[\\/]* ) reldir=$srcdir/include/grub/util ;; + *) reldir=../$srcdir/include/grub/util ;; +esac +if ln -s $reldir testdir/util 2>/dev/null ; then] + AC_MSG_RESULT([yes]) + [link_dir=yes +else + link_dir=no] + AC_MSG_RESULT([no]) +[fi +rm -rf testdir] +])
configure.ac +9 -1
@@ -474,8 +474,17 @@ AC_SUBST([freetype_cflags]) AC_SUBST([freetype_libs]) # Output files. -AC_CONFIG_LINKS([include/grub/cpu:include/grub/$target_cpu +grub_CHECK_LINK_DIR +if test x"$link_dir" = xyes ; then + AC_CONFIG_LINKS([include/grub/cpu:include/grub/$target_cpu include/grub/machine:include/grub/$target_cpu/$platform]) +else + mkdir -p include/grub 2>/dev/null + rm -rf include/grub/cpu + cp -rp $srcdir/include/grub/$target_cpu include/grub/cpu 2>/dev/null + rm -rf include/grub/machine + cp -rp $srcdir/include/grub/$target_cpu/$platform
include/grub/machine 2>/dev/null
+fi
AC_CONFIG_FILES([Makefile gensymlist.sh genkernsyms.sh]) AC_CONFIG_FILES([stamp-h], [echo timestamp > stamp-h]) AC_OUTPUT
util/hostdisk.c +5 -0
@@ -555,7 +555,12 @@ read_device_map (const char *dev_map) e++; *e ='\0' ; +#ifdef __MINGW32__ + (void ) st; +if (grub_util_get_disk_size (p) ==-1LL ) +#else if (stat (p, &st) == -1) +#endif {free (map[drive].drive); map[drive].drive =NULL ;
util/misc.c +8 -0
@@ -311,6 +311,7 @@ grub_get_time_ms (void)return (tv.tv_sec *1000 + tv.tv_usec /1000 ); } +#ifndef __MINGW32__void grub_millisleep (grub_uint32_t ms) {
@@ -320,6 +321,7 @@ grub_millisleep (grub_uint32_t ms) ts.tv_nsec = (ms %1000 ) *1000000 ;nanosleep (&ts,NULL ); } +#endif void grub_arch_sync_caches (void *address __attribute__ ((unused)),
@@ -361,6 +363,12 @@ void sleep (int s)Sleep (s *1000 ); } +void +grub_millisleep (grub_uint32_t ms) +{ +Sleep (ms); +} +grub_int64_t grub_util_get_disk_size (char *name) {
Signature · 1 line
Bean
Quoted 8 lines · Bean
Quoted 2 lines
It seems you defined the mingw32 version of
grub_millisleepunconditionally.Hi,
Are you suggesting adding some test in configure.ac ? Although
grub_millisleepfor mingw32 uses Windows API Sleep, I guess it's safe to assume it's present.
I just meant that when __MINGW32__ is not defined, the function is implemented twice:
Quoted 13 lines
util/misc.c +2
-0+#ifndef __MINGW32__void grub_millisleep (grub_uint32_t ms) {@@ -320,6 +321,7 @@ grub_millisleep (grub_uint32_t ms) ts.tv_nsec = (ms %1000 ) *1000000 ;nanosleep (&ts,NULL ); } +#endif void grub_arch_sync_caches (void *address __attribute__ ((unused)),
util/misc.c void sleep (int s) · line 371
Quoted 9 lines
util/misc.c +6
-0@@ -361,6 +363,12 @@ void sleep (int s)Sleep (s *1000 ); } +void +grub_millisleep (grub_uint32_t ms) +{ +Sleep (ms); +} +
why not put them together anyway? Like #ifdef __MINGW32__ ... #else ... #endif
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Quoted 29 lines · Robert Millan
Quoted 8 lines · Bean
Quoted 2 lines
It seems you defined the mingw32 version of
grub_millisleepunconditionally.Hi,
Are you suggesting adding some test in configure.ac ? Although
grub_millisleepfor mingw32 uses Windows API Sleep, I guess it's safe to assume it's present.I just meant that when
__MINGW32__is not defined, the function is implemented twice:Quoted 16 lines
+#ifndef
__MINGW32__
void
grub_millisleep (grub_uint32_tms)
{util/misc.c +1
-0@@ -320,6 +321,7 @@ grub_millisleep (grub_uint32_t ms) ts.tv_nsec = (ms % 1000) * 1000000; nanosleep (&ts, NULL); } +#endif void
grub_arch_sync_caches (void *address__attribute__((unused)),util/misc.c +0
-0@@ -361,6 +363,12 @@ void sleep (int s) Sleep (s * 1000); }
Quoted 8 lines
util/misc.c void sleep (int s) · line 371
Quoted 6 lines
util/misc.c +6
-0+void +grub_millisleep (grub_uint32_t ms) +{ + Sleep (ms); +} +why not put them together anyway? Like #ifdef
__MINGW32__... #else ... #endif
Hi,
The header file <windows.h> is included after grub_millisleep, so Sleep is not defined yet, perhaps it'd be better to move #include <windows.h> to the beginning of file.
Signature · 1 line
Bean
Committed.
Signature · 1 line
Bean
Quoted 4 lines · Bean
The header file <
windows.h> is included aftergrub_millisleep, so Sleep is not defined yet, perhaps it'd be better to move #include <windows.h> to the beginning of file.
Agreed.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."