summaryrefslogtreecommitdiff
path: root/configure.d/config_modules_agent
blob: 32726799fa9e203d98f9e75822a66b24a520f95d (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
# -*- autoconf -*-
#
# generate empty files
#
# Create include file list for snmp_vars.h to use.
mibdir="agent/mibgroup"
if test ! -d agent; then
  mkdir agent
fi
if test ! -d agent/mibgroup; then
  mkdir agent/mibgroup
fi
j="$mibdir/mib_module_includes.h  $mibdir/agent_module_includes.h \
   $mibdir/mib_module_inits.h     $mibdir/agent_module_inits.h    \
   $mibdir/mib_module_shutdown.h  $mibdir/agent_module_shutdown.h \
   include/net-snmp/agent/mib_module_config.h                     \
                   include/net-snmp/agent/agent_module_config.h   \
   $mibdir/mib_module_dot_conf.h  $mibdir/agent_module_dot_conf.h"

for i in $j; do
  rm -f $i
  echo "/* This file is automatically generated by configure.  Do not modify by hand. */" > $i
done

#
# Do hairy agent module processing.
#
AC_MSG_CHECKING([for and configuring mib modules to use])

# set up the CPP command
MODULECPP="$CPP $PARTIALTARGETFLAGS -DNETSNMP_FEATURE_CHECKING -I${srcdir}/include -I${srcdir}/agent/mibgroup"
if test "x$enable_mfd_rewrites" = "xyes"; then
  MODULECPP="$MODULECPP -DNETSNMP_ENABLE_MFD_REWRITES"
fi

module_list=""
mib_module_list=""
agent_module_list=""
new_with_mib_modules=`echo $with_mib_modules | $SED 's/,/ /g;'`
new_with_out_mib_modules=`echo $with_out_mib_modules | $SED 's/,/ /g;'`

# set up initial module list
new_module_list="$new_with_mib_modules default_modules"

# minor modifications
if test "x$enable_agent" = "xno"; then
   # minimum mib module list for snmptrapd
   new_module_list="mibII/vacm_vars mibII/vacm_conf utilities/execute $new_with_mib_modules"
   default_mibs=SNMPv2-MIB:IF-MIB:IP-MIB:TCP-MIB:UDP-MIB
   default_mibs_install=" "
elif test "x$mini_agent" = "xyes"; then
   # define the mini agent flag to reduce our load list from default_mibs.h
   MODULECPP="$MODULECPP -DNETSNMP_MINI_AGENT"
fi

test_modules="$new_module_list"
new_module_list=""

# remove modules that were explicitly excluded
for i in $test_modules
 do
  if echo " $new_with_out_mib_modules " | $GREP " $i " > /dev/null; then
    mib_cfg_msg="mib module '$i' is both included and excluded."
    AC_MSG_WARN([mib module conflict])
    if test "x$with_mib_cfg_checks" = "xyes"; then
      AC_MSG_WARN([user with    : $with_mib_modules])
      AC_MSG_WARN([final with   : $new_module_list])
      AC_MSG_WARN([user without : $with_out_mib_modules])
      AC_MSG_WARN([final without: $new_with_out_mib_modules])
      AC_MSG_ERROR([$mib_cfg_msg])
    else
      AC_MSG_WARN([$mib_cfg_msg It will be excluded])
      AC_MSG_CACHE_ADD([*** MIB Module warning *** $mib_cfg_msg It has been excluded.])
    fi
  else
    new_module_list="$new_module_list $i"
  fi
done

AC_MSG_RESULT([$new_module_list.])

#---------------------
# loop over module list
#
all_warnings=""
if test "x$with_mib_cfg_debug" = "xyes"; then
   module_debug=1
else
   module_debug=0
fi
first_pass=1
output_to=normal

if test ! -d mk ; then
  mkdir mk
fi


module_rules=mk/module_rules.mk
echo "# contents below built automatically by configure; do not edit by hand" > $module_rules

#
# make file sub-pieces
#
for i in module_list_deps mib_module_list_deps agent_module_list_deps ; do
  eval "$i=mk/${i}.mk"
  echo "# contents below built automatically by configure; do not edit by hand" > mk/${i}.mk
done

#
# variable settings sub-pieces
#
for i in module_list_code mib_module_list_code agent_module_list_code module_list mib_module_list agent_module_list ; do
  eval "$i=mk/${i}.mk"
  echo "# contents below built automatically by configure; do not edit by hand" > mk/${i}.mk
  echo "$i= \\" >> mk/${i}.mk
done

echo $ECHO_N "echo " $ECHO_C > mk/MODULE_LIST.mk
MODULE_LIST=mk/MODULE_LIST.mk


#---------------------
# until we have an empty module list...
#   (modules may add new modules, and until all dependencies are done...)
#
while test "x$new_module_list" != "x"; do
  AC_MSG_MODULE_DBG(-e,"\n****************************************************************")
  AC_MSG_MODULE_DBG("nml: $new_module_list")

  #---------------------
  # loop over all the modules in the current list
  #
  for j in $new_module_list
    do

    #---------------------
    # figure out which sub-blocks to build in parts
    if echo "$j" | $GREP "=" ; then
       # build a shared object file
       # format: sofilename=module1:module2
       # XXX: currently doesn't do this
       dl_name=`echo $j | $SED 's/=.*//'`
       dl_names="$dl_names $dl_name"
       dl_objects=`echo $j | $SED 's/.*=//'`
       module_sublist=`echo $dl_objects | $SED 's/:/ /g'`
       saved_sublist=""
       saved_sublist_code=""
       output_to=separate

       # create output files
       # these actually get nuked later
       output_inits="agent/mibgroup/${dl_name}-dll.c"
       output_hdrs="agent/mibgroup/${dl_name}-hdrs.h"
    else
       # not a special token invocation
       module_sublist=$j
       output_to=normal
       output_t=
    fi

    while test "x$module_sublist" != "x" ; do

    #---------------------
    # loop over all the modules in the sub list
    for i in $module_sublist
    do

    AC_MSG_MODULE_DBG(-e "\n================================================================")
    AC_MSG_MODULE_DBG("testing $i")
    need_header=0

    #---------------------
    # build a pseudo include header that includes current config and
    # system symbols:
    rm -f conftest.$ac_ext module_tmp_header.h
    AC_LANG_CONFTEST([AC_LANG_SOURCE([[
#include NETSNMP_SYSTEM_INCLUDE_FILE
#include "$srcdir/$mibdir/$i.h"]])])
    mv conftest.$ac_ext module_tmp_header.h

    #---------------------
    # macro: config_belongs_in(ARG)
    #   ARG: either
    #     - mib_module   => libnetsnmpmibs   (default)
    #     - agent_module => libnetsnmpagent
    #
    AH_TOP([#define config_belongs_in(x)])
    module_type=mib_module
    if test -f $srcdir/$mibdir/$i.h; then
      changequote(, )
      module_type=`$MODULECPP module_tmp_header.h | \
                   $SED -n 's@.*config_belongs_in(\([^)]*\)).*@\1@p'`
      changequote([, ])
    fi
    if test "x$module_type" = "x" ; then
      module_type=mib_module
    fi
    if test "x$output_to" = "xnormal" ; then
     	output_inits="$mibdir/${module_type}_inits.h"
     	output_hdrs="$mibdir/${module_type}_includes.h"
    fi

    #--------------------
    # check for duplicates within the dll system. 
    #   - if found in a dll, then remove from the dll and add to main
    dblfix=""
    for dltest in $dl_names ; do
      eval mod_files="\"\$dl_${dltest}_files\""
      if echo " $mod_files " | $GREP " $i " > /dev/null; then
        # some dll module has already seen this, unload it from that list
        # and include it in the core (again)
        AC_MSG_MODULE_DBG("removing $i from $dltest")
        mod_files=`echo " $mod_files " | $SED "s@ $i @@"`
        dblfix="__XXX__"
        eval "dl_${dltest}_files=\"$mod_files\""

        module_list="$module_list $i"
	echo "read_config.lo: mibgroup/$i.h" >> $module_list_deps
	if test $module_type = "agent_module" ; then
 	    echo "snmp_vars.lo: mibgroup/$i.h" >> $agent_module_list_deps
        else
 	    echo "mib_modules.lo: mibgroup/$i.h" >> $mib_module_list_deps
        fi
        eval ${module_type}_list="\"\$${module_type}_list $i\""
	echo "	$i \\" >> $module_list_code
	echo $ECHO_N " $i" $ECHO_C >> $MODULE_LIST
        eval tmpfilevar=\$`echo ${module_type}_list_code`
        echo "	$i \\" >> $tmpfilevar

	# XXX: add this to the main init list; this is possible not
	# quite in the right spot any longer but we're stuck with it.
	# Adding it back to the original ordered spot would be a
	# nightmare.  Ok, we're already in nightmare code so that
	# wolud have to be a night-terror.
        mnm=`echo $i | $SED 's/.*\///;s/\.c$//;'`
	output_inits_tmp="$mibdir/${module_type}_inits.h"
	echo "  if (should_init(\"$mnm\")) init_$mnm();" >> $output_inits_tmp
        # XXX: even worse, we loose whether the header is needed or not.
     	output_hdrs_tmp="$mibdir/${module_type}_includes.h"
        echo '#include "'"mibgroup/$i.h"'"' >> $output_hdrs_tmp
      fi
    done

    #---------------------
    # make sure module wasn't explicitly excluded, or already added
    #
    if test "x$dblfix" != "x" ; then
      AC_MSG_MODULE_DBG("$i was duplicated -- putting into main")
    elif echo " $new_with_out_mib_modules " | $GREP " $i " > /dev/null; then
      AC_MSG_MODULE_DBG("$i was excluded")
    elif echo " $module_list " | $GREP " $i " > /dev/null; then
      AC_MSG_MODULE_DBG("$i already tested")
    else

      #---------------------
      # process modules header, checking for config_ pseudo-macros
      #

      #---------------------
      # does the header file for the module exist?
      #   macros are only processed if it does
      if test -f $srcdir/$mibdir/$i.h; then
        new_list=""

        #---------------------
      	# macro: config_exclude(modules)
      	#  - lists conflicts with other modules
      	#    - EG: new MIB implementations exclude old and vice-versa
      	#
        # check if $i has any conflicts
        #
        AH_TOP([#define config_exclude(x)])
        new_list_excl=`$MODULECPP module_tmp_header.h | \
                       $SED -n 's/.*config_exclude(\(.*\)).*/\1/p'`
	if test "x$new_list_excl" != "x"; then
          AC_MSG_MODULE_DBG("$i excludes $new_list_excl")
	  for j in $new_list_excl
	    do
	    if echo " $module_list $new_mib_module_list $new_list_two " | $GREP " $j " > /dev/null; then
              mib_cfg_msg="mib module '$i' excludes module '$j' but another module requires it"
              AC_MSG_WARN([mib module error])
              if test "x$with_mib_cfg_checks" = "xyes"; then
	        AC_MSG_ERROR([$mib_cfg_msg])
              else
	        AC_MSG_WARN([$mib_cfg_msg])
                AC_MSG_CACHE_ADD([*** MIB Module warning *** $mib_cfg_msg])
              fi
	    else
	      new_with_out_mib_modules="$j $new_with_out_mib_modules"
              AC_MSG_MODULE_DBG("$j added to excluded list")
	    fi
	  done
	fi

        #---------------------
      	# macro: config_arch_require(ARCH,modules)
      	#  - lists modules required for a given ARCH
        #
        # check if $i has any architecture specific requirements
        #
        AH_TOP([#define config_arch_require(x,y)])
        changequote(, )
        new_list_arch=`$MODULECPP module_tmp_header.h | \
                       $SED -n 's/.*config_arch_require( *\([^ ]*\) *, *\([^ ]*\) *).*/\1-xarchx-\2/p'`
        changequote([, ])
	if test "x$new_list_arch" != "x"; then
          for j in $new_list_arch
	    do
	    archtest=`echo $j | $SED 's/-xarchx-.*//'`
	    # target_os may have been changed to a #define of 1...
	    if test "x$archtest" = "x1" -o "x$target_os" = "x$archtest" -o "x$PARTIALTARGETOS" = "x$archtest"; then
	      new_list="$new_list `echo $j | $SED 's/.*-xarchx-//'`"
              AC_MSG_MODULE_DBG(" $i required adding arch files: `echo $j | $SED 's/.*-xarchx-//'`")
	    fi
	  done
	fi
        AC_MSG_MODULE_DBG(" $i required arch files: $new_list")

        #---------------------
      	# macro: config_version_require((base, version, version-modules, ...))
      	#  - lists alternative modules used from different versions.
        #
        AH_TOP([#define config_version_require(x)])
        [new_list_alt3=`$MODULECPP module_tmp_header.h | \
            $AWK '
                BEGIN {
                    if("'"$enable_new_features"'" == "yes")
                        method="max";
                    else if("'"$enable_old_features"'" == "yes")
                        method="max-less";
                    else
                        method="max-less-equal";
                    FS = ".";
                    split("'"$with_features_of"'", a);
                    version=sprintf("%03d%03d%03d%03d", a[1], a[2], a[3], a[4]);
                }
                /config_version_require/ {
                    gsub("^.*config_version_require *\\\\(\\\\(", "");
                    gsub("\\\\)\\\\).*$", "");
                    gsub(", *", ",");
                    FS = ",";
                    n = split($0, a);
                    FS = ".";
                    actver = "000000000000";
                    actstr = a[1];
                    for(i = 2; i < n; i += 2) {
                        split(a[i], b);
                        curver=sprintf("%03d%03d%03d%03d", b[1], b[2], b[3], b[4]);
                        if (curver > actver && (method != "max-less" || curver < version) && (method != "max-less-equal" || curver <= version)) {
                            actver = curver;
                            actstr = a[i + 1];
                        }
                    }
                    printf(" %s", actstr);
                }'`]
        AC_MSG_MODULE_DBG(" $i required versioned features: $new_list_alt3")
        new_list="${new_list}${new_list_alt3}"

        #---------------------
      	# macro: config_require(modules)
      	#  - lists modules required for this module
        #
        # check if $i has any other required modules
        #
        AH_TOP([#define config_require(x)])
        new_list="$new_list `$MODULECPP module_tmp_header.h | \
                  $SED -n 's/.*config_require(\(.*\)).*/\1/p'`"
        AC_MSG_MODULE_DBG(" $i will test: $new_list")
	if test "x$new_list" != "x"; then
	  for j in $new_list
	    do
            AC_MSG_MODULE_DBG(-n " $i wants to add $j: ")
	    if test ! -f $srcdir/$mibdir/$j.h -a ! -f $srcdir/$mibdir/$j.c; then
              AC_MSG_WARN([mib module error])
	      AC_MSG_ERROR([mib module "$i" requires module "$j" but $j.h or $j.c could not be found in $srcdir/$mibdir])
	    elif echo " $new_with_out_mib_modules " | $GREP " $j " > /dev/null; then
	      if test "x$i" != "xdefault_modules" ; then
                mib_cfg_msg="mib module '$i' requires module '$j' but someone told me to compile without it"
                AC_MSG_WARN([mib module error])
                if test "x$with_mib_cfg_checks" = "xyes"; then
                  AC_MSG_ERROR([$mib_cfg_msg])
                else
                  AC_MSG_WARN([$mib_cfg_msg])
                  AC_MSG_CACHE_ADD([*** MIB Module warning *** $mib_cfg_msg])
                fi
#	    elif echo " $module_list $new_list_two $new_module_list " | $GREP " $j " > /dev/null; then
#              AC_MSG_MODULE_DBG("  $j included previously")
              fi
	    else
	      new_list_two="$new_list_two $j"
              AC_MSG_MODULE_DBG("  $j included")
	    fi
	  done
	fi

        #---------------------
      	# macro: config_add_mib(SOME-MIB)
      	#  - lists MIBs to be added to the default to-load list.
        #
        # check if $i has any mibs to add
        #
        AH_TOP([#define config_add_mib(x)])
        new_mibs=`$MODULECPP module_tmp_header.h | \
                  $SED -n 's/.*config_add_mib(\(.*\)).*/\1/p'`
	if test "x$new_mibs" != "x"; then
	    for j in $new_mibs
		do
		if test "x`echo :$default_mibs: | $GREP :$j:`" = "x"; then
		    default_mibs="$default_mibs:$j"
		fi
		if test -f $srcdir/mibs/$j.txt; then
		    if echo $default_mibs_install | $GREP " $j " > /dev/null; then
			    :
		    else
			    default_mibs_install="$default_mibs_install $j.txt"
		    fi
		fi
	    done
	fi # new mibs

        #-------------------
        # add the current module to the list of stuff to compile, etc.
        #
        # add $i to module list
        #
        AC_MSG_MODULE_DBG("  $i added (based on $i.h)")
        module_list="$module_list $i"
        eval ${module_type}_list="\"\$${module_type}_list $i\""

	echo "read_config.lo: mibgroup/$i.h" >> $module_list_deps
	if test $module_type = "agent_module" ; then
 	    echo "snmp_vars.lo: mibgroup/$i.h" >> $agent_module_list_deps
        else
 	    echo "mib_modules.lo: mibgroup/$i.h" >> $mib_module_list_deps
        fi

        #-------------------
        # check for unsupported config_load_mib
        #
        if $MODULECPP module_tmp_header.h | $GREP -q config_load_mib; then
          AC_MSG_WARN([mib module error])
      	  AC_MSG_WARN([mib module "$i" uses the "config_load_mib" directive, which is no longer supported.  It probably won't work.])
        fi # grep config_load_mib

        #-------------------
        # check for config_parse_dot_conf
        #  (generally not used any longer; old auto-load a .conf token)
        #
        AH_TOP([#define config_parse_dot_conf(w,x,y,z)])
        changequote(, )
        $MODULECPP module_tmp_header.h | \
        $SED -n 's@.*config_parse_dot_conf(\([^)]*\), *\([^),]*\), *\([^),]*\), *\([^),]*\)).*@register_config_handler("snmpd",\1, \2, \3, \4);@p' >> $mibdir/mib_module_dot_conf.h
	changequote([, ])

        #---------------------
      	# macro: config_error(error text)
      	#  - used to signal a configuration error from a module
        #
        # check if $i has any errors, or warnings
        #
        AH_TOP([#define config_error(x)])
        error=`$MODULECPP module_tmp_header.h | \
               $SED -n 's/.*config_error(\(.*\)).*/\1/p'`
	if test "x$error" != "x"; then
          echo
          echo
          AC_MSG_ERROR([$i: *** $error ***])
        fi

        #---------------------
      	# macro: config_warning(warning text)
      	#  - used to signal a configuration "warning" to be printed to the user
        #
        AH_TOP([#define config_warning(x)])
        warning=`$MODULECPP module_tmp_header.h | \
                 $SED -n 's/.*config_warning(\(.*\)).*/\1/p'`
	if test "x$warning" != "x"; then
          all_warnings="$all_warnings $warning
"
        fi

      #---------------------
      # Check for a .c file if the .h didn't exist
      #
      elif test -f $srcdir/$mibdir/$i.c; then
        if echo " $module_list $new_list_two $new_module_list " | $GREP " $i      " > /dev/null; then
           AC_MSG_MODULE_DBG("  $i already included")
        else
           AC_MSG_MODULE_DBG("  $i added (based on $i.c)")
	   module_list="$module_list $i"
	   mib_module_list="$mib_module_list $i"
        fi

      #---------------------
      # No .h or .c = error!  (typo?)
      #
      else # no $i.h or $i.c
        AC_MSG_WARN([mib module error])
	AC_MSG_ERROR([module files $i.h or $i.c could not be found in $srcdir/$mibdir])
      fi # no $i.h

      #-------------------
      # check for init/shutdown routines too
      #
      has_c_code=no
      if test -f $srcdir/$mibdir/$i.c; then
        if test "x$output_to" = "xnormal" ; then
	  echo "	$i \\" >> $module_list_code
  	  echo $ECHO_N " $i" $ECHO_C >> $MODULE_LIST
          eval tmpfilevar=\$`echo ${module_type}_list_code`
          echo "	$i \\" >> $tmpfilevar
        else
          eval "dl_${dl_name}_files=\"\$dl_${dl_name}_files $i\""
          saved_sublist_code="$saved_sublist_code $i"
        fi
        mnm=`echo $i | $SED 's/.*\///;s/\.c$//;'`
        AC_MSG_MODULE_DBG(-e "\nchecking '$srcdir/$mibdir/$i.c' ($mnm/`basename $i`) C file for init/shutdown")
        if test "x$mnm" != "x`basename $i`"; then
           AC_MSG_WARN([mib module error])
	   AC_MSG_ERROR([conflicting names: $mnm != `basename $i`])
        fi
        temp_init=`$GREP init_$mnm $srcdir/$mibdir/$i.c | $GREP -v _init_$mnm`
	if test "x$temp_init" != "x"; then
            AC_MSG_MODULE_DBG(-e "adding init_$mnm() to list")
            need_header=1
	    echo "  if (should_init(\"$mnm\")) init_$mnm();" >> $output_inits
	fi
	$GREP shutdown_$mnm $srcdir/$mibdir/$i.c > /dev/null
        if test $? -eq 0 ; then
            if test $module_debug -eq 1; then
              echo -e "\nadding shutdown_$mnm() to list"
            fi
            need_header=1
	    echo "  if (should_init(\"$mnm\")) shutdown_$mnm();" >> $mibdir/${module_type}_shutdown.h
	fi
      fi # test -f $srcdir/$mibdir/$i.c

      #-------------------
      # if there is a shutdown/init list,
      #
      if test $need_header -eq 1 ; then
         echo '#include "'"mibgroup/$i.h"'"' >> $output_hdrs
      else
         echo '/*#include "'"mibgroup/$i.h"'"*/' >> $output_hdrs
      fi

      #-------------------
      # check for output directory (for building outside of source tree
      #
      changequote(, )
      if test "x`echo $i | $SED 's/\///g;'`" != "x$i"; then
	mnd=`echo $i | $SED 's/\/[^/]*$//;'`
	if test ! -d ./$mibdir/$mnd; then
	    module_directories="$module_directories ./$mibdir/$mnd"
	fi
      fi # module directory test
      changequote([, ])

      #-------------------
      # define USING_*_MODULE
      #
      changequote(, )
      sym="`echo ${i} | $SED 's/[^a-zA-Z0-9_]/_/g' | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`"
      changequote([, ])
      echo "/* Define if compiling with the ${i} module files.  */" >> include/net-snmp/agent/${module_type}_config.h
      echo "#define USING_${sym}_MODULE 1" >> include/net-snmp/agent/${module_type}_config.h
      echo " " >> include/net-snmp/agent/${module_type}_config.h

      #-------------------
      echo $ECHO_N " $i$ECHO_C"
    fi #
    done # for i in $module_sublist

    if test "$output_to" = "separate" ; then
      if test "x$new_list_two" = "x" ; then
        # no new sub-modules to add to the current target
        output_to="normal"

        dllcleans="$saved_sublist_o $dllcleans"
        output_inits=""
        module_sublist=""
      else
        # a module had sub-modules required; keep goin'
        saved_sublist="$saved_sublist $module_sublist"
        module_sublist="$new_list_two"
        new_list_two=""
      fi
    else
      module_sublist=""
    fi

    done # while module_sublist
  done # for j in $new_module_list

  # remember the top level modules for later reporting
  if test $first_pass = 1 ; then
    # remember this list for later reporting
    top_level_modules="$new_module_list => $new_list_two"
    first_pass=0
  fi
  #-------------------
  # if $i added new modules vis config_*,
  # check those modules for requirements too
  #
  # transfer the new module to check list to the normal variable
  #
  if test "x$new_list_two" ; then
    output_to=normal
  fi
  new_module_list="$new_list_two"
  new_list_two=""
done # while test "x$new_module_list" != "x"; do
echo ""

#--------------------
# construct the dll code files and make rules.  This can't be done
# until now because duplicate use of a module means it gets removed
# from the dll and put into the main agent.
#
for i in $dl_names ; do
  eval mod_files="\"\$dl_${i}_files\""
  echo "components in the $i dll: $mod_files"

  output_inits="agent/mibgroup/${i}-dll.c"
  output_hdrs="agent/mibgroup/${i}-hdrs.h"

  AC_MSG_MODULE_DBG("creating dll file: $output_inits")
  for ofile in $output_inits $output_hdrs ; do
    if test -f $ofile ; then
      if $GREP "this file created automatically by configure" $ofile > /dev/null 2>&1 ; then
  	:
      else
  	AC_MSG_ERROR([$ofile already existed ; can't build dll object $i])
      fi
    fi
    cat > $ofile << EOFIF
/* xDo not edit; this file created automatically by configure */
EOFIF
  done

  cat >> $output_inits << EOFOC
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "${i}-hdrs.h"
void
init_$i(void) {
EOFOC

  # create the .so rule
  saved_sublist_o=`echo "$mod_files " | $SED 's/^ *//g;s/  */.o /g;'`

  # create the rules for each object
  for j in $mod_files ; do
    cat >> $module_rules << EOFR
$j.o: $j.c
	\$(CC) -c \$(CPPFLAGS) \$(CFLAGS) \$(DLFLAGS) -o \$@ \$<

EOFR
    mnm=`echo $j | $SED 's/.*\///;s/\.c$//;'`
    echo "  if (should_init(\"$mnm\")) init_$mnm();" >> $output_inits
  done

  # create the rule for the .so and wrapper code
  cat >> $module_rules << EOFM
${i}-dll.o: ${i}-dll.c
	\$(CC) -c \$(CPPFLAGS) \$(CFLAGS) \$(DLFLAGS) -o \$@ \$<

${i}.so: $saved_sublist_o ${i}-dll.o
	\$(CC) \$(CPPFLAGS) \$(CFLAGS) \$(DLFLAGS) -o \$@ $saved_sublist_o ${i}-dll.o

EOFM
        cat >> $output_inits << EOFOCFIN
}
EOFOCFIN

done

# cleanup
rm -f conftest.$ac_ext module_tmp_header.h

#-------------------
# build module lists for Makefiles
#
changequote(, )

for i in module_list_o module_list_c module_list_lo module_list_ft mib_module_list_o mib_module_list_c mib_module_list_lo mib_module_list_ft mibgroup_list_o mibgroup_list_lo mibgroup_list_ft agent_module_list_o agent_module_list_c agent_module_list_lo agent_module_list_ft agentgroup_list_o agentgroup_list_lo agentgroup_list_ft ; do
  eval "$i=mk/${i}.mk"
done

$SED 's/^module_list_code/module_list_o/;s/\([^=]\)  *\\/\1.o \\/g'  < $module_list_code  > $module_list_o
$SED 's/^module_list_code/module_list_c/;s/\([^=]\)  *\\/\1.c \\/g'  < $module_list_code  > $module_list_c
$SED 's/^module_list_code/module_list_lo/;s/\([^=]\)  *\\/\1.lo \\/g' < $module_list_code  > $module_list_lo
$SED 's/^module_list_code/module_list_ft/;s/\([^=]\)  *\\/\1.ft \\/g' < $module_list_code  > $module_list_ft

$SED 's/^mib_module_list_code/mib_module_list_o/;s/\([^=]\)  *\\/\1.o \\/g'  < $mib_module_list_code  > $mib_module_list_o
$SED 's/^mib_module_list_code/mib_module_list_c/;s/\([^=]\)  *\\/\1.c \\/g'  < $mib_module_list_code  > $mib_module_list_c
$SED 's/^mib_module_list_code/mib_module_list_lo/;s/\([^=]\)  *\\/\1.lo \\/g' < $mib_module_list_code  > $mib_module_list_lo
$SED 's/^mib_module_list_code/mib_module_list_ft/;s/\([^=]\)  *\\/\1.ft \\/g' < $mib_module_list_code  > $mib_module_list_ft

$SED 's/^mib_module_list_o/mibgroup_list_o/;s@\([^ 	]*\)\.o@mibgroup/\1.o@g' < $mib_module_list_o > $mibgroup_list_o
$SED 's/^mib_module_list_lo/mibgroup_list_lo/;s@\([^ 	]*\)\.lo@mibgroup/\1.lo@g' < $mib_module_list_lo > $mibgroup_list_lo
$SED 's/^mib_module_list_ft/mibgroup_list_ft/;s@\([^ 	]*\)\.ft@mibgroup/\1.ft@g' < $mib_module_list_ft > $mibgroup_list_ft

$SED 's/^agent_module_list_code/agent_module_list_o/;s/\([^=]\)  *\\/\1.o \\/g'  < $agent_module_list_code  > $agent_module_list_o
$SED 's/^agent_module_list_code/agent_module_list_c/;s/\([^=]\)  *\\/\1.c \\/g'  < $agent_module_list_code  > $agent_module_list_c
$SED 's/^agent_module_list_code/agent_module_list_lo/;s/\([^=]\)  *\\/\1.lo \\/g' < $agent_module_list_code  > $agent_module_list_lo
$SED 's/^agent_module_list_code/agent_module_list_ft/;s/\([^=]\)  *\\/\1.ft \\/g' < $agent_module_list_code  > $agent_module_list_ft

$SED 's/^agent_module_list_o/agentgroup_list_o/;s@\([^ 	]*\)\.o@mibgroup/\1.o@g' < $agent_module_list_o > $agentgroup_list_o
$SED 's/^agent_module_list_lo/agentgroup_list_lo/;s@\([^ 	]*\)\.lo@mibgroup/\1.lo@g' < $agent_module_list_lo > $agentgroup_list_lo
$SED 's/^agent_module_list_ft/agentgroup_list_ft/;s@\([^ 	]*\)\.ft@mibgroup/\1.ft@g' < $agent_module_list_ft > $agentgroup_list_ft

for i in module_list_o module_list_c module_list_lo module_list_ft mib_module_list_o mib_module_list_c mib_module_list_lo mib_module_list_ft mibgroup_list_o mibgroup_list_lo mibgroup_list_ft agent_module_list_o agent_module_list_c agent_module_list_lo agent_module_list_ft agentgroup_list_o agentgroup_list_lo agentgroup_list_ft ; do
	# hpux make (at least) doesn't like a trailing \ on the last
	# line even when the next line contains nothing but
	# whitespace.
	lasttoken=`awk '{lasttoken=$1}END{print lasttoken}' mk/$i.mk`
	$SED "s#$lasttoken \\\\#$lasttoken#" < mk/$i.mk > mk/$i.mk.tmp
	mv mk/$i.mk.tmp mk/$i.mk

	# add a closing comment
	echo "" >> mk/$i.mk
	echo "# end configure generated code" >> mk/$i.mk
done

changequote([, ])

if test $module_debug -eq 1; then
   echo -e "\nFinal module list: $module_list_code"
   exit
fi
if test "x$with_mib_cfg_checks" = "xyes"; then
  AC_MSG_CACHE_ADD([Agent Module list: $module_list_code])
fi
AC_SUBST_FILE(MODULE_LIST)
AC_SUBST_FILE(module_list_c)
AC_SUBST_FILE(module_list_o)
AC_SUBST_FILE(module_list_lo)
AC_SUBST_FILE(module_list_ft)
AC_SUBST_FILE(mib_module_list_c)
AC_SUBST_FILE(mib_module_list_o)
AC_SUBST_FILE(mib_module_list_lo)
AC_SUBST_FILE(mib_module_list_ft)
AC_SUBST_FILE(agent_module_list_c)
AC_SUBST_FILE(agent_module_list_o)
AC_SUBST_FILE(agent_module_list_lo)
AC_SUBST_FILE(agent_module_list_ft)
AC_SUBST_FILE(mibgroup_list_o)
AC_SUBST_FILE(mibgroup_list_lo)
AC_SUBST_FILE(mibgroup_list_ft)
AC_SUBST_FILE(agentgroup_list_o)
AC_SUBST_FILE(agentgroup_list_lo)
AC_SUBST_FILE(agentgroup_list_ft)

AC_SUBST(default_mibs_install)
AC_SUBST(dllcleans)
AC_SUBST_FILE(module_rules)
AC_SUBST_FILE(module_list_deps)
AC_SUBST_FILE(mib_module_list_deps)
AC_SUBST_FILE(agent_module_list_deps)

AC_MSG_RESULT(.)

if test $module_debug -eq 1; then
AC_MSG_CACHE_ADD(Agent MIB code:            $module_list)
fi
AC_MSG_CACHE_ADD(Agent MIB code:            $top_level_modules)

# end hairy agent module processing

AC_MSG_CHECKING([if directories need to be created])
for i in $module_directories; do
  $srcdir/mkinstalldirs $i
done
AC_MSG_RESULT(.)

#-------------------
# Define default mibs
#
AC_MSG_CHECKING([default mib files to read])
if test "x$NETSNMP_DEFAULT_MIBS" = "x"; then
  NETSNMP_DEFAULT_MIBS="$default_mibs"
fi
if test "x$PARTIALTARGETOS" = "xmingw32" -o "x$PARTIALTARGETOS" = "xmingw32msvc" -o "x$PARTIALTARGETOS" = "xcygwin"; then
  # mingw32 and cygwin use ';' as the environment variable separator char
  ENV_SEPARATOR=";"
  NETSNMP_DEFAULT_MIBS=`echo "$NETSNMP_DEFAULT_MIBS" | $SED 's/:/;/g'`
  default_mibs=`echo "$default_mibs" | $SED 's/:/;/g'`
else
  ENV_SEPARATOR=":"
fi
AC_SUBST(ENV_SEPARATOR)
AC_DEFINE_UNQUOTED(NETSNMP_DEFAULT_MIBS,"$NETSNMP_DEFAULT_MIBS")
AC_SUBST(NETSNMP_DEFAULT_MIBS)
AC_MSG_RESULT($NETSNMP_DEFAULT_MIBS)

#-------------------
# Define symbols for conditional compilation in makefiles
#

if echo " $agent_module_list " | \
   fgrep ' agentx/agentx_config ' | \
   fgrep ' agentx/client ' | \
   fgrep ' agentx/protocol ' > /dev/null ; then
   NETSNMP_HAVE_AGENTX_LIBS_TRUE=''
   NETSNMP_HAVE_AGENTX_LIBS_FALSE='#'
else
   NETSNMP_HAVE_AGENTX_LIBS_TRUE='#'
   NETSNMP_HAVE_AGENTX_LIBS_FALSE=''
fi
AC_SUBST([NETSNMP_HAVE_AGENTX_LIBS_TRUE])
AC_SUBST([NETSNMP_HAVE_AGENTX_LIBS_FALSE])