From ad8da11f6d0664e0fb3c8707a869425088daea7e Mon Sep 17 00:00:00 2001
From: Rusty Russell
Date: Sun, 9 Nov 2008 01:46:34 +1100
Subject: [PATCH] Static generation of web pages. Based on GSoC work, and
still needs more polish (particularly uploading is untested).
---
Makefile | 63 +++++++++++---
Makefile-ccan | 11 +++
web/logo.html | 9 +-
web/menulist.html | 28 +++----
web/static-configuration | 74 +++++++++++++++++
web/staticall.php | 80 ++++++++++++++++++
web/staticindex.php | 77 +++++++++++++++++
web/staticmoduleinfo.php | 90 ++++++++++++++++++++
web/staticupload.php | 55 ++++++++++++
web/upload.php | 14 ++++
web/uploader.php | 175 +++------------------------------------
11 files changed, 486 insertions(+), 190 deletions(-)
create mode 100644 Makefile-ccan
create mode 100644 web/static-configuration
create mode 100644 web/staticall.php
create mode 100644 web/staticindex.php
create mode 100644 web/staticmoduleinfo.php
create mode 100644 web/staticupload.php
diff --git a/Makefile b/Makefile
index 6329f05b..e11ddc27 100644
--- a/Makefile
+++ b/Makefile
@@ -1,27 +1,74 @@
# Hacky makefile to compile everything and run the tests in some kind of sane order.
# V=--verbose for verbose tests.
+# This can be overridden on cmdline to generate pages elsewhere.
+WEBDIR=webpages/
+
CFLAGS=-g -Wall -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -Werror -Iccan -I.
ALL=$(patsubst ccan/%/test, %, $(wildcard ccan/*/test))
ALL_DIRS=$(patsubst %, ccan/%, $(ALL))
ALL_DEPENDS=$(patsubst %, ccan/%/.depends, $(ALL))
-ALL_LIBS=$(patsubst %, ccan/%.o, $(ALL))
+ALL_PAGES=$(patsubst ccan/%, $(WEBDIR)/info/%.html, $(ALL_DIRS))
+DIRECT_TARBALLS=$(patsubst ccan/%, $(WEBDIR)/tarballs/%.tar.bz2, $(ALL_DIRS))
+DEPEND_TARBALLS=$(patsubst ccan/%, $(WEBDIR)/tarballs/with-deps/%.tar.bz2, $(ALL_DIRS))
+WEB_SUBDIRS=$(WEBDIR)/tarballs $(WEBDIR)/tarballs/with-deps $(WEBDIR)/info
-libccan.a: $(ALL_LIBS)
- $(AR) r $@ $^
+include Makefile-ccan
check: $(ALL_DIRS:%=test-%)
distclean: clean
rm -f $(ALL_DEPENDS)
+ rm -rf $(WEBDIR)
+
+webpages: $(WEB_SUBDIRS) $(WEBDIR)/junkcode $(ALL_PAGES) $(WEBDIR)/list.html $(WEBDIR)/index.html $(WEBDIR)/upload.html $(WEBDIR)/example-config.h $(WEBDIR)/ccan.jpg $(DIRECT_TARBALLS) $(DEPEND_TARBALLS) $(WEBDIR)/ccan.tar.bz2 $(WEBDIR)/Makefile-ccan
+
+$(WEB_SUBDIRS):
+ mkdir -p $@
+
+$(WEBDIR)/junkcode:
+ cp -a junkcode $@
+
+# Override implicit attempt to link directory.
+$(ALL_DIRS):
+ @touch $@
+
+$(WEBDIR)/ccan.tar.bz2:
+ tar cvfj $@ `bzr ls --versioned --kind=file ccan`
+
+$(ALL_PAGES): tools/doc_extract web/staticmoduleinfo.php
+
+$(WEBDIR)/list.html: web/staticall.php tools/doc_extract $(DIRECT_TARBALLS) $(DEPEND_TARBALLS) $(WEBDIR)/ccan.tar.bz2
+ php5 web/staticall.php ccan/ $(WEBDIR) > $@
+
+$(WEBDIR)/upload.html: web/staticupload.php
+ php5 web/staticupload.php > $@
+
+$(WEBDIR)/index.html: web/staticindex.php
+ php5 web/staticindex.php > $@
+
+$(WEBDIR)/example-config.h: config.h
+ cp $< $@
+
+$(WEBDIR)/Makefile-ccan: Makefile-ccan
+ cp $< $@
+
+$(WEBDIR)/ccan.jpg: web/ccan.jpg
+ cp $< $@
+
+$(WEBDIR)/info/%.html: ccan/% ccan/%/test $(WEBDIR)/tarballs/%.tar.bz2 $(WEBDIR)/tarballs/with-deps/%.tar.bz2
+ URLPREFIX=../ php5 web/staticmoduleinfo.php ccan/$* > $@
+
+$(WEBDIR)/tarballs/%.tar.bz2: ccan/% ccan/%/test
+ tar -c -v -j -f $@ `bzr ls --versioned --kind=file ccan/$*`
+
+$(WEBDIR)/tarballs/with-deps/%.tar.bz2: ccan/% ccan/%/test tools/ccan_depends
+ tar cvfj $@ $$(echo ccan/$* $$(tools/ccan_depends ccan/$*) | xargs -n 1 bzr ls --versioned --kind=file)
$(ALL_DEPENDS): %/.depends: tools/ccan_depends
tools/ccan_depends $* > $@ || ( rm -f $@; exit 1 )
-$(ALL_LIBS):
- $(LD) -r -o $@ $^ /dev/null
-
test-ccan/%: tools/run_tests ccan/%.o
@echo Testing $*...
@if tools/run_tests $(V) ccan/$* | grep ^'not ok'; then exit 1; else exit 0; fi
@@ -38,10 +85,6 @@ inter-depends: $(ALL_DEPENDS)
test-depends: $(ALL_DEPENDS)
for f in $(ALL_DEPENDS); do echo test-ccan/`basename \`dirname $$f\``: `sed -n 's,ccan/\(.*\),test-ccan/\1,p' < $$f`; done > $@
-lib-depends: $(foreach D,$(ALL),$(wildcard $D/*.[ch]))
- for c in $(ALL); do echo ccan/$$c.o: `ls ccan/$$c/*.c | grep -v /_info.c | sed 's/.c$$/.o/'`; done > $@
-
include tools/Makefile
-include inter-depends
-include test-depends
--include lib-depends
diff --git a/Makefile-ccan b/Makefile-ccan
new file mode 100644
index 00000000..cbd9871c
--- /dev/null
+++ b/Makefile-ccan
@@ -0,0 +1,11 @@
+# Example makefile which makes a "libccan.a" of everything under ccan/
+# You could just do:
+# SRCFILES += $(shell find ccan/ -name '[a-z]*.c')
+
+CFLAGS=-g -O2 -Wall -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -Werror -Iccan -I.
+
+CFILES=$(wildcard ccan/*/[a-z]*.c)
+OBJFILES=$(CFILES:.c=.o)
+
+libccan.a: $(OBJFILES)
+ $(AR) r $@ $^
diff --git a/web/logo.html b/web/logo.html
index 7239556c..61c8f7e7 100644
--- a/web/logo.html
+++ b/web/logo.html
@@ -1,3 +1,8 @@
+
ccan
@@ -6,10 +11,10 @@
-
+
|
Comprehensive C Archieve Network
|
-
\ No newline at end of file
+
diff --git a/web/menulist.html b/web/menulist.html
index 7e0232cb..aa5993f5 100644
--- a/web/menulist.html
+++ b/web/menulist.html
@@ -1,30 +1,26 @@
diff --git a/web/static-configuration b/web/static-configuration
new file mode 100644
index 00000000..3ff84923
--- /dev/null
+++ b/web/static-configuration
@@ -0,0 +1,74 @@
+";
+ $raw=extract_field($field,$module);
+ foreach (explode("\n", $raw) as $line) {
+ if ($line == "") {
+ switch ($state) {
+ case "inpara":
+ $state="endpara";
+ $result .= "
";
+ break;
+ }
+ } else if ($line[0] == " " || $line[0] == "\t") {
+ switch ($state) {
+ case "literal":
+ break;
+ case "inpara":
+ $result .= "";
+ case "endpara":
+ $result .= "";
+ $state = "literal";
+ }
+ } else {
+ switch ($state) {
+ case "literal":
+ $result .= "
";
+ case "endpara":
+ $result .= "";
+ $state = "inpara";
+ }
+ }
+ $result .= $line . "\n";
+ }
+
+ switch ($state) {
+ case "literal":
+ $result .= "";
+ break;
+ case "inpara":
+ $result .= "
";
+ break;
+ }
+ return $result;
+}
+?>
diff --git a/web/staticall.php b/web/staticall.php
new file mode 100644
index 00000000..3a6407ff
--- /dev/null
+++ b/web/staticall.php
@@ -0,0 +1,80 @@
+
+
+ List of all CCAN modules:
+
+
+Note that two downloads are offered: the first includes with all the
+other ccan modules this module uses, the second is a standalone
+download.
+
+
+
+Or you can just download the tarball of everything (=$tarballsize?>K).
+
+
+
+Name |
+Summary / Link to details |
+Download |
+
+read())) {
+ if ($entry[0] != '.') {
+ array_push($modules, $entry);
+ }
+}
+sort($modules);
+
+foreach ($modules as $module) {
+ $summary=extract_field('summary',$argv[1].$module);
+ $with_deps="$tar_dir/with-deps/$module.tar.bz2";
+ $no_deps="$tar_dir/$module.tar.bz2";
+ $with_dep_size = round((filesize($argv[2]."/".$with_deps) + 1023) / 1024);
+ $no_dep_size = round((filesize($argv[2]."/".$no_deps) + 1023) / 1024);
+ ?>
+
+ =$module?> |
+ =$summary?> |
+ =$with_dep_size?>K /
+ =$no_dep_size?>K |
+
+ close();
+?>
+
+
+ Contents of Junkcode:
+
+(This is contributed code which was dumped here: these gems may need some polishing.)
+
+
+
+read())) {
+ if ($entry[0] != '.') {
+ array_push($files, $entry);
+ }
+}
+
+sort($files);
+foreach ($files as $file) {
+ $size = round((filesize($argv[2]."/junkcode/".$file) + 1023) / 1024);
+ echo "$file (${size}K) |
\n";
+}
+$d->close();
+?>
+
+
+
diff --git a/web/staticindex.php b/web/staticindex.php
new file mode 100644
index 00000000..9dace4e7
--- /dev/null
+++ b/web/staticindex.php
@@ -0,0 +1,77 @@
+
+
+The Idea
+
+
+That nice snippets of C code should be moved out of junkcode
+directories and exposed to a wider world, where they can become
+something useful.
+
+
+
+CCAN is loosely modelled after the succesful CPAN project
+for Perl code development and sharing.
+
+
+Getting The Code
+
+
+Once you grab some modules, there are two basic
+ways to use it:
+
+- Just hack it to compile in your project.
+
+
- Use it in place by giving it a "config.h" (steal
+ this example) and compiling all the .c
+ files which don't start with "_" (eg. as in this simple Makefile).
+
+
+
+
+There's also a
+Bazaar repository for all the CCAN
+infrastructure at
+http://ccan.ozlabs.org/repo.
+
+
+Module Contributions
+
+
+We welcome new code! The guide to creating new modules is a work in
+progress (just copy an existing module), but anyone can
+just upload code.
+
+
+
+"GPLv2 or later" and supersets thereof (eg. LGPLv2+ or BSD)
+licenses preferred.
+
+
+Complaints, Ideas and Infrastructure
+
+
+We have a low volume
+mailing list for discussion of CCAN in general, and you're welcome
+to join.
+
+
+
+
+We also have an IRC channel: #ccan on Freenode.
+
+
+
+We also have a wiki; feel free to enhance it.
+
+
+
+Rusty Russell
+
+
+
+