summaryrefslogtreecommitdiff
path: root/configure.ac
blob: ddb52b99294528693739c8fa16096870b9ff9554 (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
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
dnl Process this file with autoconf to produce a configure script.

dnl ******************************************************************
dnl  Set up autoconf and automake
dnl ******************************************************************
AC_INIT([sane-backends],
        m4_esyscmd_s([tools/git-version-gen --prefix '' .tarball-version]),
        [sane-devel@alioth-lists.debian.net])
AC_PREREQ([2.69])               dnl minimum autoconf version required
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_HEADERS([include/sane/config.h])

AM_INIT_AUTOMAKE([1.15 subdir-objects -Wall])
AM_SILENT_RULES

dnl ******************************************************************
dnl  Determine SANE version components and release status
dnl ******************************************************************
AS_IF([test x = "x$AWK"],[AC_PROG_AWK])
AS_IF([test x = "x`echo $VERSION | sed 's/[[.0-9]]//g'`"],
            [is_release=yes],
            [is_release=no])
V_MAJOR=`echo $VERSION | $AWK -F. '{print $1}'`
V_MINOR=`echo $VERSION | $AWK -F. '{print $2}'`
V_REV=`echo $VERSION | $AWK -F. '{print $3}' | sed 's/^\([[0-9]]*\).*/\1/'`;

AC_DEFINE_UNQUOTED(SANE_DLL_V_MAJOR, $V_MAJOR, [SANE DLL major number])
AC_DEFINE_UNQUOTED(SANE_DLL_V_MINOR, $V_MINOR, [SANE DLL minor number])
AC_DEFINE_UNQUOTED(SANE_DLL_V_BUILD, $V_REV, [SANE DLL revision number])
AC_SUBST(V_MAJOR)
AC_SUBST(V_MINOR)
AC_SUBST(V_REV)

dnl ******************************************************************
dnl  Set up the compiler and linker
dnl ******************************************************************
AC_PROG_CC
AC_PROG_CXX
AM_PROG_CC_C_O
AM_PATH_PYTHON(2.7)
sane_save_CC=$CC
AC_PROG_CC_C99                  dnl enables extensions to ISO C99 :-(
AS_IF([test xno != "x$ac_cv_prog_cc_c99"],
      [AC_MSG_CHECKING([for $sane_save_CC option for ISO C99 w/o extensions])
       AS_CASE([$ac_cv_prog_cc_c99],
               [-std=gnu99],      [sane_prog_cc_c99="-std=c99"],
               [-qlanglvl=extc99],[sane_prog_cc_c99="-qlanglvl=stdc99"])
       AS_IF([test "x$ac_cv_prog_cc_c99" = "x$sane_prog_cc_c99"],
             [AC_MSG_RESULT([$ac_cv_prog_cc_99])],
             [AC_MSG_RESULT([$sane_prog_cc_c99])
              CC="$sane_save_CC $sane_prog_cc_c99"])
      ])
AC_PROG_GCC_TRADITIONAL
AC_USE_SYSTEM_EXTENSIONS        dnl call before running the C compiler

AM_PROG_AR
LT_INIT([disable-static win32-dll])
LT_PREREQ([2.4.6])

dnl *****************************************************************
dnl  Set up I18N/L10N support
dnl *****************************************************************
AM_GNU_GETTEXT([external])
AM_GNU_GETTEXT_VERSION([0.19.8])

dnl ***********************************************************************
dnl Checks for programs.
dnl ***********************************************************************
AC_PATH_PROG(SANE_CONFIG_PATH, sane-config, no)

dnl Call explicitly before using PKG_*
PKG_PROG_PKG_CONFIG

AM_CONDITIONAL(CROSS_COMPILING, test x$cross_compiling = xyes)

dnl ***********************************************************************
dnl set compiler/linker flags
dnl ***********************************************************************
SANE_SET_AM_CFLAGS([$is_release])
AX_CXX_COMPILE_STDCXX_11([noext], [optional])
SANE_SET_AM_LDFLAGS

dnl ***********************************************************************
dnl Checks for unix variants
dnl ***********************************************************************
AC_SEARCH_LIBS([strerror],[cposix])

AC_NEED_BYTEORDER_H([include/byteorder.h])
AX_CREATE_STDINT_H([include/_stdint.h])

dnl ***********************************************************************
dnl Checks for libraries
dnl ***********************************************************************
AC_ARG_ENABLE(dynamic,
	AS_HELP_STRING([--disable-dynamic],
		       [Disable dynamic loading of backends]),
	[enable_dynamic=$enableval], [enable_dynamic=auto])
SANE_CHECK_DLL_LIB
dnl Checks for Backend libraries.
AC_CHECK_LIB(m, sqrt, MATH_LIB="-lm")
AC_SUBST(MATH_LIB)
case ${host_os} in
  os2*)
  AC_CHECK_LIB(syslog, syslog, SYSLOG_LIBS="-lsyslog")
  ;;
  beos*)
  AC_CHECK_LIB(be, syslog, SYSLOG_LIBS="-lbe")
  ;;
esac
AC_SUBST(SYSLOG_LIBS)

SANE_CHECK_JPEG
SANE_CHECK_TIFF
SANE_CHECK_PNG
SANE_CHECK_IEEE1284
SANE_CHECK_PTHREAD
SANE_CHECK_LOCKING
SANE_CHECK_GPHOTO2

dnl **************************************************************
dnl Check for V4L availability
dnl **************************************************************

AC_ARG_WITH(v4l,
	    AS_HELP_STRING([--with-v4l],
			   [include the v4l backend @<:@default=yes@:>@]),
	    [# If --with-v4l=no or --without-v4l, disable backend
             # as "$with_v4l" will be set to "no"])

if test "$with_v4l" != "no" ; then
  PKG_CHECK_MODULES(LIBV4L, [libv4l1 >= 0.8.3], have_libv4l1=yes, have_libv4l1=no)
fi

dnl **************************************************************
dnl Check for AVAHI availability
dnl **************************************************************

AC_ARG_WITH(avahi,
  AS_HELP_STRING([--with-avahi],
    [enable Avahi support @<:@default=check@:>@]),
  [],
  [with_avahi=check])

AS_IF([test xno != "x$with_avahi"],
  [PKG_CHECK_MODULES(AVAHI, [avahi-client >= 0.6.24],
    [with_avahi=yes
    ],
    [AS_IF([test xcheck != "x$with_avahi"],
       [AC_MSG_ERROR([Avahi support requested but not found])])
     with_avahi=no
    ])
  ])

 AS_IF([test xno != "x$with_avahi"],
 	[AC_DEFINE(WITH_AVAHI,
  		[1], [Define to 1 if Avahi support is available])],
 	[AC_DEFINE(WITH_AVAHI,
  		[0], [Define to 1 if Avahi support is available])])

AM_CONDITIONAL([have_libavahi], [test x != "x$AVAHI_LIBS"])

dnl check sane to make sure we don't have two installations
AC_CHECK_LIB(sane, sane_init, LIBSANE_EXISTS="yes")


dnl **************************************************************
dnl Check for libsnmp availability
dnl **************************************************************

AC_ARG_WITH(snmp,
  AS_HELP_STRING([--with-snmp],
    [enable SNMP support @<:@default=check@:>@]),
  [],
  [with_snmp=check])

AS_IF([test xno != "x$with_snmp"],
  [PKG_CHECK_MODULES(SNMP, [netsnmp >= 5.6],
    [with_snmp=yes
    ],
    [AS_IF([test xcheck != "x$with_snmp"],
       [AC_MSG_ERROR([libsnmp requested but not found])])
     with_snmp=no
    ])
  ])

 AS_IF([test xno != "x$with_snmp"],
 	[AC_DEFINE(HAVE_LIBSNMP,
  		[1], [Define to 1 if libsnmp is available])],
 	[AC_DEFINE(HAVE_LIBSNMP,
  		[0], [Define to 1 if libsnmp is available])])

AM_CONDITIONAL([have_snmp], [test x != "x$SNMP_LIBS"])

dnl ***********************************************************************
dnl Checks for header files.
dnl ***********************************************************************
AC_HEADER_STDC
AC_CHECK_HEADERS(fcntl.h unistd.h libc.h sys/dsreq.h sys/select.h \
    sys/time.h sys/shm.h sys/ipc.h sys/scanio.h os2.h \
    sys/socket.h sys/io.h sys/hw.h sys/types.h linux/ppdev.h \
    dev/ppbus/ppi.h machine/cpufunc.h sys/sem.h poll.h \
    windows.h be/kernel/OS.h limits.h sys/ioctl.h asm/types.h\
    netinet/in.h tiffio.h ifaddrs.h pwd.h getopt.h)
AC_CHECK_HEADERS([asm/io.h],,,[#include <sys/types.h>])

SANE_CHECK_MISSING_HEADERS

AC_CHECK_HEADERS(winsock2.h, SOCKET_LIB="-lws2_32")

AC_CHECK_HEADER(resmgr.h,[
	AC_CHECK_LIB(
		resmgr,
		rsm_open_device,[
			AC_DEFINE(HAVE_RESMGR,1,[define if you have the resmgr library])
			RESMGR_LIBS="-lresmgr"
		]
	)
])
AC_SUBST(RESMGR_LIBS)

dnl ***********************************************************************
dnl Checks for types and structures
dnl ***********************************************************************

AC_TYPE_SIZE_T
AC_TYPE_PID_T
AC_TYPE_SSIZE_T
SANE_CHECK_U_TYPES

# from Python, check for "long long" type
AC_MSG_CHECKING(for long long support)
have_long_long=no
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[long long x; x = (long long)0;]])],[AC_DEFINE(HAVE_LONG_LONG, 1, Define if the long long type is available.) have_long_long=yes],[])
AC_MSG_RESULT($have_long_long)

AC_MSG_CHECKING([for socklen_t in <sys/socket.h>])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <sys/socket.h>
]], [[socklen_t len]])],AC_MSG_RESULT(yes),
[AC_MSG_RESULT(no); AC_DEFINE(socklen_t,int,
[Define socklen_t as \'int\' if necessary.])])

AC_MSG_CHECKING([for union semun in <sys/sem.h>])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
]], [[union semun test_semun]])],[AC_MSG_RESULT(yes);
AC_DEFINE(HAVE_UNION_SEMUN,1,[Define if union semun is available.])],
[AC_MSG_RESULT(no)])

