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