bouquins-bchs/Makefile
2017-04-03 21:06:29 +02:00

158 lines
4.0 KiB
Makefile

.SUFFIXES: .html .js .min.js
# The default installation is for a default-install OpenBSD box that's
# running HTTPS (only).
# File-system location (directory) of static media.
# See HTURI for the web-visible component.
HTDOCS = /usr/local/www/bouquins/
# URL location (path) of static media.
# See HTDOCS.
HTURI =
# File-system location (directory) of CGI script.
# See CGIURI.
CGIBIN = /usr/local/www/bouquins/cgi-bin
# File-system location of database.
# See RDDIR.
DATADIR = /usr/local/www/data
# Web-server relative location of system log file.
# This will have all logging messages by the system.
LOGFILE = /logs/system.log
# Compilation and link options.
# If on a static architecture, STATIC is -static; otherwise empty.
# I use /usr/local for kcgi and ksql, hence using them here.
STATIC = -static
CFLAGS += -I/usr/local/include
LDFLAGS += -L/usr/local/lib
# Web-server relative location of DATADIR.
# See DATADIR.
RDDIR = /data
# Name of installed CGI script, since some servers like to have ".cgi"
# appended to everything.
# See TARGET.
CGINAME = bouquins
# URL location (filename) of CGI script.
# See CGIBIN and CGINAME.
CGIURI = /cgi-bin/$(CGINAME)
# This is the name of the binary we're going to build.
# It differs from CGINAME in that it's the install source.
# See CGINAME.
TARGET = bouquins
# If on an HTTPS-only installation, should be "-DSECURE".
SECURE = -DSECURE
# File-system location (directory) of Swagger API.
APIDOCS = /var/www/htdocs/api-docs
# Override these with an optional local file.
sinclude GNUmakefile.local
DATABASE = metadata.db
OBJS = db.o db_author.o db_book.o db_series.o json.o main.o
EXT = externals
BOOTSTRAP_VERSION = 3.3.7
BOOTSTRAP_DIST = bootstrap-$(BOOTSTRAP_VERSION)-dist
BOOTSTRAP_URL = https://github.com/twbs/bootstrap/releases/download/v$(BOOTSTRAP_VERSION)/$(BOOTSTRAP_DIST).zip
BOOTSTRAP_TMP_ZIP = $(EXT)/bootstrap.zip
VUE_URL = https://vuejs.org/js/vue.min.js
VUEJS = $(EXT)/vue.min.js
HTMLS = index.html book.html author.html series.html search.html
JSMINS = index.min.js book.min.js author.min.js series.min.js search.min.js $(VUEJS)
CSS = $(EXT)/$(BOOTSTRAP_DIST)/css/bootstrap.min.css
FONTS = $(EXT)/$(BOOTSTRAP_DIST)/fonts/*
CFLAGS += -g -W -Wall -O2 $(SECURE)
CFLAGS += -DLOGFILE=\"$(LOGFILE)\"
CFLAGS += -DDATADIR=\"$(RDDIR)\"
CFLAGS += -DDATABASE=\"$(DATABASE)\"
VERSION = 0.0.0
.if defined(DEBUG)
CFLAGS += -DDEBUG
.endif
all: $(TARGET) $(HTMLS) $(JSMINS)
api: swagger.json
$(BOOTSTRAP_TMP_ZIP):
fetch -o $(BOOTSTRAP_TMP_ZIP) $(BOOTSTRAP_URL)
$(EXT)/$(BOOTSTRAP_DIST): $(BOOTSTRAP_TMP_ZIP)
unzip -d $(EXT) $(BOOTSTRAP_TMP_ZIP)
$(VUEJS):
fetch -o $(VUEJS) $(VUE_URL)
$(EXT): $(EXT)/$(BOOTSTRAP_DIST) $(VUEJS)
packwww: $(EXT) $(HTMLS) $(JSMINS)
mkdir -p build build/css build/fonts build/js
cp $(HTMLS) build
cp $(JSMINS) $(VUEJS) build/js
cp $(CSS) build/css
cp $(FONTS) build/fonts
packcgi: $(TARGET)
mkdir -p build/cgi-bin
cp $(TARGET) build/cgi-bin
cp $(OBJS) build/cgi-bin
package: packcgi packwww
tar czf bouquins.tar.gz -C build cgi-bin $(HTMLS) css js fonts
rm -rf build/*
installwww: all
mkdir -p $(HTDOCS) $(HTDOCS)/css $(HTDOCS)/fonts $(HTDOCS)/js
install -m 0444 $(HTMLS) $(HTDOCS)
install -m 0444 $(JSMINS) $(HTDOCS)/js
install -m 0444 $(CSS) $(HTDOCS)/css
install -m 0444 $(FONTS) $(HTDOCS)/fonts
installapi: api
mkdir -p $(APIDOCS)
install -m 0444 swagger.json $(APIDOCS)
updatecgi: all
mkdir -p $(CGIBIN)
install -m 0555 $(TARGET) $(CGIBIN)/$(CGINAME)
install -m 0555 $(OBJS) $(CGIBIN)/
installcgi: updatecgi
mkdir -p $(DATADIR)
chmod 0777 $(DATADIR)
clean:
rm -f $(TARGET) $(JSMINS) $(OBJS)
rm -f swagger.json
.js.min.js:
sed -e "s!@HTURI@!$(HTURI)!g" \
-e "s!@VERSION@!$(VERSION)!g" \
-e "s!@CGIURI@!$(CGIURI)!g" $< >$@
$(TARGET): $(OBJS)
$(CC) $(STATIC) -o $@ $(OBJS) $(LDFLAGS) -lksql -lkcgi -lkcgijson -lz -lsqlite3 -pthread
$(OBJS): extern.h
swagger.json: swagger.in.json
@rm -f $@
sed -e "s!@VERSION@!$(VERSION)!g" -e "s!@TARGET@!$(TARGET)!g" swagger.in.json >$@
@chmod 400 $@