AC_MSG_CHECKING([for struct flock in fcntl.h])
AC_EGREP_HEADER([struct flock], fcntl.h, [AC_MSG_RESULT(yes) ;
                AC_DEFINE(HAVE_STRUCT_FLOCK, 1,
                [Define if struct flock is available.])], AC_MSG_RESULT(no))

AC_MSG_CHECKING([for Linux ioctl defines])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <sys/ioctl.h>
#include <asm/types.h>
]],[[
__u32 houba = _IOR('v',14, unsigned long);
]])],[AC_MSG_RESULT(yes);
have_linux_ioctl_defines="yes";],AC_MSG_RESULT(no))

dnl ***********************************************************************
dnl Checks for compiler characteristics
dnl ***********************************************************************
AC_C_BIGENDIAN
AC_C_CONST
AC_C_INLINE

dnl ***********************************************************************
dnl Checks for library functions
dnl ***********************************************************************

dnl Functions for which we provide an implementation if missing
AC_CONFIG_LIBOBJ_DIR([lib])
AC_FUNC_ALLOCA
AC_REPLACE_FUNCS([getenv inet_ntop inet_pton sigprocmask \
    sleep snprintf strcasestr strdup strndup strsep syslog usleep \
    vsyslog])
AS_IF([test x != x$ALLOCA],
      [LTALLOCA=`echo "$ALLOCA" | sed 's/\.o$//; s/\.obj$//'`.lo])
AC_SUBST(LTALLOCA)

dnl Define SOCKET_LIB, NSL_LIB, BIND_LIB, and RESOLV_LIB  when required
dnl for functions we use.
AC_CHECK_FUNC(gethostbyaddr,, [AC_CHECK_LIB(bind, gethostbyaddr, BIND_LIB="-lbind")])
AC_CHECK_FUNC(gethostbyaddr,, [AC_CHECK_LIB(nsl, gethostbyaddr, NSL_LIB="-lnsl")])
AC_CHECK_FUNC(socket,, [AC_CHECK_LIB(socket, socket, SOCKET_LIB="-lsocket")])
AC_CHECK_FUNC(inet_aton,, [AC_CHECK_LIB(resolv, inet_aton, RESOLV_LIB="-lresolv")])

dnl Group related network libraries together so they can always be linked
dnl in.
SOCKET_LIBS="$SOCKET_LIB $NSL_LIB $BIND_LIB $RESOLV_LIB"
AC_SUBST(SOCKET_LIBS)

dnl define HAVE_* values for network functions.  This may require
dnl SOCKET_LIBS so set LIBS temporarily.
save_LIBS="$LIBS"
LIBS="$LIBS $SOCKET_LIBS"
AC_CHECK_FUNCS(inet_addr inet_aton inet_ntoa)
LIBS="$save_LIBS"

if test "$ac_cv_header_be_kernel_OS_h" = "yes" ; then
    dnl those are known to be broken in BeOS (BONE)
    ac_cv_func_getaddrinfo=no
    ac_cv_func_getnameinfo=no
fi

AC_FUNC_MMAP
AC_CHECK_FUNCS(atexit ioperm i386_set_ioperm \
    mkdir strftime strstr strtod  \
    cfmakeraw tcsendbreak strcasecmp strncasecmp _portaccess \
    getaddrinfo getnameinfo poll setitimer iopl getuid getpass)

dnl sys/io.h might provide ioperm but not inb,outb (like for
dnl non i386/x32/x86_64 with musl libc)
if test "${ac_cv_header_sys_io_h}" = "yes"; then
  AC_MSG_CHECKING([for inb,outb (provided by sys/io.h)])
  AC_LINK_IFELSE(
    [AC_LANG_PROGRAM([[#include <sys/io.h>]],
      [[inb(0);outb(0,0);]])],
    [AC_MSG_RESULT([yes])
      sane_cv_have_sys_io_h_with_inb_outb="yes"],
    [AC_MSG_RESULT([no])
      sane_cv_have_sys_io_h_with_inb_outb="no"
      AC_MSG_WARN([sys/io.h does not provide inb,outb (non i386/x32/x86_64 arch?)])])
  if test "$sane_cv_have_sys_io_h_with_inb_outb" = "yes"; then
    AC_DEFINE(SANE_HAVE_SYS_IO_H_WITH_INB_OUTB, 1, [Define to 1 if you have the <sys/io.h> providing inb,outb.])
  fi
else
  sane_cv_have_sys_io_h_with_inb_outb="no"
fi

SANE_PROTOTYPES

if test "$ac_cv_header_os2_h" = "yes" ; then
  AC_DEFINE(strncasecmp, strnicmp, [Define for OS/2 only])
  AC_DEFINE(strcasecmp, stricmp, [Define for OS/2 only])
fi

if test "$ac_cv_header_getopt_h" = "yes" ; then
  AC_CHECK_FUNCS(getopt_long)
fi

# Slightly abuse the AC_LIBOBJ macro to mark files as replacement code
AS_IF([test x$ac_cv_header_getopt_h != xyes \
       && test x$ac_cv_func_getopt_long != xyes],
      [AC_LIBOBJ(getopt)
       AC_LIBOBJ(getopt1)])

dnl ***********************************************************************
dnl checks for system services
dnl ***********************************************************************
if test -c /dev/urandom ; then
    AC_DEFINE(HAVE_DEV_URANDOM, 1, [Is /dev/urandom available?])
fi

AC_ARG_WITH(systemd,
	AS_HELP_STRING([--with-systemd], [enable systemd support @<:@default=yes@:>@]))
if test "x$with_systemd" != xno ; then
  PKG_CHECK_MODULES(SYSTEMD, [libsystemd], have_systemd=yes, have_systemd=no)
  if test "x$have_systemd" = xno; then
    PKG_CHECK_MODULES(SYSTEMD, [libsystemd-daemon], have_systemd=yes, have_systemd=no)
  fi
  if test "x$have_systemd" = xyes; then
    AC_DEFINE(HAVE_SYSTEMD, 1, [Is /usr/include/systemd/sd-daemon.h available?])
  else
    if test "x$with_systemd" = xyes; then
      AC_MSG_ERROR([Systemd support was requested but systemd was not found])
    fi
  fi
fi

dnl ******************************************************************
dnl Check for USB support
dnl ******************************************************************

AC_ARG_WITH(usb,
  AS_HELP_STRING([--with-usb], [enable USB support @<:@default=check@:>@]),
  [],
  [with_usb=check])
AS_IF([test xno != "x$with_usb"],
  [have_usb=no
   AS_CASE(x$host_os,           dnl odd-ball operating systems first
    [xbeos*],
      [AC_CHECK_HEADER(be/drivers/USB_scanner.h, [have_usb=yes])],
    [xos2*],
      [AC_CHECK_HEADER(usbcalls.h,
        [AC_CHECK_LIB(usbcall, UsbQueryNumberDevices,
          [USB_LIBS="-lusbcall"
           have_usb=yes
           AC_DEFINE(HAVE_USBCALLS, [1],
             [Define to 1 if you have usbcall.dll.])
          ])
        ],
        [],
        [#include <usb.h>
         #include <os2.h>
        ])
      ],
    [dnl default to libusb-1.x, fall back to libusb-0.x if missing
     PKG_CHECK_MODULES([USB], [libusb-1.0],
      [AC_DEFINE([HAVE_LIBUSB], [1],
        [Define to 1 if you have libusb-1.0])
       have_usb=yes
      ],
      [PKG_CHECK_MODULES([USB], [libusb >= 0.1.8],
        [AC_DEFINE([HAVE_LIBUSB_LEGACY], [1],
          [Define to 1 if you have libusb-0.1])
         have_usb=yes
        ],
        [dnl 10+ years old libusb or Windows version
         AC_CHECK_HEADER(usb.h,
          AC_CHECK_LIB(usb, usb_interrupt_read,
            [USB_LIBS="-lusb"
             have_usb=yes
            ]))
         AC_CHECK_HEADERS(lusb0_usb.h,
           AC_CHECK_LIB(usb, usb_interrupt_read,
             [USB_LIBS="-lusb"
              have_usb=yes
             ]))
        ])
      ])
    ])
  ])
AS_IF([test xyes = "x$with_usb" && test xyes != "x$have_usb"],
  [AC_MSG_ERROR([USB support requested but required libraries not found.])
  ])
AM_CONDITIONAL([have_usblib], [test x != "x$USB_LIBS"])

dnl ******************************************************************
dnl Check for libcurl availability
dnl ******************************************************************
AC_ARG_WITH(libcurl,
  AS_HELP_STRING([--with-libcurl],
    [enable functionality that needs libcurl @<:@default=check@:>@]),
  [],
  [with_libcurl=check])

AS_IF([test xno != "x$with_libcurl"],
  [PKG_CHECK_MODULES(libcurl, [libcurl],
     [with_libcurl=yes
     ],
     [AS_IF([test xcheck != "x$with_libcurl"],
        [AC_MSG_ERROR([libcurl requested but not found])])
      with_libcurl=no
     ])
  ])

AS_IF([test xno != "x$with_libcurl"],
 	[AC_DEFINE(HAVE_LIBCURL,
  		[1], [Define to 1 if libcurl is available])],
 	[AC_DEFINE(HAVE_LIBCURL,
  		[0], [Define to 1 if libcurl is available])])

AM_CONDITIONAL([have_libcurl], [test x != "x$libcurl_LIBS"])

dnl ******************************************************************
dnl Check for poppler-glib availability
dnl ******************************************************************
AC_ARG_WITH(poppler-glib,
  AS_HELP_STRING([--with-poppler-glib],
    [enable functionality that needs poppler-glib @<:@default=check@:>@]),
  [],
  [with_poppler_glib=check])

AS_IF([test xno != "x$with_poppler_glib"],
  [PKG_CHECK_MODULES(POPPLER_GLIB, [poppler-glib],
     [with_poppler_glib=yes
     ],
     [AS_IF([test xcheck != "x$with_poppler_glib"],
        [AC_MSG_ERROR([poppler-glib requested but not found])])
      with_poppler_glib=no
     ])
  ])

  AS_IF([test xno != "x$with_poppler_glib"],
 	[AC_DEFINE(HAVE_POPPLER_GLIB,
  		[1], [Define to 1 if libpoppler-glib is available])],
 	[AC_DEFINE(HAVE_POPPLER_GLIB,
  		[0], [Define to 1 if libpoppler-glib is available])])

AM_CONDITIONAL([have_poppler_glib], [test x != "x$POPPLER_GLIB_LIBS"])

dnl ******************************************************************
dnl Check for USB record/replay support
dnl ******************************************************************
AC_ARG_WITH(usb_record_replay,
            AS_HELP_STRING([--with-usb-record-replay],
                           [enable USB record and replay to XML files @<:@default=yes@:>@]))

if test "x$with_usb_record_replay" != "xno"; then
  PKG_CHECK_MODULES([XML], [libxml-2.0], have_libxml=yes, have_libxml=no)
  if test "x$have_libxml" = xyes; then
    AC_DEFINE(HAVE_LIBXML2, 1, [Define to 1 if libxml2 is available])
    AC_DEFINE(WITH_USB_RECORD_REPLAY, 1, [define if USB record replay is enabled])
  else
    if test "x$with_usb_record_replay" = xyes; then
      AC_MSG_ERROR([USB record and replay support was requested but libxml-2.0 was not found])
    fi
  fi
fi
AM_CONDITIONAL([have_libxml2], [test x != "x$XML_LIBS"])

dnl ************
dnl SCSI Support
dnl ************

dnl FIXME: These are a lot of header files to scan.  We should
dnl scan for just one that is unique per platform and then do
dnl conditional scans for more specific only as needed.

# Unset VERSION during the SCSI header check
sed "s!^#define VERSION .*!/* & */!" confdefs.h > confdefs.h.tmp
mv confdefs.h.tmp confdefs.h

AC_CHECK_HEADERS(IOKit/scsi/SCSITaskLib.h IOKit/cdb/IOSCSILib.h \
  IOKit/scsi/SCSICommandOperationCodes.h \
  IOKit/scsi-commands/SCSICommandOperationCodes.h scsi.h sys/scsi.h \
  sys/scsicmd.h sys/scsiio.h bsd/dev/scsireg.h scsi/sg.h \
  camlib.h gscdds.h sys/scsi/scsi.h sys/scsi/sgdefs.h \
  sys/scsi/targets/scgio.h apollo/scsi.h sys/sdi_comm.h \
  sys/passthrudef.h)

# Restore VERSION
sed "s!/\* \(#define VERSION .*\) \*/!\1!" confdefs.h > confdefs.h.tmp
mv confdefs.h.tmp confdefs.h

AC_CHECK_HEADERS([io/cam/cam.h],,,[#include <io/common/iotypes.h>])
AC_CHECK_HEADERS([ntddscsi.h ddk/ntddscsi.h],,,[#include <windows.h>])

dnl FreeBSD < 3
if test "$ac_cv_header_sys_scsiio_h" = "yes" \
  && test "$ac_cv_header_scsi_h" = "yes"; then
  AC_MSG_CHECKING([if 'scsireq_t' needs to be defined as 'struct scsireq'])
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <sys/scsiio.h>
#include <scsi.h>
]], [[scsireq_t req]])],,
   [AC_MSG_RESULT(yes);
    AC_DEFINE(scsireq_t, struct scsireq_t,
	      [Define scsireq_t as \'struct scsireq\' if necessary.])])
fi
AC_CHECK_LIB(scsi, scsireq_enter, SCSI_LIBS="-lscsi") # FreeBSD needs this

dnl FreeBSD >= 3
AC_CHECK_LIB(cam, cam_open_device, SCSI_LIBS="-lcam")  # FreeBSD 3+ needs this

AC_CHECK_FUNCS(scsireq_enter)

if test "$ac_cv_header_scsi_sg_h" = "yes"; then
  AC_MSG_CHECKING([for sg_header.target_status in <scsi/sg.h>])
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <sys/types.h>
#include <scsi/sg.h>
]],[[
struct sg_header hdr;
hdr.target_status = 1;
return 0;
]])],[AC_MSG_RESULT(yes);
   AC_DEFINE(HAVE_SG_TARGET_STATUS,1,
	     [Define if sg_header.target_status is available.])],
	     AC_MSG_RESULT(no))
