/config.h
/config.make
/newpost
-/posts-tables.h
-/etag.h
+/posts-tables.c
/blog-*.c
blogz_PROGRAMS= $(cgis) $(tools)
$(BLOGZ_FCGI)_SRCS=blog.c posts.c $(blogz_TEMPLATES) blogio-fcgi.c fcgi.c
-$(BLOGZ_CGI)_SRCS=blog.c posts.c $(blogz_TEMPLATES) blogio-stdio.c
+$(BLOGZ_CGI)_SRCS=blog.c posts.c $(blogz_TEMPLATES) blogio-stdio.c
newpost_SRCS=newpost.c
-built_SRCS=$(sort $(foreach prog,$(blogz_PROGRAMS),$($(prog)_SRCS)))
-
dist_PROGRAMS=$(BLOGZ_CGI) $(BLOGZ_FCGI) newpost
dist_SRCS=$(sort $(foreach prog,$(dist_PROGRAMS),$($(prog)_SRCS)))
dist_EXTRA=Makefile \
README COPYING \
apache-site-cgi.conf apache-site.conf \
config.h.in \
- blogio.h etag.h fast-cgi.h fcgi.h posts.h template.h \
+ blogio.h fast-cgi.h fcgi.h posts.h template.h \
$(patsubst blog-%.c,template/blog-%.html.in,$(blogz_TEMPLATES)) \
makeindex.pl \
maketemplate.pl
all: $(blogz_PROGRAMS)
dist: blogz-$(dist_VERSION).tar.gz
-define make_program=
-$(1): $(2)
- $$(CC) -o $$@ $$(LDFLAGS) $$^ $$(LDLIBS)
-endef
+$(BLOGZ_FCGI): $($(BLOGZ_FCGI)_SRCS:.c=.o) posts-tables.o
+ $(CC) -o $@ $(LDFLAGS) $^ $(LDLIBS)
+
+$(BLOGZ_CGI): $($(BLOGZ_CGI)_SRCS:.c=.o) posts-tables.o
+ $(CC) -o $@ $(LDFLAGS) $^ $(LDLIBS)
-$(foreach prog,$(blogz_PROGRAMS),$(eval $(call make_program,$(prog),$($(prog)_SRCS:.c=.o))))
-#$(foreach prog,$(blogz_PROGRAMS),$(info $(call make_program,$(prog),$($(prog)_SRCS:.c=.o))))
+newpost: $(newpost_SRCS:.c=.o)
+ $(CC) -o $@ $(LDFLAGS) $^ $(LDLIBS)
# database indexing
-posts-tables.h: $(DB_POST) makeindex.pl
+posts-tables.c: $(DB_POST) makeindex.pl
./makeindex.pl $(DB_POST) > $@ || rm $@
-.deps/posts.d posts.o: posts-tables.h
# template compilation
blog-%.c: template/blog-%.html maketemplate.pl
./maketemplate.pl blog_send_$* $< > $@ || rm $@
-# the etag is related to cache management. it changes any time any of the blog contents could change.
-etag.h: posts-tables.h $(blogz_TEMPLATES)
- date --rfc-3339 ns | md5sum | awk '{ printf "static const char* etag = \"%s\";\n",$$1 }' > etag.h
-
-blog.o: etag.h
-
clean:
rm -f posts-tables.h $(blogz_TEMPLATES) config.make
rm -f *.o
$^
# Make management
-config.make: config.h Makefile
+config.make: config.h
sed -e 's@//@#//@' \
-e 's/^#define \([a-zA-Z0-9_]*\) "\(.*\)"/\1=\2/' \
-e 's/^#define \([a-zA-Z0-9_]*\) \(.*\)/\1=\2/' \
.INTERMEDIATE: $(blogz_TEMPLATES)
ifeq (,$(filter clean install-db dist,$(MAKECMDGOALS)))
+built_SRCS=$(sort $(foreach prog,$(blogz_PROGRAMS),$($(prog)_SRCS)))
-include $(patsubst %.c,.deps/%.d,$(built_SRCS))
endif
#include "posts.h"
#include "template.h"
#include "blogio.h"
-#include "etag.h"
static const char *db = DB_POST;
+extern const char etag[];
/**
* Basic CGI variable parser, silently truncates out of range values and other broken behaviour
}
close IN;
-print "static const postid_t post_id[] = {\n";
+print "#include \"posts.h\"\n";
+
+# the etag is related to cache management. it changes any time any of the blog contents could change.
+$etag = `date --rfc-3339 ns | md5sum`;
+$etag =~ s/ .*\n//;
+print "const char etag[] = \"$etag\";\n";
+
+print "const postid_t post_id[] = {\n";
$i = 0;
foreach $k (@allids) {
print " 0x$k,";
}
}
print "\n};\n";
+print "const int post_id_SIZEOF = sizeof(post_id)/sizeof(post_id[0]);\n";
-print "static const char *post_file[] = {\n";
+print "const char *post_file[] = {\n";
foreach $k (@allfiles) {
print "\"$k\",\n";
}
print "\n};\n";
-print "static const char *post_title[] = {\n";
+print "const char *post_title[] = {\n";
foreach $k (@alltitles) {
$k =~ s/"/\\"/g;
print "\"$k\",\n";
}
print "\n};\n";
-print "static const struct post_index post_index[] = {\n";
+print "const struct post_index post_index[] = {\n";
foreach $k (sort keys %bymonth) {
@foo = @{$bymonth{$k}};
}
print "};\n";
+print "const int post_index_SIZEOF = sizeof(post_index)/sizeof(post_index[0]);\n";
# build keyword index
%allmeta = ();
%bases = ();
$i = 0;
$base = 0;
-print "static const int post_tag_table"."[] = { ";
+print "const int post_tag_table"."[] = { ";
for $key (@keys) {
my @list = @{$bytag{$key}};
print "/* $key */ ";
}
print "};\n";
-print "static const struct post_tag post_tag[] = {\n";
+print "const struct post_tag post_tag[] = {\n";
$i = 0;
for $key (@keys) {
my @list = @{$bytag{$key}};
$i++;
}
print "};\n";
-
+print "const int post_tag_SIZEOF = sizeof(post_tag)/sizeof(post_tag[0]);\n";
# Build inverse index
my %allbits = ();
$i *= 2;
}
-print "static const uint64_t post_tagmap[] = {\n";
+print "const uint64_t post_tagmap[] = {\n";
$i = 0;
foreach $k (@allids) {
my $w = $allmeta{$k};
#include "config.h"
#include "posts.h"
-#include "posts-tables.h"
-#define post_id_SIZEOF (sizeof(post_id)/sizeof(post_id[0]))
-#define post_index_SIZEOF (sizeof(post_index)/sizeof(post_index[0]))
-#define post_tag_SIZEOF (sizeof(post_tag)/sizeof(post_tag[0]))
+// from post-tables.o
+extern const postid_t post_id[];
+extern const char *post_file[];
+extern const char *post_title[];
+extern const struct post_index post_index[];
+extern const int post_tag_table[];
+extern const struct post_tag post_tag[];
+extern const uint64_t post_tagmap[];
+
+extern const int post_id_SIZEOF;
+extern const int post_index_SIZEOF;
+extern const int post_tag_SIZEOF;
static int cmp_postid(const void *ap, const void *bp) {
const postid_t *a = ap;
* Find up to 'max' posts which are younger than or equal to post 'from'.
*/
int blog_posts(postid_t from, postid_t *ids, int max, postid_t *newer, postid_t *older) {
- int size =sizeof(post_id)/sizeof(post_id[0]);
+ int size = post_id_SIZEOF;
int i;
int j = 0;
#ifndef _POSTS_H
#define _POSTS_H
+#include <stdlib.h>
+#include <stdint.h>
+
struct post_index {
const char month[8];
int i0, i1;