Subversion Repositories

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

Rev 107 | Go to most recent revision | Details | 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
 
5
 LIB= ../../lib/lib_nossl.a $(BASE_LIBS)
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)
11
        $(CC) $(LDFLAGS) -o template_expand log.o empty.o template_expand_main.o $(LIB)
12
@@ -19,10 +19,28 @@ template_expand: template_expand_main.o 
13
 template_compile: template_compile_main.o log.o empty.o $(LIB)
14
        $(CC) $(LDFLAGS) -o template_compile log.o empty.o template_compile_main.o $(LIB)
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 *~ \#*\#
41
--- /dev/null
42
+++ b/templates/src/makedeps.pl
43
@@ -0,0 +1,45 @@
44
+#!/usr/bin/perl
45
+#
46
+# Generate proper list of dependancies between templates
47
+
48
+my %index = ();
49
+my %uses = ();
50
+
51
+sub scan {
52
+  my ($file) = @_;
53
+
54
+  if (!exists $uses{$file}) {
55
+    grep {
56
+       $_ ne '' and open(FILE, '<', "$_/${file}.t")
57
+    } '.', split(/ :/, $ENV{'VPATH'} || '')
58
+    or die "failed to open ${file}: $!\n";
59
+    while (<FILE>) {
60
+      $uses{$file}{$1} = 1 if /^%\s+CALL ([\w-_]+)/;
61
+    }
62
+    close(FILE);
63
+
64
+    foreach (keys %{$uses{$file}}) {
65
+      $uses{$file}{$_} = 1 foreach keys %{scan($_)};
66
+    }
67
+    $uses{$file}{$file} = 1;
68
+    $index{$file} = 1;
69
+  }
70
+  return $uses{$file}
71
+}
72
+
73
+my $suffix = '';
74
+if ($ARGV[0] eq '--frontend') {
75
+  shift;
76
+  $suffix = '_frontend';
77
+}
78
+my $name = shift;
79
+
80
+$, = ' '; $\ = "\n";
81
+foreach my $i (@ARGV) {
82
+  $i =~ s/([\w-_]+)\.t/$1/;
83
+  print "$i.html:", map {"$_.t"} sort keys %{scan($i)};
84
+}
85
+
86
+my @all = sort keys %index;
87
+print "_template_index$suffix.c:", map {"$_.t"} @all;
88
+print "$name$suffix.so:", "_template_index$suffix.o", map {"$_.o"} @all;
89
--- /dev/null
90
+++ b/templates/src/template-set.make.in
91
@@ -0,0 +1,66 @@
92
+ifndef NAME
93
+NAME := $(notdir $(CURDIR))
94
+endif
95
+
96
+CPPFLAGS = -I/usr/include/prayer
97
+LDFLAGS_TEMPLATELIB = -shared \
98
+       -Wl,--defsym=template_map=template_map_$(NAME) \
99
+       -Wl,--defsym=template_map_count=template_map_$(NAME)_count
100
+
101
+EXPAND  = $(LIB_PREFIX)/template_expand
102
+COMPILE = $(LIB_PREFIX)/template_compile
103
+MKINDEX = $(LIB_PREFIX)/build_index.pl
104
+MKDEPS  = $(LIB_PREFIX)/makedeps.pl
105
+
106
+SESSION_LIB    = $(NAME)$(SHLIBEXT)
107
+FRONTEND_LIB   = $(NAME)_frontend$(SHLIBEXT)
108
+TEMPLATE_LIBS ?= $(SESSION_LIB) $(FRONTEND_LIB)
109
+TARGETS       ?= $(TEMPLATE_LIBS)
110
+
111
+VARS=$(filter-out common.vars,$(wildcard *.vars))
112
+HTML=$(VARS:.vars=.html)
113
+
114
+all: $(TARGETS)
115
+
116
+$(TEMPLATE_LIBS):
117
+       $(CC) $(LDFLAGS) $(LDFLAGS_TEMPLATELIB) -o $@ $^
118
+
119
+_template_index.c _template_index_frontend.c:
120
+       $(MKINDEX) $(NAME) $(^F) > $@
121
+
122
+%.c: %.t
123
+       $(COMPILE) $(NAME) $@ $(basename $<)
124
+
125
+install-sources:
126
+       $(INSTALL) -o $(RO_USER) -g $(RO_GROUP) -m $(PUBLIC_DIR) \
127
+         -d $(DESTDIR)$(PREFIX)/templates/$(NAME)
128
+       $(INSTALL) -o $(RO_USER) -g $(RO_GROUP) -m $(PUBLIC_FILE) \
129
+         *.t *.vars $(DESTDIR)$(PREFIX)/templates/$(NAME)
130
+
131
+install-libs: $(TEMPLATE_LIBS)
132
+       $(INSTALL) -o $(RO_USER) -g $(RO_GROUP) -m $(PUBLIC_DIR) \
133
+         -d $(DESTDIR)$(LIB_PREFIX)/templates
134
+       $(INSTALL) -o $(RO_USER) -g $(RO_GROUP) -m $(PUBLIC_FILE) \
135
+         $(TEMPLATE_LIBS) $(DESTDIR)$(LIB_PREFIX)/templates/
136
+
137
+clean:
138
+       rm -f $(TARGETS) *.html *.o *.c
139
+distclean: clean
140
+       rm -f *.d
141
+
142
+test: $(HTML)
143
+
144
+%.html: %.t %.vars common.vars
145
+       $(EXPAND) $@ $* common.vars $*.vars
146
+
147
+%_frontend.d: FRONTEND_FLAG = --frontend
148
+%_frontend.d: TEMPLATES = $(TEMPLATES_FRONTEND)
149
+export VPATH
150
+$(TEMPLATE_LIBS:$(SHLIBEXT)=.d):
151
+       $(MKDEPS) $(FRONTEND_FLAG) $(NAME) $(TEMPLATES) > $@
152
+       sed -ri 's/^(_template_index[^:]*)/\1 $@/' $@
153
+
154
+include $(TEMPLATE_LIBS:$(SHLIBEXT)=.d)
155
+
156
+.PHONY: all install-sources install-libs clean distclean test
157
+.DELETE_ON_ERROR: