home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 15 / AACD15.ISO / AACD / Magazine / HomeAutomation / Apache / bin / apxs < prev    next >
Encoding:
Text File  |  2000-07-11  |  20.3 KB  |  656 lines

  1. #!/usr/bin/perl
  2. ## ====================================================================
  3. ## Copyright (c) 1998-1999 The Apache Group.  All rights reserved.
  4. ##
  5. ## Redistribution and use in source and binary forms, with or without
  6. ## modification, are permitted provided that the following conditions
  7. ## are met:
  8. ##
  9. ## 1. Redistributions of source code must retain the above copyright
  10. ##    notice, this list of conditions and the following disclaimer. 
  11. ##
  12. ## 2. Redistributions in binary form must reproduce the above copyright
  13. ##    notice, this list of conditions and the following disclaimer in
  14. ##    the documentation and/or other materials provided with the
  15. ##    distribution.
  16. ##
  17. ## 3. All advertising materials mentioning features or use of this
  18. ##    software must display the following acknowledgment:
  19. ##    "This product includes software developed by the Apache Group
  20. ##    for use in the Apache HTTP server project (http://www.apache.org/)."
  21. ##
  22. ## 4. The names "Apache Server" and "Apache Group" must not be used to
  23. ##    endorse or promote products derived from this software without
  24. ##    prior written permission. For written permission, please contact
  25. ##    apache@apache.org.
  26. ##
  27. ## 5. Products derived from this software may not be called "Apache"
  28. ##    nor may "Apache" appear in their names without prior written
  29. ##    permission of the Apache Group.
  30. ##
  31. ## 6. Redistributions of any form whatsoever must retain the following
  32. ##    acknowledgment:
  33. ##    "This product includes software developed by the Apache Group
  34. ##    for use in the Apache HTTP server project (http://www.apache.org/)."
  35. ##
  36. ## THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
  37. ## EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  38. ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  39. ## PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
  40. ## ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  42. ## NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  43. ## LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  44. ## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  45. ## STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  46. ## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  47. ## OF THE POSSIBILITY OF SUCH DAMAGE.
  48. ## ====================================================================
  49. ##
  50. ## This software consists of voluntary contributions made by many
  51. ## individuals on behalf of the Apache Group and was originally based
  52. ## on public domain software written at the National Center for
  53. ## Supercomputing Applications, University of Illinois, Urbana-Champaign.
  54. ## For more information on the Apache Group and the Apache HTTP server
  55. ## project, please see <http://www.apache.org/>.
  56. ##
  57.  
  58. ##
  59. ##  apxs -- APache eXtenSion tool
  60. ##  Written by Ralf S. Engelschall <rse@apache.org>
  61. ##
  62.  
  63. require 5.003;
  64. use strict;
  65. package apxs;
  66.  
  67. ##
  68. ##  Configuration
  69. ##
  70.  
  71. my $CFG_TARGET        = q(httpd);            # substituted via Makefile.tmpl 
  72. my $CFG_CC            = q(m68k-unknown-amigaos-gcc);                # substituted via Makefile.tmpl
  73. my $CFG_CFLAGS        = q(-mstackextend -O3 -Dfork=vfork -m68060 -resident32 -mstackextend -Dfork=vfork -I/studi/kuhlmann/cross/php4/php-4.0.1pl2-amiga -I/studi/kuhlmann/cross/php4/php-4.0.1pl2-amiga/main -I/studi/kuhlmann/cross/php4/php-4.0.1pl2-build/main -I/studi/kuhlmann/cross/php4/php-4.0.1pl2-amiga/Zend -I/studi/kuhlmann/cross/php4/php-4.0.1pl2-build/Zend -I/studi/kuhlmann/cross/php4/php-4.0.1pl2-build -DUSE_EXPAT -I../lib/expat-lite -DNO_DL_NEEDED `../apaci`);            # substituted via Makefile.tmpl
  74. my $CFG_CFLAGS_SHLIB  = q();      # substituted via Makefile.tmpl
  75. my $CFG_LD_SHLIB      = q();          # substituted via Makefile.tmpl
  76. my $CFG_LDFLAGS_SHLIB = q(); # substituted via Makefile.tmpl 
  77. my $CFG_LIBS_SHLIB    = q();        # substituted via Makefile.tmpl 
  78. my $CFG_PREFIX        = q(/Apache);            # substituted via APACI install
  79. my $CFG_SBINDIR       = q(/Apache/bin);           # substituted via APACI install
  80. my $CFG_INCLUDEDIR    = q(/Apache/include/apache);        # substituted via APACI install
  81. my $CFG_LIBEXECDIR    = q(/Apache/libexec);        # substituted via APACI install
  82. my $CFG_SYSCONFDIR    = q(/Apache/conf);        # substituted via APACI install
  83.  
  84. ##
  85. ##  Cleanup the above stuff
  86. ##
  87. $CFG_CFLAGS =~ s|^\s+||;
  88. $CFG_CFLAGS =~ s|\s+$||;
  89. $CFG_CFLAGS =~ s|\s+`.+apaci`||;
  90.  
  91. ##
  92. ##  parse argument line
  93. ##
  94.  
  95. #   defaults for parameters
  96. my $opt_n = '';
  97. my $opt_g = '';
  98. my $opt_c = 0;
  99. my $opt_o = '';
  100. my @opt_D = ();
  101. my @opt_I = ();
  102. my @opt_L = ();
  103. my @opt_l = ();
  104. my @opt_W = ();
  105. my @opt_S = ();
  106. my $opt_e = 0;
  107. my $opt_i = 0;
  108. my $opt_a = 0;
  109. my $opt_A = 0;
  110. my $opt_q = 0;
  111.  
  112. #   this subroutine is derived from Perl's getopts.pl with the enhancement of
  113. #   the "+" metacharater at the format string to allow a list to be build by
  114. #   subsequent occurance of the same option.
  115. sub Getopts {
  116.     my ($argumentative, @ARGV) = @_;
  117.     my (@args, $first, $rest, $pos);
  118.     my ($errs) = 0;
  119.     local ($_);
  120.     local ($[) = 0;
  121.  
  122.     @args = split( / */, $argumentative);
  123.     while(@ARGV && ($_ = $ARGV[0]) =~ /^-(.)(.*)/) {
  124.         ($first, $rest) = ($1,$2);
  125.         if ($_ =~ m|^--$|) {
  126.             shift(@ARGV);
  127.             last;
  128.         }
  129.         $pos = index($argumentative,$first);
  130.         if ($pos >= $[) {
  131.             if ($args[$pos+1] eq ':') {
  132.                 shift(@ARGV);
  133.                 if ($rest eq '') {
  134.                     unless (@ARGV) {
  135.                         print STDERR "apxs:Error: Incomplete option: $first (needs an argument)\n";
  136.                         ++$errs;
  137.                     }
  138.                     $rest = shift(@ARGV);
  139.                 }
  140.                 eval "\$opt_$first = \$rest;";
  141.             }
  142.             elsif ($args[$pos+1] eq '+') {
  143.                 shift(@ARGV);
  144.                 if ($rest eq '') {
  145.                     unless (@ARGV) {
  146.                         print STDERR "apxs:Error: Incomplete option: $first (needs an argument)\n";
  147.                         ++$errs;
  148.                     }
  149.                     $rest = shift(@ARGV);
  150.                 }
  151.                 eval "push(\@opt_$first, \$rest);";
  152.             }
  153.             else {
  154.                 eval "\$opt_$first = 1";
  155.                 if ($rest eq '') {
  156.                     shift(@ARGV);
  157.                 }
  158.                 else {
  159.                     $ARGV[0] = "-$rest";
  160.                 }
  161.             }
  162.         }
  163.         else {
  164.             print STDERR "apxs:Error: Unknown option: $first\n";
  165.             ++$errs;
  166.             if ($rest ne '') {
  167.                 $ARGV[0] = "-$rest";
  168.             }
  169.             else {
  170.                 shift(@ARGV);
  171.             }
  172.         }
  173.     }
  174.     return ($errs == 0, @ARGV);
  175. }
  176.  
  177. sub usage {
  178.     print STDERR "Usage: apxs -g [-S <var>=<val>] -n <modname>\n";
  179.     print STDERR "       apxs -q [-S <var>=<val>] <query> ...\n";
  180.     print STDERR "       apxs -c [-S <var>=<val>] [-o <dsofile>] [-D <name>[=<value>]]\n";
  181.     print STDERR "               [-I <incdir>] [-L <libdir>] [-l <libname>] [-Wc,<flags>]\n";
  182.     print STDERR "               [-Wl,<flags>] <files> ...\n";
  183.     print STDERR "       apxs -i [-S <var>=<val>] [-a] [-A] [-n <modname>] <dsofile> ...\n";
  184.     print STDERR "       apxs -e [-S <var>=<val>] [-a] [-A] [-n <modname>] <dsofile> ...\n";
  185.     exit(1);
  186. }
  187.  
  188. #   option handling
  189. my $rc;
  190. ($rc, @ARGV) = &Getopts("qn:gco:I+D+L+l+W+S+eiaA", @ARGV);
  191. &usage if ($rc == 0);
  192. &usage if ($#ARGV == -1 and not $opt_g);
  193. &usage if (not $opt_q and not ($opt_g and $opt_n) and not $opt_i and not $opt_c and not $opt_e);
  194.  
  195. #   argument handling
  196. my @args = @ARGV;
  197. my $name = 'unknown';
  198. $name = $opt_n if ($opt_n ne '');
  199.  
  200. #   overriding of configuration variables
  201. if (@opt_S) {
  202.     my ($opt_S);
  203.     foreach $opt_S (@opt_S) {
  204.         if ($opt_S =~ m/^([^=]+)=(.*)$/) {
  205.             my ($var, $val) = ($1, $2);
  206.             my $oldval = eval "\$CFG_$var";
  207.             unless ($var and $oldval) {
  208.                 print STDERR "apxs:Error: no config variable $var\n";
  209.                 &usage;
  210.             }
  211.             eval "\$CFG_${var}=\"${val}\"";
  212.         } else {
  213.             print STDERR "apxs:Error: malformatted -S option\n";
  214.             &usage;
  215.         }       
  216.     }
  217. }
  218.  
  219. ##
  220. ##  Initial DSO support check
  221. ##
  222. if (not -x "$CFG_SBINDIR/$CFG_TARGET") {
  223.     print STDERR "apxs:Error: $CFG_SBINDIR/$CFG_TARGET not found or not executable\n";
  224.     exit(1);
  225. }
  226. if (not grep(/mod_so/, `$CFG_SBINDIR/$CFG_TARGET -l`)) {
  227.     print STDERR "apxs:Error: Sorry, no DSO support for Apache available\n";
  228.     print STDERR "apxs:Error: under your platform. Make sure the Apache\n";
  229.     print STDERR "apxs:Error: module mod_so is compiled into your server\n";
  230.     print STDERR "apxs:Error: binary `$CFG_SBINDIR/$CFG_TARGET'.\n";
  231.     exit(1);
  232. }
  233.  
  234. ##
  235. ##  Operation
  236. ##
  237.  
  238. #   helper function for executing a list of
  239. #   system command with return code checks
  240. sub execute_cmds {
  241.     my (@cmds) = @_;
  242.     my ($cmd, $rc);
  243.  
  244.     foreach $cmd (@cmds) {
  245.         print STDERR "$cmd\n";
  246.         $rc = system("$cmd");
  247.         if ($rc != 0) {
  248.             printf(STDERR "apxs:Break: Command failed with rc=%d\n", $rc << 8);
  249.             exit(1);
  250.         }
  251.     }
  252. }
  253.  
  254. if ($opt_g) {
  255.     ##
  256.     ##  SAMPLE MODULE SOURCE GENERATION
  257.     ##
  258.  
  259.     if (-d $name) {
  260.         print STDERR "apxs:Error: Directory `$name' already exists. Remove it first\n";
  261.         exit(1);
  262.     }
  263.  
  264.     my $data = join('', <DATA>);
  265.     $data =~ s|%NAME%|$name|sg;
  266.     $data =~ s|%TARGET%|$CFG_TARGET|sg;
  267.  
  268.     my ($mkf, $src) = ($data =~ m|^(.+)-=#=-\n(.+)|s);
  269.  
  270.     print STDERR "Creating [DIR]  $name\n";
  271.     system("mkdir $name");
  272.     print STDERR "Creating [FILE] $name/Makefile\n";
  273.     open(FP, ">${name}/Makefile") || die;
  274.     print FP $mkf;
  275.     close(FP);
  276.     print STDERR "Creating [FILE] $name/mod_$name.c\n";
  277.     open(FP, ">${name}/mod_${name}.c") || die;
  278.     print FP $src;
  279.     close(FP);
  280.  
  281.     exit(0);
  282. }
  283.  
  284. if ($opt_q) {
  285.     ##
  286.     ##  QUERY INFORMATION 
  287.     ##
  288.  
  289.     my $result = '';
  290.     my $arg;
  291.     foreach $arg (@args) {
  292.         my $ok = 0;
  293.         my $name;
  294.         foreach $name (qw(
  295.             TARGET CC CFLAGS CFLAGS_SHLIB LD_SHLIB LDFLAGS_SHLIB LIBS_SHLIB
  296.             PREFIX SBINDIR INCLUDEDIR LIBEXECDIR SYSCONFDIR
  297.         )) {
  298.             if ($arg eq $name or $arg eq lc($name)) {
  299.                 my $val = eval "\$CFG_$name";
  300.                 $result .= "${val}##";
  301.                 $ok = 1;
  302.             }
  303.         }
  304.         if (not $ok) {
  305.             printf(STDERR "apxs:Error: Invalid query string `%s'\n", $arg);
  306.             exit(1);
  307.         }
  308.     }
  309.     $result =~ s|##$||;
  310.     $result =~ s|##| |g;
  311.     print $result;
  312. }
  313.  
  314. if ($opt_c) {
  315.     ##
  316.     ##  DSO COMPILATION
  317.     ##
  318.  
  319.     #   split files into sources and objects
  320.     my @srcs = ();
  321.     my @objs = ();
  322.     my $f;
  323.     foreach $f (@args) {
  324.         if ($f =~ m|\.c$|) {
  325.             push(@srcs, $f);
  326.         }
  327.         else {
  328.             push(@objs, $f);
  329.         }
  330.     }
  331.  
  332.     #   determine output file
  333.     my $dso_file;
  334.     if ($opt_o eq '') {
  335.         if ($#srcs > -1) {
  336.             $dso_file = $srcs[0];
  337.             $dso_file =~ s|\.[^.]+$|.so|;
  338.         }
  339.         elsif ($#objs > -1) {
  340.             $dso_file = $objs[0];
  341.             $dso_file =~ s|\.[^.]+$|.so|;
  342.         }
  343.         else {
  344.             $dso_file = "mod_unknown.so";
  345.         }
  346.     }
  347.     else {
  348.         $dso_file = $opt_o;
  349.     }
  350.  
  351.     #   create compilation commands
  352.     my @cmds = ();
  353.     my $opt = '';
  354.     my ($opt_Wc, $opt_I, $opt_D);
  355.     foreach $opt_Wc (@opt_W) {
  356.         $opt .= "$1 " if ($opt_Wc =~ m|^\s*c,(.*)$|);
  357.     }
  358.     foreach $opt_I (@opt_I) {
  359.         $opt .= "-I$opt_I ";
  360.     }
  361.     foreach $opt_D (@opt_D) {
  362.         $opt .= "-D$opt_D ";
  363.     }
  364.     my $cflags = "$CFG_CFLAGS $CFG_CFLAGS_SHLIB";
  365.     my $s;
  366.     foreach $s (@srcs) {
  367.         my $o = $s;
  368.         $o =~ s|\.c$|.o|;
  369.         $o =~ s|^.*/||;
  370.         push(@cmds, "$CFG_CC $cflags -I$CFG_INCLUDEDIR $opt -c $s");
  371.         unshift(@objs, $o);
  372.     }
  373.  
  374.     #   create link command
  375.     my $cmd = "$CFG_LD_SHLIB $CFG_LDFLAGS_SHLIB -o $dso_file";
  376.     my $o;
  377.     foreach $o (@objs) {
  378.         $cmd .= " $o";
  379.     }
  380.     $opt = '';
  381.     my ($opt_Wl, $opt_L, $opt_l);
  382.     foreach $opt_Wl (@opt_W) {
  383.         if ($CFG_LD_SHLIB !~ m/gcc$/) {
  384.             $opt .= " $1" if ($opt_Wl =~ m|^\s*l,(.*)$|);
  385.         } else {
  386.             $opt .= " -W$opt_Wl";
  387.         }
  388.     }
  389.     foreach $opt_L (@opt_L) {
  390.         $opt .= " -L$opt_L";
  391.     }
  392.     foreach $opt_l (@opt_l) {
  393.         $opt .= " -l$opt_l";
  394.     }
  395.     $cmd .= $opt;
  396.     $cmd .= " $CFG_LIBS_SHLIB";
  397.     push(@cmds, $cmd);
  398.  
  399.     #   execute the commands
  400.     &execute_cmds(@cmds);
  401.  
  402.     #   allow one-step compilation and installation
  403.     if ($opt_i or $opt_e) {
  404.         @args = ($dso_file);
  405.     }
  406. }
  407.  
  408. if ($opt_i or $opt_e) {
  409.     ##
  410.     ##  DSO INSTALLATION
  411.     ##
  412.  
  413.     #   determine installation commands
  414.     #   and corresponding LoadModule/AddModule directives
  415.     my @lmd = ();
  416.     my @amd = ();
  417.     my @cmds = ();
  418.     my $f;
  419.     foreach $f (@args) {
  420.         if ($f !~ m|\.so$|) {
  421.             print STDERR "apxs:Error: file $f is not a DSO\n";
  422.             exit(1);
  423.         }
  424.         my $t = $f;
  425.         $t =~ s|^.+/([^/]+)$|$1|;
  426.         if ($opt_i) {
  427.             push(@cmds, "cp $f $CFG_LIBEXECDIR/$t");
  428.             push(@cmds, "chmod 755 $CFG_LIBEXECDIR/$t");
  429.         }
  430.  
  431.         #   determine module symbolname and filename
  432.         my $filename = '';
  433.         if ($name eq 'unknown') {
  434.             $name = '';
  435.             my $base = $f;
  436.             $base =~ s|\.[^.]+$||;
  437.             if (-f "$base.c") {
  438.                 open(FP, "<$base.c");
  439.                 my $content = join('', <FP>);
  440.                 close(FP);
  441.                 if ($content =~ m|.*module\s+(?:MODULE_VAR_EXPORT\s+)?([a-zA-Z0-9_]+)_module\s*=\s*.*|s) {
  442.                     $name = "$1";
  443.                     $filename = "$base.c";
  444.                     $filename =~ s|^[^/]+/||;
  445.                 }
  446.             }
  447.             if ($name eq '') {
  448.                 if ($base =~ m|.*mod_([a-zA-Z0-9_]+)\..+|) {
  449.                     $name = "$1";
  450.                     $filename = $base;
  451.                     $filename =~ s|^[^/]+/||;
  452.                 }
  453.             }
  454.             if ($name eq '') {
  455.                 print STDERR "apxs:Error: Sorry, cannot determine bootstrap symbol name.\n";
  456.                 print STDERR "apxs:Error: Please specify one with option `-n'.\n";
  457.                 exit(1);
  458.             }
  459.         }
  460.         if ($filename eq '') {
  461.             $filename = "mod_${name}.c";
  462.         }
  463.         my $dir = $CFG_LIBEXECDIR;
  464.         $dir =~ s|^$CFG_PREFIX/?||;
  465.         $dir =~ s|(.)$|$1/|;
  466.         push(@lmd, sprintf("LoadModule %-18s %s", "${name}_module", "$dir$t"));
  467.         push(@amd, sprintf("AddModule %s", $filename));
  468.     }
  469.  
  470.     #   execute the commands
  471.     &execute_cmds(@cmds);
  472.  
  473.     #   activate module via LoadModule/AddModule directive
  474.     if ($opt_a or $opt_A) {
  475.         if (not -f "$CFG_SYSCONFDIR/$CFG_TARGET.conf") {
  476.             print STDERR "apxs:Error: Config file $CFG_SYSCONFDIR/$CFG_TARGET.conf not found\n";
  477.             exit(1);
  478.         }
  479.  
  480.         open(FP, "<$CFG_SYSCONFDIR/$CFG_TARGET.conf") || die;
  481.         my $content = join('', <FP>);
  482.         close(FP);
  483.  
  484.         if ($content !~ m|\n#?\s*LoadModule\s+|) {
  485.             print STDERR "apxs:Error: Activation failed for custom $CFG_SYSCONFDIR/$CFG_TARGET.conf file.\n";
  486.             print STDERR "apxs:Error: At least one `LoadModule' directive already has to exist.\n";
  487.             exit(1);
  488.         }
  489.  
  490.         my $lmd;
  491.         my $c = '';
  492.         $c = '#' if ($opt_A);
  493.         foreach $lmd (@lmd) {
  494.             my $what = $opt_A ? "preparing" : "activating";
  495.             if ($content !~ m|\n#?\s*$lmd|) {
  496.                  $content =~ s|^(.*\n#?\s*LoadModule\s+[^\n]+\n)|$1$c$lmd\n|sg;
  497.             } else {
  498.                  $content =~ s|^(.*\n)#?\s*$lmd[^\n]*\n|$1$c$lmd\n|sg;
  499.             }
  500.             $lmd =~ m|LoadModule\s+(.+?)_module.*|;
  501.             print STDERR "[$what module `$1' in $CFG_SYSCONFDIR/$CFG_TARGET.conf]\n";
  502.         }
  503.         my $amd;
  504.         foreach $amd (@amd) {
  505.             if ($content !~ m|\n#?\s*$amd|) {
  506.                  $content =~ s|^(.*\n#?\s*AddModule\s+[^\n]+\n)|$1$c$amd\n|sg;
  507.             } else {
  508.                  $content =~ s|^(.*\n)#?\s*$amd[^\n]*\n|$1$c$amd\n|sg;
  509.             }
  510.         }
  511.         if (@lmd or @amd) {
  512.             if (open(FP, ">$CFG_SYSCONFDIR/$CFG_TARGET.conf.new")) {
  513.                 print FP $content;
  514.                 close(FP);
  515.                 system("cp $CFG_SYSCONFDIR/$CFG_TARGET.conf $CFG_SYSCONFDIR/$CFG_TARGET.conf.bak && " .
  516.                        "cp $CFG_SYSCONFDIR/$CFG_TARGET.conf.new $CFG_SYSCONFDIR/$CFG_TARGET.conf && " .
  517.                        "rm $CFG_SYSCONFDIR/$CFG_TARGET.conf.new");
  518.             } else {
  519.                 print STDERR "apxs:Error: unable to open configuration file\n";
  520.             }
  521.         }
  522.     }
  523. }
  524.  
  525. ##EOF##
  526. __DATA__
  527. ##
  528. ##  Makefile -- Build procedure for sample %NAME% Apache module
  529. ##  Autogenerated via ``apxs -n %NAME% -g''.
  530. ##
  531.  
  532. #   the used tools
  533. APXS=apxs
  534. APACHECTL=apachectl
  535.  
  536. #   additional user defines, includes and libraries
  537. #DEF=-Dmy_define=my_value
  538. #INC=-Imy/include/dir
  539. #LIB=-Lmy/lib/dir -lmylib
  540.  
  541. #   the default target
  542. all: mod_%NAME%.so
  543.  
  544. #   compile the DSO file
  545. mod_%NAME%.so: mod_%NAME%.c
  546.     $(APXS) -c $(DEF) $(INC) $(LIB) mod_%NAME%.c
  547.  
  548. #   install the DSO file into the Apache installation
  549. #   and activate it in the Apache configuration
  550. install: all
  551.     $(APXS) -i -a -n '%NAME%' mod_%NAME%.so
  552.  
  553. #   cleanup
  554. clean:
  555.     -rm -f mod_%NAME%.o mod_%NAME%.so
  556.  
  557. #   simple test
  558. test: reload
  559.     lynx -mime_header http://localhost/%NAME%
  560.  
  561. #   reload the module by installing and restarting Apache
  562. reload: install restart
  563.  
  564. #   the general Apache start/restart/stop procedures
  565. start:
  566.     $(APACHECTL) start
  567. restart:
  568.     $(APACHECTL) restart
  569. stop:
  570.     $(APACHECTL) stop
  571.  
  572. -=#=-
  573. /* 
  574. **  mod_%NAME%.c -- Apache sample %NAME% module
  575. **  [Autogenerated via ``apxs -n %NAME% -g'']
  576. **
  577. **  To play with this sample module, first compile it into a
  578. **  DSO file and install it into Apache's libexec directory 
  579. **  by running:
  580. **
  581. **    $ apxs -c -i mod_%NAME%.c
  582. **
  583. **  Then activate it in Apache's %TARGET%.conf file, for instance
  584. **  for the URL /%NAME%, as follows:
  585. **
  586. **    #   %TARGET%.conf
  587. **    LoadModule %NAME%_module libexec/mod_%NAME%.so
  588. **    <Location /%NAME%>
  589. **    SetHandler %NAME%
  590. **    </Location>
  591. **
  592. **  Then after restarting Apache via
  593. **
  594. **    $ apachectl restart
  595. **
  596. **  you immediately can request the URL /%NAME and watch for the
  597. **  output of this module. This can be achieved for instance via:
  598. **
  599. **    $ lynx -mime_header http://localhost/%NAME% 
  600. **
  601. **  The output should be similar to the following one:
  602. **
  603. **    HTTP/1.1 200 OK
  604. **    Date: Tue, 31 Mar 1998 14:42:22 GMT
  605. **    Server: Apache/1.3.4 (Unix)
  606. **    Connection: close
  607. **    Content-Type: text/html
  608. **  
  609. **    The sample page from mod_%NAME%.c
  610. */ 
  611.  
  612. #include "httpd.h"
  613. #include "http_config.h"
  614. #include "http_protocol.h"
  615. #include "ap_config.h"
  616.  
  617. /* The sample content handler */
  618. static int %NAME%_handler(request_rec *r)
  619. {
  620.     r->content_type = "text/html";      
  621.     ap_send_http_header(r);
  622.     if (!r->header_only)
  623.         ap_rputs("The sample page from mod_%NAME%.c\n", r);
  624.     return OK;
  625. }
  626.  
  627. /* Dispatch list of content handlers */
  628. static const handler_rec %NAME%_handlers[] = { 
  629.     { "%NAME%", %NAME%_handler }, 
  630.     { NULL, NULL }
  631. };
  632.  
  633. /* Dispatch list for API hooks */
  634. module MODULE_VAR_EXPORT %NAME%_module = {
  635.     STANDARD_MODULE_STUFF, 
  636.     NULL,                  /* module initializer                  */
  637.     NULL,                  /* create per-dir    config structures */
  638.     NULL,                  /* merge  per-dir    config structures */
  639.     NULL,                  /* create per-server config structures */
  640.     NULL,                  /* merge  per-server config structures */
  641.     NULL,                  /* table of config file commands       */
  642.     %NAME%_handlers,       /* [#8] MIME-typed-dispatched handlers */
  643.     NULL,                  /* [#1] URI to filename translation    */
  644.     NULL,                  /* [#4] validate user id from request  */
  645.     NULL,                  /* [#5] check if the user is ok _here_ */
  646.     NULL,                  /* [#3] check access by host address   */
  647.     NULL,                  /* [#6] determine MIME type            */
  648.     NULL,                  /* [#7] pre-run fixups                 */
  649.     NULL,                  /* [#9] log a transaction              */
  650.     NULL,                  /* [#2] header parser                  */
  651.     NULL,                  /* child_init                          */
  652.     NULL,                  /* child_exit                          */
  653.     NULL                   /* [#0] post read-request              */
  654. };
  655.  
  656.