This repository has been archived by the owner on Nov 4, 2024. It is now read-only.
forked from wikireader/wikireader
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
533 lines (410 loc) · 15.6 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
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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
# Makefile - a Makefile for setting up Wiki Reader
#
# (C) Copyright 2008, 2009 Openmoko, Inc.
# Authors: xiangfu liu <[email protected]>
# Sean Moss-Pultz <[email protected]>
# Christopher Hall <[email protected]>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# version 3 as published by the Free Software Foundation.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA
# ----- Toolchain configuration data --------------------------------------
GCC_VERSION = 3.3.2
GCC_PACKAGE = gcc-${GCC_VERSION}.tar.gz
GCC_URL = ftp://ftp.gnu.org/gnu/gcc/${GCC_PACKAGE}
BINUTILS_VERSION = 2.10.1
BINUTILS_PACKAGE = binutils-${BINUTILS_VERSION}.tar.gz
BINUTILS_URL= ftp://ftp.gnu.org/gnu/binutils/${BINUTILS_PACKAGE}
SAMO_LIB := $(shell readlink -m ./samo-lib)
HOST_TOOLS := $(shell readlink -m ./host-tools)
LICENSES := $(shell readlink -m ./Licenses)
MISC_FILES := ${SAMO_LIB}/misc-files
DOWNLOAD_DIR = ${HOST_TOOLS}/toolchain-download
SUM_DIR = ${HOST_TOOLS}/toolchain-sums
export PATH := ${HOST_TOOLS}/toolchain-install/bin:${PATH}
CONFIG_FILE := "samo-lib/include/config.h"
CONFIG_FILE_DEFAULT := "samo-lib/include/config.h-default"
CONFIG_FILE_EXISTS := $(shell [ -f ${CONFIG_FILE} ] && echo 1)
ifeq (${CONFIG_FILE_EXISTS},)
$(shell cp ${CONFIG_FILE_DEFAULT} ${CONFIG_FILE})
$(error edit ${CONFIG_FILE} file and re-run make)
endif
# ----- configuration data --------------------------------------
ALL_TARGETS =
ALL_TARGETS += mbr
ALL_TARGETS += jackknife
ALL_TARGETS += forth
ALL_TARGETS += flash
ALL_TARGETS += mahatma
ALL_TARGETS += qt4-simulator
ALL_TARGETS += hash-gen
ALL_TARGETS += pcf2bmf
ALL_TARGETS += fonts
.PHONY: all
all: ${ALL_TARGETS}
# ----- installation ------------------------------------------
DESTDIR_PATH := $(shell readlink -m "${DESTDIR}")
WORKDIR_PATH := $(shell readlink -m "${WORKDIR}")
VERSION_TAG ?= $(shell date '+%Y%m%d%H%M')
VERSION_FILE := ${DESTDIR_PATH}/version.txt
SHA_LEVEL := 256
CHECKSUM_FILE := ${DESTDIR_PATH}/sha${SHA_LEVEL}.txt
.PHONY: jig-install
jig-install: validate-destdir forth-install flash-install mbr-install
.PHONY: install
install: validate-destdir forth-install mahatma-install fonts-install misc-files-install version
.PHONY: version
version: validate-destdir
@if [ -z "${VERSION_TAG}" ] ; then echo VERSION_TAG: "'"${VERSION_TAG}"'" is not valid ; exit 1; fi
${RM} "${VERSION_FILE}" "${CHECKSUM_FILE}" "${DESTDIR_PATH}"/*.idx-tmp "${DESTDIR_PATH}"/*~
echo VERSION: ${VERSION_TAG} >> "${VERSION_FILE}"
cd "${DESTDIR_PATH}" && sha${SHA_LEVEL}sum * >> "${CHECKSUM_FILE}"
.PHONY: misc-files-install
misc-files-install: validate-destdir
${RM} "${MISC_FILES}"/*~
${RM} "${LICENSES}"/*~
cp -p "${MISC_FILES}"/* "${DESTDIR_PATH}"/
cp -p "${LICENSES}"/* "${DESTDIR_PATH}"/
.PHONY: validate-destdir
validate-destdir:
@if [ ! -d "${DESTDIR_PATH}" ] ; then echo DESTDIR: "'"${DESTDIR_PATH}"'" is not a directory ; exit 1; fi
# ----- main program ------------------------------------------
.PHONY: mahatma
mahatma: mini-libc fatfs
${MAKE} -C samo-lib/mahatma
.PHONY: mahatma-install
mahatma-install: mahatma validate-destdir
${MAKE} -C samo-lib/mahatma install DESTDIR="${DESTDIR_PATH}"
# ----- lib stuff -------------------------------------------
.PHONY:mini-libc
mini-libc: gcc
${MAKE} -C samo-lib/mini-libc/
.PHONY: fatfs
fatfs: mini-libc drivers
${MAKE} -C samo-lib/fatfs/
.PHONY: drivers
drivers: mini-libc
${MAKE} -C samo-lib/drivers/
# ----- toolchain stuff --------------------------------------
BINUTILS_FILE = ${DOWNLOAD_DIR}/${BINUTILS_PACKAGE}
BINUTILS_SUM = ${SUM_DIR}/${BINUTILS_PACKAGE}.SHA256
GCC_FILE = ${DOWNLOAD_DIR}/${GCC_PACKAGE}
GCC_SUM = ${SUM_DIR}/${GCC_PACKAGE}.SHA256
GET_FILE = $(eval $(call GET_FILE1,$(strip ${1}),$(strip ${2}),$(strip ${3}),$(strip ${4})))
define GET_FILE1
${1}:
@mkdir -p "$${DOWNLOAD_DIR}"
@if ! ([ -f "${2}" ] && cd "$${DOWNLOAD_DIR}" && sha256sum --check "${3}") ; \
then \
${RM} "${2}" ; \
wget -c -O "${2}" "${4}"; \
else \
echo Already downloaded: ${2} ; \
fi
@touch "$$@"
endef
$(call GET_FILE,binutils-download,${BINUTILS_FILE},${BINUTILS_SUM},${BINUTILS_URL})
$(call GET_FILE,gcc-download,${GCC_FILE},${GCC_SUM},${GCC_URL})
binutils-patch: binutils-download
mkdir -p host-tools/toolchain-install
rm -rf "host-tools/binutils-${BINUTILS_PACKAGE}"
tar -xvzf "${BINUTILS_FILE}" -C host-tools/
cd host-tools && \
cd "binutils-${BINUTILS_VERSION}" && \
cat ../toolchain-patches/0001-binutils-EPSON-changes-to-binutils.patch | patch -p1 && \
cat ../toolchain-patches/0002-binutils-EPSON-make-it-compile-hack-for-recent-gcc.patch | patch -p1
touch "$@"
binutils: binutils-patch
cd host-tools && \
cd "binutils-${BINUTILS_VERSION}" && \
mkdir -p build && \
cd build && \
CPPFLAGS="-D_FORTIFY_SOURCE=0" ../configure --prefix "${HOST_TOOLS}/toolchain-install" --target=c33-epson-elf && \
CPPFLAGS="-D_FORTIFY_SOURCE=0" ${MAKE} && \
${MAKE} install
touch "$@"
gcc-patch: gcc-download
mkdir -p host-tools/toolchain-install
tar -xvzf "${GCC_FILE}" -C host-tools/
cd host-tools && \
cd "gcc-${GCC_VERSION}" && \
cat ../toolchain-patches/0001-gcc-EPSON-modified-sources.patch | patch -p1 && \
cat ../toolchain-patches/0002-gcc-Force-that-the-assembly-of-libgcc-complies-wit.patch | patch -p1 && \
cat ../toolchain-patches/0003-gcc-Use-the-C-implementations-for-division-and-mod.patch | patch -p1
touch "$@"
gcc: binutils gcc-patch
cd host-tools && \
export PATH="${HOST_TOOLS}/toolchain-install/bin:${PATH}" && \
cd "gcc-${GCC_VERSION}" && \
mkdir -p build && \
cd build && \
CPPFLAGS="-D_FORTIFY_SOURCE=0" ../configure --prefix "${HOST_TOOLS}/toolchain-install" --target=c33-epson-elf --enable-languages=c && \
CPPFLAGS="-D_FORTIFY_SOURCE=0" ${MAKE} && \
${MAKE} install
touch "$@"
.PHONY: qt4-simulator
qt4-simulator: mahatma
cd host-tools/qt4-simulator && qmake-qt4 && ${MAKE}
.PHONY: console-simulator
console-simulator: mahatma
cd host-tools/console-simulator && ${MAKE}
# ----- hash-gen --------------------------------------
.PHONY: hash-gen
hash-gen:
cd host-tools/hash-gen && ${MAKE}
# ----- pcf2bmf --------------------------------------
.PHONY: pcf2bmf
pcf2bmf:
cd host-tools/pcf2bmf && ${MAKE}
# ----- fonts --------------------------------------
.PHONY: fonts
fonts: pcf2bmf
cd host-tools/fonts && ${MAKE}
.PHONY: fonts-install
fonts-install: fonts validate-destdir
cd host-tools/fonts && ${MAKE} DESTDIR="${DESTDIR_PATH}" install
# ----- build the database --------------------------------------
XML_FILES_PATH := $(foreach f,${XML_FILES},$(shell readlink -m "${f}"))
RENDER_BLOCK ?= 0
.PHONY: index
index: validate-destdir
cd host-tools/offline-renderer && ${MAKE} index \
XML_FILES="${XML_FILES_PATH}" RENDER_BLOCK="${RENDER_BLOCK}" \
WORKDIR="${WORKDIR_PATH}" DESTDIR="${DESTDIR_PATH}"
.PHONY: parse
parse: validate-destdir
cd host-tools/offline-renderer && ${MAKE} parse \
XML_FILES="${XML_FILES_PATH}" RENDER_BLOCK="${RENDER_BLOCK}" \
WORKDIR="${WORKDIR_PATH}" DESTDIR="${DESTDIR_PATH}"
.PHONY: render
render: fonts validate-destdir
cd host-tools/offline-renderer && ${MAKE} render \
XML_FILES="${XML_FILES_PATH}" RENDER_BLOCK="${RENDER_BLOCK}" \
WORKDIR="${WORKDIR_PATH}" DESTDIR="${DESTDIR_PATH}"
.PHONY: combine
combine: validate-destdir
cd host-tools/offline-renderer && ${MAKE} combine \
XML_FILES="${XML_FILES_PATH}" RENDER_BLOCK="${RENDER_BLOCK}" \
WORKDIR="${WORKDIR_PATH}" DESTDIR="${DESTDIR_PATH}"
.PHONY: hash
hash: validate-destdir hash-gen
cd "${DESTDIR}" && ${HOST_TOOLS}/hash-gen/hash-gen \
--pfx="${DESTDIR_PATH}/pedia.pfx" \
--fnd="${DESTDIR_PATH}/pedia.fnd" \
--hsh="${DESTDIR_PATH}/pedia.hsh"
stamp-r-index:
rm -f "$@"
cd host-tools/offline-renderer && ${MAKE} index \
XML_FILES="${XML_FILES_PATH}" RENDER_BLOCK="${RENDER_BLOCK}" \
WORKDIR="${WORKDIR_PATH}" DESTDIR="${DESTDIR_PATH}"
touch "$@"
.PHONY: clean-index
clean-index:
rm -f stamp-r-index
MAKE_BLOCK = $(eval $(call MAKE_BLOCK1,$(strip ${1}),$(strip ${2}),$(strip ${3})))
define MAKE_BLOCK1
.PHONY: parse${1}
parse${1}: stamp-r-index stamp-r-parse${1}
.PHONY: render${1} fonts parse${1}
render${1}: stamp-r-render${1}
stamp-r-parse${1}:
rm -f "$$@"
$${MAKE} RENDER_BLOCK=${1} START=${2} COUNT=${3} parse
touch "$$@"
#.NOTPARALLEL: stamp-r-render${1}
stamp-r-render${1}:
rm -f "$$@"
$${MAKE} RENDER_BLOCK=${1} render
touch "$$@"
.PHONY: stamp-r-clean${1}
stamp-r-clean${1}:
rm -f stamp-r-parse${1} stamp-r-render${1}
endef
# ------------------------------------------------
# set this to make even distibution over 27 blocks
# need a better way of setting this
# ------------------------------------------------
ARTICLE_COUNT_K ?= 114
MACHINE_COUNT = 9
PARALLEL_BUILD = 3
MAX_BLOCK := $(shell expr ${MACHINE_COUNT} '*' ${PARALLEL_BUILD} - 1)
# the first(0) and last(MAX_BLOCK) are special
$(call MAKE_BLOCK,0,1,$(shell expr ${ARTICLE_COUNT_K} '*' 1000 - 1))
ITEMS := $(shell i=1; while [ $${i} -lt ${MAX_BLOCK} ]; do echo $${i}; i=$$(($${i} + 1)); done)
$(foreach i,${ITEMS},$(call MAKE_BLOCK,${i},$(shell expr ${i} '*' ${ARTICLE_COUNT_K})k,${ARTICLE_COUNT_K}k))
$(call MAKE_BLOCK,${MAX_BLOCK},$(shell expr ${MAX_BLOCK} '*' ${ARTICLE_COUNT_K})k,all)
MAKE_FARM = $(eval $(call MAKE_FARM1,$(strip ${1}),$(strip ${2}),$(strip ${3})))
define MAKE_FARM1
.PHONY: farm${1}-parse
farm${1}-parse: $$(foreach i,${2},parse$$(strip $${i}))
.PHONY: farm${1}-render
farm${1}-render: $$(foreach i,${2},render$$(strip $${i}))
.PHONY: farm${1}-clean
farm${1}-clean: $$(foreach i,${2},stamp-r-clean$$(strip $${i}))
.PHONY: farm${1}
farm${1}: farm${1}-parse farm${1}-render
endef
MAKE_MACHINE = $(eval $(call MAKE_MACHINE1,$(strip ${1}),$(strip ${2}),$(strip ${3})))
define MAKE_MACHINE1
$(call MAKE_FARM,${1}, $(shell expr ${1} - 1) $(shell expr ${1} - 1 + ${2}) $(shell expr ${1} - 1 + 2 '*' ${2}))
endef
MACHINE_LIST := $(shell i=1; while [ $${i} -le ${MACHINE_COUNT} ]; do echo $${i}; i=$$(($${i} + 1)); done)
$(foreach i,${MACHINE_LIST},$(call MAKE_MACHINE,${i},${MACHINE_COUNT}))
# ----- wiki Dump --------------------------------------
.PHONY: getwikidump
getwikidump:
wget http://download.wikimedia.org/enwiki/latest/enwiki-latest-pages-articles.xml.bz2
# ----- forth -----------------------------------------------
# forth interpreter
.PHONY: forth
forth: gcc mini-libc fatfs drivers
${MAKE} -C samo-lib/forth
.PHONY: forth-install
forth-install: forth
${MAKE} -C samo-lib/forth install DESTDIR="${DESTDIR_PATH}"
# ----- flash -----------------------------------------------
# flash programmer that runs on the device
.PHONY: flash
flash: gcc mini-libc fatfs drivers
${MAKE} -C samo-lib/flash
.PHONY: flash-install
flash-install: flash
${MAKE} -C samo-lib/flash install DESTDIR="${DESTDIR_PATH}"
# ----- mbr -------------------------------------------------
# master boot record
define FindTTY
for i in USBconsole ttyUSB2 ttyUSB1 ttyUSB0;
do
d="/dev/$${i}";
if [ -e "$${d}" ];
then
echo -n $${d};
exit 0;
fi;
done;
echo -n /dev/TTY-NOT-FOUND;
exit 1;
endef
define FindAUX
for i in USBjtag;
do
d="/dev/$${i}";
if [ -e "$${d}" ];
then
echo -n $${d};
exit 0;
fi;
done;
echo -n /dev/TTY-NOT-FOUND;
exit 1;
endef
BOOTLOADER_TTY ?= $(shell ${FindTTY})
BOOTLOADER_AUX ?= $(shell ${FindAUX})
SERIAL_NUMBER ?= No Serial Number
.PHONY: print-mbr-tty
print-mbr-tty:
@echo BOOTLOADER_TTY = "${BOOTLOADER_TTY}"
@echo BOOTLOADER_AUX = "${BOOTLOADER_AUX}"
.PHONY: mbr
mbr: gcc fatfs
${MAKE} -C samo-lib/mbr
.PHONY: mbr-rs232
mbr-rs232: gcc fatfs
${MAKE} -C samo-lib/mbr mbr-rs232
.PHONY: jackknife
jackknife:
${MAKE} -C host-tools/jackknife
.PHONY: flash-mbr
flash-mbr: mbr jackknife
${MAKE} -C samo-lib/mbr BOOTLOADER_TTY="${BOOTLOADER_TTY}" BOOTLOADER_AUX="${BOOTLOADER_AUX}" SERIAL_NUMBER="${SERIAL_NUMBER}" $@
.PHONY: mbr-install
mbr-install: mbr
${MAKE} -C samo-lib/mbr install DESTDIR="${DESTDIR_PATH}"
# ----- clean and help --------------------------------------
.PHONY: complete-clean
complete-clean: clean clean-toolchain
rm -f binutils-download gcc-download
.PHONY: clean
clean: clean-qt4-simulator clean-console-simulator
${MAKE} clean -C samo-lib/mini-libc
${MAKE} clean -C host-tools/jackknife
${MAKE} clean -C host-tools/hash-gen
${MAKE} clean -C host-tools/pcf2bmf
${MAKE} clean -C host-tools/flash07
${MAKE} clean -C host-tools/fonts
${MAKE} clean -C host-tools/offline-renderer
${MAKE} clean -C samo-lib/mbr
${MAKE} clean -C samo-lib/drivers
${MAKE} clean -C samo-lib/fatfs
${MAKE} clean -C samo-lib/forth
${MAKE} clean -C samo-lib/flash
${MAKE} clean -C samo-lib/mahatma
${RM} stamp-r-*
.PHONY: clean-toolchain
clean-toolchain:
rm -rf host-tools/toolchain-install
rm -rf host-tools/gcc-${GCC_VERSION}
rm -rf host-tools/binutils-${BINUTILS_VERSION}
rm -f binutils-patch binutils
rm -f gcc-patch gcc
.PHONY: clean-qt4-simulator
clean-qt4-simulator:
(cd host-tools/qt4-simulator; ${MAKE} distclean || true)
.PHONY: clean-console-simulator
clean-console-simulator:
${MAKE} clean -C host-tools/console-simulator
.PHONY:help
help:
@echo
@echo 'Some of the more useful targets:'
@echo
@echo ' all - compile all the source'
@echo ' install - install forth, mahatma, fonts in DESTDIR'
@echo ' index - convert XML_FILES to index files in DESTDIR'
@echo ' parse - parse XML_FILES into one HTML file in WORKDIR'
@echo ' render - render HTML in WORKDIR into one big data file in DESTDIR'
@echo ' combine - combine temporary indices to one file in DESTDIR'
@echo ' farm<1..8> - parse/render XML_FILES into 3 data files in DESTDIR (use -j3)'
@echo ' farm<1..8>-parse - parse XML_FILES into 3 HTML files in WORKDIR (use -j3)'
@echo ' farm<1..8>-render - render WORKDIR HTML files into 3 data files in DESTDIR (use -j3)'
@echo ' farm<1..8>-clean - remove stamp files to repeat process'
@echo ' mbr - compile bootloader'
@echo ' mbr-install - install flash.rom in DESTDIR'
@echo ' mahatma - compile kernel'
@echo ' mahatma-install - install mahatma as kernel in DESTDIR'
@echo ' forth - compile forth'
@echo ' forth-install - install forth files in DESTDIR'
@echo ' flash - compile flash (programs flash.rom from SD Card'
@echo ' flash-install - install flash programmer in DESTDIR'
@echo ' fonts - compile fonts'
@echo ' fonts-install - install font files in DESTDIR'
@echo ' gcc - compile gcc toolchain'
@echo ' flash-mbr - flash bootloader to the E07 board'
@echo ' qt4-simulator - compile the Qt4 simulator'
@echo ' console-simulator - compile the console simulator'
@echo ' clean - clean everything except the toochain'
@echo ' clean-toolchain - clean just the toochain'
@echo ' jig-install - copy flash program and image; forth and programs to SD Card'
@echo ' p33 - terminal emulator (console debugging)'
@echo
.PHONY:testhelp
testhelp:
${MAKE} --print-data-base --question | \
awk '/^[^.%][-A-Za-z0-9_]*:/ \
{ print substr($$1, 1, length($$1)-1) }' | \
sort | \
pr --omit-pagination --width=80 --columns=1
#use this like: make print-MAKE
print-%:
@echo $* is $($*)
.PHONY: p33
p33:
./samo-lib/scripts/p33