forked from wikireader/wikireader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
1065 lines (819 loc) · 33.3 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
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Makefile - a Makefile for setting up Wiki Reader
#
# (C) Copyright 2008, 2009 Openmoko, Inc.
# Authors: xiangfu liu <xiangfu@openmoko.org>
# Sean Moss-Pultz <sean@openmoko.com>
# Christopher Hall <hsw@openmoko.com>
#
# 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
# Control variables
# =================
# These can be overridden on the command line:
# (defaults indicated in [])
#
# XML_FILES list of files to process
#
# WIKI_LANGUAGE Language code [en]
#
# WIKI_LANGUAGE_VARIANT Variant Language code []
# examples for WIKI_LANGUAGE=zh
# WIKI_LANGUAGE_VARIANT=zh_CN
# WIKI_LANGUAGE_VARIANT=zh_TW
#
# WIKI_FILE_PREFIX Prefix for all files in a data directory [wiki]
#
# WIKI_VERSION Version code for the current rendering operation [${todays-date}]
#
# WIKI_DIR_SUFFIX Combined with language code to make a unique
# directory name [pedia]
#
# DESTDIR Directory where rendered data will be stored
#
# WORKDIR Directory where all the working databases are stored
#
# TEMPDIR Optional directory to store LaTeX work files, point
# to a RAM disk [derived from ${WORKDIR}]
#
# VERSION_TAG Optional version string for the root programs/fonts [${todays-date}]
#
# PROGRESS_BAR Enable progress bar when compiling wiki.app [NO]
#
# TEMPERATURE_DISPLAY Enable temperature display when compiling wiki.app [NO]
#
# BOOT_LOGO A PNG filename in the samo-lib/mbr directory [wikireader.png]
#
# GRIFO_EXAMPLES Compile / install grifo examples [NO]
#
# EXTRACT_VERSION_FROM a link to XML file name that has an embedded date
# which will be used to set WIKI_VERSION
#
# MACHINE_COUNT Number of machines in the build cluster [9]
#
# PARALLEL_BUILD Number of threads/cores usable on each machine [3]
#
# Items controlling the compression - for reducing data size to fit smaller SD Card
#
# ENABLE_LANGUAGES_LINKS Enable links to other languages [YES]
#
# ENABLE_IMAGES Enable embedded images (Formulae) [YES]
#
# ARTICLES_PER_BLOCK Maximum number of articles to group in one block [1] (max 255)
# Larger number will give greater compression, but much slower load times
#
# ARTICLE_BLOCK_SIZE Size limit of compression block [262144] (max 524288)
# Only applies when ARTICLES_PER_BLOCK > 1
#
# MAX_ARTICLE_LENGTH Shorten articles over this length (length of rendered byte code) [UNLIMITED]
# Include standard definitions
# ============================
CROSS_COMPILER := NO
# +++START_UPDATE_MAKEFILE: Start of auto included code
# The text between the +++ and --- tags is copied by the
# UpdateMakefiles script. Do not remove or change these tags.
# ---
# Autodetect root directory
define FIND_ROOT_DIR
while : ; do \
d=$$(pwd) ; \
[ -d "$${d}/samo-lib" ] && echo $${d} && exit 0 ; \
[ X"/" = X"$${d}" ] && echo ROOT_DIRECTORY_NOT_FOUND && exit 1 ; \
cd .. ; \
done
endef
ROOT_DIR := $(shell ${FIND_ROOT_DIR})
# Directory of Makefile includes
MK_DIR := ${ROOT_DIR}/samo-lib/Mk
# Include the initial Makefile setup
include ${MK_DIR}/definitions.mk
# ---END_UPDATE_MAKEFILE: End of auto included code
# 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}
DOWNLOAD_DIR = ${HOST_TOOLS}/toolchain-download
SUM_DIR = ${HOST_TOOLS}/toolchain-sums
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
# macro to simplify primary targets
# =================================
STD_BASE = $(eval $(call STD_BASE1,$(strip ${1}),$(strip ${2}),$(strip ${3}),$(strip ${4})))
STD_RULE = ${STD_BASE}$(eval $(call STD_RULE1,$(strip ${1}),$(strip ${2}),$(strip ${3}),$(strip ${4}),$(strip ${5})))
define STD_RULE1
.PHONY: ${1}
${1}: ${3}
$${MAKE} -C "${2}" all ${5}
ALL_TARGETS += ${1}
ifeq (INSTALL,${4})
.PHONY: ${1}-install
${1}-install: ${1} validate-destdir
${MAKE} -C "${2}" DESTDIR="$${DESTDIR_PATH}" install ${5}
INSTALL_TARGETS += ${1}-install
endif
endef
define STD_BASE1
.PHONY: ${1}-clean
${1}-clean:
$${MAKE} -C "${2}" clean
CLEAN_TARGETS += ${1}-clean
.PHONY: ${1}-requires
${1}-requires:
$${MAKE} -C "${2}" requires
REQUIRES_TARGETS += ${1}-requires
endef
# Makefile entry point
# ====================
ALL_TARGETS =
.PHONY: all build release build_core release_core
all: all-targets
# For building the wikimedia docker images
build:
docker build --rm --compress --no-cache -t stephenmw/wikireader:latest .
release: build
docker push stephenmw/wikireader:latest
build_core:
cd core && docker build --rm --compress --no-cache -t stephenmw/wikireader_core:latest .
release_core: build_core
docker push stephenmw/wikireader_core:latest
# wiki naming
# ===========
EXTRACT_VERSION_PATH := $(realpath ${EXTRACT_VERSION_FROM})
ifneq (,$(strip ${EXTRACT_VERSION_PATH}))
WIKI_VERSION := $(subst .,,$(suffix $(subst -,.,$(patsubst %-pages-articles,%,$(notdir $(basename ${EXTRACT_VERSION_PATH}))))))
endif
WIKI_LANGUAGE ?= en
WIKI_FILE_PREFIX ?= wiki
WIKI_DIR_SUFFIX ?= pedia
WIKI_VERSION ?= $(shell date '+%Y%m%d')
MACHINE_COUNT ?= 9
PARALLEL_BUILD ?= 3
MAX_CONCURRENCY ?= $(shell nproc --all)
# Installation
# ============
DESTDIR_PATH := $(abspath ${DESTDIR})
WORKDIR_PATH := $(abspath ${WORKDIR})
TEMPDIR_PATH := $(abspath ${TEMPDIR})
ifeq (,$(strip ${TEMPDIR_PATH}))
TEMPDIR_PATH := ${WORKDIR_PATH}/tmp
endif
VERSION_TAG ?= $(shell date '+%Y%m%d')
VERSION_FILE := ${DESTDIR_PATH}/version.txt
SHA_LEVEL := 256
CHECKSUM_FILE := sha${SHA_LEVEL}.txt
.PHONY: jig-install
jig-install: validate-destdir forth-install flash-install mbr-install
# default install method - now set to use grifo
.PHONY: install
install: ginstall
# install grifo version
.PHONY: ginstall
ginstall: validate-destdir grifo-install init-ini-install wiki-install forth-install fonts-install nls-install misc-files-install version clear-history
# install the default init.ini
.PHONY: init-ini-install
init-ini-install: validate-destdir
${STRIP_HASH_OR_BLANK_LINES} "${LICENSE_DIR}"/init.ini > "${DESTDIR_PATH}"/init.ini
# set up version and checksum files
.PHONY: version
version: validate-destdir
@if [ -z "${VERSION_TAG}" ] ; then echo VERSION_TAG: "'"${VERSION_TAG}"'" is not valid ; exit 1; fi
${RM} "${VERSION_FILE}" "${DESTDIR_PATH}"/*.idx-tmp "${DESTDIR_PATH}"/*~
${RM} "${DESTDIR_PATH}"/*/*.idx-tmp
echo VERSION: ${VERSION_TAG} >> "${VERSION_FILE}"
find '${DESTDIR_PATH}' -mindepth 1 -type d -print -exec \
${MAKE} -C '{}' -f '${PWD}/$(firstword ${MAKEFILE_LIST})' DESTDIR='${DESTDIR_PATH}' '${CHECKSUM_FILE}' ';'
(cd '${DESTDIR_PATH}' && sha${SHA_LEVEL}sum $$(find . -maxdepth 1 -type f -printf '%f\n' | grep -v '${CHECKSUM_FILE}') > '${CHECKSUM_FILE}')
.PHONY: clean-sha
clean-sha:
find "${DESTDIR_PATH}" -type f -name '${CHECKSUM_FILE}' -print -delete
# rebuild checksum if out of date
${CHECKSUM_FILE}: $(filter-out ${CHECKSUM_FILE},$(wildcard *))
${RM} '$@'
sha${SHA_LEVEL}sum * > '$@'
# create empty history and password files
# set up other required files
.PHONY: clear-history
clear-history: validate-destdir
${RM} "${DESTDIR_PATH}"/[wW][iI][kK][iI].[pP][aA][sS]
${RM} "${DESTDIR_PATH}"/[wW][iI][kK][iI].[hH][sS][tT]
${RM} "${DESTDIR_PATH}"/[wW][iI][kK][iI].[iI][nN][iI]
${RM} "${DESTDIR_PATH}"/[wW][iI][kK][iI].[iI][nN][fF]
dd if=/dev/zero of="${DESTDIR_PATH}/wiki.hst" bs=67584 count=1
dd if=/dev/zero of="${DESTDIR_PATH}/wiki.pas" bs=40 count=1
dd if=/dev/zero of="${DESTDIR_PATH}/wiki.tem" bs=10 count=1
${STRIP_HASH_OR_BLANK_LINES} "${LICENSE_DIR}"/wiki.inf > "${DESTDIR_PATH}"/wiki.inf
id=$$(grep -n -m 1 '${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}' "${DESTDIR_PATH}/wiki.inf"); \
id=$${id%%:*}; \
[ -z "$${id}" ] && id=1; \
echo wiki_id=$${id%%:*} > "${DESTDIR_PATH}/wiki.ini"
.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
@if [ ! -d "${DESTDIR_PATH}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}" ] ; then echo DESTDIR: "'"${DESTDIR_PATH}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}"'" is not a directory ; exit 1; fi
# Libraries
# =========
$(call STD_RULE, mini-libc, ${SAMO_LIB}/mini-libc, toolchain)
$(call STD_RULE, fatfs, ${SAMO_LIB}/fatfs, mini-libc drivers)
$(call STD_RULE, drivers, ${SAMO_LIB}/drivers, mini-libc)
# GCC and Binutils toolchain
# ==========================
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} -r "${HOST_TOOLS}/binutils-${BINUTILS_PACKAGE}"
tar -xvzf "${BINUTILS_FILE}" -C ${HOST_TOOLS}
cd "${HOST_TOOLS}/binutils-${BINUTILS_VERSION}" && \
for p in ../toolchain-patches/*-binutils-*.patch ; \
do \
patch -p1 < "$${p}" ; \
done
${TOUCH} "$@"
binutils: binutils-patch
cd "${HOST_TOOLS}/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}/gcc-${GCC_VERSION}" && \
for p in ../toolchain-patches/*-gcc-*.patch ; \
do \
patch -p1 < "$${p}" ; \
done
${TOUCH} "$@"
gcc: binutils gcc-patch
export PATH="${HOST_TOOLS}/toolchain-install/bin:${PATH}" && \
cd "${HOST_TOOLS}/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: toolchain
toolchain: toolchain-requires gcc
.PHONY: toolchain-requires
toolchain-requires:
true $(call REQUIRED_BINARY, patch, patch)
true $(call REQUIRED_BINARY, gcc, gcc)
true $(call REQUIRED_BINARY, lex, flex)
true $(call REQUIRED_BINARY, bison, bison)
REQUIRES_TARGETS += toolchain-requires
# QT simulator
# ============
ifeq (DEPRECATED,)
.PHONY: qt4-simulator
qt4-simulator: qt4-simulator-requires
cd ${HOST_TOOLS}/qt4-simulator && qmake && ${MAKE}
.PHONY: qt4-simulator-requires
qt4-simulator-requires:
true $(call REQUIRED_BINARY, g++, g++)
true $(call REQUIRED_BINARY, qmake, qt4-qmake libqt4-dev)
REQUIRES_TARGETS += qt4-simulator-requires
.PHONY: qt4-simulator-clean
qt4-simulator-clean:
${MAKE} -C "${HOST_TOOLS}/qt4-simulator" distclean || true
CLEAN_TARGETS += qt4-simulator-clean
.PHONY: sim4
sim4: qt4-simulator validate-destdir
cd "${DESTDIR}" && ${HOST_TOOLS}/qt4-simulator/bin/wikisim ${ARTICLE}
.PHONY: sim4d
sim4d: qt4-simulator validate-destdir
cd "${DESTDIR}" && gdb --args ${HOST_TOOLS}/qt4-simulator/bin/wikisim ${ARTICLE}
# the console simulator is presently broken
#$(call STD_RULE, console-simulator, ${HOST_TOOLS}/console-simulator)
else
.PHONY: sim4
sim4:
@echo error: deprecated target, replaced by: make DESTDIR=some_image_dir wiki-simulate
endif
# Font processing
# ===============
$(call STD_RULE, pcf2bmf, ${HOST_TOOLS}/pcf2bmf)
$(call STD_RULE, fonts, ${HOST_TOOLS}/fonts, pcf2bmf, INSTALL)
# Compression interface
# =====================
# in case the platform lacks the python-lzma package
# (only present in ?Ubuntu >= lucid 10.04)
# then there is a local verion of the older PyLZMA module
# that can be installed instead
.PHONY: local-pylzma-install
local-pylzma-install:
${MAKE} -C "${HOST_TOOLS}/offline-renderer" pylzma
# Build the database from wiki XML files
# ======================================
$(call STD_BASE, offline-renderer, ${HOST_TOOLS}/offline-renderer)
# wikis
XML_FILES_PATH = $(realpath ${XML_FILES})
# default for simgle machine
RENDER_BLOCK ?= 0
# rendering compression parameters
# images are the output of the math turning it to NO will show TeX from 'alt'
ENABLE_LANGUAGES_LINKS ?= YES
ENABLE_IMAGES ?= YES
ARTICLES_PER_BLOCK ?= 1
ARTICLE_BLOCK_SIZE ?= 262144
MAX_ARTICLE_LENGTH ?= UNLIMITED
# erase the working directories for the current language
.PHONY: cleandirs
cleandirs:
@if [ -z "${DESTDIR_PATH}" ] ; then echo missing DESTDIR ; exit 1 ; fi
@if [ -z "${WORKDIR_PATH}" ] ; then echo missing WORKDIR ; exit 1 ; fi
@if [ -z "${TEMPDIR_PATH}" ] ; then echo missing TEMPDIR ; exit 1 ; fi
${RM} -r "${DESTDIR_PATH}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}"
${RM} -r "${TEMPDIR_PATH}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}"
${RM} -r "${WORKDIR_PATH}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}"
# only create dirs (does not erase them)
.PHONY: createdirs
createdirs:
@if [ -z "${DESTDIR_PATH}" ] ; then echo missing DESTDIR ; exit 1 ; fi
@if [ -z "${WORKDIR_PATH}" ] ; then echo missing WORKDIR ; exit 1 ; fi
@if [ -z "${TEMPDIR_PATH}" ] ; then echo missing TEMPDIR ; exit 1 ; fi
${MKDIR} "${DESTDIR_PATH}"
${MKDIR} "${DESTDIR_PATH}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}"
${MKDIR} "${WORKDIR_PATH}"
${MKDIR} "${WORKDIR_PATH}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}"
${MKDIR} "${TEMPDIR_PATH}"
${MKDIR} "${TEMPDIR_PATH}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}"
.PHONY: index
index: validate-destdir
${MAKE} -C "${HOST_TOOLS}/offline-renderer" index \
WIKI_LANGUAGE="${WIKI_LANGUAGE}" \
WIKI_LANGUAGE_VARIANT="${WIKI_LANGUAGE_VARIANT}" \
WIKI_FILE_PREFIX="${WIKI_FILE_PREFIX}" \
WIKI_DIR_SUFFIX="${WIKI_DIR_SUFFIX}" \
XML_FILES="${XML_FILES_PATH}" RENDER_BLOCK="${RENDER_BLOCK}" \
WIKI_VERSION="${WIKI_VERSION}" \
TEMPDIR="${TEMPDIR_PATH}" \
WORKDIR="${WORKDIR_PATH}" DESTDIR="${DESTDIR_PATH}"
.PHONY: parse
parse: validate-destdir
sem --jobs ${MAX_CONCURRENCY} --id WIKIREADER --fg -u -- \
${MAKE} -C "${HOST_TOOLS}/offline-renderer" parse \
WIKI_LANGUAGE="${WIKI_LANGUAGE}" \
WIKI_LANGUAGE_VARIANT="${WIKI_LANGUAGE_VARIANT}" \
WIKI_FILE_PREFIX="${WIKI_FILE_PREFIX}" \
WIKI_DIR_SUFFIX="${WIKI_DIR_SUFFIX}" \
XML_FILES="${XML_FILES_PATH}" RENDER_BLOCK="${RENDER_BLOCK}" \
WIKI_VERSION="${WIKI_VERSION}" \
TEMPDIR="${TEMPDIR_PATH}" \
WORKDIR="${WORKDIR_PATH}" DESTDIR="${DESTDIR_PATH}"
.PHONY: render
render: fonts validate-destdir
sem --jobs ${MAX_CONCURRENCY} --id WIKIREADER --fg -u -- \
${MAKE} -C "${HOST_TOOLS}/offline-renderer" render \
WIKI_LANGUAGE="${WIKI_LANGUAGE}" \
WIKI_LANGUAGE_VARIANT="${WIKI_LANGUAGE_VARIANT}" \
WIKI_FILE_PREFIX="${WIKI_FILE_PREFIX}" \
WIKI_DIR_SUFFIX="${WIKI_DIR_SUFFIX}" \
XML_FILES="${XML_FILES_PATH}" RENDER_BLOCK="${RENDER_BLOCK}" \
ENABLE_LANGUAGES_LINKS="${ENABLE_LANGUAGES_LINKS}" \
ENABLE_IMAGES="${ENABLE_IMAGES}" \
ARTICLES_PER_BLOCK="${ARTICLES_PER_BLOCK}" \
ARTICLE_BLOCK_SIZE="${ARTICLE_BLOCK_SIZE}" \
MAX_ARTICLE_LENGTH="${MAX_ARTICLE_LENGTH}" \
WIKI_VERSION="${WIKI_VERSION}" \
TEMPDIR="${TEMPDIR_PATH}" \
WORKDIR="${WORKDIR_PATH}" DESTDIR="${DESTDIR_PATH}"
.PHONY: combine
combine: validate-destdir
${MAKE} -C "${HOST_TOOLS}/offline-renderer" combine \
WIKI_LANGUAGE="${WIKI_LANGUAGE}" \
WIKI_LANGUAGE_VARIANT="${WIKI_LANGUAGE_VARIANT}" \
WIKI_FILE_PREFIX="${WIKI_FILE_PREFIX}" \
WIKI_DIR_SUFFIX="${WIKI_DIR_SUFFIX}" \
XML_FILES="${XML_FILES_PATH}" RENDER_BLOCK="${RENDER_BLOCK}" \
WIKI_VERSION="${WIKI_VERSION}" \
TEMPDIR="${TEMPDIR_PATH}" \
WORKDIR="${WORKDIR_PATH}" DESTDIR="${DESTDIR_PATH}"
# run all stages (for testing small XML sample files)
.PHONY: iprc
iprc: index parse render combine
# Build database using multiple machines
# ======================================
ifneq (,$(strip ${WORKDIR_PATH}))
ifneq (,$(strip ${DESTDIR_PATH}))
INDEX_STAMP := ${WORKDIR_PATH}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}/stamp-index
PARSE_STAMP := ${WORKDIR_PATH}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}/stamp-parse
RENDER_STAMP := ${WORKDIR_PATH}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}/stamp-render
# ---------------------------------------------------------------------------------------
# Get the number of articles from the indexer and compute how many articles per instance
# ---------------------------------------------------------------------------------------
COUNTS_FILE = ${WORKDIR_PATH}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}/counts.text
TOTAL_ARTICLES = $(shell awk '/^Articles:/{ print $$2 }' "${COUNTS_FILE}" 2>/dev/null || echo 0)
TOTAL_INSTANCES := $(shell expr ${MACHINE_COUNT} '*' ${PARALLEL_BUILD})
# 64 dat files is the maximum allowed
CHECK := $(shell if [ ${TOTAL_INSTANCES} -gt 64 ]; then echo 0; else echo 1; fi )
ifeq ($(strip ${CHECK}),0)
$(error Too many machines or processes being used. Maximum is 64 total instances)
endif
MAX_BLOCK := $(shell expr ${TOTAL_INSTANCES} - 1)
ARTICLES_PER_INSTANCE = $(shell expr ${TOTAL_ARTICLES} / ${TOTAL_INSTANCES})
ITEMS = $(shell i=0; while [ $${i} -lt ${TOTAL_INSTANCES} ]; do echo $${i}; i=$$(($${i} + 1)); done)
# check that the counts are correct to render all articles
.PHONY: print-render-info
print-render-info:
@echo WORKDIR_PATH = ${WORKDIR_PATH}
@echo DESTDIR_PATH = ${DESTDIR_PATH}
@echo TEMPDIR_PATH = ${TEMPDIR_PATH}
@echo XML_FILES_PATH = ${XML_FILES_PATH}
@echo TOTAL_ARTICLES = ${TOTAL_ARTICLES}
@echo MACHINE_COUNT = ${MACHINE_COUNT}
@echo PARALLEL_BUILD = ${PARALLEL_BUILD}
@echo TOTAL_INSTANCES = ${TOTAL_INSTANCES}
@echo ARTICLES_PER_INSTANCE = ${ARTICLES_PER_INSTANCE}
@echo ITEMS = ${ITEMS}
@echo files = 0 .. ${MAX_BLOCK}
# index
${INDEX_STAMP}:
${RM} "$@"
${MAKE} -C "${HOST_TOOLS}/offline-renderer" index \
XML_FILES="${XML_FILES_PATH}" RENDER_BLOCK="${RENDER_BLOCK}" \
WORKDIR="${WORKDIR_PATH}" DESTDIR="${DESTDIR_PATH}"
${TOUCH} "$@"
.PHONY: index-clean
index-clean:
${RM} "${INDEX_STAMP}" "${COUNTS_FILE}"
${RM} "${WORKDIR_PATH}"/*.db
${RM} "${WORKDIR_PATH}"/*.db.*
# create the individual threads
# makeblock 0..n
MAKE_BLOCK = $(eval $(call MAKE_BLOCK1,$(strip ${1})))
define MAKE_BLOCK1
.PHONY: parse${1}
parse${1}: ${PARSE_STAMP}${1}
.PHONY: render${1}
render${1}: ${RENDER_STAMP}${1}
START_${1} = $$(shell expr ${1} '*' $${ARTICLES_PER_INSTANCE} + 1)
COUNT_${1} = $$(shell if [ "${1}" -ge $$$$(($${TOTAL_INSTANCES} - 1)) ] ; then echo all; else echo $${ARTICLES_PER_INSTANCE}; fi)
${PARSE_STAMP}${1}: ${INDEX_STAMP}
${RM} "$$@"
$${MAKE} RENDER_BLOCK='${1}' START='$${START_${1}}' COUNT='$${COUNT_${1}}' parse
${TOUCH} "$$@"
${RENDER_STAMP}${1}: ${PARSE_STAMP}${1}
${RM} "$$@"
$${MAKE} RENDER_BLOCK='${1}' render
${TOUCH} "$$@"
.PHONY: stamp-clean${1}
stamp-clean${1}: stamp-parse-clean${1} stamp-render-clean${1}
.PHONY: stamp-parse-clean${1}
stamp-parse-clean${1}:
${RM} "${PARSE_STAMP}${1}"
# this is to reuse the existing parsed html after a re-index
# (but only if the stamps already exist)
.PHONY: stamp-parse-touch${1}
stamp-parse-touch${1}:
[ -e "${PARSE_STAMP}${1}" ] && ${TOUCH} "${PARSE_STAMP}${1}"
.PHONY: stamp-render-clean${1}
stamp-render-clean${1}:
${RM} "${RENDER_STAMP}${1}"
endef
$(foreach i,${ITEMS},$(call MAKE_BLOCK,${i}))
# Per machine rules
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: farm${1}-parse-clean farm${1}-render-clean
.PHONY: farm${1}-parse-clean
farm${1}-parse-clean: $$(foreach i,${2},stamp-parse-clean$$(strip $${i}))
.PHONY: farm${1}-parse-touch
farm${1}-parse-touch: $$(foreach i,${2},stamp-parse-touch$$(strip $${i}))
.PHONY: farm${1}-render-clean
farm${1}-render-clean: $$(foreach i,${2},stamp-render-clean$$(strip $${i}))
.PHONY: farm${1}
farm${1}: farm${1}-parse farm${1}-render
endef
.PHONY: farm-index
farm-index: ${INDEX_STAMP}
MAKE_MACHINE = $(eval $(call MAKE_MACHINE1,$(strip ${1}),$(strip ${2}),$(strip ${3})))
define MAKE_MACHINE1
$(call MAKE_FARM,${1}, $(shell j=$$((${1} - 1)); while [ $${j} -lt ${TOTAL_INSTANCES} ]; do echo $${j}; j=$$(($${j} + ${2})); done))
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}))
# end of WORKDIR/DESTDIR check above
endif
endif
# Download the latest translations
# ================================
ALL_LANGUAGES := af ar br cs da de en es fi fr gl gsw hu ia ja mk ml nl no pms pt pt-br ru te tr
LICENSE_DIR = XML-Licenses
# These items reference wiki articles since the process needs XML
# data files, the macro below will export the xml and download it
# directly from the sites.
#
# Any items left blank will revert to English version
#
# Note: the ones that link to deed.XX are html so cannot be used
# with the present program (these will just use English).
TERMS_da := Wikipedia:Ophavsret
#LICENSE_da := http://creativecommons.org/licenses/by-sa/3.0/deed.da
TERMS_de := Nutzungsbedingungen
LICENSE_de := Wikipedia:Lizenzbestimmungen_Commons_Attribution-ShareAlike_3.0_Unported
TERMS_en := Terms_of_Use
LICENSE_en := Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_License
TERMS_es := Términos_de_Uso
#LICENSE_es := http://creativecommons.org/licenses/by-sa/3.0/deed.es
TERMS_fi := Käyttöehdot
LICENSE_fi := Wikipedia:Creative_Commons_Attribution-Share_Alike_3.0_Unported_-lisenssiehdot
TERMS_fr := Conditions_d\'utilisation
#LICENSE_fr := http://creativecommons.org/licenses/by-sa/3.0/deed.fr
TERMS_ja := 利用規約
LICENSE_ja := Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_License
TERMS_nl := Gebruiksvoorwaarden
#LICENSE_nl := http://creativecommons.org/licenses/by-sa/3.0/deed.nl
TERMS_pt := Condições_de_Uso
#LICENSE_pt := http://creativecommons.org/licenses/by-sa/3.0/deed.pt
WIKIMEDIA_EXPORT := http://wikimediafoundation.org/wiki/Special:Export
LICENSE_EXTRA_SUFFIX := ?curonly=1&templates=1&wpDownload=1
TERMS_EXTRA_SUFFIX := ?curonly=1&wpDownload=1
# macro to retrieve files from various web sites
define GET_FILES
mkdir -p "${LICENSE_DIR}/${1}" ; \
[ -n "${2}" ] && \
wget --output-document="-" "${WIKIMEDIA_EXPORT}/${2}${TERMS_EXTRA_SUFFIX}" \
| sed 's/[[:space:]]*$$//' > "${LICENSE_DIR}/${1}/terms.xml" ; \
[ -n "${3}" ] && \
wget --output-document="-" "http://${1}.wikipedia.org/wiki/Special:Export/${3}${LICENSE_EXTRA_SUFFIX}" \
| sed 's/[[:space:]]*$$//;s/<title>Wikipedia:/<title>Wikipedia - /' > "${LICENSE_DIR}/${1}/license.xml" ; \
true ;
endef
.PHONY: fetch-nls
fetch-nls: $(foreach lang,${ALL_LANGUAGES},fetch-nls-${lang})
# fetch one language e.g. fetch-nls-en
fetch-nls-%:
echo fetching nls files for: $*
$(call GET_FILES,$*,${TERMS_$*},${LICENSE_$*})
# install nls file
.PHONY: nls-install
nls-install: validate-destdir
@. ${WIKI_NAMES} ; \
find "${DESTDIR}" -type d | \
( while read dir ; \
do \
d=$$(basename "$${dir}") ; \
for suffix in $${ListOfAllContentTypes} ; \
do \
language="$${d%$${suffix}}" ; \
if [ X"$${language}" != X"$${d}" ] ; \
then \
src="${LICENSE_DIR}/$${d%$${suffix}}/wiki.nls" ; \
native_name=$$(${SCRIPTS}/nls-print "$${language}") ; \
[ -f "$${src}" ] || src="${LICENSE_DIR}/en/wiki.nls" ; \
${SCRIPTS}/nls-installer --prefix="${DESTDIR_PATH}" \
--language="$${language}" \
--suffix="$${suffix}" \
--output="wiki.nls.tmp" \
--base="${LICENSE_DIR}/en/wiki.nls" \
--nls="$${src}" \
--change="$${native_name}" \
--verbose ; \
t_in="${DESTDIR_PATH}/$${language}$${suffix}/wiki.nls.tmp" ; \
t_out="${DESTDIR_PATH}/$${language}$${suffix}/wiki.nls" ; \
if cmp -s "$${t_in}" "$${t_out}" ; \
then \
rm -f "$${t_in}" ; \
else \
rm -f "$${t_out}" ; \
mv "$${t_in}" "$${t_out}" ; \
fi ; \
break ; \
fi ; \
done \
done \
)
# Download the latest Mediawiki dump
# ==================================
.PHONY: getwikidump
getwikidump:
wget http://download.wikimedia.org/enwiki/latest/enwiki-latest-pages-articles.xml.bz2
# Forth interpreter
# =================
$(call STD_RULE, forth, ${SAMO_LIB}/forth, gcc mini-libc fatfs drivers, INSTALL)
# FLASH programmer that runs on the device
# ========================================
$(call STD_RULE, flash, ${SAMO_LIB}/flash, gcc mini-libc fatfs drivers, INSTALL)
# Grifo small kernel
# ==================
GRIFO_EXAMPLES ?= NO
$(call STD_RULE, grifo, ${SAMO_LIB}/grifo, gcc mini-libc fatfs, INSTALL, INSTALL_GRIFO_SIMULATION="${INSTALL_GRIFO_SIMULATION}" BUILD_EXAMPLES="${GRIFO_EXAMPLES}")
.PHONY: grifo-simulate
grifo-simulate: validate-destdir
make INSTALL_GRIFO_SIMULATION=YES DESTDIR="${DESTDIR}" grifo-install
cd "${DESTDIR}" && ./init.app
# Main wiki application using grifo
# =================================
# default: progress bar = off
PROGRESS_BAR ?= NO
TEMPERATURE_DISPLAY ?= NO
$(call STD_RULE, wiki, wiki, gcc mini-libc grifo, INSTALL, PROGRESS_BAR="${PROGRESS_BAR}" TEMPERATURE_DISPLAY="${TEMPERATURE_DISPLAY}" INSTALL_GRIFO_SIMULATION="${INSTALL_GRIFO_SIMULATION}")
.PHONY: wiki-simulate
wiki-simulate: validate-destdir
make INSTALL_GRIFO_SIMULATION=YES DESTDIR="${DESTDIR}" wiki-install
cd "${DESTDIR}" && ./wiki.app
VALGRIND_OPTS += --leak-check=full
VALGRIND_OPTS += --leak-resolution=high
VALGRIND_OPTS += --show-reachable=no
VALGRIND_OPTS += --undef-value-errors=yes
VALGRIND_OPTS += --track-origins=yes
VALGRIND_OPTS += --partial-loads-ok=no
VALGRIND_OPTS += --freelist-vol=10000000
VALGRIND_OPTS += --workaround-gcc296-bugs=no
#VALGRIND_OPTS += --ignore-ranges=0xPP-0xQQ[,0xRR-0xSS]
VALGRIND_OPTS += --malloc-fill=0xff
VALGRIND_OPTS += --free-fill=0xff
.PHONY: wiki-valgrind
wiki-valgrind: validate-destdir
make INSTALL_GRIFO_SIMULATION=YES DESTDIR="${DESTDIR}" wiki-install
cd "${DESTDIR}" && valgrind ${VALGRIND_OPTS} ./wiki.app
# 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
FLASH_UPDATE ?= NO
BOOT_LOGO ?= wikireader.png
.PHONY: print-mbr-tty
print-mbr-tty:
@echo BOOTLOADER_TTY = "${BOOTLOADER_TTY}"
@echo BOOTLOADER_AUX = "${BOOTLOADER_AUX}"
$(call STD_RULE, mbr, ${SAMO_LIB}/mbr, gcc fatfs, INSTALL, LOGO="${BOOT_LOGO}")
$(call STD_RULE, jackknife, ${HOST_TOOLS}/jackknife)
$(call STD_RULE, flash07, ${HOST_TOOLS}/flash07)
.PHONY: mbr-rs232
mbr-rs232: gcc fatfs
${MAKE} -C "${SAMO_LIB}/mbr" mbr-rs232
.PHONY: flash-mbr
flash-mbr: mbr jackknife flash07
${MAKE} -C "${SAMO_LIB}/mbr" BOOTLOADER_TTY="${BOOTLOADER_TTY}" BOOTLOADER_AUX="${BOOTLOADER_AUX}" SERIAL_NUMBER="${SERIAL_NUMBER}" FLASH_UPDATE="${FLASH_UPDATE}" $@
.PHONY: flash-test-jig
flash-test-jig: mbr jackknife flash07
${MAKE} -C "${SAMO_LIB}/mbr" FLASH_TEST_JIG=YES BOOTLOADER_TTY="${BOOTLOADER_TTY}" BOOTLOADER_AUX="${BOOTLOADER_AUX}" SERIAL_NUMBER="${SERIAL_NUMBER}" flash-mbr
# final list of all items to build
# ================================
.PHONY: all-targets
all-targets: ${ALL_TARGETS}
# list required packages
# ======================
.PHONY: requirements
requirements: ${REQUIRES_TARGETS}
# Clean up generated files
# ========================
.PHONY: complete-clean
complete-clean: clean clean-toolchain
${RM} binutils-download gcc-download
.PHONY: clean
clean: ${CLEAN_TARGETS}
${RM} stamp-r-*
.PHONY: clean-toolchain
clean-toolchain:
${RM} -r "${HOST_TOOLS}/toolchain-install"
${RM} -r "${HOST_TOOLS}/gcc-${GCC_VERSION}"
${RM} -r "${HOST_TOOLS}/binutils-${BINUTILS_VERSION}"
${RM} binutils-patch binutils
${RM} gcc-patch gcc
# Update the Makefiles
# ====================
# Change the method of including definitions by
# copying part of Mk/definitions.mk into each Makefile
# if it requires it.
.PHONY: update-makefiles
update-makefiles:
@${SCRIPTS}/UpdateMakefiles --verbose \
--source="${MK_DIR}/definitions.mk" \
$(shell find "${ROOT_DIR}" -name Makefile)
# Print information about some targets
# ====================================
.PHONY: help