import of rt 3.0.4
[freeside.git] / rt / m4 / rt_layout.m4
1 dnl
2 dnl @synopsis RT_LAYOUT(configlayout, layoutname)
3 dnl
4 dnl This macro reads an Apache-style layout file (specified as the
5 dnl configlayout parameter), and searches for a specific layout
6 dnl (named using the layoutname parameter).
7 dnl
8 dnl The entries for a given layout are then inserted into the
9 dnl environment such that they become available as substitution
10 dnl variables. In addition, the rt_layout_name variable is set
11 dnl (but not exported) if the layout is valid.
12 dnl
13 dnl This code is heavily borrowed *cough* from the Apache 2 codebase.
14 dnl
15
16 AC_DEFUN([RT_LAYOUT],[
17         if test ! -f $srcdir/config.layout; then
18                 AC_MSG_WARN([Layout file $srcdir/config.layout not found])
19                 rt_layout_name=no
20         else
21                 pldconf=./config.pld
22                 $PERL  -0777 -p -e "\$layout = '$2';"  -e '
23                 s/.*<Layout\s+$layout>//gims; 
24                 s/\<\/Layout\>.*//s; 
25                 s/^#.*$//m;
26                 s/^\s+//gim;
27                 s/\s+$/\n/gim;
28                 s/\+$/\/rt3/gim;
29                 # m4 will not let us just use $1, we need @S|@1
30                 s/^\s*((?:bin|sbin|libexec|data|sysconf|sharedstate|localstate|lib|include|oldinclude|info|man)dir)\s*:\s*(.*)$/@S|@1=@S|@2/gim;
31                 s/^\s*(.*?)\s*:\s*(.*)$/\(test "x\@S|@@S|@1" = "xNONE" || test "x\@S|@@S|@1" = "x") && @S|@1=@S|@2/gim;
32                  ' < $1 > $pldconf
33
34                 if test -s $pldconf; then
35                         rt_layout_name=$2
36                         . $pldconf
37                         changequote({,})
38                         for var in prefix exec_prefix bindir sbindir \
39                                  sysconfdir mandir libdir datadir htmldir \
40                                  localstatedir logfiledir masonstatedir \
41                                  sessionstatedir customdir custometcdir customhtmldir \
42                                  customlexdir customlibdir manualdir; do
43                                 eval "val=\"\$$var\""
44                                 val=`echo $val | sed -e 's:\(.\)/*$:\1:'`
45                                 val=`echo $val | 
46                                         sed -e 's:[\$]\([a-z_]*\):${\1}:g'`
47                                 eval "$var='$val'"
48                         done
49                         changequote([,])
50                 else
51                         rt_layout_name=no
52                 fi
53                 #rm $pldconf
54         fi
55         RT_SUBST_EXPANDED_ARG(prefix)
56         RT_SUBST_EXPANDED_ARG(exec_prefix)
57         RT_SUBST_EXPANDED_ARG(bindir)
58         RT_SUBST_EXPANDED_ARG(sbindir)
59         RT_SUBST_EXPANDED_ARG(sysconfdir)
60         RT_SUBST_EXPANDED_ARG(mandir)
61         RT_SUBST_EXPANDED_ARG(libdir)
62         RT_SUBST_EXPANDED_ARG(datadir)
63         RT_SUBST_EXPANDED_ARG(htmldir)
64         RT_SUBST_EXPANDED_ARG(manualdir)
65         RT_SUBST_EXPANDED_ARG(localstatedir)
66         RT_SUBST_EXPANDED_ARG(logfiledir)
67         RT_SUBST_EXPANDED_ARG(masonstatedir)
68         RT_SUBST_EXPANDED_ARG(sessionstatedir)
69         RT_SUBST_EXPANDED_ARG(customdir)
70         RT_SUBST_EXPANDED_ARG(custometcdir)
71         RT_SUBST_EXPANDED_ARG(customhtmldir)
72         RT_SUBST_EXPANDED_ARG(customlexdir)
73         RT_SUBST_EXPANDED_ARG(customlibdir)
74 ])dnl