Subject: | Sys-CPU-0.51 does not compile on FreeBSD |
The attached patch addresses the failed compilation on FreeBSD 7.2.
This issue is also tracked at
https://bugs.gentoo.org/show_bug.cgi?id=303289
Turns out an almost identical patch is already in the FreeBSD ports
tree, see
http://www.freebsd.org/cgi/cvsweb.cgi/ports/devel/p5-Sys-Cpu/files/patch-CPU.xs
Additional information:
Show quoted text
> perl -v
This is perl, v5.8.8 built for i686-freebsd
...
Show quoted text> uname -a
FreeBSD foo 7.2-RELEASE FreeBSD Gentoo 7.2-r3 #2: Mon Feb 1 20:13:21
CST 2010 hattne@foo:/usr/src/sys-7.2-r3/i386/compile/LIFE i386
Show quoted text> i686-gentoo-freebsd7.2-gcc -c -DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H
-fno-strict-aliasing -pipe -Wdeclaration-after-statement -march=pentium4
-O2 -pipe -fomit-frame-pointer -DVERSION=\"0.51\" -DXS_VERSION=\"0.51\"
-DPIC -fPIC "-I/usr/lib/perl5/5.8.8/i686-freebsd/CORE" CPU.c
CPU.xs: In function 'XS_Sys__CPU_cpu_clock':
CPU.xs:338: error: 'processor_info_t' undeclared (first use in this
function)
CPU.xs:338: error: (Each undeclared identifier is reported only once
CPU.xs:338: error: for each function it appears in.)
CPU.xs:338: error: expected ';' before 'info'
CPU.xs:339: error: 'infop' undeclared (first use in this function)
CPU.xs:339: error: 'P_ONLINE' undeclared (first use in this function)
CPU.xs: In function 'XS_Sys__CPU_cpu_type':
CPU.xs:376: error: 'processor_info_t' undeclared (first use in this
function)
CPU.xs:376: error: expected ';' before 'info'
CPU.xs:377: error: 'infop' undeclared (first use in this function)
gmake: *** [CPU.o] Error 1
Subject: | Sys-CPU-0.51-fbsd.patch |
--- CPU.xs.orig 2010-02-01 13:07:41 -0600
+++ CPU.xs 2010-02-01 13:11:57 -0600
@@ -40,6 +40,12 @@
#define _have_cpu_clock
#define _have_cpu_type
#endif
+#ifdef __FreeBSD__
+ #include <sys/sysctl.h>
+ #define _have_cpu_clock
+ #define _have_cpu_type
+#endif
+
#ifdef WINDOWS
/* Registry Functions */
@@ -271,6 +277,30 @@
#endif
+#ifdef __FreeBSD__
+int
+fbsd_get_cpu_clock()
+{
+ size_t len;
+ int clockrate;
+
+ len = sizeof(clockrate);
+ if (sysctlbyname("hw.clockrate", &clockrate, &len, NULL, 0) != 0)
+ return (0);
+ return (clockrate);
+}
+
+int
+fbsd_get_type_name(char *name, size_t len)
+{
+ int mib[2];
+
+ mib[0] = CTL_HW;
+ mib[1] = HW_MODEL;
+ return (sysctl(mib, 2, name, &len, NULL, 0));
+}
+#endif
+
int get_cpu_count() {
int ret;
char buffer[255];
@@ -334,6 +373,9 @@
#ifdef __APPLE__
clock = CurrentProcessorSpeed();
#endif
+#ifdef __FreeBSD__
+ clock = fbsd_get_cpu_clock();
+#endif
#ifndef _have_cpu_clock
processor_info_t info, *infop=&info;
if ( processor_info(0, infop) == 0 && infop->pi_state == P_ONLINE) {
@@ -372,6 +414,9 @@
#ifdef __APPLE__
value = apple_get_type_name();
#endif
+#ifdef __FreeBSD__
+ fbsd_get_type_name(value, MAX_IDENT_SIZE);
+#endif
#ifndef _have_cpu_type /* not linux, not windows */
processor_info_t info, *infop=&info;
if (processor_info (0, infop)==0) {