1# SYNOPSIS
2#
3#   AX_LINUX_DISTRIBUTION
4#
5# DESCRIPTION
6#
7#	Try to detect the name and version of the Linux distribution where the software is being run
8#
9#   In configure.in:
10#
11#     dnl For my rpm.m4 macros
12#     AC_SUBST(LINUX_DISTRIBUTION_NAME)
13#     AC_SUBST(LINUX_DISTRIBUTION_VERSION)
14#
15#  	Daniel Varela <dvarela@ecmwf.int> 2011
16#   Version 1.1 (2011-11-11)
17
18
19dnl AX_LINUX_DISTRIBUTION
20dnl Figure out the Linux distribution where the software is being built
21dnl automake target
22
23AC_DEFUN([AX_LINUX_DISTRIBUTION],
24[dnl
25AC_REQUIRE([AC_CANONICAL_HOST])
26HOST_CPU=${host_cpu}
27HOST_VENDOR=${host_vendor}
28HOST_OS=${host_os}
29
30if test x$HOST_OS = "xlinux-gnu"
31then
32	AC_MSG_CHECKING(for Linux distribution )
33
34	# This works for Fedora, RedHat and Slackware
35	for f in /etc/fedora-release /etc/redhat-release /etc/slackware-release
36	do
37		if test -f $f; then
38			distro=`cat $f`
39			break
40		fi
41	done
42
43	# This works in Ubuntu (11 at least)
44	if test -f /etc/lsb-release; then
45		distro=`cat /etc/lsb-release | grep DISTRIB_ID | awk -F= '{print $2}' `
46		distro_version=`cat /etc/lsb-release | grep DISTRIB_RELEASE | awk -F= '{print $2}' `
47	fi
48
49	# For SuSE
50	if test -f /etc/SuSE-release; then
51		distro=`cat /etc/SuSE-release | head -1`
52		#distro_version=`cat /etc/SuSE-release | tail -1 | awk -F= '{print $2}' `
53	fi
54
55	# At least Debian has this
56	if test -f /etc/issue.net -a "x$distro" = x; then
57		distro=`cat /etc/issue.net | head -1`
58	fi
59
60	# Everything else
61	if test "x$distro" = x; then
62		distro="Unknown Linux"
63	fi
64
65	LINUX_DISTRIBUTION_NAME=$distro
66	LINUX_DISTRIBUTION_VERSION=$distro_version
67    AC_MSG_RESULT($LINUX_DISTRIBUTION_NAME $LINUX_DISTRIBUTION_VERSION)
68
69else
70	LINUX_DISTRIBUTION_NAME=$HOST_OS
71	LINUX_DISTRIBUTION_VERSION=""
72	AC_MSG_NOTICE(OS is non-Linux UNIX $HOST_OS.)
73fi
74
75AC_SUBST(LINUX_DISTRIBUTION_NAME)
76AC_SUBST(LINUX_DISTRIBUTION_VERSION)
77])
78