fi

if test "$ac_cv_header_IOKit_scsi_SCSITaskLib_h" = "yes"; then
  AC_MSG_CHECKING([for SCSITaskSGElement in IOKit/scsi/SCSITaskLib.h])
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#undef VERSION
#include <IOKit/scsi/SCSITaskLib.h>
]],[[
SCSITaskSGElement range;
return 0;
]])],[AC_MSG_RESULT(yes);
  AC_DEFINE(HAVE_SCSITASKSGELEMENT, 1,
	    [Define if SCSITaskSGElement is available.])],
  AC_MSG_RESULT(no))
fi

# Multiple platforms can set SCSI_LIBS so do substitution at end.
AC_SUBST(SCSI_LIBS)

AC_ARG_ENABLE(scsibuffersize,
  AS_HELP_STRING([--enable-scsibuffersize=N],
                 [specify the default size in bytes of the buffer for SCSI
                  commands @<:@default=131072@:>@]),
  [set_scsibuffersize="$enableval"], [set_scsibuffersize=131072])
AC_DEFINE_UNQUOTED(SCSIBUFFERSIZE, $set_scsibuffersize,
                   [SCSI command buffer size])
dnl FIXME: Move this to configuration printout area but probably
dnl but probably needs to be wrapped by what ever uses it so its
dnl only printed when used.
echo "scsi buffersize: $set_scsibuffersize"

