]> mj.ucw.cz Git - libucw.git/commitdiff
update the code so that it compiles both on Linux and Darwin
authorRobert Spalek <robert@ucw.cz>
Fri, 27 Oct 2006 03:10:36 +0000 (20:10 -0700)
committerRobert Spalek <robert@ucw.cz>
Fri, 27 Oct 2006 03:10:36 +0000 (20:10 -0700)
lib/autoconf.cfg
lib/lizard-safe.c
lib/math.h
lib/proctitle.c
lib/qache.c
lib/sighandler.c

index 39317a256fcffbad4da122cd812c63fb79c2e174..664b8153cab79a990a98801f8441e680d7bc3235 100644 (file)
@@ -1,5 +1,6 @@
 # Automatic configuration of the UCW Library
 # (c) 2005 Martin Mares <mj@ucw.cz>
+# (c) 2006 Robert Spalek <robert@ucw.cz>
 
 ### OS ###
 
@@ -12,6 +13,8 @@ Test("OS", "Checking on which OS we run", sub {
 
 if (Get("OS") eq "Linux") {
        Set("CONFIG_LINUX");
+} elsif (Get("OS") eq "Darwin") {
+       Set("CONFIG_DARWIN");
 } else {
        Fail "Don't know how to run on this operating system.";
 }
@@ -24,7 +27,7 @@ Test("CC", "Checking for C compiler", sub { return "gcc"; });
 # GCC version
 Test("GCCVER", "Checking for GCC version", sub {
        my $gcc = Get("CC");
-       my $ver = `$gcc --version | sed '2,\$d; s/^\\(.* \\)\\?\\([0-9]*\\.[0-9]*\\).*/\\2/'`;
+       my $ver = `$gcc --version | sed '2,\$d; s/^\\(.* \\)*\\([0-9]*\\.[0-9]*\\).*/\\2/'`;
        chomp $ver;
        Fail "Unable to determine GCC version" if $? || $ver eq "";
        return $ver;
@@ -48,8 +51,8 @@ Test("ARCH", "Checking for machine architecture", sub {
        }
 });
 
-sub parse_cpuinfo() {
-       IsSet("CONFIG_EXACT_CPU") && IsSet("CONFIG_LINUX") && open X, "/proc/cpuinfo" || undef;
+sub parse_cpuinfo_linux() {
+       open X, "/proc/cpuinfo" || undef;
        my %pc = ();
        while (<X>) {
                chomp;
@@ -57,15 +60,37 @@ sub parse_cpuinfo() {
                /^([^\t]+)\t+:\s*(.*)$/ and $pc{$1}=$2;
        }
        close X;
+       return ($pc{'vendor_id'},
+               $pc{'cpu family'},
+               $pc{'model'});
+}
+
+sub parse_cpuinfo_darwin() {
+       @cpu = (`sysctl -n machdep.cpu.vendor`,
+               `sysctl -n machdep.cpu.family`,
+               `sysctl -n machdep.cpu.model`);
+       chomp @cpu;
+       return @cpu;
+}
 
-       my $vendor = $pc{'vendor_id'} || "";
-       my $family = $pc{'cpu family'} || 0;
-       my $model  = $pc{'model'} || 0;
-       return ($vendor, $family, $model);
+sub parse_cpuinfo() {
+       my @cpu;
+       if (IsSet("CONFIG_EXACT_CPU")) {
+               if (IsSet("CONFIG_LINUX")) {
+                       @cpu = parse_cpuinfo_linux();
+               } elsif (IsSet("CONFIG_DARWIN")) {
+                       @cpu = parse_cpuinfo_darwin();
+               }
+       }
+       $cpu[0] = "" if !defined $cpu[0];
+       $cpu[1] = 0 if !defined $cpu[1];
+       $cpu[2] = 0 if !defined $cpu[2];
+       return @cpu;
 }
 
 Test("CPU_ARCH", "Checking for CPU architecture", sub {
        my $mach = Get("ARCH");
+       my $arch = "";
        if ($mach eq "i386") {
                Set("CPU_I386");
                UnSet("CPU_64BIT_POINTERS");
@@ -73,7 +98,6 @@ Test("CPU_ARCH", "Checking for CPU architecture", sub {
                UnSet("CPU_BIG_ENDIAN");
                Set("CPU_ALLOW_UNALIGNED");
                Set("CPU_STRUCT_ALIGN" => 4);
-               my $arch = "";
                if (my ($vendor, $family, $model) = parse_cpuinfo()) {
                        # Try to understand CPU vendor, family and model [inspired by MPlayer's configure script]
                        if ($vendor eq "AuthenticAMD") {
@@ -88,7 +112,8 @@ Test("CPU_ARCH", "Checking for CPU architecture", sub {
                                        elsif ($model >= 3) { $arch = "prescott"; }
                                        else { $arch = "pentium4"; }
                                } elsif ($family == 6 && $gccver >= 3003) {
-                                       if (($model == 9 || $model == 13) && $gccver >= 3004) { $arch = "pentium-m"; }
+                                       if ($model == 15) { $arch = "prescott"; }
+                                       elsif (($model == 9 || $model == 13) && $gccver >= 3004) { $arch = "pentium-m"; }
                                        elsif ($model >= 7) { $arch = "pentium3"; }
                                        elsif ($model >= 3) { $arch = "pentium2"; }
                                }
@@ -104,7 +129,7 @@ Test("CPU_ARCH", "Checking for CPU architecture", sub {
                        }
                        Log (($arch ne "") ? "(using /proc/cpuinfo) " : "(don't understand /proc/cpuinfo) ");
                }
-               return $arch ? $arch : "i386";
+               return $arch;
        } elsif ($mach eq "amd64") {
                Set("CPU_AMD64");
                Set("CPU_64BIT_POINTERS");
@@ -121,22 +146,24 @@ Test("CPU_ARCH", "Checking for CPU architecture", sub {
                        }
                        Log (($arch ne "") ? "(using /proc/cpuinfo) " : "(don't understand /proc/cpuinfo) ");
                }
-               return $arch ? $arch : "x86-64";
+               return $arch;
        } else {
-               return undef;
+               return "";
        }
 });
 
-if (!IsSet("CPU_ARCH")) { Warn "CPU type not recognized, using defaults, keep fingers crossed."; }
-
 ### Compiler and its Options ###
 
-# C flags: tell the compiler we're speaking C99
-Set("CLANG" => "-std=gnu99");
+# C flags: tell the compiler we're speaking C99, and disable common symbols
+Set("CLANG" => "-std=gnu99 -fno-common");
 
 # C optimizations
 Set("COPT" => '-O2');
-Append("COPT", '-march=$(CPU_ARCH)') if IsSet("CPU_ARCH");
+if (Get("CPU_ARCH") eq "") {
+       Warn "CPU type not recognized, using defaults, keep fingers crossed.";
+} else {
+       Append("COPT", '-march=$(CPU_ARCH)');
+}
 
 # C optimizations for highly exposed code
 Set("COPT2" => '-O3');
@@ -183,6 +210,23 @@ if (IsSet("CONFIG_DEBUG")) {
        Append("LOPT" => "-s");
 }
 
+if (IsSet("CONFIG_DARWIN")) {
+       # gcc-4.0 on Darwin doesn't set this in the gnu99 mode
+       Append("CLANG" => "-fnested-functions");
+       # Directory hierarchy of the fink project
+       Append("LIBS" => "-L/sw/lib");
+       Append("COPT" => "-I/sw/include");
+       # LFS is not supported, but all file functions are automatically 64-bit
+       UnSet("CONFIG_LFS");
+       # Fill in some constants not found in the system header files
+       Set("PAGE_SIZE" => `sysctl -n hw.pagesize`);
+       Set("SOL_TCP" => 6);            #missing in /usr/include/netinet/tcp.h
+}
+
+if (!IsSet("CONFIG_LARGE_FILES")) {
+       UnSet("CONFIG_LFS");
+}
+
 # Decide how will lib/partmap.c work
 Set("PARTMAP_IS_MMAP") if IsSet("CPU_64BIT_POINTERS");
 
index c91b847a147406dd42deb2060f46525c9ff05e24..84e52da18e54dd5f87f84fba75dd12d4d186671e 100644 (file)
@@ -54,7 +54,7 @@ lizard_realloc(struct lizard_buffer *buf, uns max_len)
   if (buf->ptr)
     munmap(buf->ptr, buf->len + PAGE_SIZE);
   buf->len = max_len;
-  buf->ptr = mmap(NULL, buf->len + PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+  buf->ptr = mmap(NULL, buf->len + PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
   if (buf->ptr == MAP_FAILED)
     die("mmap(anonymous): %m");
   if (mprotect(buf->ptr + buf->len, PAGE_SIZE, PROT_NONE) < 0)
index d79c7bec96ea00765c393340e528e4848547ae65..f891a210dc4b472f6294bb914746f898aa19b577 100644 (file)
@@ -15,4 +15,6 @@
 #define log log_msg
 #undef exception
 
+#ifdef CONFIG_LINUX
 float logf(float);
+#endif
index e364fc4b015bcdd33f7c6c1449fb4eca7bed5b85..f605aef18b7b4b9f5aa3cd3fa29b02b0e9a81cce 100644 (file)
@@ -20,7 +20,7 @@ static char *spt_start, *spt_end;
 void
 setproctitle_init(int argc, char **argv)
 {
-#ifdef linux
+#ifdef CONFIG_LINUX
   int i, len;
   char **env, **oldenv, *t;
 
index 3802c3f6a1372ed6e59075ffdd77c3e897d8f9d8..3c4be273ab1c1bd0b24d100cc4439781da75a61c 100644 (file)
@@ -13,6 +13,7 @@
 
 #include <unistd.h>
 #include <fcntl.h>
+#include <sys/stat.h>
 #include <sys/mman.h>
 #include <sys/user.h>
 
index ca8269083afc44ebc7836ebc0c6f41e9acecaedc..4d991d8562f4b7cdfe70a44d7f8978b1a5037d4f 100644 (file)
@@ -10,7 +10,7 @@
 #include <string.h>
 #include <signal.h>
 
-sh_sighandler_t signal_handler[_NSIG];
+sh_sighandler_t signal_handler[NSIG];
 
 static void
 signal_handler_internal(int sig)
@@ -29,7 +29,7 @@ handle_signal(int signum, struct sigaction *oldact)
   struct sigaction act;
   bzero(&act, sizeof(act));
   act.sa_handler = signal_handler_internal;
-  act.sa_flags = SA_NOMASK;
+  act.sa_flags = SA_NODEFER;
   if (sigaction(signum, &act, oldact) < 0)
     die("sigaction: %m");
 }