summaryrefslogtreecommitdiff
path: root/acinclude.m4
blob: 59044b8475ffb192b51b17ade68c153c32790837 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
dnl
dnl LIBGTOP_CHECK_TYPE
dnl
dnl Improved version of AC_CHECK_TYPE which takes into account
dnl that we need to #include some other header files on some
dnl systems to get some types.

dnl AC_LIBGTOP_CHECK_TYPE(TYPE, DEFAULT)
AC_DEFUN(AC_LIBGTOP_CHECK_TYPE,
[AC_REQUIRE([AC_HEADER_STDC])dnl
AC_MSG_CHECKING(for $1)
AC_CACHE_VAL(ac_cv_type_$1,
[AC_EGREP_CPP(dnl
changequote(<<,>>)dnl
<<(^|[^a-zA-Z_0-9])$1[^a-zA-Z_0-9]>>dnl
changequote([,]), [#include <sys/types.h>
#if STDC_HEADERS
#include <stdlib.h>
#include <stddef.h>
#endif

/* For Tru64 */
#ifdef HAVE_SYS_BITYPES_H
#include <sys/bitypes.h>
#endif
], ac_cv_type_$1=yes, ac_cv_type_$1=no)])dnl
AC_MSG_RESULT($ac_cv_type_$1)
if test $ac_cv_type_$1 = no; then
  AC_DEFINE($1, $2)
fi
])

dnl This is used internally for <glibtop-config.h>.

AC_DEFUN([GNOME_LIBGTOP_TYPES_PRIVATE],
[
	AC_CHECK_HEADERS(sys/bitypes.h)
	AC_LIBGTOP_CHECK_TYPE(u_int64_t, unsigned long long int)
	AC_LIBGTOP_CHECK_TYPE(int64_t, signed long long int)
	AC_LIBGTOP_CHECK_TYPE(u_int8_t, unsigned char)
	AC_LIBGTOP_CHECK_TYPE(int8_t, signed char)
])

dnl This file is intended for use both internally in libgtop and in every program
dnl that wants to use it.
dnl
dnl It defines the following variables:
dnl
dnl * 'libgtop_sysdeps_dir'    - sysdeps dir for libgtop.
dnl * 'libgtop_sysdeps_name'   - name of the sysdeps dir.
dnl * 'libgtop_use_machine_h'  - some of system dependend parts of libgtop provide
dnl                              their own header file. In this case we need to
dnl                              define 'HAVE_GLIBTOP_MACHINE_H'.
dnl * 'libgtop_need_server'    - is the server really needed? Defines 'NEED_LIBGTOP'
dnl                              if true; defines conditional 'NEED_LIBGTOP'.

AC_DEFUN([LIBGTOP_HACKER_TESTS],[
	AC_REQUIRE([AC_CANONICAL_HOST])

	case "$host_os" in
	linux*)
	  AC_ARG_WITH(linux-sysctl,
	  [  --with-linux-sysctl     Use the sysctl () interface from Martin Baulig],[
	  linux_sysctl="$withval"],[linux_sysctl=auto])
	  if test $linux_sysctl = yes ; then
	    AC_CHECK_HEADER(linux/libgtop.h, linux_sysctl=yes, linux_sysctl=no)
	  elif test $linux_sysctl = auto ; then
	    AC_MSG_CHECKING(for LibGTop sysctl support in Linux Kernel)
	    AC_TRY_RUN([
#include <stdio.h>
#include <stdlib.h>

#include <sys/user.h>
#include <sys/sysctl.h>
#include <linux/libgtop.h>

#define SIZE(x) sizeof(x)/sizeof(x[0])

int name[2] = { CTL_LIBGTOP, LIBGTOP_VERSION };

int
main (void)
{
    unsigned version;
    size_t size = sizeof (version);

    if (sysctl (name, SIZE (name), &version, &size, NULL, 0))
	exit (1);
    else if (version < 1)
	exit (2);
    else
	exit (0);
}
], linux_sysctl=yes, linux_sysctl=no, linux_sysctl=no)
	    AC_MSG_RESULT($linux_sysctl)
	  fi
	  if test $linux_sysctl = yes ; then
	    AC_DEFINE(HAVE_LINUX_SYSCTL)
	  fi
	  AM_CONDITIONAL(LINUX_SYSCTL, test $linux_sysctl = yes)
	  ;;
	esac
])

