Subversion Repositories

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

Rev 104 | Rev 113 | Go to most recent revision | 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
 
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
107 magnus 91
@@ -0,0 +1,67 @@
104 magnus 92
+ifndef NAME
93
+NAME := $(notdir $(CURDIR))
94
+endif
95
+
96
+CPPFLAGS = -I/usr/include/prayer
107 magnus 97
+CFLAGS += -fPIC
98
+LDFLAGS_TEMPLATELIB = -shared -fPIC \
104 magnus 99
+       -Wl,--defsym=template_map=template_map_$(NAME) \
100
+       -Wl,--defsym=template_map_count=template_map_$(NAME)_count
101
+
102
+EXPAND  = $(LIB_PREFIX)/template_expand
103
+COMPILE = $(LIB_PREFIX)/template_compile
104
+MKINDEX = $(LIB_PREFIX)/build_index.pl
105
+MKDEPS  = $(LIB_PREFIX)/makedeps.pl
106
+
107
+SESSION_LIB    = $(NAME)$(SHLIBEXT)
108
+FRONTEND_LIB   = $(NAME)_frontend$(SHLIBEXT)
109
+TEMPLATE_LIBS ?= $(SESSION_LIB) $(FRONTEND_LIB)
110
+TARGETS       ?= $(TEMPLATE_LIBS)
111
+
112
+VARS=$(filter-out common.vars,$(wildcard *.vars))
113
+HTML=$(VARS:.vars=.html)
114
+
115
+all: $(TARGETS)
116
+
117
+$(TEMPLATE_LIBS):
118
+       $(CC) $(LDFLAGS) $(LDFLAGS_TEMPLATELIB) -o $@ $^
119
+
120
+_template_index.c _template_index_frontend.c:
121
+       $(MKINDEX) $(NAME) $(^F) > $@
122
+
123
+%.c: %.t
124
+       $(COMPILE) $(NAME) $@ $(basename $<)
125
+
126
+install-sources:
127
+       $(INSTALL) -o $(RO_USER) -g $(RO_GROUP) -m $(PUBLIC_DIR) \
128
+         -d $(DESTDIR)$(PREFIX)/templates/$(NAME)
129
+       $(INSTALL) -o $(RO_USER) -g $(RO_GROUP) -m $(PUBLIC_FILE) \
130
+         *.t *.vars $(DESTDIR)$(PREFIX)/templates/$(NAME)
131
+
132
+install-libs: $(TEMPLATE_LIBS)
133
+       $(INSTALL) -o $(RO_USER) -g $(RO_GROUP) -m $(PUBLIC_DIR) \
134
+         -d $(DESTDIR)$(LIB_PREFIX)/templates
135
+       $(INSTALL) -o $(RO_USER) -g $(RO_GROUP) -m $(PUBLIC_FILE) \
136
+         $(TEMPLATE_LIBS) $(DESTDIR)$(LIB_PREFIX)/templates/
137
+
138
+clean:
139
+       rm -f $(TARGETS) *.html *.o *.c
140
+distclean: clean
141
+       rm -f *.d
142
+
143
+test: $(HTML)
144
+
145
+%.html: %.t %.vars common.vars
146
+       $(EXPAND) $@ $* common.vars $*.vars
147
+
148
+%_frontend.d: FRONTEND_FLAG = --frontend
149
+%_frontend.d: TEMPLATES = $(TEMPLATES_FRONTEND)
150
+export VPATH
151
+$(TEMPLATE_LIBS:$(SHLIBEXT)=.d):
152
+       $(MKDEPS) $(FRONTEND_FLAG) $(NAME) $(TEMPLATES) > $@
153
+       sed -ri 's/^(_template_index[^:]*)/\1 $@/' $@
154
+
155
+include $(TEMPLATE_LIBS:$(SHLIBEXT)=.d)
156
+
157
+.PHONY: all install-sources install-libs clean distclean test
158
+.DELETE_ON_ERROR: