-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_makefile
executable file
·358 lines (308 loc) · 11.9 KB
/
gen_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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
#!/usr/bin/env tclsh8.6
#
# Makefile generator, quick & hopefully not too dirty style.
#
global catalog master-template site-template adp2html
# Read configuration
source gen_makefile.conf
#Try to detect the location of the catalog file
if {[file exists "catalog.en.adp"]} then {
set main_dir "./"
} elseif {[file exists "../catalog.en.adp"]} then {
set main_dir "../"
} elseif {[file exists "../../catalog.en.adp"]} then {
set main_dir "../../"
}
#Try to detect the location of the master template
if {[file exists "default-master.adp"]} then {
set master-template "default-master.adp"
} elseif {[file exists "../default-master.adp"]} then {
set master-template "../default-master.adp"
} elseif {[file exists "../../default-master.adp"]} then {
set master-template "../../default-master.adp"
}
#Try to detect the location of the site template
if {[file exists "site-master.adp"]} then {
set site-template "site-master.adp"
} elseif {[file exists "../site-master.adp"]} then {
set site-template "../site-master.adp"
} elseif {[file exists "../../site-master.adp"]} then {
set site-template "../../site-master.adp"
}
#Try to detect the location of templatemirror.adp
if {[file exists "templatemirror.adp"]} then {
set templatemirror "templatemirror.adp"
} elseif {[file exists "../templatemirror.adp"]} then {
set templatemirror "../templatemirror.adp"
} elseif {[file exists "../../templatemirror.adp"]} then {
set templatemirror "../../templatemirror.adp"
}
if $subdir then {
#Try to detect the location of the adp2html tool
if {[file exists adp2html]} then {
set adp2html ./adp2html
} elseif {[file exists ../adp2html]} then {
set adp2html ../adp2html
} elseif {[file exists ../../adp2html]} then {
set adp2html ../../adp2html
}
} else {
set adp2html ./adp2html
}
#Determine build directory
if {[string index $build_dir 0] eq "/"} then {
set output_dir $build_dir
} else {
set output_dir "${main_dir}${build_dir}"
}
if [info exists this_directory] then {
append output_dir / $this_directory
}
if {[string index $output_dir end] ne "/"} then {
append output_dir /
}
#Put some variables in Makefile
puts "
URL_EXTENSION=.var
URL_EXTENSION_EN=.html
#
# OS depended stuff
#
ifeq (\$(OS),linux)
EXE=
else
EXE=.exe
endif
OBJ=.o
# require GNU Fileutils
RM=rm -f
MV=mv -f
#adp2html tools
ADP2HTML=$adp2html\$(EXE)
ifndef PP
PP=fpc
endif
"
if $subdir {
puts ".PHONY: all all_pages clean output_directory"
puts "default: all"
puts "all: output_directory all_pages"
puts "english: output_directory all_en_pages"
} else {
puts ".PHONY: all all_pages clean zip tar output_directory"
puts "default: all"
puts "all: \$(ADP2HTML) all_pages down_all down2_all fcl_all tools_all output_directory contrib_all"
puts "english: \$(ADP2HTML) all_en_pages down_all_en down2_all_en fcl_all_en tools_all_en output_directory contrib_all"
}
set all ""
set all_pages ""
#Generate normal pages
foreach page $pages {
set rootname [file rootname $page]
# Generate html files
foreach language $languages {
set catalog "${main_dir}catalog.${language}.adp"
if [info exists language_fileext($language)] then {
set fileext $language_fileext($language)
} else {
set fileext $language
}
set html_file "$rootname.html.$fileext"
puts "${output_dir}${html_file}: $page ${master-template} ${site-template} ${catalog}"
puts "\t$adp2html -p x=\$(URL_EXTENSION) -c $catalog -l $language_locale($language) -m ${master-template} -o $output_dir/$html_file -oe $language_encoding($language) $page"
lappend all_pages ${output_dir}${html_file}
}
# Generate rule for English only file.
set catalog "${main_dir}catalog.en.adp"
set html_file "$rootname.html"
puts "${output_dir}${html_file}: $page ${master-template} ${site-template} ${catalog}"
puts "\t$adp2html -p x=\$(URL_EXTENSION_EN) -c $catalog -l en_US -m ${master-template} -o $output_dir/$html_file -oe ISO-8859-1 $page"
lappend en_only_pages "${output_dir}${html_file}"
puts ""
# Generate var file
set var_file "${rootname}.var"
lappend all_pages "${output_dir}${var_file}"
puts "${output_dir}${var_file}: gen_makefile.conf"
puts "\techo > $var_file"
foreach language $languages {
if [info exists language_fileext($language)] then {
set fileext $language_fileext($language)
} else {
set fileext $language
}
set html_file "$rootname.html.$fileext"
puts "\techo 'URI: $html_file' >> $var_file"
puts "\techo 'Content-language: $language' >> $var_file"
puts "\techo 'Content-type: text/html; charset=$language_encoding($language)' >> ${output_dir}/$var_file"
puts "\techo >> $var_file"
}
}
#Generate mirror pages.
foreach mirror $mirrors {
set mirror_name [lindex $mirror 0]
set mirror_url [lindex $mirror 1]
set small_mirror_name [string tolower $mirror_name]
foreach page $mirror_pages {
set rootname [file rootname [lindex $page 0]]
set pagename [lindex $page 0]
set latestversion [lindex $page 2]
# Generate html files
foreach language $languages {
set catalog "${main_dir}catalog.${language}.adp"
if [info exists language_fileext($language)] then {
set fileext $language_fileext($language)
} else {
set fileext $language
}
set html_file "${rootname}-${small_mirror_name}.html.${fileext}"
puts "${output_dir}${html_file}: ${pagename} ${master-template} ${site-template} ${catalog}"
puts "\t$adp2html -p x=\$(URL_EXTENSION) -p mirror_url=${mirror_url} -p mirrorsuffix=${small_mirror_name} -p latestversion=\"${latestversion}\" -c $catalog -l $language_locale($language) -m ${master-template} -o $output_dir/$html_file -oe $language_encoding($language) ${pagename}"
lappend all_pages "${output_dir}${html_file}"
}
# Generate rule for English only file.
set catalog "${main_dir}catalog.en.adp"
set html_file "${rootname}-${small_mirror_name}.html"
puts "${output_dir}${html_file}: ${pagename} ${master-template} ${site-template} ${catalog} ${output_dir}"
puts "\t$adp2html -p x=\$(URL_EXTENSION_EN) -p mirror_url=${mirror_url} -p mirrorsuffix=${small_mirror_name} -p latestversion=\"${latestversion}\" -c $catalog -l en_US -m ${master-template} -o $output_dir/$html_file -oe ISO-8859-1 ${pagename}"
lappend en_only_pages "${output_dir}${html_file}"
puts ""
# Generate var file
set var_file "${rootname}-[string tolower $mirror_name].var"
lappend all_pages "${output_dir}${var_file}"
puts "${output_dir}${var_file}: gen_makefile.conf"
puts "\techo > $var_file"
foreach language $languages {
if [info exists language_fileext($language)] then {
set fileext $language_fileext($language)
} else {
set fileext $language
}
set html_file "$rootname-[string tolower $mirror_name].html.$fileext"
puts "\techo 'URI: $html_file' >> $var_file"
puts "\techo 'Content-language: $language' >> $var_file"
puts "\techo 'Content-type: text/html; charset=$language_encoding($language)' >> $var_file"
puts "\techo >> $var_file"
}
}
}
#Generate mirror selector
foreach page $mirror_pages {
set rootname [file rootname [lindex $page 0]]
set sourceforgepath [lindex $page 1]
set latestversion [lindex $page 2]
puts ""
# Generate html mirror selector files
foreach language $languages {
set catalog "${main_dir}catalog.${language}.adp"
if [info exists language_fileext($language)] then {
set fileext $language_fileext($language)
} else {
set fileext $language
}
set html_file "${rootname}.html.$fileext"
puts "${output_dir}${html_file}: ${templatemirror} mirrors.dat ${master-template} ${catalog}"
puts "\t$adp2html -p x=\$(URL_EXTENSION) -p pagename=${rootname} -p sourceforgepath=\"${sourceforgepath}\" -p latestversion=\"${latestversion}\" -c $catalog -l $language_locale($language) -m ${master-template} -o $html_file -oe $language_encoding($language) $templatemirror"
lappend all_pages "${output_dir}${html_file}"
}
# Generate rule for English only file.
set catalog "${main_dir}catalog.en.adp"
set html_file "${rootname}.html"
puts "${output_dir}${html_file}: ${templatemirror} mirrors.dat ${master-template} ${catalog}"
puts "\t$adp2html -p x=\$(URL_EXTENSION_EN) -p pagename=${rootname} -p sourceforgepath=\"${sourceforgepath}\" -p latestversion=\"${latestversion}\" -c $catalog -l en_US -m ${master-template} -o $html_file -oe ISO-8859-1 $templatemirror"
lappend en_only_pages "${output_dir}${html_file}"
# Generate var file
set var_file "${rootname}.var"
lappend all_pages "${output_dir}${var_file}"
puts "${output_dir}${var_file}: gen_makefile.conf"
puts "\techo > $var_file"
foreach language $languages {
if [info exists language_fileext($language)] then {
set fileext $language_fileext($language)
} else {
set fileext $language
}
set html_file "$rootname.html.$fileext"
puts "\techo 'URI: $html_file' >> $var_file"
puts "\techo 'Content-language: $language' >> $var_file"
puts "\techo 'Content-type: text/html; charset=$language_encoding($language)' >> $var_file"
puts "\techo >> $var_file"
}
}
puts ""
#Generate mirrors.dat
puts "mirrors.dat:"
puts "\t\$(shell echo 'name\\tnamel\\turl' > mirrors.dat)"
foreach mirror $mirrors {
set mirror_name [lindex $mirror 0]
set mirror_namel [string tolower $mirror_name]
set mirror_url [lindex $mirror 1]
puts "\t\$(shell echo '$mirror_name\\t$mirror_namel\\t$mirror_url' >> mirrors.dat)"
}
lappend all "mirrors.dat"
puts ""
puts "all_pages: [join $all] [join $all_pages]"
puts "all_en_pages: [join $all] [join $en_only_pages]"
puts ""
#Put some standard rules in Makefile
if $subdir {
puts "
# clean
clean:
\trm -f *.html.* *.var mirrors.dat
#output directory
output_directory:
\tmkdir -p $output_dir
"
} else {
puts "
#adp2html tool
\$(ADP2HTML): adp2html.pp
\t\$(PP) \$(OPT) -Xs adp2html.pp
#output directory
output_directory:
\tmkdir -p $output_dir
# down subdir
down_all:
\t\$(MAKE) -C down all
down2_all:
\t\$(MAKE) -C down2 all
fcl_all:
\t\$(MAKE) -C fcl all
tools_all:
\t\$(MAKE) -C tools all
contrib_all:
\t\$(MAKE) -C contrib all
down_all_en:
\t\$(MAKE) -C down english
down2_all_en:
\t\$(MAKE) -C down2 english
fcl_all_en:
\t\$(MAKE) -C fcl english
tools_all_en:
\t\$(MAKE) -C tools english
# clean
clean: clean_down clean_down2 clean_fcl clean_tools clean_contrib
\trm -f *.html.* *.var mirrors.dat adp2html
clean_down:
\t\$(MAKE) -C down clean
clean_down2:
\t\$(MAKE) -C down2 clean
clean_fcl:
\t\$(MAKE) -C fcl clean
clean_tools:
\t\$(MAKE) -C tools clean
clean_contrib:
\t\$(MAKE) -C contrib clean
# archives (unix only)
tar: all
\tfind -name '*.html' -or -name '*.html.*' -or -name '*.var' -or -name '*.gif' -or -name '*.png' -or -name '*.css' -or -name '*.jpg' > file_list
\ttar -C $output_dir -czf htmls.tar.gz -T file_list \$(OTHERFILES)
zip: all
\tzip ${main_dir}htmls.zip `find -name '*.html' -or -name '*.html.*' -or -name '*.var' -or -name '*.gif' -or -name '*.png' -or -name '*.css' -or -name '*.jpg'` \$(OTHERFILES)
english_tar: english
\tfind -name '*.html' -or -name '*.html.*' -or -name '*.var' -or -name '*.gif' -or -name '*.png' -or -name '*.css' -or -name '*.jpg' > file_list
\ttar -czf ${main_dir}htmls.tar.gz -T file_list \$(OTHERFILES)
english_zip: english
\tzip ${main_dir}htmls.zip `find -name '*.html' -or -name '*.html.*' -or -name '*.var' -or -name '*.gif' -or -name '*.png' -or -name '*.css' -or -name '*.jpg'` \$(OTHERFILES)
"
}