blob: 5d8677e079990396f01f91348537350822f759b5 [file] [log] [blame]
Luigi Santivettid93cb0f2020-02-17 22:21:28 +00001PY?=python3
2PELICAN?=pelican
3PELICANOPTS=
4
5BASEDIR=$(CURDIR)
Luigi Santivettid93cb0f2020-02-17 22:21:28 +00006CONFFILE=$(BASEDIR)/pelicanconf.py
7PUBLISHCONF=$(BASEDIR)/publishconf.py
Luigi Santivetti6ce0e132020-10-07 23:28:00 +01008OUTPUTDIR=$(BASEDIR)/output
9OUTPUTDIR_THEME=$(OUTPUTDIR)/theme
10OUTPUTDIR_PHOTOS=$(OUTPUTDIR)/photos
11OUTPUTDIR_VIDEOS=$(OUTPUTDIR)/videos
12
13ifeq ($(PELICAN_CONTENT),)
14 INPUTDIR=$(BASEDIR)/content
15else
16 INPUTDIR=$(PELICAN_CONTENT)
17endif
Luigi Santivettid93cb0f2020-02-17 22:21:28 +000018
19FTP_HOST=localhost
20FTP_USER=anonymous
21FTP_TARGET_DIR=/
22
23SSH_HOST=localhost
24SSH_PORT=22
25SSH_USER=root
26SSH_TARGET_DIR=/var/www
27
28S3_BUCKET=my_s3_bucket
29
30CLOUDFILES_USERNAME=my_rackspace_username
31CLOUDFILES_API_KEY=my_rackspace_api_key
32CLOUDFILES_CONTAINER=my_cloudfiles_container
33
34DROPBOX_DIR=~/Dropbox/Public/
35
36GITHUB_PAGES_BRANCH=gh-pages
37
Luigi Santivetti6ce0e132020-10-07 23:28:00 +010038INSTALLSUDO ?= 0
39ifeq ($(INSTALLSUDO),1)
40 SUDO := sudo -E
41endif
42INSTALLFLAGS := $(INSTALLFLAGS) -rXaA
43INSTALLDIR ?=
44# Copy the whole directory theme
45INSTALLDIR_THEME ?=
46# Copy contents only
47INSTALLDIR_PHOTOS ?=
48INSTALLDIR_VIDEOS ?=
Luigi Santivettid93cb0f2020-02-17 22:21:28 +000049
50DEBUG ?= 0
51ifeq ($(DEBUG), 1)
52 PELICANOPTS += -D
53endif
54
55RELATIVE ?= 0
56ifeq ($(RELATIVE), 1)
57 PELICANOPTS += --relative-urls
58endif
59
60help:
61 @echo 'Makefile for a pelican Web site '
62 @echo ' '
63 @echo 'Usage: '
64 @echo ' make html (re)generate the web site '
Luigi Santivetti6ce0e132020-10-07 23:28:00 +010065 @echo ' make clean-html remove all html files and folders '
66 @echo ' make clean-theme remove output/theme '
67 @echo ' make clean-photos remove output/photos '
68 @echo ' make clean-videos remove output/videos '
69 @echo ' make distclean remove output and __pycache__ '
70 @echo ' make clean remove output folder '
Luigi Santivettid93cb0f2020-02-17 22:21:28 +000071 @echo ' make regenerate regenerate files upon modification '
72 @echo ' make publish generate using production settings '
73 @echo ' make serve [PORT=8000] serve site at http://localhost:8000'
74 @echo ' make serve-global [SERVER=0.0.0.0] serve (as root) to $(SERVER):80 '
75 @echo ' make devserver [PORT=8000] start/restart develop_server.sh '
76 @echo ' make stopserver stop local server '
77 @echo ' make ssh_upload upload the web site via SSH '
78 @echo ' make rsync_upload upload the web site via rsync+ssh '
79 @echo ' make dropbox_upload upload the web site via Dropbox '
80 @echo ' make ftp_upload upload the web site via FTP '
81 @echo ' make s3_upload upload the web site via S3 '
82 @echo ' make cf_upload upload the web site via Cloud Files'
83 @echo ' make github upload the web site via gh-pages '
Luigi Santivetti6ce0e132020-10-07 23:28:00 +010084 @echo ' make install-html copy *.html, html folders locally '
85 @echo ' make install-theme copy output/theme locally '
86 @echo ' make install-photos copy output/photos locally '
87 @echo ' make install-videos copy output/videos locally '
88 @echo ' make install copy output/* locally '
Luigi Santivettid93cb0f2020-02-17 22:21:28 +000089 @echo ' '
90 @echo 'Set the DEBUG variable to 1 to enable debugging, e.g. make DEBUG=1 html '
91 @echo 'Set the RELATIVE variable to 1 to enable relative urls '
92 @echo ' '
93
94html:
95 $(PELICAN) $(INPUTDIR) -o $(OUTPUTDIR) -s $(CONFFILE) $(PELICANOPTS)
96
Luigi Santivetti6ce0e132020-10-07 23:28:00 +010097clean-html:
98 find "$(OUTPUTDIR)" -type f -name *.html -delete
99 find "$(OUTPUTDIR)" -type d -empty -delete
100
101clean-theme:
102 [ ! -d "$(OUTPUTDIR_THEME)" ] || rm -rf $(OUTPUTDIR_THEME)
103
104clean-photos:
105 [ ! -d "$(OUTPUTDIR_PHOTOS)" ] || rm -rf $(OUTPUTDIR_PHOTOS)
106
107clean-videos:
108 [ ! -d "$(OUTPUTDIR_VIDEOS)" ] || rm -rf $(OUTPUTDIR_VIDEOS)
109
Luigi Santivettid93cb0f2020-02-17 22:21:28 +0000110clean:
Luigi Santivetti6ce0e132020-10-07 23:28:00 +0100111 [ ! -d "$(OUTPUTDIR)" ] || rm -rf $(OUTPUTDIR)
112
113distclean: clean
114 find $(BASEDIR) -type d -name "__pycache__" -exec rm -rf '{}' '+'
Luigi Santivettid93cb0f2020-02-17 22:21:28 +0000115
116regenerate:
117 $(PELICAN) -r $(INPUTDIR) -o $(OUTPUTDIR) -s $(CONFFILE) $(PELICANOPTS)
118
119serve:
120ifdef PORT
121 cd $(OUTPUTDIR) && $(PY) -m pelican.server $(PORT)
122else
123 cd $(OUTPUTDIR) && $(PY) -m pelican.server
124endif
125
126serve-global:
127ifdef SERVER
128 cd $(OUTPUTDIR) && $(PY) -m pelican.server 80 $(SERVER)
129else
130 cd $(OUTPUTDIR) && $(PY) -m pelican.server 80 0.0.0.0
131endif
132
133
134devserver:
135ifdef PORT
136 $(BASEDIR)/develop_server.sh restart $(PORT)
137else
138 $(BASEDIR)/develop_server.sh restart
139endif
140
141stopserver:
142 $(BASEDIR)/develop_server.sh stop
143 @echo 'Stopped Pelican and SimpleHTTPServer processes running in background.'
144
145publish:
146 $(PELICAN) $(INPUTDIR) -o $(OUTPUTDIR) -s $(PUBLISHCONF) $(PELICANOPTS)
147
148ssh_upload: publish
149 scp -P $(SSH_PORT) -r $(OUTPUTDIR)/* $(SSH_USER)@$(SSH_HOST):$(SSH_TARGET_DIR)
150
151rsync_upload: publish
152 rsync -e "ssh -p $(SSH_PORT)" -P -rvzc --delete $(OUTPUTDIR)/ $(SSH_USER)@$(SSH_HOST):$(SSH_TARGET_DIR) --cvs-exclude
153
154dropbox_upload: publish
155 cp -r $(OUTPUTDIR)/* $(DROPBOX_DIR)
156
157ftp_upload: publish
158 lftp ftp://$(FTP_USER)@$(FTP_HOST) -e "mirror -R $(OUTPUTDIR) $(FTP_TARGET_DIR) ; quit"
159
160s3_upload: publish
161 s3cmd sync $(OUTPUTDIR)/ s3://$(S3_BUCKET) --acl-public --delete-removed --guess-mime-type --no-mime-magic --no-preserve
162
163cf_upload: publish
164 cd $(OUTPUTDIR) && swift -v -A https://auth.api.rackspacecloud.com/v1.0 -U $(CLOUDFILES_USERNAME) -K $(CLOUDFILES_API_KEY) upload -c $(CLOUDFILES_CONTAINER) .
165
166github: publish
167 ghp-import -m "Generate Pelican site" -b $(GITHUB_PAGES_BRANCH) $(OUTPUTDIR)
168 git push origin $(GITHUB_PAGES_BRANCH)
169
Luigi Santivetti6ce0e132020-10-07 23:28:00 +0100170install-html:
171 [ -d "$(OUTPUTDIR)" ] && [ -d "$(INSTALLDIR)" ] && \
172 $(SUDO) rsync $(INSTALLFLAGS) \
173 --exclude=$(notdir $(OUTPUTDIR_THEME)) \
174 --exclude=$(notdir $(OUTPUTDIR_PHOTOS)) \
175 --exclude=$(notdir $(OUTPUTDIR_VIDEOS)) \
176 $(OUTPUTDIR)/* $(INSTALLDIR)
177
178install-theme:
179 [ -d "$(OUTPUTDIR_THEME)" ] && [ -d "$(INSTALLDIR_THEME)" ] && \
180 $(SUDO) rsync $(INSTALLFLAGS) $(OUTPUTDIR_THEME) $(INSTALLDIR_THEME)/
181
182install-photos:
183 [ ! -d "$(OUTPUTDIR_PHOTOS)" ] && { echo "Nothing to do for: install-photos"; \
184 exit 0; } || [ -d "$(INSTALLDIR_PHOTOS)" ] && \
185 $(SUDO) rsync $(INSTALLFLAGS) $(OUTPUTDIR_PHOTOS)/ $(INSTALLDIR_PHOTOS)
186
187install-videos:
188 [ ! -d "$(OUTPUTDIR_VIDEOS)" ] && { echo "Nothing to do for: install-videos"; \
189 exit 0; } || [ -d "$(INSTALLDIR_VIDEOS)" ] && \
190 $(SUDO) rsync $(INSTALLFLAGS) $(OUTPUTDIR_VIDEOS)/ $(INSTALLDIR_VIDEOS)
191
192install: install-html install-theme install-photos install-videos
Luigi Santivettid93cb0f2020-02-17 22:21:28 +0000193
194
Luigi Santivetti6ce0e132020-10-07 23:28:00 +0100195.PHONY: html help clean clean-html clean-theme clean-photos regenerate serve serve-global devserver stopserver publish ssh_upload rsync_upload dropbox_upload ftp_upload s3_upload cf_upload github install install-html install-theme install-photos