Various cleanup
[blerg.git] / Makefile
1 include libs.mk
2
3 ARCH=$(shell uname -m)
4 CFLAGS ?= -g -Wall
5 ifeq ($(ARCH),x86_64)
6         CFLAGS += -fPIC
7 endif
8 INCLUDES = -I. -Idatabase -Icommon -Ibuilddeps/scrypt-1.1.6/lib/crypto $(YAJL_INCLUDES)
9 HTTP_INCLUDES = -Ihttp $(MHD_INCLUDES)
10 CGI_INCLUDES = -Icgi $(CGI_UTIL_INCLUDES)
11 LDFLAGS ?=
12 HTTP_LIBDIRS = $(MHD_LIBDIR) $(YAJL_LIBDIR)
13 CGI_LIBDIRS = $(CGI_UTIL_LIBDIR) $(YAJL_LIBDIR)
14
15 targets = blerg.a blerg_auth.a blergtool blerglatest blerg.cgi perl-lib www/build/enyo-blerg.js
16 blerg_a_objects = database/database.o database/tags.o database/util.o database/configuration.o database/subscription.o common/stringbucket.o common/stringring.o
17 blerg_auth_a_objects = common/auth.o common/md5.o
18 blergtool_objects = tools/blergtool.o blerg.a
19 blerglatest_objects = tools/blerglatest.o blerg.a common/json.o
20 http_blerg_objects = http/http_blerg.o http/canned_responses.o common/app.o common/json.o blerg_auth.a builddeps/scrypt.a blerg.a
21 cgi_blerg_objects = cgi/cgi_blerg.o cgi/canned_responses.o common/app.o common/json.o blerg_auth.a builddeps/scrypt.a blerg.a
22
23 all: $(targets)
24
25 clean:
26         rm -f $(targets) $(blerg_a_objects) $(blerg_auth_a_objects) $(blergtool_objects) $(blerglatest_objects) $(http_blerg_objects) $(cgi_blerg_objects) builddeps/*.a
27         @-make -C builddeps/scrypt-1.1.6 distclean
28         @-make -C builddeps/scrypt-1.1.6/lib/crypto clean
29         @-make -C lib/perl/Blerg-Database clean
30
31 .PHONY: perl-lib
32 perl-lib:
33         cd lib/perl/Blerg-Database && perl Makefile.PL
34         make -C lib/perl/Blerg-Database
35
36 blerg.a: $(blerg_a_objects)
37         ar rcu $@ $(blerg_a_objects)
38
39 blerg_auth.a: builddeps/scrypt.a $(blerg_auth_a_objects)
40         ar rcu $@ $(blerg_auth_a_objects)
41
42 blergtool: $(blergtool_objects)
43         $(CC) $(LDFLAGS) $^ -o $@
44
45 blerglatest: $(blerglatest_objects)
46         $(CC) $(YAJL_LIBDIR) $(LDFLAGS) $^ -lyajl_s -o $@
47
48 blerg.httpd: $(http_blerg_objects)
49         $(CC) $(HTTP_LIBDIRS) $(LDFLAGS) $(http_blerg_objects) -lpthread -lmicrohttpd -lyajl_s -o $@
50
51 blerg.cgi: $(cgi_blerg_objects)
52         $(CC) $(CGI_LIBDIRS) $(LDFLAGS) $(cgi_blerg_objects) -lcgi-util -lyajl_s -o $@
53
54 http/%.o: http/%.c
55         $(CC) $(INCLUDES) $(HTTP_INCLUDES) $(CFLAGS) -c $< -o $@
56
57 cgi/%.o: cgi/%.c
58         $(CC) $(INCLUDES) $(CGI_INCLUDES) $(CFLAGS) -c $< -o $@
59
60 %.o: %.c
61         $(CC) $(INCLUDES) $(CFLAGS) -c $< -o $@
62
63 www/build/enyo-blerg.js: www/jssrc/blerg/* www/jssrc/package.js www/jssrc/package-min.js
64         which node >/dev/null   # Please install Node.js to re-minify the JS
65         cd www/jssrc && enyo/tools/minify.sh -output ../build/enyo-blerg -no-alias package-min.js
66
67 builddeps/scrypt-1.1.6/config.h:
68         cd builddeps/scrypt-1.1.6 && ./configure
69
70 builddeps/scrypt.a: builddeps/scrypt-1.1.6/config.h
71         make -C builddeps/scrypt-1.1.6/lib/crypto CFLAGS="$(CFLAGS)"
72         cp builddeps/scrypt-1.1.6/lib/crypto/scrypt.a builddeps/
73
74 .PHONY: docs
75 docs: www/doc/perl www/doc/perl/Blerg-Database.html
76
77 www/doc/perl:
78         mkdir $@
79
80 www/doc/perl/Blerg-Database.html: lib/perl/Blerg-Database/lib/Blerg/Database.pm
81         pod2html $< > $@
82
83 .PHONY: install
84 install:
85         @echo "Please use 'make install-environment' to install BlĂ«rg to an environment"
86
87 .PHONY: install-environment
88 install-environment: all docs
89         @if [ -z "$(ENV_DIR)" ]; then \
90                 echo "Specify the install directory in the ENV_DIR variable"; \
91                 exit 1; \
92         fi
93         install --mode 755 -d \
94                 $(ENV_DIR)/bin \
95                 $(ENV_DIR)/lib/cgi-bin \
96                 $(ENV_DIR)/etc \
97                 $(ENV_DIR)/data/data \
98                 $(ENV_DIR)/data/hash_tags \
99                 $(ENV_DIR)/data/ref_tags \
100                 $(ENV_DIR)/www/build \
101                 $(ENV_DIR)/www/css \
102                 $(ENV_DIR)/www/doc/perl \
103                 $(ENV_DIR)/www/images
104         install --mode 755 blerg.cgi rss.cgi $(ENV_DIR)/lib/cgi-bin/
105         install --mode 755 blergtool blerglatest $(ENV_DIR)/bin/
106         install --mode 644 www/favicon.gif www/favicon.ico www/index.html \
107                 www/welcome.html \
108                 $(ENV_DIR)/www/
109         install --mode 644 www/build/enyo-blerg.js www/build/enyo-blerg.css \
110                 $(ENV_DIR)/www/build/
111         install --mode 644 www/css/blerg.css www/css/doc.css \
112                 $(ENV_DIR)/www/css/
113         install --mode 644 www/doc/changelog.html www/doc/index.html \
114                 www/doc/post_help.html www/doc/privacy_data.html \
115                 www/doc/contact.html \
116                 $(ENV_DIR)/www/doc/
117         install --mode 644 www/doc/perl/Blerg-Database.html \
118                 $(ENV_DIR)/www/doc/perl/
119         install --mode 644 www/images/blerglogo.png www/images/corner.svg \
120                 www/images/play.png www/images/rss.png \
121                 $(ENV_DIR)/www/images/
122         www/jssrc/lib/onyx/deploy.sh $(ENV_DIR)/www/jssrc/lib/onyx
123         cd lib/perl/Blerg-Database && perl Makefile.PL INSTALL_BASE="$(ENV_DIR)"
124         make -C lib/perl/Blerg-Database install
125         perl scripts/write-environment-configs.pl $(ENV_DIR)