]> granicus.if.org Git - apache/blob - support/apxs.in
apply Apache License, Version 2.0
[apache] / support / apxs.in
1 #!@perlbin@ -w
2 #
3 # Copyright 2000-2004 Apache Software Foundation
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 require 5.004;
18 use strict;
19 package apxs;
20
21 ##
22 ##  Configuration
23 ##
24
25 my %config_vars = ();
26
27 my $installbuilddir = "@exp_installbuilddir@";
28 get_config_vars("$installbuilddir/config_vars.mk",\%config_vars);
29
30 # read the configuration variables once
31
32 my $prefix         = get_vars("prefix");
33 my $CFG_PREFIX     = $prefix;
34 my $exec_prefix    = get_vars("exec_prefix");
35 my $datadir        = get_vars("datadir");
36 my $localstatedir  = get_vars("localstatedir");
37 my $CFG_TARGET     = get_vars("progname");
38 my $CFG_SYSCONFDIR = get_vars("sysconfdir");
39 my $CFG_CFLAGS     = join ' ', map { get_vars($_) }
40   qw(SHLTCFLAGS CFLAGS NOTEST_CPPFLAGS EXTRA_CPPFLAGS EXTRA_CFLAGS);
41 my $includedir     = get_vars("includedir");
42 my $CFG_INCLUDEDIR = eval qq("$includedir");
43 my $CFG_CC         = get_vars("CC");
44 my $libexecdir     = get_vars("libexecdir");
45 my $CFG_LIBEXECDIR = eval qq("$libexecdir");
46 my $sbindir        = get_vars("sbindir");
47 my $CFG_SBINDIR    = eval qq("$sbindir");
48 my $ltflags        = $ENV{'LTFLAGS'};
49 $ltflags or $ltflags = "--silent";
50
51 my %internal_vars = map {$_ => 1}
52     qw(TARGET CC CFLAGS CFLAGS_SHLIB LD_SHLIB LDFLAGS_SHLIB LIBS_SHLIB
53        PREFIX SBINDIR INCLUDEDIR LIBEXECDIR SYSCONFDIR);
54
55 ##
56 ##  parse argument line
57 ##
58
59 #   defaults for parameters
60 my $opt_n = '';
61 my $opt_g = '';
62 my $opt_c = 0;
63 my $opt_o = '';
64 my @opt_D = ();
65 my @opt_I = ();
66 my @opt_L = ();
67 my @opt_l = ();
68 my @opt_W = ();
69 my @opt_S = ();
70 my $opt_e = 0;
71 my $opt_i = 0;
72 my $opt_a = 0;
73 my $opt_A = 0;
74 my $opt_q = 0;
75 my $opt_h = 0;
76 my $opt_p = 0;
77
78 #   this subroutine is derived from Perl's getopts.pl with the enhancement of
79 #   the "+" metacharacter at the format string to allow a list to be built by
80 #   subsequent occurrences of the same option.
81 sub Getopts {
82     my ($argumentative, @ARGV) = @_;
83     my $errs = 0;
84     local $_;
85     local $[ = 0;
86
87     my @args = split / */, $argumentative;
88     while (@ARGV && ($_ = $ARGV[0]) =~ /^-(.)(.*)/) {
89         my ($first, $rest) = ($1,$2);
90         if ($_ =~ m|^--$|) {
91             shift @ARGV;
92             last;
93         }
94         my $pos = index($argumentative,$first);
95         if ($pos >= $[) {
96             if ($pos < $#args && $args[$pos+1] eq ':') {
97                 shift @ARGV;
98                 if ($rest eq '') {
99                     unless (@ARGV) {
100                         error("Incomplete option: $first (needs an argument)");
101                         $errs++;
102                     }
103                     $rest = shift(@ARGV);
104                 }
105                 eval "\$opt_$first = \$rest;";
106             }
107             elsif ($pos < $#args && $args[$pos+1] eq '+') {
108                 shift @ARGV;
109                 if ($rest eq '') {
110                     unless (@ARGV) {
111                         error("Incomplete option: $first (needs an argument)");
112                         $errs++;
113                     }
114                     $rest = shift(@ARGV);
115                 }
116                 eval "push(\@opt_$first, \$rest);";
117             }
118             else {
119                 eval "\$opt_$first = 1";
120                 if ($rest eq '') {
121                     shift(@ARGV);
122                 }
123                 else {
124                     $ARGV[0] = "-$rest";
125                 }
126             }
127         }
128         else {
129             error("Unknown option: $first");
130             $errs++;
131             if ($rest ne '') {
132                 $ARGV[0] = "-$rest";
133             }
134             else {
135                 shift(@ARGV);
136             }
137         }
138     }
139     return ($errs == 0, @ARGV);
140 }
141
142 sub usage {
143     print STDERR "Usage: apxs -g [-S <var>=<val>] -n <modname>\n";
144     print STDERR "       apxs -q [-S <var>=<val>] <query> ...\n";
145     print STDERR "       apxs -c [-S <var>=<val>] [-o <dsofile>] [-D <name>[=<value>]]\n";
146     print STDERR "               [-I <incdir>] [-L <libdir>] [-l <libname>] [-Wc,<flags>]\n";
147     print STDERR "               [-Wl,<flags>] [-p] <files> ...\n";
148     print STDERR "       apxs -i [-S <var>=<val>] [-a] [-A] [-n <modname>] <dsofile> ...\n";
149     print STDERR "       apxs -e [-S <var>=<val>] [-a] [-A] [-n <modname>] <dsofile> ...\n";
150     exit(1);
151 }
152
153 #   option handling
154 my $rc;
155 ($rc, @ARGV) = &Getopts("qn:gco:I+D+L+l+W+S+eiaAp", @ARGV);
156 &usage if ($rc == 0);
157 &usage if ($#ARGV == -1 and not $opt_g);
158 &usage if (not $opt_q and not ($opt_g and $opt_n) and not $opt_i and not $opt_c and not $opt_e);
159
160 #   argument handling
161 my @args = @ARGV;
162 my $name = 'unknown';
163 $name = $opt_n if ($opt_n ne '');
164
165 if (@opt_S) {
166     my ($opt_S);
167     foreach $opt_S (@opt_S) {
168         if ($opt_S =~ m/^([^=]+)=(.*)$/) {
169             my ($var) = $1;
170             my ($val) = $2;
171             my $oldval = eval "\$CFG_$var";
172
173             unless ($var and $oldval) {
174                 print STDERR "apxs:Error: no config variable $var\n";
175                 &usage;
176             }
177
178             eval "\$CFG_${var}=\"${val}\"";
179         } else {
180             print STDERR "apxs:Error: malformatted -S option\n";
181             &usage;
182         }       
183     }
184 }
185
186 ##
187 ##  Initial shared object support check
188 ##
189 my $httpd = get_vars("sbindir") . "/" . get_vars("progname");
190 $httpd = eval qq("$httpd");
191 $httpd = eval qq("$httpd");
192 my $envvars = get_vars("sbindir") . "/envvars";
193 $envvars = eval qq("$envvars");
194 $envvars = eval qq("$envvars");
195
196 #allow apxs to be run from the source tree, before installation
197 if ($0 =~ m:support/apxs$:) {
198     ($httpd = $0) =~ s:support/apxs$::;
199 }
200
201 unless (-x "$httpd") {
202         error("$httpd not found or not executable");
203         exit 1;
204 }
205
206 unless (grep /mod_so/, `. $envvars && $httpd -l`) {
207     error("Sorry, no shared object support for Apache");
208     error("available under your platform. Make sure");
209     error("the Apache module mod_so is compiled into");
210     error("your server binary `$httpd'.");
211     exit 1;
212 }
213
214 sub get_config_vars{
215     my ($file, $rh_config) = @_;
216
217     open IN, $file or die "cannot open $file: $!";
218     while (<IN>){
219         if (/^\s*(.*?)\s*=\s*(.*)$/){
220             $rh_config->{$1} = $2;
221         }
222     }
223     close IN;
224 }
225
226 sub get_vars {
227     my $result = '';
228     my $ok = 0;
229     my $arg;
230     foreach $arg (@_) {
231         if (exists $config_vars{$arg} or exists $config_vars{lc $arg}) {
232             my $val = exists $config_vars{$arg}
233                 ? $config_vars{$arg}
234                 : $config_vars{lc $arg};
235             $val =~ s/[()]//g;
236             $result .= eval "qq($val)" if defined $val;
237             $result .= ";;";
238             $ok = 1;
239         }
240         if (not $ok) {
241             if (exists $internal_vars{$arg} or exists $internal_vars{lc $arg}) {
242                 my $val = exists $internal_vars{$arg} ? $arg : lc $arg;
243                 $val = eval "\$CFG_$val";
244                 $result .= eval "qq($val)" if defined $val;
245                 $result .= ";;";
246                 $ok = 1;
247             }
248             if (not $ok) {
249                 error("Invalid query string `$arg'");
250                 exit(1);
251             }
252         }
253     }
254     $result =~ s|;;$||;
255     $result =~ s|:| |;
256     return $result;
257 }
258
259 ##
260 ##  Operation
261 ##
262
263 #   helper function for executing a list of
264 #   system command with return code checks
265 sub execute_cmds {
266     my (@cmds) = @_;
267     my ($cmd, $rc);
268
269     foreach $cmd (@cmds) {
270         notice($cmd);
271         $rc = system $cmd;
272         if ($rc) {
273             error(sprintf "Command failed with rc=%d\n", $rc << 8);
274             exit 1 ;
275         }
276     }
277 }
278
279 if ($opt_g) {
280     ##
281     ##  SAMPLE MODULE SOURCE GENERATION
282     ##
283
284     if (-d $name) {
285         error("Directory `$name' already exists. Remove first");
286         exit(1);
287     }
288
289     my $data = join('', <DATA>);
290     $data =~ s|%NAME%|$name|sg;
291     $data =~ s|%TARGET%|$CFG_TARGET|sg;
292     $data =~ s|%PREFIX%|$prefix|sg;
293     $data =~ s|%INSTALLBUILDDIR%|$installbuilddir|sg;
294
295     my ($mkf, $mods, $src) = ($data =~ m|^(.+)-=#=-\n(.+)-=#=-\n(.+)|s);
296
297     notice("Creating [DIR]  $name");
298     system("mkdir $name");
299     notice("Creating [FILE] $name/Makefile");
300     open(FP, ">${name}/Makefile") || die;
301     print FP $mkf;
302     close(FP);
303     notice("Creating [FILE] $name/modules.mk");
304     open(FP, ">${name}/modules.mk") || die;
305     print FP $mods;
306     close(FP);
307     notice("Creating [FILE] $name/mod_$name.c");
308     open(FP, ">${name}/mod_${name}.c") || die;
309     print FP $src;
310     close(FP);
311     notice("Creating [FILE] $name/.deps");
312     system("touch ${name}/.deps");
313
314     exit(0);
315 }
316
317
318 if ($opt_q) {
319     ##
320     ##  QUERY INFORMATION 
321     ##
322     my $result = get_vars(@args);
323     print "$result\n";
324 }
325
326 my $apr_bindir = get_vars("APR_BINDIR");
327
328 if (! -x "$apr_bindir/apr-config") {
329     error("$apr_bindir/apr-config not found!");
330     exit(1);
331 }
332
333 my $apu_bindir = get_vars("APU_BINDIR");
334
335 if (! -x "$apu_bindir/apu-config") {
336     error("$apu_bindir/apu-config not found!");
337     exit(1);
338 }
339
340 my $libtool = `$apr_bindir/apr-config --installbuilddir`;
341 chomp($libtool);
342 $libtool = "$libtool/libtool";
343
344 my $apr_includedir = `$apr_bindir/apr-config --includes`;
345 chomp($apr_includedir);
346 my $apu_includedir = `$apu_bindir/apu-config --includes`;
347 chomp($apu_includedir);
348
349 if ($opt_c) {
350     ##
351     ##  SHARED OBJECT COMPILATION
352     ##
353
354     #   split files into sources and objects
355     my @srcs = ();
356     my @objs = ();
357     my $f;
358     foreach $f (@args) {
359         if ($f =~ m|\.c$|) {
360             push(@srcs, $f);
361         }
362         else {
363             push(@objs, $f);
364         }
365     }
366
367     #   determine output file
368     my $dso_file;
369     if ($opt_o eq '') {
370         if ($#srcs > -1) {
371             $dso_file = $srcs[0];
372             $dso_file =~ s|\.[^.]+$|.la|;
373         }
374         elsif ($#objs > -1) {
375             $dso_file = $objs[0];
376             $dso_file =~ s|\.[^.]+$|.la|;
377         }
378         else {
379             $dso_file = "mod_unknown.so";
380         }
381     }
382     else {
383         $dso_file = $opt_o;
384     }
385
386     #   create compilation commands
387     my @cmds = ();
388     my $opt = '';
389     my ($opt_Wc, $opt_I, $opt_D);
390     foreach $opt_Wc (@opt_W) {
391         $opt .= "$1 " if ($opt_Wc =~ m|^\s*c,(.*)$|);
392     }
393     foreach $opt_I (@opt_I) {
394         $opt .= "-I$opt_I ";
395     }
396     foreach $opt_D (@opt_D) {
397         $opt .= "-D$opt_D ";
398     }
399     my $cflags = "$CFG_CFLAGS";
400     my $s;
401     my $mod;
402     foreach $s (@srcs) {
403         my $slo = $s;
404         $slo =~ s|\.c$|.slo|;
405         my $lo = $s;
406         $lo =~ s|\.c$|.lo|;
407         my $la = $s;
408         $la =~ s|\.c$|.la|;
409         my $o = $s;
410         $o =~ s|\.c$|.o|;
411         push(@cmds, "$libtool $ltflags --mode=compile $CFG_CC $cflags -I$CFG_INCLUDEDIR $apr_includedir $apu_includedir $opt -c -o $lo $s && touch $slo");
412         unshift(@objs, $lo);
413     }
414
415     #   create link command
416     my $o;
417     my $lo;     
418     foreach $o (@objs) {
419         $lo .= " $o";
420     }
421     my ($opt_Wl, $opt_L, $opt_l);
422     foreach $opt_Wl (@opt_W) {
423         if ($CFG_CC !~ m/gcc$/) {
424             $opt .= " $1" if ($opt_Wl =~ m|^\s*l,(.*)$|);
425         } else {
426             $opt .= " -W$opt_Wl";
427         }
428     }
429     foreach $opt_L (@opt_L) {
430         $opt .= " -L$opt_L";
431     }
432     foreach $opt_l (@opt_l) {
433         $opt .= " -l$opt_l";
434     }
435
436     if ($opt_p == 1) {
437         
438         my $apr_libs=`$apr_bindir/apr-config --cflags --ldflags --link-libtool --libs`;
439         chomp($apr_libs);
440         my $apu_libs=`$apu_bindir/apu-config --ldflags --link-libtool --libs`;
441         chomp($apu_libs);
442         
443         $opt .= " ".$apu_libs." ".$apr_libs;
444     }
445     else {
446         my $apr_ldflags=`$apr_bindir/apr-config --ldflags`;
447         chomp($apr_ldflags);
448         $opt .= " -rpath $CFG_LIBEXECDIR -module -avoid-version $apr_ldflags";
449     }
450
451     push(@cmds, "$libtool $ltflags --mode=link $CFG_CC -o $dso_file $opt $lo");
452
453     #   execute the commands
454     &execute_cmds(@cmds);
455
456     #   allow one-step compilation and installation
457     if ($opt_i or $opt_e) {
458         @args = ( $dso_file );
459     }
460 }
461
462 if ($opt_i or $opt_e) {
463     ##
464     ##  SHARED OBJECT INSTALLATION
465     ##
466
467     #   determine installation commands
468     #   and corresponding LoadModule directive
469     my @lmd = ();
470     my @cmds = ();
471     my $f;
472     foreach $f (@args) {
473         if ($f !~ m#(\.so$|\.la$)#) {
474             error("file $f is not a shared object");
475             exit(1);
476         }
477         my $t = $f;
478         $t =~ s|^.+/([^/]+)$|$1|;
479         $t =~ s|\.la$|\.so|;
480         if ($opt_i) {
481             push(@cmds, "$installbuilddir/instdso.sh SH_LIBTOOL='" .
482                  "$libtool' $f $CFG_LIBEXECDIR");
483             push(@cmds, "chmod 755 $CFG_LIBEXECDIR/$t");
484         }
485
486         #   determine module symbolname and filename
487         my $filename = '';
488         if ($name eq 'unknown') {
489             $name = '';
490             my $base = $f;
491             $base =~ s|\.[^.]+$||;
492             if (-f "$base.c") {
493                 open(FP, "<$base.c");
494                 my $content = join('', <FP>);
495                 close(FP);
496                 if ($content =~ m|.*module\s+(?:AP_MODULE_DECLARE_DATA\s+)?([a-zA-Z0-9_]+)_module\s*=\s*.*|s) {
497                     $name = "$1";
498                     $filename = "$base.c";
499                     $filename =~ s|^[^/]+/||;
500                 }
501             }
502             if ($name eq '') {
503                 if ($base =~ m|.*mod_([a-zA-Z0-9_]+)\..+|) {
504                     $name = "$1";
505                     $filename = $base;
506                     $filename =~ s|^[^/]+/||;
507                 }
508             }
509             if ($name eq '') {
510                 error("Sorry, cannot determine bootstrap symbol name");
511                 error("Please specify one with option `-n'");
512                 exit(1);
513             }
514         }
515         if ($filename eq '') {
516             $filename = "mod_${name}.c";
517         }
518         my $dir = $CFG_LIBEXECDIR;
519         $dir =~ s|^$CFG_PREFIX/?||;
520         $dir =~ s|(.)$|$1/|;
521         $t =~ s|\.la$|.so|;
522         push(@lmd, sprintf("LoadModule %-18s %s", "${name}_module", "$dir$t"));
523     }
524
525     #   execute the commands
526     &execute_cmds(@cmds);
527
528     #   activate module via LoadModule/AddModule directive
529     if ($opt_a or $opt_A) {
530         if (not -f "$CFG_SYSCONFDIR/$CFG_TARGET.conf") {
531             error("Config file $CFG_SYSCONFDIR/$CFG_TARGET.conf not found");
532             exit(1);
533         }
534
535         open(FP, "<$CFG_SYSCONFDIR/$CFG_TARGET.conf") || die;
536         my $content = join('', <FP>);
537         close(FP);
538
539         if ($content !~ m|\n#?\s*LoadModule\s+|) {
540             error("Activation failed for custom $CFG_SYSCONFDIR/$CFG_TARGET.conf file.");
541             error("At least one `LoadModule' directive already has to exist.");
542             exit(1);
543         }
544
545         my $lmd;
546         my $c = '';
547         $c = '#' if ($opt_A);
548         foreach $lmd (@lmd) {
549             my $what = $opt_A ? "preparing" : "activating";
550             if ($content !~ m|\n#?\s*$lmd|) {
551                 # check for open <containers>, so that the new LoadModule
552                 # directive always appears *outside* of an <container>.
553
554                 my $before = ($content =~ m|^(.*\n)#?\s*LoadModule\s+[^\n]+\n|s)[0];
555
556                 # the '()=' trick forces list context and the scalar
557                 # assignment counts the number of list members (aka number
558                 # of matches) then
559                 my $cntopen = () = ($before =~ m|^\s*<[^/].*$|mg);
560                 my $cntclose = () = ($before =~ m|^\s*</.*$|mg);
561
562                 if ($cntopen == $cntclose) {
563                     # fine. Last LoadModule is contextless.
564                     $content =~ s|^(.*\n#?\s*LoadModule\s+[^\n]+\n)|$1$c$lmd\n|s;
565                 }
566                 elsif ($cntopen < $cntclose) {
567                     error('Configuration file is not valid. There are sections'
568                           . ' closed before opened.');
569                     exit(1);
570                 }
571                 else {
572                     # put our cmd after the section containing the last
573                     # LoadModule.
574                     my $found =
575                     $content =~ s!\A (               # string and capture start
576                                   (?:(?:
577                                     ^\s*             # start of conf line with a
578                                     (?:[^<]|<[^/])   # directive which does not
579                                                      # start with '</'
580
581                                     .*(?:$)\n        # rest of the line.
582                                                      # the '$' is in parentheses
583                                                      # to avoid misinterpreting
584                                                      # the string "$\" as
585                                                      # perl variable.
586
587                                     )*               # catch as much as possible
588                                                      # of such lines. (including
589                                                      # zero)
590
591                                     ^\s*</.*(?:$)\n? # after the above, we
592                                                      # expect a config line with
593                                                      # a closing container (</)
594
595                                   ) {$cntopen}       # the whole pattern (bunch
596                                                      # of lines that end up with
597                                                      # a closing directive) must
598                                                      # be repeated $cntopen
599                                                      # times. That's it.
600                                                      # Simple, eh? ;-)
601
602                                   )                  # capture end
603                                  !$1$c$lmd\n!mx;
604
605                     unless ($found) {
606                         error('Configuration file is not valid. There are '
607                               . 'sections opened and not closed.');
608                         exit(1);
609                     }
610                 }
611             } else {
612                 # replace already existing LoadModule line
613                 $content =~ s|^(.*\n)#?\s*$lmd[^\n]*\n|$1$c$lmd\n|s;
614             }
615             $lmd =~ m|LoadModule\s+(.+?)_module.*|;
616             notice("[$what module `$1' in $CFG_SYSCONFDIR/$CFG_TARGET.conf]");
617         }
618         if (@lmd) {
619             if (open(FP, ">$CFG_SYSCONFDIR/$CFG_TARGET.conf.new")) {
620                 print FP $content;
621                 close(FP);
622                 system("cp $CFG_SYSCONFDIR/$CFG_TARGET.conf $CFG_SYSCONFDIR/$CFG_TARGET.conf.bak && " .
623                        "cp $CFG_SYSCONFDIR/$CFG_TARGET.conf.new $CFG_SYSCONFDIR/$CFG_TARGET.conf && " .
624                        "rm $CFG_SYSCONFDIR/$CFG_TARGET.conf.new");
625             } else {
626                 notice("unable to open configuration file");
627             }
628         }
629     }
630 }
631
632 sub error{
633     print STDERR "apxs:Error: $_[0].\n";
634 }
635
636 sub notice{
637     print STDERR "$_[0]\n";
638 }
639
640 ##EOF##
641 __DATA__
642 ##
643 ##  Makefile -- Build procedure for sample %NAME% Apache module
644 ##  Autogenerated via ``apxs -n %NAME% -g''.
645 ##
646
647 builddir=.
648 top_srcdir=%PREFIX%
649 top_builddir=%PREFIX%
650 include %INSTALLBUILDDIR%/special.mk
651
652 #   the used tools
653 APXS=apxs
654 APACHECTL=apachectl
655
656 #   additional defines, includes and libraries
657 #DEFS=-Dmy_define=my_value
658 #INCLUDES=-Imy/include/dir
659 #LIBS=-Lmy/lib/dir -lmylib
660
661 #   the default target
662 all: local-shared-build
663
664 #   install the shared object file into Apache 
665 install: install-modules
666
667 #   cleanup
668 clean:
669         -rm -f mod_%NAME%.o mod_%NAME%.lo mod_%NAME%.slo mod_%NAME%.la 
670
671 #   simple test
672 test: reload
673         lynx -mime_header http://localhost/%NAME%
674
675 #   install and activate shared object by reloading Apache to
676 #   force a reload of the shared object file
677 reload: install restart
678
679 #   the general Apache start/restart/stop
680 #   procedures
681 start:
682         $(APACHECTL) start
683 restart:
684         $(APACHECTL) restart
685 stop:
686         $(APACHECTL) stop
687
688 -=#=-
689 mod_%NAME%.la: mod_%NAME%.slo
690         $(SH_LINK) -rpath $(libexecdir) -module -avoid-version  mod_%NAME%.lo
691 DISTCLEAN_TARGETS = modules.mk
692 shared =  mod_%NAME%.la
693 -=#=-
694 /* 
695 **  mod_%NAME%.c -- Apache sample %NAME% module
696 **  [Autogenerated via ``apxs -n %NAME% -g'']
697 **
698 **  To play with this sample module first compile it into a
699 **  DSO file and install it into Apache's modules directory 
700 **  by running:
701 **
702 **    $ apxs -c -i mod_%NAME%.c
703 **
704 **  Then activate it in Apache's %TARGET%.conf file for instance
705 **  for the URL /%NAME% in as follows:
706 **
707 **    #   %TARGET%.conf
708 **    LoadModule %NAME%_module modules/mod_%NAME%.so
709 **    <Location /%NAME%>
710 **    SetHandler %NAME%
711 **    </Location>
712 **
713 **  Then after restarting Apache via
714 **
715 **    $ apachectl restart
716 **
717 **  you immediately can request the URL /%NAME% and watch for the
718 **  output of this module. This can be achieved for instance via:
719 **
720 **    $ lynx -mime_header http://localhost/%NAME% 
721 **
722 **  The output should be similar to the following one:
723 **
724 **    HTTP/1.1 200 OK
725 **    Date: Tue, 31 Mar 1998 14:42:22 GMT
726 **    Server: Apache/1.3.4 (Unix)
727 **    Connection: close
728 **    Content-Type: text/html
729 **  
730 **    The sample page from mod_%NAME%.c
731 */ 
732
733 #include "httpd.h"
734 #include "http_config.h"
735 #include "http_protocol.h"
736 #include "ap_config.h"
737
738 /* The sample content handler */
739 static int %NAME%_handler(request_rec *r)
740 {
741     if (strcmp(r->handler, "%NAME%")) {
742         return DECLINED;
743     }
744     r->content_type = "text/html";      
745
746     if (!r->header_only)
747         ap_rputs("The sample page from mod_%NAME%.c\n", r);
748     return OK;
749 }
750
751 static void %NAME%_register_hooks(apr_pool_t *p)
752 {
753     ap_hook_handler(%NAME%_handler, NULL, NULL, APR_HOOK_MIDDLE);
754 }
755
756 /* Dispatch list for API hooks */
757 module AP_MODULE_DECLARE_DATA %NAME%_module = {
758     STANDARD20_MODULE_STUFF, 
759     NULL,                  /* create per-dir    config structures */
760     NULL,                  /* merge  per-dir    config structures */
761     NULL,                  /* create per-server config structures */
762     NULL,                  /* merge  per-server config structures */
763     NULL,                  /* table of config file commands       */
764     %NAME%_register_hooks  /* register hooks                      */
765 };
766