summaryrefslogtreecommitdiff
path: root/Makefile
blob: 18efe6ef0965de35e67ca0e05af872225fafd3bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
INSTALL="install"
TAR="tar"
GREP="grep"
NODE="node"
NPM="npm"
DESTDIR="./dist"
PKG_VERSION := $( $(GREP) -Po '(?<="version": ")[^"]*' )
TMPDIR := $(shell mktemp -d)
# default modules
MODULES="php"

all: builddirs npm_dependencies swig htmlmin min-css min-js copy-img submodules
	
swig:
	$(NODE) node_modules/swig/bin/swig.js render -j dist.json templates/upload_logged.swig > $(CURDIR)/build/upload_logged.html
	$(NODE) node_modules/swig/bin/swig.js render -j dist.json templates/upload_unlogged.swig > $(CURDIR)/build/upload_unlogged.html
	$(NODE) node_modules/swig/bin/swig.js render -j dist.json templates/404.swig > $(CURDIR)/build/404.html

htmlmin:
	$(NODE) node_modules/htmlmin/bin/htmlmin $(CURDIR)/build/upload_logged.html -o $(CURDIR)/build/upload_logged.html
	$(NODE) node_modules/htmlmin/bin/htmlmin $(CURDIR)/build/upload_unlogged.html -o $(CURDIR)/build/upload_unlogged.html
	$(NODE) node_modules/htmlmin/bin/htmlmin $(CURDIR)/build/404.html -o $(CURDIR)/build/404.html

installdirs:
	mkdir -p $(DESTDIR)/ $(DESTDIR)/img
ifneq (,$(findstring php,$(MODULES)))
	mkdir -p $(DESTDIR)/classes $(DESTDIR)/includes
endif
ifneq (,$(findstring moe,$(MODULES)))
	mkdir -p $(DESTDIR)/moe/{css,fonts,includes,js,login,panel/css/font,panel/css/images,register,templates}
endif
	
min-css:
	$(NODE) $(CURDIR)/node_modules/.bin/cleancss --s0 $(CURDIR)/static/css/pomf.css > $(CURDIR)/build/pomf.min.css

min-js:
	echo "// @source https://github.com/pomf/pomf/tree/master/static/js" > $(CURDIR)/build/pomf.min.js 
	echo "// @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt Expat" >> $(CURDIR)/build/pomf.min.js
	$(NODE) $(CURDIR)/node_modules/.bin/uglifyjs  --screw-ie8 ./static/js/app.js >> $(CURDIR)/build/pomf.min.js 
	echo "// @license-end" >> $(CURDIR)/build/pomf.min.js

copy-img:
	cp -v $(CURDIR)/static/img/*.png $(CURDIR)/build/img/

copy-php:
ifneq ($(wildcard $(CURDIR)/static/php/.),)
	cp -rv $(CURDIR)/static/php/* $(CURDIR)/build/
else
	$(error The php submodule was not found)
endif

copy-moe:
ifneq ($(wildcard $(CURDIR)/moe/.),)
	cp -rv $(CURDIR)/moe $(CURDIR)/build/
else
	$(error The moe submodule was not found)
endif

install: installdirs
	cp -rv $(CURDIR)/build/* $(DESTDIR)/

dist:
	DESTDIR=$(TMPDIR)/pomf-$(PKGVERSION)
	export DESTDIR
	install
	$(TAR) cJf pomf-$(PKG_VERSION).tar.xz $(DESTDIR)
	rm -rf $(TMPDIR)
	
clean:
	rm -rvf $(CURDIR)/node_modules 
	rm -rvf $(CURDIR)/build
	
uninstall:
	rm -rvf $(DESTDIR)/
	
npm_dependencies:
	$(NPM) install

builddirs:
	mkdir -p $(CURDIR)/build $(CURDIR)/build/img 
ifneq (,$(findstring php,$(MODULES)))
	mkdir -p $(CURDIR)/build/classes $(CURDIR)/build/includes
endif
ifneq (,$(findstring moe,$(MODULES)))
	mkdir -p $(CURDIR)/build/moe/{css,fonts,includes,js,login,panel/css/font,panel/css/images,register,templates}
endif

submodules:
	$(info The following modules will be enabled: $(MODULES))
ifneq (,$(findstring php,$(MODULES)))
	$(MAKE) copy-php
endif
ifneq (,$(findstring moe,$(MODULES)))
	$(MAKE) copy-moe
endif