ifdef CARMEN_HOME
  ifeq ($(CARMEN_HOME)/src/Makefile.vars, $(wildcard $(CARMEN_HOME)/src/Makefile.vars))
    include $(CARMEN_HOME)/src/Makefile.vars
  else
    $(warning )
    $(warning The CARMEN_HOME variable no longer points to a valid directory.)
    $(warning Please re-run configure.)
    $(warning )
    $(error )
  endif
else
  ifeq (Makefile.vars, $(wildcard Makefile.vars))
    include Makefile.vars
  else
  ifeq (../Makefile.vars, $(wildcard ../Makefile.vars))
    include ../Makefile.vars
  else
  ifeq (../../Makefile.vars, $(wildcard ../../Makefile.vars))
    include ../../Makefile.vars
  else
    $(error You need to run 'configure' first)
  endif
  endif
  endif
endif

ifndef CC
  CC = gcc
endif
ifndef CXX
CXX = g++
endif
ifndef LINK
LINK = $(CC)
endif
RM = rm -rf
#ifndef AR
AR = ar cr
#endif
ifndef RANLIB
RANLIB = ranlib
endif
CP = cp -f
LN = ln -s
NEWER = cmp -s
TOUCH = touch
MKDIR = mkdir -p
ECHO = @echo
DOXYGEN = doxygen

ifndef NO_GRAPHICS 
GTK_CONFIG=pkg-config gtk+-2.0
endif

ifndef CARMEN_LOUD
SILENT = @
MAKEFLAGS += -s
else
SILENT =
export CARMEN_LOUD
endif

SRC_DIR = $(CARMEN_HOME)/src
INC_DIR = $(CARMEN_HOME)/include
LIB_DIR = $(CARMEN_HOME)/lib

### CHANGED BY SAM 3/06 ###
#BIN_DIR = $(CARMEN_HOME)/bin
BIN_BASE_DIR = $(CARMEN_HOME)/bin
BIN_DIR = $(CARMEN_HOME)/bin/$(PLATFORM)
RSS_HOME = $(CARMEN_HOME)/../
RSS_BIN_DIR = $(RSS_HOME)/bin/$(PLATFORM)
###########################

MAN_DIR = $(CARMEN_HOME)/man
DOC_DIR = $(CARMEN_HOME)/doc

GLOBAL_INC_DIR = $(INSTALL_PATH)/include
GLOBAL_LIB_DIR = $(INSTALL_PATH)/lib
GLOBAL_BIN_DIR = $(INSTALL_PATH)/bin
GLOBAL_MAN_DIR = $(INSTALL_PATH)/man

pathsearch = $(firstword $(wildcard $(addsuffix /$(1),$(subst :, ,$(PATH)))))

CFLAGS += -DCOMPILE_WITHOUT_LASER_SUPPORT -DCOMPILE_WITHOUT_MAP_SUPPORT

CFLAGS += -Wall -W -Werror -D_REENTRANT
ifdef NO_STRICT_ALIASING
CFLAGS += -Wno-strict-aliasing
endif
CXXFLAGS += -Wall -W -Werror -D_REENTRANT

ifdef CARMEN_DEBUG
CFLAGS += -g
CXXFLAGS += -g
else
CFLAGS += -O3
CXXFLAGS += -O3
endif

ifdef FOUND_SUSE
CFLAGS += -finline-limit=2000 -DFOUND_SUSE
CXXFLAGS += -finline-limit=2000 
endif

ifdef CARMEN_MEMORY_DEBUG
CFLAGS += -DCARMEN_MEMORY_DEBUG
LFLAGS += -ldmalloc
endif

IFLAGS += -I$(INC_DIR) 
LFLAGS += -L$(LIB_DIR) -L/usr/local/lib $(USER_LIBS) -lpthread -lm 

ifdef IPC_DIR
CFLAGS += -DEXTERNAL_IPC
IFLAGS += -I$(IPC_DIR)/include 
LFLAGS += -L$(IPC_DIR)/lib/Linux 
endif

ifdef NO_GRAPHICS
CFLAGS += -DNO_GRAPHICS
CXXFLAGS += -DNO_GRAPHICS
else
CFLAGS += -DHAVE_GRAPHICS
CXXFLAGS += -DHAVE_GRAPHICS
endif

ifdef NO_JOYSTICK
CFLAGS += -DNO_JOYSTICK
CXXFLAGS += -DNO_JOYSTICK
else
CFLAGS += -DHAVE_JOYSTICK
CXXFLAGS += -DHAVE_JOYSTICK
endif

ifdef NO_TCPD
CFLAGS += -DNO_TCPD
CXXFLAGS += -DNO_TCPD
else
CFLAGS += -DHAVE_TCPD
CXXFLAGS += -DHAVE_TCPD
endif

ifdef NO_LIBJPEG
CFLAGS += -DNO_LIBJPEG
CXXFLAGS += -DNO_LIBJPEG
else
CFLAGS += -DHAVE_LIBJPEG
CXXFLAGS += -DHAVE_LIBJPEG
endif

ifdef NO_ZLIB
CFLAGS += -DNO_ZLIB
CXXFLAGS += -DNO_ZLIB
else
CFLAGS += -DHAVE_ZLIB
CXXFLAGS += -DHAVE_ZLIB
LFLAGS_POST += -lz
endif

ifdef NO_LIBART
CFLAGS += -DNO_LIBART
CXXFLAGS += -DNO_LIBART
else
CFLAGS += -DHAVE_LIBART
CXXFLAGS += -DHAVE_LIBART
endif

ifdef NO_READLINE
CFLAGS += -DNO_READLINE
CXXFLAGS += -DNO_READLINE
else
CFLAGS += -DHAVE_READLINE
CXXFLAGS += -DHAVE_READLINE
endif

ifdef NO_STRICT_ALIASING
CFLAGS += -DNO_STRICT_ALIASING
CXXFLAGS += -DNO_STRICT_ALIASING
else
CFLAGS += -DHAVE_STRICT_ALIASING
CXXFLAGS += -DHAVE_STRICT_ALIASING
endif

ifdef CYGWIN
CFLAGS += -DCYGWIN
CXXFLAGS += -DCYGWIN
endif

all:
