--- Makefile.orig	2009-08-02 04:21:23.798978000 +0200
+++ Makefile	2009-08-31 18:08:02.000000000 +0200
@@ -17,6 +17,12 @@
   COMPILE_ARCH=$(shell uname -p | sed -e s/i.86/i386/)
 endif
 
+ifeq ($(COMPILE_PLATFORM),freebsd)
+  ifeq ($(COMPILE_ARCH),amd64)
+    COMPILE_ARCH=x86_64
+  endif
+endif
+
 ifeq ($(COMPILE_PLATFORM),mingw32)
   ifeq ($(COMPILE_ARCH),i386)
     COMPILE_ARCH=x86
@@ -528,15 +534,28 @@
 
 ifeq ($(PLATFORM),freebsd)
 
-  ifneq (,$(findstring alpha,$(shell uname -m)))
-    ARCH=axp
-  else #default to i386
-    ARCH=i386
-  endif #alpha test
+  FREEBSD_ARCH = $(ARCH)
+  ifeq ($(ARCH),amd64)
+    ARCH = x86_64
+  endif
+
+  ifeq ($(FREEBSD_ARCH),x86_64)
+    FREEBSD_ARCH = amd64
+  endif
+
+  ifndef HOMEPATH
+    HOMEPATH = /.ioquake3
+  endif
 
+  ifndef DEFAULT_LIBDIR
+    DEFAULT_LIBDIR = /usr/local/lib/ioquake3
+  endif
 
   BASE_CFLAGS = -Wall -fno-strict-aliasing -Wimplicit -Wstrict-prototypes \
-    -DUSE_ICON $(SDL_CFLAGS)
+    -DUSE_ICON $(shell sdl-config --cflags) -DMAP_ANONYMOUS=MAP_ANON \
+    -DHOMEPATH=\\\"$(HOMEPATH)\\\" \
+    -DDEFAULT_LIBDIR=\\\"$(DEFAULT_LIBDIR)\\\" \
+    $(shell make -f /dev/null -VCFLAGS MACHINE_ARCH=$(FREEBSD_ARCH))
 
   ifeq ($(USE_OPENAL),1)
     BASE_CFLAGS += -DUSE_OPENAL
@@ -555,8 +574,15 @@
       -fomit-frame-pointer -fexpensive-optimizations
   else
   ifeq ($(ARCH),i386)
-    RELEASE_CFLAGS=$(BASE_CFLAGS) -DNDEBUG -O3 -mtune=pentiumpro \
-      -march=pentium -fomit-frame-pointer -pipe -ffast-math \
+    RELEASE_CFLAGS=$(BASE_CFLAGS) -DNDEBUG -O3 \
+      -fomit-frame-pointer -pipe -ffast-math \
+      -falign-loops=2 -falign-jumps=2 -falign-functions=2 \
+      -funroll-loops -fstrength-reduce
+    HAVE_VM_COMPILED=true
+  else
+  ifeq ($(ARCH),x86_64)
+    RELEASE_CFLAGS=$(BASE_CFLAGS) -DNDEBUG -O3 \
+      -fomit-frame-pointer -pipe -ffast-math \
       -falign-loops=2 -falign-jumps=2 -falign-functions=2 \
       -funroll-loops -fstrength-reduce
     HAVE_VM_COMPILED=true
@@ -564,6 +590,7 @@
     BASE_CFLAGS += -DNO_VM_COMPILED
   endif
   endif
+  endif
 
   DEBUG_CFLAGS=$(BASE_CFLAGS) -g