forked from mirrors/kore
new build script for modules, which should be used as a base for
all new modules written by others.
This commit is contained in:
parent
c9f5bb82c9
commit
ae5da79f61
2
README
2
README
|
@ -30,6 +30,6 @@ Platforms support
|
|||
Any other BSD might function, but is untested.
|
||||
|
||||
Right now Kore development is a moving process, so expect bugs.
|
||||
If you run into said bugs please contact me at patches@coders.se.
|
||||
If you run into said bugs please contact me at joris@coders.se.
|
||||
|
||||
More information can be found on https://kore.io/
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
*BSD support
|
||||
Auxiliary library framework
|
||||
Better logging facilities
|
||||
Ability to load one module per domain
|
||||
GET arguments (only POST supported)
|
||||
POST multiform/form-data support
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
# Example Kore module
|
||||
|
||||
.SUFFIXES: .html .css
|
||||
|
||||
CC=gcc
|
||||
BIN=example.module
|
||||
|
||||
HTML= html/index.html html/profile.html
|
||||
H_SRCS= $(HTML:.html=.c)
|
||||
|
||||
CSS= css/style.css
|
||||
C_SRCS= $(CSS:.css=.c)
|
||||
|
||||
S_SRC= src/example.c $(H_SRCS) $(C_SRCS)
|
||||
S_OBJS= $(S_SRC:.c=.o)
|
||||
|
||||
CFLAGS+=-I. -I../includes
|
||||
CFLAGS+=-Wall -Wstrict-prototypes -Wmissing-prototypes
|
||||
CFLAGS+=-Wmissing-declarations -Wshadow -Wpointer-arith -Wcast-qual
|
||||
CFLAGS+=-Wsign-compare -g
|
||||
LDFLAGS+=-shared
|
||||
|
||||
all:
|
||||
make clean
|
||||
make example.module
|
||||
|
||||
example.module: html_inject $(H_SRCS) $(C_SRCS) $(S_OBJS)
|
||||
$(CC) $(LDFLAGS) $(S_OBJS) -o $(BIN)
|
||||
make clean_o
|
||||
|
||||
html_inject: tools/html_inject.c
|
||||
$(CC) $(CFLAGS) tools/html_inject.c -o tools/html_inject
|
||||
|
||||
.html.c:
|
||||
tools/html_inject $< `basename $<` > $@
|
||||
|
||||
.css.c:
|
||||
tools/html_inject $< `basename $<` > $@
|
||||
|
||||
.c.o:
|
||||
$(CC) -fPIC $(CFLAGS) -c $< -o $@
|
||||
|
||||
clean:
|
||||
make clean_o
|
||||
rm -f css/*.c html/*.c tools/html_inject $(BIN)
|
||||
rm -f static.h
|
||||
|
||||
clean_o:
|
||||
rm -f css/*.o html/*.o src/*.o
|
|
@ -1,14 +0,0 @@
|
|||
<!DOCTYPE>
|
||||
<head>
|
||||
<link rel="stylesheet" href="/css/style.css" type="text/css">
|
||||
<title>Your KORE module worked!</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div class="content">
|
||||
<p>This is a dynamic (regex) path example</p>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,71 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2013 Joris Vink <joris@coders.se>
|
||||
#
|
||||
# Kore module build script, use this as a base for building
|
||||
# your own modules for kore.
|
||||
|
||||
# The name of the module you will be building
|
||||
MODULE=example.module
|
||||
|
||||
# The directory containing all your media files (HTML, CSS, ...).
|
||||
# These files will be compiled into the module and symbols will
|
||||
# be exported for you to use in your code (see static.h after building).
|
||||
MEDIA_DIR=media
|
||||
|
||||
# The directory containing your module source.
|
||||
SOURCE_DIR=src
|
||||
|
||||
# The directory containing the Kore source code.
|
||||
KORE_DIR=../../
|
||||
|
||||
# Compiler settings.
|
||||
CC=gcc
|
||||
CFLAGS="-I. -I${KORE_DIR}includes -Wall -Wstrict-prototypes \
|
||||
-Wmissing-prototypes -Wmissing-declarations -Wshadow \
|
||||
-Wpointer-arith -Wcast-qual -Wsign-compare -g"
|
||||
LDFLAGS+=-shared
|
||||
|
||||
# Functions used in the build process.
|
||||
function create_and_empty_dir {
|
||||
if [ ! -d $1 ]; then
|
||||
mkdir $1;
|
||||
fi
|
||||
|
||||
rm -f $1/*
|
||||
}
|
||||
|
||||
### Begin building ####
|
||||
echo "Building module ${MODULE}..."
|
||||
rm -f ${MODULE}
|
||||
|
||||
${CC} ${CFLAGS} tools/inject.c -o tools/inject
|
||||
|
||||
create_and_empty_dir ${SOURCE_DIR}/${MEDIA_DIR}
|
||||
create_and_empty_dir .objs
|
||||
|
||||
for file in `find ${MEDIA_DIR} -type f`; do
|
||||
echo "Injecting $file";
|
||||
base=`basename $file`;
|
||||
./tools/inject $file $base > ${SOURCE_DIR}/${MEDIA_DIR}/${base}.c;
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Injection error, check above messages for clues.";
|
||||
exit 1;
|
||||
fi
|
||||
done
|
||||
|
||||
for src in `find ${SOURCE_DIR} -type f`; do
|
||||
base=`basename $src`;
|
||||
${CC} ${CFLAGS} -fPIC -c $src -o .objs/${base}.o
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Build error, check above messages for clues.";
|
||||
exit 1;
|
||||
fi
|
||||
done
|
||||
|
||||
${CC} ${LDFLAGS} `find .objs -name \*.o -type f` -o ${MODULE}
|
||||
echo "Building completed!"
|
||||
|
||||
rm -rf ${SOURCE_DIR}/${MEDIA_DIR}
|
||||
rm -rf .objs
|
||||
rm -f tools/inject
|
|
@ -1,4 +1,5 @@
|
|||
<!DOCTYPE>
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="/css/style.css" type="text/css">
|
||||
<title>Your KORE module worked!</title>
|
|
@ -20,7 +20,7 @@ workers 2
|
|||
#onload myinit
|
||||
|
||||
# Specifies what module to be loaded.
|
||||
load example/example.module
|
||||
load ./example.module
|
||||
|
||||
# Domain configuration
|
||||
#
|
||||
|
@ -46,7 +46,6 @@ domain 10.211.55.3 {
|
|||
accesslog /var/log/kore_access.log
|
||||
static /css/style.css serve_style_css
|
||||
static / serve_index
|
||||
dynamic ^/[a-z0-9_]*$ serve_profile
|
||||
}
|
||||
|
||||
#domain domain.com {
|
|
@ -42,7 +42,6 @@
|
|||
|
||||
int serve_style_css(struct http_request *);
|
||||
int serve_index(struct http_request *);
|
||||
int serve_profile(struct http_request *);
|
||||
|
||||
int
|
||||
serve_style_css(struct http_request *req)
|
||||
|
@ -85,15 +84,3 @@ serve_index(struct http_request *req)
|
|||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int
|
||||
serve_profile(struct http_request *req)
|
||||
{
|
||||
int ret;
|
||||
|
||||
http_response_header_add(req, "content-type", "text/html");
|
||||
ret = http_response(req, 200, static_html_profile,
|
||||
static_len_html_profile);
|
||||
|
||||
return (ret);
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
extern u_int8_t static_css_style[];
|
||||
extern u_int32_t static_len_css_style;
|
||||
extern time_t static_mtime_css_style;
|
||||
extern u_int8_t static_html_index[];
|
||||
extern u_int32_t static_len_html_index;
|
||||
extern time_t static_mtime_html_index;
|
||||
extern u_int8_t static_css_style[];
|
||||
extern u_int32_t static_len_css_style;
|
||||
extern time_t static_mtime_css_style;
|
||||
extern u_int8_t static_html_index[];
|
||||
extern u_int32_t static_len_html_index;
|
||||
extern time_t static_mtime_html_index;
|
||||
extern u_int8_t static_css_style[];
|
||||
extern u_int32_t static_len_css_style;
|
||||
extern time_t static_mtime_css_style;
|
||||
extern u_int8_t static_html_index[];
|
||||
extern u_int32_t static_len_html_index;
|
||||
extern time_t static_mtime_html_index;
|
|
@ -20,6 +20,7 @@
|
|||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -29,52 +30,66 @@ int
|
|||
main(int argc, char *argv[])
|
||||
{
|
||||
struct stat st;
|
||||
size_t len;
|
||||
FILE *fp, *hdr;
|
||||
char *ext, *p, *c, buf[1024];
|
||||
ssize_t len;
|
||||
FILE *hdr;
|
||||
char *ext, c[1];
|
||||
int fd, newline, count;
|
||||
|
||||
if (argc != 3)
|
||||
err(1, "arguments");
|
||||
if ((fp = fopen(argv[1], "r")) == NULL)
|
||||
err(1, "fopen() %d", errno);
|
||||
exit(1);
|
||||
|
||||
if ((fd = open(argv[1], O_RDONLY)) == -1)
|
||||
err(1, "open() %d", errno);
|
||||
if ((hdr = fopen("static.h", "a+")) == NULL)
|
||||
err(1, "fopen() %d", errno);
|
||||
if ((ext = strchr(argv[2], '.')) != NULL)
|
||||
*(ext)++ = '\0';
|
||||
else
|
||||
ext = "";
|
||||
|
||||
if (stat(argv[1], &st) == -1) {
|
||||
printf("stat(%s) failed: %d\n", argv[1], errno);
|
||||
exit(99);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
printf("/**** AUTO GENERATED BY MAKEFILE - DO NOT TOUCH ****/\n");
|
||||
printf("#include <sys/param.h>\n\n");
|
||||
printf("u_int8_t *static_%s_%s = (u_int8_t *)", ext, argv[2]);
|
||||
printf("u_int8_t static_%s_%s[] = {", ext, argv[2]);
|
||||
|
||||
len = 0;
|
||||
while (fgets(buf, sizeof(buf), fp)) {
|
||||
if ((p = strchr(buf, '\n')) != NULL)
|
||||
*p = '\0';
|
||||
|
||||
printf("\n\t\"");
|
||||
for (c = buf; *c != '\0'; c++) {
|
||||
if (*c == '"' || *c == '\\')
|
||||
printf("\\");
|
||||
printf("%c", *c);
|
||||
len++;
|
||||
count = 0;
|
||||
newline = 1;
|
||||
for (;;) {
|
||||
if (newline) {
|
||||
printf("\n\t");
|
||||
count = 0;
|
||||
newline = 0;
|
||||
}
|
||||
|
||||
printf("\\n\"");
|
||||
len++;
|
||||
len = read(fd, c, 1);
|
||||
if (len == 0)
|
||||
break;
|
||||
|
||||
if (len == -1) {
|
||||
printf("read(): %d\n", errno);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (len != 1)
|
||||
exit(1);
|
||||
|
||||
printf("0x%02x, ", c[0]);
|
||||
if (count++ == 10)
|
||||
newline = 1;
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
close(fd);
|
||||
|
||||
printf(";\n\n");
|
||||
printf("u_int32_t static_len_%s_%s = %ld;\n", ext, argv[2], len);
|
||||
printf("};\n\n");
|
||||
printf("u_int32_t static_len_%s_%s = %ld;\n", ext, argv[2], st.st_size);
|
||||
printf("time_t static_mtime_%s_%s = %ld;\n", ext, argv[2], st.st_mtime);
|
||||
|
||||
fprintf(hdr, "extern u_int8_t *static_%s_%s;\n", ext, argv[2]);
|
||||
fprintf(hdr, "extern u_int8_t static_%s_%s[];\n", ext, argv[2]);
|
||||
fprintf(hdr, "extern u_int32_t static_len_%s_%s;\n", ext, argv[2]);
|
||||
fprintf(hdr, "extern time_t static_mtime_%s_%s;\n", ext, argv[2]);
|
||||
fclose(hdr);
|
Loading…
Reference in New Issue