AC_DEFUN([LIBGTOP_CHECK_SYSDEPS_DIR],[
	AC_MSG_CHECKING(for libgtop sysdeps directory)

	case "$host_os" in
	linux*)
	  libgtop_sysdeps_dir=linux
	  libgtop_use_machine_h=no
	  libgtop_have_sysinfo=no
	  libgtop_need_server=no
	  libgtop_have_sysdeps=yes
	  libgtop_dynlink_ok=yes
	  ;;
	freebsd*|netbsd*|openbsd*)
	  libgtop_sysdeps_dir=freebsd
	  libgtop_use_machine_h=yes
	  libgtop_need_server=yes
	  libgtop_have_sysdeps=no
	  libgtop_postinstall='chgrp kmem $(bindir)/libgtop_server && chmod 2755 $(bindir)/libgtop_server'
	  libgtop_dynlink_ok=yes
	  ;;
        bsdi*)
	  libgtop_sysdeps_dir=freebsd
	  libgtop_use_machine_h=yes
	  libgtop_need_server=yes
	  libgtop_have_sysdeps=no
	  libgtop_postinstall='chgrp kmem $(bindir)/libgtop_server && chmod 2755 $(bindir)/libgtop_server'
	  libgtop_dynlink_ok=yes
	  ;;
	solaris*)
	  libgtop_sysdeps_dir=solaris
	  libgtop_use_machine_h=yes
	  libgtop_need_server=yes
	  libgtop_have_sysdeps=yes
	  libgtop_postinstall='chgrp sys $(bindir)/libgtop_server && chmod 2755 $(bindir)/libgtop_server'
	  libgtop_dynlink_ok=no
	  ;;
	osf*)
	  libgtop_sysdeps_dir=osf1
	  libgtop_use_machine_h=yes
	  libgtop_need_server=yes
	  libgtop_have_sysdeps=yes
	  libgtop_dynlink_ok=yes
	  ;;
	*)
	  if test x$hacker_mode = xyes ; then
	    case "$host_os" in
	    sunos4*)
	      #Please note that this port is obsolete and not working at
	      #all. It is only useful for people who want to fix it ... :-)
	      libgtop_sysdeps_dir=sun4
	      libgtop_use_machine_h=yes
	      libgtop_need_server=yes
	      libgtop_have_sysdeps=no
	      libgtop_dynlink_ok=no
	      ;;
	    *)
	      libgtop_sysdeps_dir=stub
	      libgtop_use_machine_h=no
	      libgtop_need_server=no
	      libgtop_have_sysdeps=yes
	      libgtop_dynlink_ok=yes
	      ;;
	    esac
	  else
	    libgtop_sysdeps_dir=stub
	    libgtop_use_machine_h=no
	    libgtop_need_server=no
	    libgtop_have_sysdeps=yes
	    libgtop_dynlink_ok=yes
	  fi
	  ;;
	esac

	test -z "$libgtop_postinstall" && libgtop_postinstall=:

	AC_MSG_RESULT($libgtop_sysdeps_dir)
])

AC_DEFUN([GNOME_LIBGTOP_DYNLINK],[
	AC_MSG_CHECKING(whether to build gmodulized LibGTop)

	AC_ARG_ENABLE(modules,
	[  --disable-modules       Disables dynamic module loading],[
	if test x$withval = xyes; then 
	  with_modules=yes
        else
          with_modules=no
	fi
	],[with_modules=auto])

	dynworks=false
	deps=
	if test x$with_modules = xno; then
	  AC_MSG_RESULT(no)
	else
	  AC_MSG_RESULT(yes)
	fi

	AC_MSG_CHECKING(whether dynamic modules work)
	if test x$with_modules = xauto; then
	  oLIBS="$LIBS"
	  oCFLAGS="$CFLAGS"
	  LIBS="`glib-config --libs gmodule`"
	  CFLAGS="`glib-config --cflags gmodule`"
	  AC_TRY_RUN([
	    #include <glib.h>
	    #include <gmodule.h>
	    main ()
	    {
	    	if (g_module_supported ())
	    	    exit (0);
	    	else
	    	    exit (1);
	    }
	  ], dynworks=true, dynworks=false, dynworks=true)
	  LIBS="$oLIBS"
	  CFLAGS="$oCFLAGS"
    
	  dnl Now we check to see if our libtool supports shared lib deps
	  dnl (in a rather ugly way even)
	  if $dynworks; then
	    libgtop_libtool_config="${CONFIG_SHELL-/bin/sh} libtool --config"
	    libgtop_deplibs_check=`$libgtop_libtool_config | \
	      grep '^[[a-z_]]*check[[a-z_]]*_method=[['\''\"]]' | \
	        sed 's/.*[['\''"]]\(.*\)[['\''"]]$/\1/'`
	    if test "x$libgtop_deplibs_check" = "xnone" || \
	      test "x$libgtop_deplibs_check" = "xunknown" || \
	      test "x$libgtop_deplibs_check" = "x"; then
	        dynworks=false
	    fi
	  fi
	elif test x$with_modules = xyes; then
	  dynworks=true
	else
	  dynworks=false
	fi

	if $dynworks; then
	  AC_DEFINE(LIBGTOP_USE_GMODULE)
	  GMODULE_LIBS="`glib-config --libs gmodule`"
	  GMODULE_FLAGS="`glib-config --cflags gmodule`"
	  AC_SUBST(GMODULE_LIBS)
	  AC_SUBST(GMODULE_FLAGS)
	  libgtop_use_gmodule=yes
	  libgtop_dynamic_ldflags='-export-dynamic -module'
	else
	  libgtop_use_gmodule=no
	  libgtop_dynamic_ldflags=
	fi

	AC_MSG_RESULT($libgtop_use_gmodule)

	AC_SUBST(libgtop_dynamic_ldflags)
])