AC_ARG_ENABLE(scsi-directio,
  AS_HELP_STRING([--enable-scsi-directio],
                 [enable SCSI direct IO (Linux only, dangerous, see
                  README.linux)]),
  [
    if eval "test x$enable_scsi_directio = xyes"; then
      AM_CFLAGS="$AM_CFLAGS -DENABLE_SCSI_DIRECTIO"
    fi
  ])

dnl ****
dnl IPv6
dnl ****

dnl check for IPv6 (can be overridden by --enable-ipv6)
if test "$ac_cv_func_getnameinfo" = "yes" \
  && test "$ac_cv_func_getaddrinfo" = "yes" ; then
  SANE_CHECK_IPV6
else
  ipv6="no"
fi

dnl ***********************************************************************
dnl initialize libtool
dnl ***********************************************************************
AC_ARG_ENABLE(preload,
	AS_HELP_STRING([--disable-preload],
		       [Disable preloading of backends]),
	[enable_preload=$enableval], [enable_preload=auto])

dnl Windows (cygwin/mingw), BeOS, and OS/2 need this.
case $host_os in
  cygwin* | mingw* | beos* | os2*)
  AM_LDFLAGS="$AM_LDFLAGS -no-undefined"
esac

dnl Check for lock dir

AC_ARG_WITH(lockdir, AS_HELP_STRING([--with-lockdir=DIR],
                                    [set SANE lockdir @<:@localstatedir/lock@:>@]),
                                    [locksanedir=$withval],[locksanedir=${localstatedir}/lock])
AC_SUBST(locksanedir)

configdir="${sysconfdir}/sane.d"
AC_SUBST(configdir)

dnl ***********************************************************************
dnl enable/disable backends and features based on previous tests and user's
dnl choice
dnl ***********************************************************************

AM_CPPFLAGS="${AM_CPPFLAGS} -DPATH_SANE_CONFIG_DIR=\$(configdir) \
	  -DPATH_SANE_DATA_DIR=\$(datadir) \
	  -DPATH_SANE_LOCK_DIR=\$(locksanedir) \
	  -DV_MAJOR=${V_MAJOR} -DV_MINOR=${V_MINOR}"

if test "${ac_cv_header_sys_socket_h}" = "no"; then
  echo "*** disabling saned (sys/socket.h not found)"
  SANED=
else
  SANED=saned
fi
AM_CONDITIONAL(COMPILE_SANED, test x$SANED = xsaned)

dnl These are the backends that are build in any case:

AC_ARG_ENABLE(local-backends,
  AS_HELP_STRING([--disable-local-backends],
                 [turn off compilation of all backends but net]))

ALL_BACKENDS="abaton agfafocus apple artec artec_eplus48u as6e \
        avision bh canon canon630u canon_dr canon_lide70 canon_pp cardscan \
        coolscan coolscan2 coolscan3 dc25 dc210 dc240 \
        dell1600n_net dmc epjitsu epson epson2 epsonds escl fujitsu \
        genesys gphoto2 gt68xx hp hp3500 hp3900 hp4200 hp5400 \
        hp5590 hpsj5s hpljm1005 hs2p ibm kodak kodakaio kvs1025 kvs20xx \
        kvs40xx leo lexmark lexmark_x2600 ma1509 magicolor \
        matsushita microtek microtek2 mustek mustek_pp \
        mustek_usb mustek_usb2 nec net niash pie pieusb pint \
        pixma plustek plustek_pp qcam ricoh ricoh2 rts8891 s9036 \
        sceptre sharp sm3600 sm3840 snapscan sp15c st400 \
        stv680 tamarack teco1 teco2 teco3 test u12 umax \
        umax_pp umax1220u v4l xerox_mfp p5"

# If user specifies backends manually then cause configure
# to fail if its detected it can't be compiled.  If we
# are in automatic mode then remove backend from list instead.
user_selected_backends="yes"

AC_ARG_VAR(BACKENDS, [list of backends to compile])
if eval "test x$enable_local_backends = xno"; then
   BACKENDS="net"
else
  if test "${BACKENDS}" != "" ; then
    AC_MSG_NOTICE([Manually selected backends: ${BACKENDS}])
  else
    BACKENDS="$ALL_BACKENDS"
    user_selected_backends="no"
  fi
fi

if test "${sane_cv_use_libjpeg}" = "yes"; then
  SANEI_SANEI_JPEG_LO="../sanei/sanei_jpeg.lo"
  saved_LIBS="${LIBS}"
  LIBS="${JPEG_LIBS}"
  AC_CHECK_FUNCS(jpeg_crop_scanline jpeg_skip_scanlines)
  LIBS="${saved_LIBS}"
