1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
|
--- a/templates/src/Makefile
+++ b/templates/src/Makefile
@@ -11,7 +11,7 @@ LDFLAGS = $(BASELDFLAGS)
LIB= ../../lib/lib_nossl.a
-all: template_expand template_compile
+all: template_expand template_compile template-set.make
template_expand: template_expand_main.o log.o empty.o $(LIB)
$(CC) $(LDFLAGS) -o template_expand log.o empty.o template_expand_main.o $(LIB) $(BASE_LIBS)
@@ -19,10 +19,28 @@ template_expand: template_expand_main.o
template_compile: template_compile_main.o log.o empty.o $(LIB)
$(CC) $(LDFLAGS) -o template_compile log.o empty.o template_compile_main.o $(LIB) $(BASE_LIBS)
+template-set.make: template-set.make.in
+ find_templates () { sed -rn 's/.*template_expand\("([^"]*)".*/\1/p' "$$@" | sort -u; };\
+ format_variable () { (echo $$1 '='; shift; echo -n ' '$$@) | fmt -c | sed '$$!s/$$/ \\/'; };\
+ (echo include $(PREFIX)/config.make; echo;\
+ format_variable TEMPLATES `find_templates ../../cmd/cmd_*`; echo;\
+ format_variable TEMPLATES_FRONTEND login `find_templates ../../servers/prayer*`; echo;\
+ cat template-set.make.in) > template-set.make
+
%.o: %.c Makefile
$(CC) $(CFLAGS) -I../../lib -c $<
install:
+ $(INSTALL) -o $(RO_USER) -g $(RO_GROUP) -m $(PUBLIC_DIR) \
+ -d $(BROOT)$(LIB_PREFIX) $(BROOT)$(PREFIX) $(BROOT)/usr/include/prayer
+ $(INSTALL) -o $(RO_USER) -g $(RO_GROUP) -m $(PUBLIC_EXEC) \
+ template_compile template_expand build_index.pl makedeps.pl ${BROOT}${LIB_PREFIX}
+ $(INSTALL) -o $(RO_USER) -g $(RO_GROUP) -m $(PUBLIC_FILE) \
+ ../../lib/*.h ${BROOT}/usr/include/prayer
+ $(INSTALL) -o $(RO_USER) -g $(RO_GROUP) -m $(PUBLIC_FILE) \
+ template-set.make ${BROOT}$(PREFIX)
+ $(INSTALL) -o $(RO_USER) -g $(RO_GROUP) -m $(PUBLIC_FILE) \
+ ../../Config ${BROOT}$(PREFIX)/config.make
clean:
rm -f template_expand template_compile *.o *~ \#*\#
--- a/templates/src/makedeps.pl
+++ b/templates/src/makedeps.pl
@@ -4,51 +4,44 @@
#
# Generate proper list of dependancies between templates
-%uses = ();
+my %index = ();
+my %uses = ();
-while ($file=shift(@ARGV)) {
- $file = $1 if ($file =~ /([\w-_]+)\.t/);
+sub scan {
+ my ($file) = @_;
- open(FILE, "<${file}.t") or die "failed to open ${file}: $!\n";
-
- while (<FILE>) {
- next unless /^%\s+CALL ([\w-_]+)/;
+ if (!exists $uses{$file}) {
+ grep {
+ $_ ne '' and open(FILE, '<', "$_/${file}.t")
+ } '.', split(/ :/, $ENV{'VPATH'} || '')
+ or die "failed to open ${file}: $!\n";
+ while (<FILE>) {
+ $uses{$file}{$1} = 1 if /^%\s+CALL ([\w-_]+)/;
+ }
+ close(FILE);
- $uses{$file} = [] if (not $uses{$file});
- push(@{$uses{$file}}, $1);
+ foreach (keys %{$uses{$file}}) {
+ $uses{$file}{$_} = 1 foreach keys %{scan($_)};
+ }
+ $uses{$file}{$file} = 1;
+ $index{$file} = 1;
}
-
- close(FILE);
+ return $uses{$file}
}
-foreach $i (sort keys %uses) {
- # Sort and uniq
- @{$uses{$i}} = keys %{{ map { $_ => 1 } sort(@{$uses{$i}}) }};
+my $suffix = '';
+if ($ARGV[0] eq '--frontend') {
+ shift;
+ $suffix = '_frontend';
}
+my $name = shift;
-foreach $i (sort keys %uses) {
- printf("%s.html: %s.t", $i, $i);
- foreach $j (@{$uses{$i}}) {
- @list = ();
- recurse($j, {}, \@list);
- foreach $k (@list) {
- printf(" %s.t", $k);
- }
- }
- printf("\n");
+$, = ' '; $\ = "\n";
+foreach my $i (@ARGV) {
+ $i =~ s/([\w-_]+)\.t/$1/;
+ print "$i.html:", map {"$_.t"} sort keys %{scan($i)};
}
-exit(0);
-
-sub recurse {
- my ($i, $usedref, $listref) = @_;
-
- # Remove repeated references to any given template/
- return if defined($$usedref{$i});
- $$usedref{$i} = 1;
-
- push (@{$listref}, $i);
- foreach $j (@{$uses{$i}}) {
- recurse($j, $usedref, $listref);
- }
-}
+my @all = sort keys %index;
+print "_template_index$suffix.c:", map {"$_.t"} @all;
+print "$name$suffix.so:", "_template_index$suffix.o", map {"$_.o"} @all;
--- /dev/null
+++ b/templates/src/template-set.make.in
@@ -0,0 +1,67 @@
+ifndef NAME
+NAME := $(notdir $(CURDIR))
+endif
+
+CPPFLAGS = -I/usr/include/prayer
+CFLAGS += -fPIC
+LDFLAGS_TEMPLATELIB = -shared -fPIC \
+ -Wl,--defsym=template_map=template_map_$(NAME) \
+ -Wl,--defsym=template_map_count=template_map_$(NAME)_count
+
+EXPAND = $(LIB_PREFIX)/template_expand
+COMPILE = $(LIB_PREFIX)/template_compile
+MKINDEX = $(LIB_PREFIX)/build_index.pl
+MKDEPS = $(LIB_PREFIX)/makedeps.pl
+
+SESSION_LIB = $(NAME)$(SHLIBEXT)
+FRONTEND_LIB = $(NAME)_frontend$(SHLIBEXT)
+TEMPLATE_LIBS ?= $(SESSION_LIB) $(FRONTEND_LIB)
+TARGETS ?= $(TEMPLATE_LIBS)
+
+VARS=$(filter-out common.vars,$(wildcard *.vars))
+HTML=$(VARS:.vars=.html)
+
+all: $(TARGETS)
+
+$(TEMPLATE_LIBS):
+ $(CC) $(LDFLAGS) $(LDFLAGS_TEMPLATELIB) -o $@ $^
+
+_template_index.c _template_index_frontend.c:
+ $(MKINDEX) $(NAME) $(^F) > $@
+
+%.c: %.t
+ $(COMPILE) $(NAME) $@ $(basename $<)
+
+install-sources:
+ $(INSTALL) -o $(RO_USER) -g $(RO_GROUP) -m $(PUBLIC_DIR) \
+ -d $(DESTDIR)$(PREFIX)/templates/$(NAME)
+ $(INSTALL) -o $(RO_USER) -g $(RO_GROUP) -m $(PUBLIC_FILE) \
+ *.t *.vars $(DESTDIR)$(PREFIX)/templates/$(NAME)
+
+install-libs: $(TEMPLATE_LIBS)
+ $(INSTALL) -o $(RO_USER) -g $(RO_GROUP) -m $(PUBLIC_DIR) \
+ -d $(DESTDIR)$(LIB_PREFIX)/templates
+ $(INSTALL) -o $(RO_USER) -g $(RO_GROUP) -m $(PUBLIC_FILE) \
+ $(TEMPLATE_LIBS) $(DESTDIR)$(LIB_PREFIX)/templates/
+
+clean:
+ rm -f $(TARGETS) *.html *.o *.c
+distclean: clean
+ rm -f *.d
+
+test: $(HTML)
+
+%.html: %.t %.vars common.vars
+ $(EXPAND) $@ $* common.vars $*.vars
+
+%_frontend.d: FRONTEND_FLAG = --frontend
+%_frontend.d: TEMPLATES = $(TEMPLATES_FRONTEND)
+export VPATH
+$(TEMPLATE_LIBS:$(SHLIBEXT)=.d):
+ $(MKDEPS) $(FRONTEND_FLAG) $(NAME) $(TEMPLATES) > $@
+ sed -ri 's/^(_template_index[^:]*)/\1 $@/' $@
+
+include $(TEMPLATE_LIBS:$(SHLIBEXT)=.d)
+
+.PHONY: all install-sources install-libs clean distclean test
+.DELETE_ON_ERROR:
--- a/templates/src/build_index.pl
+++ b/templates/src/build_index.pl
@@ -18,7 +18,8 @@ foreach $i (@ARGV) {
@templates = sort(@templates);
print <<'EOM';
-#include "lib.h"
+#include "misc.h"
+#include "template_structs.h"
EOM
|