AC_DEFUN([GNOME_LIBGTOP_SYSDEPS],[
	AC_REQUIRE([AC_CANONICAL_HOST])

	AC_SUBST(libgtop_sysdeps_dir)
	AC_SUBST(libgtop_sysdeps_name)
	AC_SUBST(libgtop_use_machine_h)
	AC_SUBST(libgtop_need_server)
	AC_SUBST(libgtop_have_sysdeps)

	AC_ARG_ENABLE(hacker-mode,
	[  --enable-hacker-mode    Enable building of unstable sysdeps],
	[hacker_mode="$enableval"], [hacker_mode=no])

	AM_CONDITIONAL(HACKER_MODE, test x"$hacker_mode" = xyes)

	if test x$hacker_mode = xyes ; then
	  LIBGTOP_HACKER_TESTS
	  AC_ARG_WITH(sysdeps-dir,
	  [  --with-sysdeps-dir      Manually override sysdeps directory],[override_sysdeps_dir="$withval"],[override_sysdeps_dir=no])
	else
	  override_sysdeps_dir=no
	fi

	AC_ARG_WITH(libgtop-smp,
	[  --with-libgtop-smp      Enable SMP support (default-auto)],[
	libgtop_smp="$withval"],[libgtop_smp=auto])

	if test $libgtop_smp = auto ; then
	  AC_MSG_CHECKING(whether to enable SMP support)
	  case "$host_os" in
	  linux*)
	    libgtop_smp=yes
	    ;;
	  *)
	    libgtop_smp=no
	    ;;
	  esac
	  AC_MSG_RESULT($libgtop_smp)
	fi

	if test $libgtop_smp = yes ; then
	  AC_DEFINE(HAVE_LIBGTOP_SMP)
	fi

	AM_CONDITIONAL(LIBGTOP_SMP, test $libgtop_smp = yes)

	if test x$override_sysdeps_dir = xno ; then
	  LIBGTOP_CHECK_SYSDEPS_DIR
	else
	  case $override_sysdeps_dir in
	  stub)
	    libgtop_sysdeps_dir=stub
	    libgtop_use_machine_h=no
	    libgtop_have_sysinfo=no
	    libgtop_need_server=no
	    libgtop_have_sysdeps=yes
	    libgtop_dynlink_ok=yes
	    ;;
	  stub_suid)
	    libgtop_sysdeps_dir=stub_suid
	    libgtop_use_machine_h=yes
	    libgtop_have_sysinfo=no
	    libgtop_need_server=yes
	    libgtop_have_sysdeps=no
	    libgtop_dynlink_ok=yes
	    ;;
	  linux|kernel)
	    libgtop_sysdeps_dir=linux
	    libgtop_use_machine_h=no
	    libgtop_have_sysinfo=no
	    libgtop_need_server=no
	    libgtop_have_sysdeps=yes
	    libgtop_dynlink_ok=yes
	    ;;
	  bsd)
	    libgtop_sysdeps_dir=freebsd
	    libgtop_use_machine_h=yes
	    libgtop_need_server=yes
	    libgtop_have_sysdeps=no
	    libgtop_postinstall='chgrp kmem $(bindir)/libgtop_server && chmod 2755 $(bindir)/libgtop_server'
	    libgtop_dynlink_ok=yes
	    ;;
	  solaris)
	    libgtop_sysdeps_dir=solaris
	    libgtop_use_machine_h=yes
	    libgtop_need_server=yes
	    libgtop_have_sysdeps=yes
	    libgtop_postinstall='chgrp sys $(bindir)/libgtop_server && chmod 2755 $(bindir)/libgtop_server'
	    libgtop_dynlink_ok=no
	    ;;
	  osf)
	    libgtop_sysdeps_dir=osf1
	    libgtop_use_machine_h=yes
	    libgtop_need_server=yes
	    libgtop_have_sysdeps=yes
	    libgtop_dynlink_ok=yes
	    ;;
	  *)
	    AC_MSG_ERROR(Invalid value for --with-sysdeps-dir)
	    ;;
	  esac
	fi

	AC_MSG_CHECKING(for libgtop sysdeps name)
	libgtop_sysdeps_name=`echo $libgtop_sysdeps_dir | sed -e 's/_/-/g'`
	AC_MSG_RESULT($libgtop_sysdeps_name)

	AC_MSG_CHECKING(whether to use dynamic linking in LibGtop)
	AC_MSG_RESULT($libgtop_dynlink_ok)

	AC_SUBST(libgtop_sysdeps_dir)
	AC_SUBST(libgtop_postinstall)
	AC_SUBST(libgtop_have_sysinfo)

	case "$host_os" in
	*bsd*)
	  AC_CHECK_HEADERS(net/if_var.h osreldate.h)
	  AC_MSG_CHECKING([for I4B])
	  AC_TRY_COMPILE([
#include <sys/types.h>
#include <sys/socket.h>

#include <net/if.h>
#include <net/if_types.h>

#ifdef HAVE_NET_IF_VAR_H
#include <net/if_var.h>
#endif

#include <net/netisr.h>
#include <net/route.h>

#if defined(__FreeBSD__) || defined(__NetBSD__)
#include <net/if_sppp.h>
#else
#include <i4b/sppp/if_sppp.h>
#endif
],[
	size_t size = sizeof (struct sppp);
], have_i4b=yes, have_i4b=no)
	  AC_MSG_RESULT($have_i4b)
	  if test x$have_i4b = xyes; then
	    AC_DEFINE(HAVE_I4B)
	    AC_MSG_CHECKING([for I4B accounting])
	    AC_TRY_COMPILE([
#include <sys/types.h>
#include <sys/socket.h>

#include <net/if.h>
#include <net/if_types.h>

#ifdef HAVE_NET_IF_VAR_H
#include <net/if_var.h>
#endif

#include <net/netisr.h>
#include <net/route.h>

#if defined(__FreeBSD__) || defined(__NetBSD__)
#include <net/if_sppp.h>
#else
#include <i4b/sppp/if_sppp.h>
#endif

#include <machine/i4b_acct.h>
],[
	size_t size = sizeof (struct i4bisppp_softc);
], have_i4b_acct=yes, have_i4b_acct=no)
	    AC_MSG_RESULT($have_i4b_acct)
	    if test x$have_i4b_acct = xyes ; then
	      AC_DEFINE(HAVE_I4B_ACCT)
	    else
	      AC_WARN([
*** I4B accounting disabled - you won't get any PPP statistics.
*** Read "misc/i4b_acct.txt" in the LibGTop source directory
*** to see how to enable it.])
	    fi
	  fi
	  ;;
	linux*)
	  os_major_version=`uname -r | sed 's/-pre[[0-9]]*//' | \
	    sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
	  os_minor_version=`uname -r | sed 's/-pre[[0-9]]*//' | \
	    sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
	  os_micro_version=`uname -r | sed 's/-pre[[0-9]]*//' | \
	    sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
	  os_version_expr="$os_major_version 65536 * $os_minor_version 256 * + $os_micro_version + p q"

	  AC_CHECK_HEADERS(linux/version.h, have_linux_version_h=yes,
	    have_linux_version_h=no)

	  if test x$have_linux_version_h = xyes ; then
	    version_code=`cat /usr/include/linux/version.h | \
	      grep \#define | grep LINUX_VERSION_CODE`
	    os_version_code=`echo $version_code | \
	      sed 's/^.*LINUX_VERSION_CODE[[ \t]]*\([[0-9]]*\).*$/\1/'`
	  else
	    os_version_code=`echo "$os_version_expr" | dc`
	  fi

	  AC_MSG_CHECKING(for Linux kernel version code)
	  AC_DEFINE_UNQUOTED(GLIBTOP_LINUX_VERSION_CODE, $os_version_code)
	  AC_MSG_RESULT($os_version_code)
	  ;;
	solaris*)
	  os_major_version=`uname -r | sed 's/\([[0-9]]*\).\([[0-9]]\)\.*\([[0-9]]*\)/\1/'`
	  os_minor_version=`uname -r | sed 's/\([[0-9]]*\).\([[0-9]]\)\.*\([[0-9]]*\)/\2/'`
	  os_micro_version=`uname -r | sed 's/\([[0-9]]*\).\([[0-9]]\)\.*\([[0-9]]*\)/\3/'`
	  test -z "$os_micro_version" && os_micro_version=0
	  os_version_expr="$os_major_version 100 * $os_minor_version 10 * + $os_micro_version + p q"
	  os_version_code=`echo "$os_version_expr" | dc`

	  AC_MSG_CHECKING(for Solaris release code)
	  AC_DEFINE_UNQUOTED(GLIBTOP_SOLARIS_RELEASE, $os_version_code)
	  AC_MSG_RESULT($os_version_code)
	  ;;
	esac

	AC_MSG_CHECKING(for Modem lockfile)
	AC_ARG_WITH(modem-lockfile,
	  [  --with-modem-lockfile   Modem lockfile for PPP support],[libgtop_modem_lockfile="$withval"],
	  [if test -f /dev/modem ; then
	     libgtop_modem_lockfile='/var/lock/LCK..modem'
	   else
	     libgtop_modem_lockfile='/var/lock/LCK..ttyS%u'
	   fi])
	AC_MSG_RESULT($libgtop_modem_lockfile)
	AC_DEFINE_UNQUOTED(LIBGTOP_MODEM_LOCKFILE, "$libgtop_modem_lockfile")

	AC_MSG_CHECKING(for machine.h in libgtop sysdeps dir)
	AC_MSG_RESULT($libgtop_use_machine_h)

	AC_MSG_CHECKING(whether we need libgtop)
	AC_MSG_RESULT($libgtop_need_server)

	if test x$libgtop_need_server = xyes ; then
	  AC_DEFINE(NEED_LIBGTOP)
	fi

	if test x$libgtop_use_machine_h = xyes ; then
	  AC_DEFINE(HAVE_GLIBTOP_MACHINE_H)
	fi

	if test x$libgtop_dynlink_ok = xyes ; then
	  GNOME_LIBGTOP_DYNLINK
	else
	  libgtop_use_gmodule=no
	fi

	AC_SUBST(libgtop_use_gmodule)

	if test x$libgtop_have_sysdeps = xyes ; then
	  AC_DEFINE(LIBGTOP_HAVE_SYSDEPS)
	fi

	if test x$libgtop_need_server = xyes ; then
	  AC_DEFINE(LIBGTOP_NEED_SERVER)
	fi

	AM_CONDITIONAL(NEED_LIBGTOP, test x$libgtop_need_server = xyes)
	AM_CONDITIONAL(HAVE_SYSDEPS, test x$libgtop_have_sysdeps = xyes)
	AM_CONDITIONAL(LIBGTOP_USE_GMODULE, test x$libgtop_use_gmodule = xyes)
])

