Vitelity API CDR import, #11037
[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/^#.*$//gm;
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/^((?:bin|sbin|libexec|data|sysconf|sharedstate|localstate|lib|include|oldinclude|plugin|info|man)dir)\s*:\s*(.*)$/@S|@1=@S|@2/gim;
31                 # uh, should be [:=], but m4 apparently substitutes something...
32                 s/^(.*?)\s*(?::|=)\s*(.*)$/\(test "x\@S|@@S|@1" = "xNONE" || test "x\@S|@@S|@1" = "x") && @S|@1=@S|@2/gim;
33                  ' < $1 > $pldconf
34
35                 if test -s $pldconf; then
36                         rt_layout_name=$2
37                         . $pldconf
38                         changequote({,})
39                         for var in prefix exec_prefix bindir sbindir \
40                                  sysconfdir mandir libdir datadir htmldir fontdir \
41                                  localstatedir logfiledir masonstatedir plugindir \
42                                  sessionstatedir customdir custometcdir customhtmldir \
43                                  customlexdir customlibdir manualdir; do
44                                 eval "val=\"\$$var\""
45                                 val=`echo $val | sed -e 's:\(.\)/*$:\1:'`
46                                 val=`echo $val | 
47                                         sed -e 's:[\$]\([a-z_]*\):${\1}:g'`
48                                 eval "$var='$val'"
49                         done
50                         changequote([,])
51                 else
52                         rt_layout_name=no
53                 fi
54                 #rm $pldconf
55         fi
56         RT_SUBST_EXPANDED_ARG(prefix)
57         RT_SUBST_EXPANDED_ARG(exec_prefix)
58         RT_SUBST_EXPANDED_ARG(bindir)
59         RT_SUBST_EXPANDED_ARG(sbindir)
60         RT_SUBST_EXPANDED_ARG(sysconfdir)
61         RT_SUBST_EXPANDED_ARG(mandir)
62         RT_SUBST_EXPANDED_ARG(libdir)
63         RT_SUBST_EXPANDED_ARG(datadir)
64         RT_SUBST_EXPANDED_ARG(htmldir)
65         RT_SUBST_EXPANDED_ARG(fontdir)
66         RT_SUBST_EXPANDED_ARG(manualdir)
67         RT_SUBST_EXPANDED_ARG(plugindir)
68         RT_SUBST_EXPANDED_ARG(localstatedir)
69         RT_SUBST_EXPANDED_ARG(logfiledir)
70         RT_SUBST_EXPANDED_ARG(masonstatedir)
71         RT_SUBST_EXPANDED_ARG(sessionstatedir)
72         RT_SUBST_EXPANDED_ARG(customdir)
73         RT_SUBST_EXPANDED_ARG(custometcdir)
74         RT_SUBST_EXPANDED_ARG(customhtmldir)
75         RT_SUBST_EXPANDED_ARG(customlexdir)
76         RT_SUBST_EXPANDED_ARG(customlibdir)
77 ])dnl