6a96214673ffe6a9d5a22a504db815a7f8777232
[platform/upstream/gnome-common.git] / macros / gnome-libgtop-sysdeps.m4
1 dnl This file is intended for use both internally in libgtop and in every program
2 dnl that wants to use it.
3 dnl
4 dnl It defines the following variables:
5 dnl
6 dnl * 'libgtop_sysdeps_dir'    - sysdeps dir for libgtop.
7 dnl * 'libgtop_use_machine_h'  - some of system dependend parts of libgtop provide
8 dnl                              their own header file. In this case we need to
9 dnl                              define 'HAVE_GLIBTOP_MACHINE_H'.
10 dnl * 'libgtop_need_server'    - is the server really needed? Defines 'NEED_LIBGTOP'
11 dnl                              if true; defines conditional 'NEED_LIBGTOP'.
12
13 AC_DEFUN([GNOME_LIBGTOP_SYSDEPS],[
14         AC_REQUIRE([AC_CANONICAL_HOST])
15
16         AC_SUBST(libgtop_sysdeps_dir)
17         AC_SUBST(libgtop_use_machine_h)
18         AC_SUBST(libgtop_need_server)
19
20         AC_ARG_WITH(libgtop-examples,
21         [  --with-libgtop-examples Build the libgtop examples (default=no)],[
22         build_examples="$withval"], [build_examples=no])
23
24         AM_CONDITIONAL(EXAMPLES, test x"$build_examples" = xyes)
25
26         AC_ARG_WITH(linux-table,
27         [  --with-linux-table      Use the table () function from Martin Baulig],[
28         linux_table="$withval"],[linux_table=auto])
29
30         if test $linux_table = yes ; then
31           AC_CHECK_HEADER(linux/table.h, linux_table=yes, linux_table=no)
32         elif test $linux_table = auto ; then
33           AC_MSG_CHECKING(for table function in Linux Kernel)
34           AC_TRY_RUN([
35 #include <stdio.h>
36 #include <stdlib.h>
37
38 #include <unistd.h>
39 #include <linux/unistd.h>
40 #include <linux/table.h>
41
42 #include <syscall.h>
43
44 static inline _syscall3 (int, table, int, type, union table *, tbl, const void *, param);
45
46 int
47 main (void)
48 {
49         union table tbl;
50         int ret;
51
52         ret = table (TABLE_VERSION, NULL, NULL);
53
54         if (ret == -1)
55                 exit (-errno);
56
57         exit (ret < 1 ? ret : 0);
58 }
59 ], linux_table=yes, linux_table=no, linux_table=no)
60           AC_MSG_RESULT($linux_table)
61         fi
62
63         if test $linux_table = yes ; then
64           AC_DEFINE(HAVE_LINUX_TABLE)
65         fi
66
67         AM_CONDITIONAL(LINUX_TABLE, test $linux_table = yes)
68
69         AC_ARG_WITH(libgtop-smp,
70         [  --with-libgtop-smp      Enable SMP support (default-auto)],[
71         libgtop_smp="$withval"],[libgtop_smp=auto])
72
73         if test $libgtop_smp = auto ; then
74           AC_MSG_CHECKING(whether to enable SMP support)
75           AC_TRY_RUN([
76 #include <sys/utsname.h>
77 #include <string.h>
78
79 int
80 main (void)
81 {
82         struct utsname name;
83
84         if (uname (&name)) exit (1);
85
86         exit (strstr (name.version, "SMP") ? 0 : 1);
87 }
88 ], libgtop_smp=yes, libgtop_smp=no, libgtop_smp=no)
89           AC_MSG_RESULT($libgtop_smp)
90         fi
91
92         if test $libgtop_smp = yes ; then
93           AC_DEFINE(HAVE_LIBGTOP_SMP)
94         fi
95
96         AM_CONDITIONAL(LIBGTOP_SMP, test $libgtop_smp = yes)
97
98         AC_MSG_CHECKING(for libgtop sysdeps directory)
99
100         case "$host_os" in
101         linux*)
102           if test x$linux_table = xyes ; then
103             libgtop_sysdeps_dir=kernel
104             libgtop_use_machine_h=no
105           else
106             libgtop_sysdeps_dir=linux
107             libgtop_use_machine_h=no
108             libgtop_have_sysinfo=yes
109           fi
110           libgtop_need_server=no
111           ;;
112         sunos4*)
113           libgtop_sysdeps_dir=sun4
114           libgtop_use_machine_h=yes
115           libgtop_need_server=yes
116           ;;
117         osf*)
118           libgtop_sysdeps_dir=osf1
119           libgtop_use_machine_h=yes
120           libgtop_need_server=yes
121           ;;
122         freebsd*)
123           libgtop_sysdeps_dir=freebsd
124           libgtop_use_machine_h=yes
125           libgtop_need_server=yes
126           libgtop_postinstall='chgrp kmem $(bindir)/libgtop_server && chmod 2755 $(bindir)/libgtop_server'
127           ;;
128         *)
129           libgtop_sysdeps_dir=stub
130           libgtop_use_machine_h=no
131           libgtop_need_server=no
132           ;;
133         esac
134
135         test -z "$libgtop_postinstall" && libgtop_postinstall=:
136
137         AC_MSG_RESULT($libgtop_sysdeps_dir)
138
139         AC_SUBST(libgtop_sysdeps_dir)
140         AC_SUBST(libgtop_postinstall)
141         AC_SUBST(libgtop_have_sysinfo)
142
143         case "$host_os" in
144         *bsd*)
145           AC_CHECK_HEADERS(net/if_var.h)
146           AC_MSG_CHECKING([for I4B])
147           AC_TRY_COMPILE([
148 #include <sys/types.h>
149 #include <sys/socket.h>
150
151 #include <net/if.h>
152 #include <net/if_types.h>
153
154 #ifdef HAVE_NET_IF_VAR_H
155 #include <net/if_var.h>
156 #endif
157
158 #include <net/netisr.h>
159 #include <net/route.h>
160
161 #ifdef __FreeBSD__
162 #include <net/if_sppp.h>
163 #else
164 #include <i4b/sppp/if_sppp.h>
165 #endif
166 ],[
167         size_t size = sizeof (struct sppp);
168 ], have_i4b=yes, have_i4b=no)
169           AC_MSG_RESULT($have_i4b)
170           if test x$have_i4b = xyes; then
171             AC_DEFINE(HAVE_I4B)
172             AC_MSG_CHECKING([for I4B accounting])
173             AC_TRY_COMPILE([
174 #include <sys/types.h>
175 #include <sys/socket.h>
176
177 #include <net/if.h>
178 #include <net/if_types.h>
179
180 #ifdef HAVE_NET_IF_VAR_H
181 #include <net/if_var.h>
182 #endif
183
184 #include <net/netisr.h>
185 #include <net/route.h>
186
187 #ifdef __FreeBSD__
188 #include <net/if_sppp.h>
189 #else
190 #include <i4b/sppp/if_sppp.h>
191 #endif
192
193 #include <machine/i4b_acct.h>
194 ],[
195         size_t size = sizeof (struct i4bisppp_softc);
196 ], have_i4b_acct=yes, have_i4b_acct=no)
197             AC_MSG_RESULT($have_i4b_acct)
198             if test x$have_i4b_acct = xyes ; then
199               AC_DEFINE(HAVE_I4B_ACCT)
200             else
201               AC_WARN([
202 *** I4B accounting disabled - you won't get any PPP statistics.
203 *** Read "misc/i4b_acct.txt" in the LibGTop source directory
204 *** to see how to enable it.])
205             fi
206           fi
207           ;;
208         esac
209
210         AC_MSG_CHECKING(for machine.h in libgtop sysdeps dir)
211         AC_MSG_RESULT($libgtop_use_machine_h)
212
213         AC_MSG_CHECKING(whether we need libgtop)
214         AC_MSG_RESULT($libgtop_need_server)
215
216         if test x$libgtop_need_server = xyes ; then
217           AC_DEFINE(NEED_LIBGTOP)
218         fi
219
220         if test x$libgtop_use_machine_h = xyes ; then
221           AC_DEFINE(HAVE_GLIBTOP_MACHINE_H)
222         fi
223
224         AM_CONDITIONAL(NEED_LIBGTOP, test x$libgtop_need_server = xyes)
225 ])
226