Subversion Repositories

?revision_form?Rev ?revision_input??revision_submit??revision_endform?

Rev 139 | Details | Compare with Previous | Last modification | View Log | RSS feed

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