-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
217 lines (193 loc) · 7.59 KB
/
Makefile
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
SYNTAX_HIGHLIGHTER=1
PYGMENTS=1
COMPONENTS :=
ifeq ($(strip $(SYNTAX_HIGHLIGHTER)),1)
COMPONENTS += syntax_highlighter
endif
ifeq ($(strip $(PYGMENTS)),1)
COMPONENTS += pygments
endif
JS_DIR := js
CSS_DIR := css
TMPL_DIR := templates
PYGMENTS_SCRIPT := pygmentize
PYGMENTS_INSTALLED := $(strip $(shell which $(PYGMENTS_SCRIPT)))
PYGMENTS_CSS_DIR := $(CSS_DIR)/pygments
PYGMENTS_TMPL := $(TMPL_DIR)/pygments_template.txt
SH_CSS_DIR := $(CSS_DIR)/syntax_highlighter
SH_JS_DIR := $(JS_DIR)/syntax_highlighter
SH_CORE_CSS_FILES := shCore.css shCoreDefault.css
SH_CORE_JS_FILES := shCore.js
SH_TMPL := $(TMPL_DIR)/syntax_highlighter_template.txt
SH_CSS_BASE_URL := http://alexgorbatchev.com/pub/sh/current/styles
SH_PROJ_PAGE_THEMES_URL := http://alexgorbatchev.com/SyntaxHighlighter/manual/themes/
SH_PROJ_PAGE_JS_URL := http://alexgorbatchev.com/SyntaxHighlighter/manual/brushes/
SH_JS_BASE_URL := http://alexgorbatchev.com/pub/sh/current/scripts
VIM_EXT_DIR := $(HOME)/.vim
VIM_PLUGIN_DIR := $(HOME)/.vim/plugin
VIM_AFTER_SYNTAX_DIR := $(HOME)/.vim/after/syntax
R2H_VIM_PLUGIN_TARGET := $(VIM_PLUGIN_DIR)/rst_html_util.vim
R2H_VIM_AFTER_SYNTAX_TARGET := $(VIM_AFTER_SYNTAX_DIR)/rst.vim
all: $(COMPONENTS) install_vim_files
help:
@echo
@echo " -----------------------------------"
@echo " Makefile Target Help"
@echo " -----------------------------------"
@echo
@echo " Use this Makefile to build/update "
@echo " pygments and SyntaxHighlighter templates"
@echo " and build/download/update any necessary css"
@echo " and/or javascript themes + syntax highlighting"
@echo " rules."
@echo
@echo " To build with support for all syntax highlighting libs (default):"
@echo " make all"
@echo
@echo " To build without pygments support:"
@echo " make PYGMENTS=0"
@echo
@echo " To build without SyntaxHighlighter support:"
@echo " make SYNTAX_HIGHLIGHTER=0"
@echo
install_vim_files:
@echo "-------------------------------------------------------"
@echo "Installing plugin files to $(VIM_EXT_DIR)"
@echo "-------------------------------------------------------"
if [ -d "$(VIM_EXT_DIR)" ]; then \
mkdir -p $(VIM_PLUGIN_DIR) ; \
mkdir -p $(VIM_AFTER_SYNTAX_DIR) ; \
if [ -e "$(R2H_VIM_PLUGIN_TARGET)" ] \
|| [ -L "$(R2H_VIM_PLUGIN_TARGET)" ]; then \
overwrite=N ; \
prompt='File $(R2H_VIM_PLUGIN_TARGET) exists. Overwrite? [Y/N]: ' ; \
read -p "$$prompt" overwrite ; \
if [ "$$overwrite" = Y ]; then \
$(RM) "$(R2H_VIM_PLUGIN_TARGET)" ; \
ln -s $(PWD)/vim/rst_html_util.vim "$(R2H_VIM_PLUGIN_TARGET)" ; \
fi ; \
else \
echo $(R2H_VIM_PLUGIN_TARGET) ; \
ln -s $(PWD)/vim/rst_html_util.vim "$(R2H_VIM_PLUGIN_TARGET)" ; \
fi ; \
if [ -e "$(R2H_VIM_AFTER_SYNTAX_TARGET)" ] \
|| [ -L "$(R2H_VIM_AFTER_SYNTAX_TARGET)" ]; then \
overwrite=N ; \
prompt='File $(R2H_VIM_AFTER_SYNTAX_TARGET) Overwrite? [Y/N]: ' ; \
read -p "$$prompt" overwrite ; \
if [ "$$overwrite" = Y ]; then \
$(RM) "$(R2H_VIM_AFTER_SYNTAX_TARGET)" ; \
ln -s $(PWD)/vim/rst.vim "$(R2H_VIM_AFTER_SYNTAX_TARGET)" ; \
fi ; \
else \
ln -s $(PWD)vim/rst.vim "$(R2H_VIM_AFTER_SYNTAX_TARGET)" ; \
fi ; \
fi
@echo
prep_templates:
mkdir -p $(TMPL_DIR)
cp src/templates/template_clipboard.txt $(TMPL_DIR)
pygments: pygments_header pygments_css pygments_tmpl
pygments_header:
@echo -----------------------------------
@echo Setting Up Pygments Support
@echo -----------------------------------
check_pygments:
@if [ -z "$(PYGMENTS_INSTALLED)" ]; then \
echo "-------------------------------------------------------" ; \
echo "ERROR: $(PYGMENTS_SCRIPT) not found." ; \
echo "-------------------------------------------------------" ; \
echo "To use pygments syntax highlighting, you must install pygments and put" ; \
echo "$(PYGMENTS_SCRIPT) on your path. You can do this with:" ; \
echo "" ; \
echo " easy_install Pygments (may need to run with sudo or as root)" ; \
echo "" ; \
echo " OR " ; \
echo "" ; \
echo " sudo apt-get install python-pygments (on debian-based distros)" ; \
echo "" ; \
echo "-------------------------------------------------------" ; \
echo "" ; \
echo "If you do not want pygments support, make with PYGMENTS=0" ; \
echo "" ; \
echo "-------------------------------------------------------" ; \
exit 1 ; \
fi
# Generate .css stylesheet files for every style supported by pygments.
# pygments uses short css class names that can easily collide with other style
# definitions. To reduce the possibility of css class name collisions, make the
# class matchers more specific by qualifying that they only apply within a div
# element of css-class highlight, which is how pygments encapsulates a code
# block in its output.
pygments_css: check_pygments
@echo -----------------------------------
@echo Generating Pygments CSS stylesheets
@echo -----------------------------------
mkdir -p $(PYGMENTS_CSS_DIR)
for style in `$(PYGMENTS_SCRIPT) -L styles \
| awk '/^\*/ {print gensub(":","",1,$$2)}'`; do \
cat src/css/pygments/common.css > $(PYGMENTS_CSS_DIR)/$${style}.css; \
$(PYGMENTS_SCRIPT) -S $$style -f html \
| sed 's/^/div.highlight /' \
>> $(PYGMENTS_CSS_DIR)/$${style}.css; \
done
pygments_tmpl: prep_templates
@echo ----------------------------
@echo Generating Pygments Template
@echo ----------------------------
$(RM) $(PYGMENTS_TMPL)
cat src/templates/template_{head,tail}.txt >> $(PYGMENTS_TMPL)
@echo
#========================================
# SyntaxHighlighter
#========================================
syntax_highlighter: sh_header sh_css sh_js sh_tmpl
sh_header:
@echo -----------------------------------
@echo Setting Up SyntaxHighlighter Support
@echo -----------------------------------
sh_css:
@echo ---------------------------------------------
@echo Downloading SyntaxHighlighter CSS stylesheets
@echo ---------------------------------------------
mkdir -p $(SH_CSS_DIR)
for style in $(SH_CORE_CSS_FILES) `curl $(SH_PROJ_PAGE_THEMES_URL) 2>/dev/null \
| grep shTheme | grep SyntaxHighlighter \
| sed -e 's/.*<code>//' -e 's|</code>.*||' `; do \
curl -L $(SH_CSS_BASE_URL)/$$style -o $(SH_CSS_DIR)/$$style ; \
done
sh_js:
@echo ----------------------------------------
@echo Downloading SyntaxHighlighter JavaScript
@echo ----------------------------------------
mkdir -p $(SH_JS_DIR)
for js in $(SH_CORE_JS_FILES) `curl '$(SH_PROJ_PAGE_JS_URL)' 2>/dev/null \
| grep 'SyntaxHighlighter.*shBrush.*js' \
| sed -e 's/.*\(shBrush\)/\1/' -e 's|</td.*||' `; do \
curl -L $(SH_JS_BASE_URL)/$$js -o $(SH_JS_DIR)/$$js ; \
done
sh_tmpl: prep_templates
@echo -------------------------------------
@echo Generating SyntaxHighlighter Template
@echo -------------------------------------
$(RM) $(SH_TMPL)
cat src/templates/template_head.txt >> $(SH_TMPL)
echo >> $(SH_TMPL)
for css_file in $(SH_CORE_CSS_FILES); do \
abs_css_file=`readlink -f $(SH_CSS_DIR)/$$css_file` ; \
echo "<link href='file://$$abs_css_file' rel='stylesheet' type='text/css'/>" \
>> $(SH_TMPL) ; \
done
echo >> $(SH_TMPL)
for js in `find $(SH_JS_DIR) -type f |xargs -L1 readlink -f |sort -r`; do \
echo "<script src='file://$$js' type='text/javascript'></script>" \
>> $(SH_TMPL) ; \
done
echo >> $(SH_TMPL)
echo "<script language='javascript' type='text/javascript'>" >> $(SH_TMPL)
echo " SyntaxHighlighter.config.bloggerMode = true;" >> $(SH_TMPL)
echo " SyntaxHighlighter.all();" >> $(SH_TMPL)
echo "</script>" >> $(SH_TMPL)
echo >> $(SH_TMPL)
cat src/templates/template_tail.txt >> $(SH_TMPL)
.PHONY: pygments_css