fi
AM_CONDITIONAL(HAVE_JPEG, test x$sane_cv_use_libjpeg = xyes)
AC_SUBST(SANEI_SANEI_JPEG_LO)

SANE_CHECK_BACKENDS

AC_ARG_ENABLE(pnm-backend,
  AS_HELP_STRING([--enable-pnm-backend],
                 [enable the pnm backend for testing frontends (possible security risk, see PROBLEMS file)]),
                 [FILTERED_BACKENDS="${FILTERED_BACKENDS} pnm"],
                 [echo "*** pnm backend not manually selected - disabling"])

BACKENDS="$FILTERED_BACKENDS"
BACKEND_LIBS_ENABLED=""
BACKEND_CONFS_ENABLED=""
BACKEND_MANS_ENABLED=""
for backend in ${BACKENDS} ; do
  BACKEND_LIBS_ENABLED="${BACKEND_LIBS_ENABLED} libsane-${backend}.la"
  BACKEND_CONFS_ENABLED="${BACKEND_CONFS_ENABLED} ${backend}.conf"
  BACKEND_MANS_ENABLED="${BACKEND_MANS_ENABLED} sane-${backend}.5"
  if test x$backend = xgenesys; then
    with_genesys_tests=yes
  fi
  if test x$backend = xumax_pp; then
    install_umax_pp_tools=yes
  fi
done
AC_SUBST(BACKEND_LIBS_ENABLED)
AM_CONDITIONAL(WITH_GENESYS_TESTS, test xyes = x$with_genesys_tests)
AM_CONDITIONAL(INSTALL_UMAX_PP_TOOLS, test xyes = x$install_umax_pp_tools)

AC_ARG_VAR(PRELOADABLE_BACKENDS, [list of backends to preload into single DLL])
if test "${enable_preload}" = "auto"; then
  if test "${enable_shared}" = "no" || test "${enable_dynamic}" != "yes"; then
    enable_preload=yes
  fi
fi
if test "${enable_preload}" = "yes"; then
  echo "preloading backends into DLL"

  # If user specifies backends manually then cause configure
  # to fail if its detected it can't be compiled.  If we
  # are in automatic mode then remove backend from list instead.
  user_selected_backends="yes"

  if eval "test x$enable_local_backends = xno"; then
    PRELOADABLE_BACKENDS="net"
  else
    if test "${PRELOADABLE_BACKENDS}" != "" ; then
      AC_MSG_NOTICE([Manually selected preloadable backends: ${PRELOADABLE_BACKENDS}])
    else
      PRELOADABLE_BACKENDS="$BACKENDS"
      user_selected_backends="no"
    fi
  fi

  saved_BACKENDS="$BACKENDS"
  BACKENDS="${PRELOADABLE_BACKENDS}"

  SANE_CHECK_BACKENDS

  PRELOADABLE_BACKENDS="$FILTERED_BACKENDS"
  BACKENDS="$saved_BACKENDS"
else
  PRELOADABLE_BACKENDS=""
fi
PRELOADABLE_BACKENDS_ENABLED=""
# Do not initialize BACKEND_CONFS_ENABLED so that its a combination
# of all backends.
for backend in ${PRELOADABLE_BACKENDS} ; do
  BACKEND_CONFS_ENABLED="${BACKEND_CONFS_ENABLED} ${backend}.conf"
  BACKEND_MANS_ENABLED="${BACKEND_MANS_ENABLED} sane-${backend}.5"
  # Special hacks.  Normally, we create a convenience library that
  # matches the backend's name but in some cases that will conflict
  # with an external library name that also matches backend name.
  # Work around that here by renaming internal library.
  if test "${backend}" = "gphoto2"; then
    backend=gphoto2_i
  fi
  PRELOADABLE_BACKENDS_ENABLED="${PRELOADABLE_BACKENDS_ENABLED} lib${backend}.la"
done
AM_CONDITIONAL([preloadable_backends_enabled],
        [test x != "x$PRELOADABLE_BACKENDS_ENABLED"])

AC_SUBST(PRELOADABLE_BACKENDS)
AC_SUBST(PRELOADABLE_BACKENDS_ENABLED)
AC_SUBST(BACKEND_CONFS_ENABLED)
AC_SUBST(BACKEND_MANS_ENABLED)

dnl in BeOS, backends are not installed in lib/sane, but add-ons/sane/
dnl we account for both installing in /boot/beos and ~/config
case $host_os in
  beos*)
  libdir='${exec_prefix}/add-ons'
  ;;
esac

AC_ARG_ENABLE(parport-directio,
  AS_HELP_STRING([--enable-parport-directio],
                 [enable direct hardware access to the parallel port, so
                  frontends will require special permission level]),
  [
    if eval "test x$enable_parport_directio = xyes"; then
      AM_CFLAGS="$AM_CFLAGS -DENABLE_PARPORT_DIRECTIO"
    fi
  ])

dnl ***********************************************************************
dnl Write output files
dnl ***********************************************************************

