AC_INIT([wmpower],[0.4.3],[michele.noberasco@tiscali.it])
AC_PREREQ(2.58)
AC_CONFIG_SRCDIR(src/wmpower.c)
AM_INIT_AUTOMAKE([1.7 check-news dist-bzip2])

AC_GNU_SOURCE
AC_PROG_INSTALL
AC_PROG_CC
AC_PROG_RANLIB

# Set my own flags for gcc
	if test "$MY_CFLAGS" = ""; then
		if test "x$GCC" = "xyes"; then
			CPULAGS=""
			MY_CFLAGS="-Os -fomit-frame-pointer -pipe -W -Wall"
			GCC_TEST_MESSAGE="Checking for gcc version"
			AC_MSG_CHECKING([$GCC_TEST_MESSAGE])
			GCCVERSION="`$CC -dumpversion`"
			AC_MSG_RESULT([$GCCVERSION])
			if test "`$CC -dumpversion | grep 3.`" != ""; then
				#Good! let see if we can see the system arch
				PROCESSOR=`cat /proc/cpuinfo`
				#Is our CPU a Celeron?
			  if test "`echo $PROCESSOR | grep \"Celeron\"`" != ""; then
				  CPUFLAGS="-march=pentium2"
				fi
				if test "`echo $PROCESSOR | grep \"Celeron (Coppermine)\"`" != ""; then
			 		CPUFLAGS="-march=pentium3"
				fi
				#Is our CPU a Pentium?
				if test "`echo $PROCESSOR | grep \"Pentium\"`" != ""; then
					CPUFLAGS="-march=pentium"
				fi
				#Is our CPU a Pentium II?
				if test "`echo $PROCESSOR | grep \"Pentium II\"`" != ""; then
					CPUFLAGS="-march=pentium2"
				fi
				#Is our CPU a Pentium III?
				if test "`echo $PROCESSOR | grep \"Pentium III\"`" != ""; then
					CPUFLAGS="-march=pentium3"
				fi
				#Is our CPU a Pentium 4?
				if test "`echo $PROCESSOR | grep \"Intel(R) Pentium(R) 4\"`" != ""; then
					CPUFLAGS="-march=pentium4"
				fi
				#K6 processor
				if test "`echo $PROCESSOR | grep \"AMD-K6(tm)\"`" != ""; then
				  CPUFLAGS="-march=k6"
				fi
				#Athlon processors
				if test "`echo $PROCESSOR | grep \"AMD Athlon(tm)\"`" != ""; then
				  CPUFLAGS="-march=athlon"
				fi
				if test "`echo $PROCESSOR | grep \"AMD Athlon(tm) MP\"`" != ""; then
				  CPUFLAGS="-march=athlon-mp"
				fi
				if test "`echo $PROCESSOR | grep \"AMD Athlon(tm) XP\"`" != ""; then
				  CPUFLAGS="-march=athlon-xp"
				fi
				if test "`echo $PROCESSOR | grep \"AMD Athlon(tm) 64\"`" != ""; then
				   CPUFLAGS="-march=athlon64"
				fi
				#Is our CPU an Ultra Sparc?
				if test "`echo $PROCESSOR | grep \"UltraSparc\"`" != ""; then
					CPUFLAGS="-mcpu=ultrasparc"
				fi
			else
				#Alas, we can set only generic arch optimizations
				PROCESSOR=`uname -m | grep 86`
				if test "$PROCESSOR" != ""; then
					CPUFLAGS="-march=$PROCESSOR"
				fi
			fi
			if test "$CPUFLAGS" != ""; then
				echo "Applying architecture optimizations: "$CPUFLAGS
			fi
			CFLAGS="$CPUFLAGS $MY_CFLAGS"
		fi
	else
		CFLAGS="$MY_CFLAGS"
	fi
# End of setting suctom flags for gcc

# Check wether we are x86 or not
	AC_MSG_CHECKING([for machine class])
	X86=""
	HW=`uname -m`
	if test "`echo $HW | grep \"86\"`" != ""; then
		X86="1"
	fi
	AC_SUBST(X86)
	AC_MSG_RESULT([$HW])
# End check for x86 hardware

# Check for C headers
	HEADERS="stdio.h stdlib.h stdarg.h string.h syslog.h time.h unistd.h ctype.h pwd.h sys/types.h \
	fcntl.h sys/stat.h sys/ioctl.h envz.h X11/X.h X11/Xlib.h X11/xpm.h X11/extensions/shape.h"
	HEADERS_ERROR_MESSAGE="One or more system headers that are necessary to compile this program are missing on this system. Cannot continue."
	AC_CHECK_HEADERS([$HEADERS],,[AC_MSG_ERROR([$HEADERS_ERROR_MESSAGE])],)
	AC_HEADER_DIRENT
# End check for C headers

# Check wether we can spawn new threads
	AC_CHECK_HEADERS([pthread.h],,[AC_MSG_ERROR([$HEADERS_ERROR_MESSAGE])],)
	AC_CHECK_LIB(pthread, pthread_create, , , )
# end threads check

AC_CONFIG_FILES([Makefile
	src/Makefile
	src/dockapp/Makefile
	src/power_management/Makefile
])
AC_OUTPUT