dnl
dnl LIBGTOP_XML_HOOK (script-if-xml-found, failflag)
dnl
dnl If failflag is "failure", script aborts due to lack of XML
dnl 
dnl Check for availability of the libxml library
dnl the XML parser uses libz if available too
dnl

AC_DEFUN([LIBGTOP_XML_HOOK],[
	LIBGTOP_XML_LIB=
	AC_PATH_PROG(XML_CONFIG,xml-config,no)
	if test "$XML_CONFIG" = no; then
		if test x$2 = xfailure; then
			AC_MSG_ERROR(Could not find xml-config)
		else
			AC_MSG_WARN(Could not find xml-config)
		fi
	else
		AC_CHECK_LIB(xml, xmlDocGetRootElement, [
			$1
			LIBGTOP_XML_LIB=`$XML_CONFIG --libs`
			AC_DEFINE(HAVE_LIBXML)
		], [
			if test x$2 = xfailure; then 
				AC_MSG_ERROR(Could not link sample xml program)
			else
				AC_MSG_WARN(Could not link sample xml program)
			fi
		], `$XML_CONFIG --libs`)
	fi
	AC_SUBST(LIBGTOP_XML_LIB)
])

AC_DEFUN([LIBGTOP_XML_CHECK], [
	LIBGTOP_XML_HOOK([],failure)
])