AC_SUBST(AM_CPPFLAGS)
AC_SUBST(AM_CFLAGS)
AC_SUBST(AM_CXXFLAGS)
AC_SUBST(AM_LDFLAGS)

AC_CONFIG_FILES([Makefile lib/Makefile sanei/Makefile frontend/Makefile \
  japi/Makefile backend/Makefile include/Makefile doc/Makefile \
  po/Makefile.in testsuite/Makefile \
  testsuite/backend/Makefile \
  testsuite/backend/genesys/Makefile \
  testsuite/sanei/Makefile testsuite/tools/Makefile \
  tools/Makefile doc/doxygen-sanei.conf doc/doxygen-genesys.conf])
AC_CONFIG_FILES([tools/sane-config], [chmod a+x tools/sane-config])
AC_CONFIG_FILES([tools/sane-backends.pc])
AC_OUTPUT

dnl ***********************************************************************
dnl print configuration information
dnl ***********************************************************************

echo "-> Variables used for compilation/linking:"
echo AM_CPPFLAGS=\"${AM_CPPFLAGS}\"
echo AM_CFLAGS=\"${AM_CFLAGS}\"
echo AM_CXXFLAGS=\"${AM_CXXFLAGS}\"
echo AM_LDFLAGS=\"${AM_LDFLAGS}\"
echo LIBS=\"${LIBS}\"
echo "-> Installation directories:"
echo "Configuration: `eval eval echo ${sysconfdir}`"
echo "Libraries:     `eval eval echo ${libdir}`"
echo "Binaries:      `eval eval echo ${bindir}` and `eval eval echo ${sbindir}`"
echo "Manpages:      `eval eval echo ${mandir}`"
echo "Documentation: `eval eval echo ${docdir}`"
if eval "test x$INSTALL_LOCKPATH = xinstall-lockpath" ; then
  echo "Lockfiles:     `eval eval echo ${locksanedir}`"
else
  echo "Lockfiles:     Feature is disabled!"
fi
echo "-> Network parameters:"
if test "${SANED}" = "saned" ; then
  echo "Build saned:   yes"
else
  echo "Build saned:   no"
fi
echo "IPv6 support:  `eval eval echo ${ipv6}`"
echo "Avahi support: `eval eval echo ${with_avahi}`"
echo "cURL support:  `eval eval echo ${with_libcurl}`"
echo "POPPLER_GLIB support:  `eval eval echo ${with_poppler_glib}`"
echo "SNMP support:  `eval eval echo ${with_snmp}`"
echo "-> The following backends will be built:"
for backend in ${BACKENDS} ; do
  echo $ECHO_N "${backend} "
done
echo
echo
echo "-> The following preload backends will be built:"
for backend in ${PRELOADABLE_BACKENDS} ; do
  echo $ECHO_N "${backend} "
done
echo

if test "$SANE_CONFIG_PATH" != "no" ; then
  SANE_INSTALLED_VERSION=`$SANE_CONFIG_PATH --version`
  SANE_INSTALLED_PREFIX=`$SANE_CONFIG_PATH --prefix`
  if test "$SANE_INSTALLED_PREFIX" != "$prefix" ; then
    echo "*** WARNING: SANE is already installed (version $SANE_INSTALLED_VERSION). The old"
    echo "*** installation is at $SANE_INSTALLED_PREFIX while SANE will now be installed"
    echo "*** at $prefix. It is recommended to uninstall the old SANE version"
    echo "*** before installing the new one to avoid problems."
  fi
else
  if test "$LIBSANE_EXISTS" = "yes" ; then
    echo "*** Warning: An old version of SANE was detected but the sane-config program"
    echo "*** couldn't be found. If you encounter any problems with SANE remove the old"
    echo "*** SANE files and reinstall this version."
  fi
fi
if eval "test x${sysconfdir} = x/usr/etc" ; then
  echo "*** WARNING: Configuration files are stored in /usr/etc. If this is not"
  echo "*** intended, use --sysconfdir to set another path (e.g. "/etc")."
fi
if test "$SELECTED_BACKENDS" != "" ; then
  echo "*** Warning: Local backends have been disabled.  This means that scanners"
  echo "*** connected to your local computer won't be supported.  Only a network"
  echo "*** connection to a remote host is possible."
fi
if test "$with_usb" != "no" && test "$have_usb" != "yes" ; then
  echo "*** Warning: sane-backends will be built without USB support.  There may"
  echo "*** be valid reasons to do so, e.g. if you don't use USB scanners or on"
  echo "*** platforms without USB support but generally this means that you"
  echo "*** can't use USB devices with SANE. The most probable cause is that"
  if test "${ac_cv_header_usb_h}" != "yes"; then
    echo "*** the libusb header file usb.h is not installed. If you use Linux"
    echo "*** you may need a package called 'libusb-dev', 'libusb-devel' or similar."
  else
    echo "*** libusb is not installed at all or is too old. See README."
  fi
fi

echo "****************************************************************"
echo "* Please be sure to read file PROBLEMS in this directory       *"
echo "* BEFORE running any of the SANE applications.  Some devices   *"
echo "* may be damaged by improper operation, so please do heed this *"
echo "* advice.                                                      *"
echo "****************************************************************"