Better kernel version detection

This commit is contained in:
Pierre Pronchery 2006-06-16 01:50:11 +00:00
parent 2dafd20a96
commit 6730960a57
2 changed files with 46 additions and 13 deletions

View File

@ -26,13 +26,22 @@ const String * sHostOS[HO_LAST+1] =
{ {
"Linux", "Linux",
"FreeBSD", "NetBSD", "OpenBSD", "FreeBSD", "NetBSD", "OpenBSD",
"SunOS",
"unknown" "unknown"
}; };
const String * sHostKernel[HK_LAST+1] = const struct HostKernel sHostKernel[] =
{ {
"2.0", "2.2", "2.4", "2.6", { HO_GNU_LINUX, "2.0" },
"2.0", "3.0", { HO_GNU_LINUX, "2.2" },
"unknown" { HO_GNU_LINUX, "2.4" },
{ HO_GNU_LINUX, "2.6" },
{ HO_NETBSD, "2.0" },
{ HO_NETBSD, "3.0" },
{ HO_SUNOS, "5.7", },
{ HO_SUNOS, "5.8", },
{ HO_SUNOS, "5.9", },
{ HO_SUNOS, "5.10", },
{ HO_UNKNOWN, "unknown" }
}; };
const String * sTargetType[TT_LAST] = { "binary", "library", "object" }; const String * sTargetType[TT_LAST] = { "binary", "library", "object" };
@ -124,11 +133,12 @@ static int _configure(Prefs * prefs, char const * directory)
/* private */ /* private */
static HostKernel _detect_kernel(HostOS os, char const * release);
static void _configure_detect(Configure * configure) static void _configure_detect(Configure * configure)
{ {
struct utsname un; struct utsname un;
if(uname(&un) != 0) if(uname(&un) < 0)
{ {
configure_error("system detection failed", 0); configure_error("system detection failed", 0);
configure->arch = HA_UNKNOWN; configure->arch = HA_UNKNOWN;
@ -138,15 +148,31 @@ static void _configure_detect(Configure * configure)
} }
configure->arch = enum_string(HA_LAST, sHostArch, un.machine); configure->arch = enum_string(HA_LAST, sHostArch, un.machine);
configure->os = enum_string(HO_LAST, sHostOS, un.sysname); configure->os = enum_string(HO_LAST, sHostOS, un.sysname);
configure->kernel = enum_string_short(HK_LAST, sHostKernel, configure->kernel = _detect_kernel(configure->os, un.release);
un.release);
if(configure->prefs->flags & PREFS_v) if(configure->prefs->flags & PREFS_v)
printf("Detected system %s version %s on %s\n", printf("Detected system %s version %s on %s\n",
sHostOS[configure->os], sHostOS[configure->os],
sHostKernel[configure->kernel], sHostKernel[configure->kernel].version,
sHostArch[configure->arch]); sHostArch[configure->arch]);
} }
static HostKernel _detect_kernel(HostOS os, char const * release)
{
unsigned int i;
for(i = 0; i != HK_LAST; i++)
{
if(sHostKernel[i].os < os)
continue;
if(sHostKernel[i].os > os)
return HK_UNKNOWN;
if(strncmp(release, sHostKernel[i].version,
strlen(sHostKernel[i].version)) == 0)
return i;
}
return i;
}
static int _load_subdirs(Prefs * prefs, char const * directory, static int _load_subdirs(Prefs * prefs, char const * directory,
configArray * ca, String * subdirs); configArray * ca, String * subdirs);

View File

@ -11,7 +11,7 @@
/* types */ /* types */
typedef enum _HostArch typedef enum _HostArch
{ {
HA_I386, HA_I486, HA_I586, HA_I686, HA_I386 = 0, HA_I486, HA_I586, HA_I686,
HA_SPARC, HA_SPARC64, HA_SPARC, HA_SPARC64,
HA_UNKNOWN HA_UNKNOWN
} HostArch; } HostArch;
@ -20,21 +20,28 @@ extern const String * sHostArch[HA_LAST+1];
typedef enum _HostOS typedef enum _HostOS
{ {
HO_GNU_LINUX, HO_GNU_LINUX = 0,
HO_FREEBSD, HO_NETBSD, HO_OPENBSD, HO_FREEBSD, HO_NETBSD, HO_OPENBSD,
HO_SUNOS,
HO_UNKNOWN HO_UNKNOWN
} HostOS; } HostOS;
# define HO_LAST HO_UNKNOWN # define HO_LAST HO_UNKNOWN
extern const String * sHostOS[HO_LAST+1]; extern const String * sHostOS[HO_LAST+1];
typedef enum _HostKernel /* FIXME feels wrong */ typedef enum _HostKernel
{ {
HK_LINUX20, HK_LINUX22, HK_LINUX24, HK_LINUX26, HK_LINUX20 = 0, HK_LINUX22, HK_LINUX24, HK_LINUX26,
HK_NETBSD20, HK_NETBSD30, HK_NETBSD20, HK_NETBSD30,
HK_SUNOS57, HK_SUNOS58, HK_SUNOS59, HK_SUNOS510,
HK_UNKNOWN HK_UNKNOWN
} HostKernel; } HostKernel;
# define HK_LAST HK_UNKNOWN # define HK_LAST HK_UNKNOWN
extern const String * sHostKernel[HK_LAST+1]; struct HostKernel
{
HostOS os;
const char * version;
};
extern const struct HostKernel sHostKernel[HK_LAST+1];
typedef enum _TargetType typedef enum _TargetType
{ {