Makefile 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945
  1. # Makefile - a Makefile for setting up Wiki Reader
  2. #
  3. # (C) Copyright 2008, 2009 Openmoko, Inc.
  4. # Authors: xiangfu liu <xiangfu@openmoko.org>
  5. # Sean Moss-Pultz <sean@openmoko.com>
  6. # Christopher Hall <hsw@openmoko.com>
  7. #
  8. # This program is free software; you can redistribute it and/or
  9. # modify it under the terms of the GNU General Public License
  10. # version 3 as published by the Free Software Foundation.
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18. # Boston, MA 02110-1301, USA
  19. # Include standard definitions
  20. # ============================
  21. CROSS_COMPILER := NO
  22. # +++START_UPDATE_MAKEFILE: Start of auto included code
  23. # The text between the +++ and --- tags is copied by the
  24. # UpdateMakefiles script. Do not remove or change these tags.
  25. # ---
  26. # Autodetect root directory
  27. define FIND_ROOT_DIR
  28. while : ; do \
  29. d=$$(pwd) ; \
  30. [ -d "$${d}/samo-lib" ] && echo $${d} && exit 0 ; \
  31. [ X"/" = X"$${d}" ] && echo ROOT_DIRECTORY_NOT_FOUND && exit 1 ; \
  32. cd .. ; \
  33. done
  34. endef
  35. ROOT_DIR := $(shell ${FIND_ROOT_DIR})
  36. # Directory of Makefile includes
  37. MK_DIR := ${ROOT_DIR}/samo-lib/Mk
  38. # Include the initial Makefile setup
  39. include ${MK_DIR}/definitions.mk
  40. # ---END_UPDATE_MAKEFILE: End of auto included code
  41. # Toolchain configuration data
  42. # ============================
  43. GCC_VERSION = 3.3.2
  44. GCC_PACKAGE = gcc-${GCC_VERSION}.tar.gz
  45. GCC_URL = ftp://ftp.gnu.org/gnu/gcc/${GCC_PACKAGE}
  46. BINUTILS_VERSION = 2.10.1
  47. BINUTILS_PACKAGE = binutils-${BINUTILS_VERSION}.tar.gz
  48. BINUTILS_URL= ftp://ftp.gnu.org/gnu/binutils/${BINUTILS_PACKAGE}
  49. DOWNLOAD_DIR = ${HOST_TOOLS}/toolchain-download
  50. SUM_DIR = ${HOST_TOOLS}/toolchain-sums
  51. CONFIG_FILE := "${SAMO_LIB}/include/config.h"
  52. CONFIG_FILE_DEFAULT := "${SAMO_LIB}/include/config.h-default"
  53. CONFIG_FILE_EXISTS := $(shell [ -f "${CONFIG_FILE}" ] && echo 1)
  54. ifeq (${CONFIG_FILE_EXISTS},)
  55. $(shell cp ${CONFIG_FILE_DEFAULT} ${CONFIG_FILE})
  56. $(error edit ${CONFIG_FILE} file and re-run make)
  57. endif
  58. # Configuration data
  59. # ==================
  60. ALL_TARGETS =
  61. ALL_TARGETS += mbr
  62. ALL_TARGETS += jackknife
  63. ALL_TARGETS += forth
  64. ALL_TARGETS += flash
  65. ALL_TARGETS += mahatma
  66. ALL_TARGETS += qt4-simulator
  67. #ALL_TARGETS += hash-gen
  68. ALL_TARGETS += pcf2bmf
  69. ALL_TARGETS += fonts
  70. .PHONY: all
  71. all: ${ALL_TARGETS}
  72. # wiki naming
  73. # ===========
  74. WIKI_LANGUAGE ?= en
  75. WIKI_FILE_PREFIX ?= wiki
  76. WIKI_DIR_SUFFIX ?= pedia
  77. # Installation
  78. # ============
  79. DESTDIR_PATH := $(abspath ${DESTDIR})
  80. WORKDIR_PATH := $(abspath ${WORKDIR})
  81. TEMPDIR_PATH := $(abspath ${TEMPDIR})
  82. ifeq (,$(strip ${TEMPDIR_PATH}))
  83. TEMPDIR_PATH := ${WORKDIR_PATH}/tmp
  84. endif
  85. VERSION_TAG ?= $(shell date '+%Y%m%d')
  86. VERSION_FILE := ${DESTDIR_PATH}/version.txt
  87. SHA_LEVEL := 256
  88. CHECKSUM_FILE := sha${SHA_LEVEL}.txt
  89. .PHONY: jig-install
  90. jig-install: validate-destdir forth-install flash-install mbr-install
  91. .PHONY: install
  92. install: validate-destdir forth-install mahatma-install fonts-install nls-install misc-files-install version
  93. .PHONY: version
  94. version: validate-destdir
  95. @if [ -z "${VERSION_TAG}" ] ; then echo VERSION_TAG: "'"${VERSION_TAG}"'" is not valid ; exit 1; fi
  96. ${RM} "${VERSION_FILE}" "${DESTDIR_PATH}"/*.idx-tmp "${DESTDIR_PATH}"/*~
  97. ${RM} "${DESTDIR_PATH}"/*/*.idx-tmp
  98. echo VERSION: ${VERSION_TAG} >> "${VERSION_FILE}"
  99. ${RM} "${DESTDIR_PATH}"/*.[pP][aA][sS] "${DESTDIR_PATH}"/*.[hH][sS][tT] "${DESTDIR_PATH}"/*.[iI][nN][iI]
  100. find "${DESTDIR_PATH}" -type d -print -exec \
  101. sh -c "cd '{}' && ${RM} '${CHECKSUM_FILE}' && sha${SHA_LEVEL}sum * > '${CHECKSUM_FILE}'" ';'
  102. .PHONY: misc-files-install
  103. misc-files-install: validate-destdir
  104. ${RM} "${MISC_FILES}"/*~
  105. ${RM} "${LICENSES}"/*~
  106. cp -p "${MISC_FILES}"/* "${DESTDIR_PATH}"/
  107. cp -p "${LICENSES}"/* "${DESTDIR_PATH}"/
  108. .PHONY: validate-destdir
  109. validate-destdir:
  110. @if [ ! -d "${DESTDIR_PATH}" ] ; then echo DESTDIR: "'"${DESTDIR_PATH}"'" is not a directory ; exit 1; fi
  111. @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
  112. # Main program
  113. # ============
  114. .PHONY: mahatma
  115. mahatma: mini-libc fatfs
  116. ${MAKE} -C ${SAMO_LIB}/mahatma
  117. .PHONY: mahatma-install
  118. mahatma-install: mahatma validate-destdir
  119. ${MAKE} -C ${SAMO_LIB}/mahatma install DESTDIR="${DESTDIR_PATH}"
  120. # Libraries
  121. # =========
  122. .PHONY:mini-libc
  123. mini-libc: toolchain
  124. ${MAKE} -C ${SAMO_LIB}/mini-libc/
  125. .PHONY: fatfs
  126. fatfs: mini-libc drivers
  127. ${MAKE} -C ${SAMO_LIB}/fatfs/
  128. .PHONY: drivers
  129. drivers: mini-libc
  130. ${MAKE} -C ${SAMO_LIB}/drivers/
  131. # GCC and Binutils toolchain
  132. # ==========================
  133. BINUTILS_FILE = ${DOWNLOAD_DIR}/${BINUTILS_PACKAGE}
  134. BINUTILS_SUM = ${SUM_DIR}/${BINUTILS_PACKAGE}.SHA256
  135. GCC_FILE = ${DOWNLOAD_DIR}/${GCC_PACKAGE}
  136. GCC_SUM = ${SUM_DIR}/${GCC_PACKAGE}.SHA256
  137. GET_FILE = $(eval $(call GET_FILE1,$(strip ${1}),$(strip ${2}),$(strip ${3}),$(strip ${4})))
  138. define GET_FILE1
  139. ${1}:
  140. @mkdir -p "$${DOWNLOAD_DIR}"
  141. @if ! ([ -f "${2}" ] && cd "$${DOWNLOAD_DIR}" && sha256sum --check "${3}") ; \
  142. then \
  143. ${RM} "${2}" ; \
  144. wget -c -O "${2}" "${4}"; \
  145. else \
  146. echo Already downloaded: ${2} ; \
  147. fi
  148. @${TOUCH} "$$@"
  149. endef
  150. $(call GET_FILE,binutils-download,${BINUTILS_FILE},${BINUTILS_SUM},${BINUTILS_URL})
  151. $(call GET_FILE,gcc-download,${GCC_FILE},${GCC_SUM},${GCC_URL})
  152. binutils-patch: binutils-download
  153. mkdir -p ${HOST_TOOLS}/toolchain-install
  154. ${RM} -r "${HOST_TOOLS}/binutils-${BINUTILS_PACKAGE}"
  155. tar -xvzf "${BINUTILS_FILE}" -C ${HOST_TOOLS}
  156. cd ${HOST_TOOLS} && \
  157. cd "binutils-${BINUTILS_VERSION}" && \
  158. for p in ../toolchain-patches/*-binutils-*.patch ; \
  159. do \
  160. patch -p1 < "$${p}" ; \
  161. done
  162. ${TOUCH} "$@"
  163. binutils: binutils-patch
  164. cd ${HOST_TOOLS} && \
  165. cd "binutils-${BINUTILS_VERSION}" && \
  166. mkdir -p build && \
  167. cd build && \
  168. CPPFLAGS="-D_FORTIFY_SOURCE=0" ../configure --prefix "${HOST_TOOLS}/toolchain-install" --target=c33-epson-elf && \
  169. CPPFLAGS="-D_FORTIFY_SOURCE=0" ${MAKE} && \
  170. ${MAKE} install
  171. ${TOUCH} "$@"
  172. gcc-patch: gcc-download
  173. mkdir -p ${HOST_TOOLS}/toolchain-install
  174. tar -xvzf "${GCC_FILE}" -C ${HOST_TOOLS}
  175. cd ${HOST_TOOLS} && \
  176. cd "gcc-${GCC_VERSION}" && \
  177. for p in ../toolchain-patches/*-gcc-*.patch ; \
  178. do \
  179. patch -p1 < "$${p}" ; \
  180. done
  181. ${TOUCH} "$@"
  182. gcc: binutils gcc-patch
  183. cd ${HOST_TOOLS} && \
  184. export PATH="${HOST_TOOLS}/toolchain-install/bin:${PATH}" && \
  185. cd "gcc-${GCC_VERSION}" && \
  186. mkdir -p build && \
  187. cd build && \
  188. CPPFLAGS="-D_FORTIFY_SOURCE=0" ../configure --prefix "${HOST_TOOLS}/toolchain-install" --target=c33-epson-elf --enable-languages=c && \
  189. CPPFLAGS="-D_FORTIFY_SOURCE=0" ${MAKE} && \
  190. ${MAKE} install
  191. ${TOUCH} "$@"
  192. .PHONY: toolchain
  193. toolchain: toolchain-requires gcc
  194. .PHONY: toolchain-requires
  195. toolchain-requires:
  196. true $(call REQUIRED_BINARY, patch, patch)
  197. true $(call REQUIRED_BINARY, gcc, gcc)
  198. true $(call REQUIRED_BINARY, lex, flex)
  199. true $(call REQUIRED_BINARY, bison, bison)
  200. # QT simulator
  201. # ============
  202. .PHONY: qt4-simulator
  203. qt4-simulator:
  204. true $(call REQUIRED_BINARY, g++, g++)
  205. true $(call REQUIRED_BINARY, qmake, qt4-qmake libqt4-dev)
  206. cd ${HOST_TOOLS}/qt4-simulator && qmake && ${MAKE}
  207. .PHONY: sim4
  208. sim4: qt4-simulator validate-destdir
  209. cd "${DESTDIR}" && ${HOST_TOOLS}/qt4-simulator/bin/wikisim ${ARTICLE}
  210. .PHONY: sim4d
  211. sim4d: qt4-simulator validate-destdir
  212. cd "${DESTDIR}" && gdb --args ${HOST_TOOLS}/qt4-simulator/bin/wikisim ${ARTICLE}
  213. .PHONY: console-simulator
  214. console-simulator:
  215. cd ${HOST_TOOLS}/console-simulator && ${MAKE}
  216. # Hash generator for search index
  217. # ===============================
  218. #.PHONY: hash-gen
  219. #hash-gen:
  220. # cd ${HOST_TOOLS}/hash-gen && ${MAKE}
  221. # Font processing
  222. # ===============
  223. .PHONY: pcf2bmf
  224. pcf2bmf:
  225. cd ${HOST_TOOLS}/pcf2bmf && ${MAKE}
  226. .PHONY: fonts
  227. fonts: pcf2bmf
  228. cd ${HOST_TOOLS}/fonts && ${MAKE}
  229. .PHONY: fonts-install
  230. fonts-install: fonts validate-destdir
  231. cd ${HOST_TOOLS}/fonts && ${MAKE} DESTDIR="${DESTDIR_PATH}" install
  232. # Compression interface
  233. # =====================
  234. # in case the platform lacks the python-lzma package
  235. # (only present in ?Ubuntu >= lucid 10.04)
  236. # then there is a local verion of the older PyLZMA module
  237. # that can be installed instead
  238. .PHONY: local-pylzma-install
  239. local-pylzma-install:
  240. ${MAKE} -C ${HOST_TOOLS}/offline-renderer pylzma
  241. # Build the database from wiki XML files
  242. # ======================================
  243. XML_FILES_PATH = $(realpath ${XML_FILES})
  244. RENDER_BLOCK ?= 0
  245. TOTAL_HTML_FILES ?= 27
  246. # rendering compression parameters
  247. # images are the output of the math turning it to NO will show TeX from 'alt'
  248. ENABLE_LANGUAGES_LINKS ?= YES
  249. ENABLE_IMAGES ?= YES
  250. ARTICLES_PER_BLOCK ?= 32
  251. ARTICLE_BLOCK_SIZE ?= 262144
  252. # erase the working directories for the current language
  253. .PHONY: cleandirs
  254. cleandirs:
  255. @if [ -z "${DESTDIR_PATH}" ] ; then echo missing DESTDIR ; exit 1 ; fi
  256. @if [ -z "${WORKDIR_PATH}" ] ; then echo missing WORKDIR ; exit 1 ; fi
  257. @if [ -z "${TEMPDIR_PATH}" ] ; then echo missing TEMPDIR ; exit 1 ; fi
  258. ${RM} -r "${DESTDIR_PATH}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}"
  259. ${RM} -r "${TEMPDIR_PATH}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}"
  260. ${RM} -r "${WORKDIR_PATH}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}"
  261. # only create dirs (does not erase them)
  262. .PHONY: createdirs
  263. createdirs:
  264. @if [ -z "${DESTDIR_PATH}" ] ; then echo missing DESTDIR ; exit 1 ; fi
  265. @if [ -z "${WORKDIR_PATH}" ] ; then echo missing WORKDIR ; exit 1 ; fi
  266. @if [ -z "${TEMPDIR_PATH}" ] ; then echo missing TEMPDIR ; exit 1 ; fi
  267. ${MKDIR} "${DESTDIR_PATH}"
  268. ${MKDIR} "${DESTDIR_PATH}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}"
  269. ${MKDIR} "${WORKDIR_PATH}"
  270. ${MKDIR} "${WORKDIR_PATH}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}"
  271. ${MKDIR} "${TEMPDIR_PATH}"
  272. ${MKDIR} "${TEMPDIR_PATH}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}"
  273. .PHONY: index
  274. index: validate-destdir
  275. cd ${HOST_TOOLS}/offline-renderer && ${MAKE} index \
  276. WIKI_LANGUAGE="${WIKI_LANGUAGE}" WIKI_FILE_PREFIX="${WIKI_FILE_PREFIX}" \
  277. WIKI_DIR_SUFFIX="${WIKI_DIR_SUFFIX}" \
  278. XML_FILES="${XML_FILES_PATH}" RENDER_BLOCK="${RENDER_BLOCK}" \
  279. TOTAL_HTML_FILES="${TOTAL_HTML_FILES}" \
  280. TEMPDIR="${TEMPDIR_PATH}" \
  281. WORKDIR="${WORKDIR_PATH}" DESTDIR="${DESTDIR_PATH}"
  282. .PHONY: parse
  283. parse: validate-destdir
  284. cd ${HOST_TOOLS}/offline-renderer && ${MAKE} parse \
  285. WIKI_LANGUAGE="${WIKI_LANGUAGE}" WIKI_FILE_PREFIX="${WIKI_FILE_PREFIX}" \
  286. WIKI_DIR_SUFFIX="${WIKI_DIR_SUFFIX}" \
  287. XML_FILES="${XML_FILES_PATH}" RENDER_BLOCK="${RENDER_BLOCK}" \
  288. TOTAL_HTML_FILES="${TOTAL_HTML_FILES}" \
  289. TEMPDIR="${TEMPDIR_PATH}" \
  290. WORKDIR="${WORKDIR_PATH}" DESTDIR="${DESTDIR_PATH}"
  291. .PHONY: merge
  292. merge: validate-destdir
  293. cd ${HOST_TOOLS}/offline-renderer && ${MAKE} merge \
  294. WIKI_LANGUAGE="${WIKI_LANGUAGE}" WIKI_FILE_PREFIX="${WIKI_FILE_PREFIX}" \
  295. WIKI_DIR_SUFFIX="${WIKI_DIR_SUFFIX}" \
  296. XML_FILES="${XML_FILES_PATH}" RENDER_BLOCK="${RENDER_BLOCK}" \
  297. TOTAL_HTML_FILES="${TOTAL_HTML_FILES}" \
  298. TEMPDIR="${TEMPDIR_PATH}" \
  299. WORKDIR="${WORKDIR_PATH}" DESTDIR="${DESTDIR_PATH}"
  300. .PHONY: render
  301. render: fonts validate-destdir
  302. cd ${HOST_TOOLS}/offline-renderer && ${MAKE} render \
  303. WIKI_LANGUAGE="${WIKI_LANGUAGE}" WIKI_FILE_PREFIX="${WIKI_FILE_PREFIX}" \
  304. WIKI_DIR_SUFFIX="${WIKI_DIR_SUFFIX}" \
  305. XML_FILES="${XML_FILES_PATH}" RENDER_BLOCK="${RENDER_BLOCK}" \
  306. TOTAL_HTML_FILES="${TOTAL_HTML_FILES}" \
  307. ENABLE_LANGUAGES_LINKS="${ENABLE_LANGUAGES_LINKS}" \
  308. ENABLE_IMAGES="${ENABLE_IMAGES}" \
  309. ARTICLES_PER_BLOCK="${ARTICLES_PER_BLOCK}" \
  310. ARTICLE_BLOCK_SIZE="${ARTICLE_BLOCK_SIZE}" \
  311. TEMPDIR="${TEMPDIR_PATH}" \
  312. WORKDIR="${WORKDIR_PATH}" DESTDIR="${DESTDIR_PATH}"
  313. .PHONY: combine
  314. combine: validate-destdir
  315. cd ${HOST_TOOLS}/offline-renderer && ${MAKE} combine \
  316. WIKI_LANGUAGE="${WIKI_LANGUAGE}" WIKI_FILE_PREFIX="${WIKI_FILE_PREFIX}" \
  317. WIKI_DIR_SUFFIX="${WIKI_DIR_SUFFIX}" \
  318. XML_FILES="${XML_FILES_PATH}" RENDER_BLOCK="${RENDER_BLOCK}" \
  319. TOTAL_HTML_FILES="${TOTAL_HTML_FILES}" \
  320. TEMPDIR="${TEMPDIR_PATH}" \
  321. WORKDIR="${WORKDIR_PATH}" DESTDIR="${DESTDIR_PATH}"
  322. #.PHONY: hash
  323. #hash: validate-destdir hash-gen
  324. # cd "${DESTDIR}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}" && ${HOST_TOOLS}/hash-gen/hash-gen \
  325. # --pfx="${DESTDIR_PATH}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}/${WIKI_FILE_PREFIX}.pfx" \
  326. # --fnd="${DESTDIR_PATH}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}/${WIKI_FILE_PREFIX}.fnd" \
  327. # --hsh="${DESTDIR_PATH}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}/${WIKI_FILE_PREFIX}.hsh"
  328. # run all stages (for testing small XML sample files)
  329. #.PHONY: iprch
  330. #iprch: index parse render combine hash
  331. # run all stages (for testing small XML sample files)
  332. .PHONY: iprc
  333. iprc: index parse render combine
  334. # Build database using multiple machines
  335. # ======================================
  336. ifneq (,$(strip ${WORKDIR_PATH}))
  337. ifneq (,$(strip ${DESTDIR_PATH}))
  338. INDEX_STAMP := ${WORKDIR_PATH}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}/stamp-index
  339. PARSE_STAMP := ${WORKDIR_PATH}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}/stamp-parse
  340. RENDER_STAMP := ${WORKDIR_PATH}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}/stamp-render
  341. # ---------------------------------------------------------------------------------------
  342. # Get the number of articles from the indexer and compute how many articles per instance
  343. # ---------------------------------------------------------------------------------------
  344. MACHINE_COUNT ?= 9
  345. PARALLEL_BUILD ?= 3
  346. COUNTS_FILE = ${WORKDIR_PATH}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}/counts.text
  347. TOTAL_ARTICLES = $(shell awk '/^Articles:/{ print $$2 }' "${COUNTS_FILE}" 2>/dev/null || echo 0)
  348. TOTAL_INSTANCES := $(shell expr ${MACHINE_COUNT} '*' ${PARALLEL_BUILD})
  349. # 64 dat files is the maximum allowed
  350. CHECK := $(shell if [ ${TOTAL_INSTANCES} -gt 64 ]; then echo 0; else echo 1; fi )
  351. ifeq ($(strip ${CHECK}),0)
  352. $(error Too many machines or processes being used. Maximum is 64 total instances)
  353. endif
  354. MAX_BLOCK := $(shell expr ${TOTAL_INSTANCES} - 1)
  355. ARTICLES_PER_INSTANCE = $(shell expr ${TOTAL_ARTICLES} / ${TOTAL_INSTANCES})
  356. ITEMS = $(shell i=0; while [ $${i} -lt ${TOTAL_INSTANCES} ]; do echo $${i}; i=$$(($${i} + 1)); done)
  357. # check that the counts are correct to render all articles
  358. .PHONY: print-render-info
  359. print-render-info:
  360. @echo WORKDIR_PATH = ${WORKDIR_PATH}
  361. @echo DESTDIR_PATH = ${DESTDIR_PATH}
  362. @echo TEMPDIR_PATH = ${TEMPDIR_PATH}
  363. @echo XML_FILES_PATH = ${XML_FILES_PATH}
  364. @echo TOTAL_ARTICLES = ${TOTAL_ARTICLES}
  365. @echo MACHINE_COUNT = ${MACHINE_COUNT}
  366. @echo PARALLEL_BUILD = ${PARALLEL_BUILD}
  367. @echo TOTAL_INSTANCES = ${TOTAL_INSTANCES}
  368. @echo ARTICLES_PER_INSTANCE = ${ARTICLES_PER_INSTANCE}
  369. @echo ITEMS = ${ITEMS}
  370. @echo files = 0 .. ${MAX_BLOCK}
  371. # index
  372. ${INDEX_STAMP}:
  373. ${RM} "$@"
  374. cd ${HOST_TOOLS}/offline-renderer && ${MAKE} index \
  375. XML_FILES="${XML_FILES_PATH}" RENDER_BLOCK="${RENDER_BLOCK}" \
  376. WORKDIR="${WORKDIR_PATH}" DESTDIR="${DESTDIR_PATH}"
  377. ${TOUCH} "$@"
  378. .PHONY: index-clean
  379. index-clean:
  380. ${RM} "${INDEX_STAMP}" "${COUNTS_FILE}"
  381. ${RM} "${WORKDIR_PATH}"/*.db
  382. ${RM} "${WORKDIR_PATH}"/*.db.*
  383. # create the individual threads
  384. # makeblock 0..n
  385. MAKE_BLOCK = $(eval $(call MAKE_BLOCK1,$(strip ${1})))
  386. define MAKE_BLOCK1
  387. .PHONY: parse${1}
  388. parse${1}: ${PARSE_STAMP}${1}
  389. .PHONY: render${1}
  390. render${1}: ${RENDER_STAMP}${1}
  391. START_${1} = $$(shell expr ${1} '*' $${ARTICLES_PER_INSTANCE} + 1)
  392. COUNT_${1} = $$(shell if [ "${1}" -ge $$$$(($${TOTAL_INSTANCES} - 1)) ] ; then echo all; else echo $${ARTICLES_PER_INSTANCE}; fi)
  393. ${PARSE_STAMP}${1}: ${INDEX_STAMP}
  394. ${RM} "$$@"
  395. $${MAKE} RENDER_BLOCK='${1}' START='$${START_${1}}' COUNT='$${COUNT_${1}}' parse
  396. ${TOUCH} "$$@"
  397. ${RENDER_STAMP}${1}: ${PARSE_STAMP}${1}
  398. ${RM} "$$@"
  399. $${MAKE} RENDER_BLOCK='${1}' render
  400. ${TOUCH} "$$@"
  401. .PHONY: stamp-clean${1}
  402. stamp-clean${1}: stamp-parse-clean${1} stamp-render-clean${1}
  403. .PHONY: stamp-parse-clean${1}
  404. stamp-parse-clean${1}:
  405. ${RM} "${PARSE_STAMP}${1}"
  406. # this is to reuse the existing parsed html after a re-index
  407. # (but only if the stamps already exist)
  408. .PHONY: stamp-parse-touch${1}
  409. stamp-parse-touch${1}:
  410. [ -e "${PARSE_STAMP}${1}" ] && ${TOUCH} "${PARSE_STAMP}${1}"
  411. .PHONY: stamp-render-clean${1}
  412. stamp-render-clean${1}:
  413. ${RM} "${RENDER_STAMP}${1}"
  414. endef
  415. $(foreach i,${ITEMS},$(call MAKE_BLOCK,${i}))
  416. # Per machine rules
  417. MAKE_FARM = $(eval $(call MAKE_FARM1,$(strip ${1}),$(strip ${2}),$(strip ${3})))
  418. define MAKE_FARM1
  419. .PHONY: farm${1}-parse
  420. farm${1}-parse: $$(foreach i,${2},parse$$(strip $${i}))
  421. .PHONY: farm${1}-render
  422. farm${1}-render: $$(foreach i,${2},render$$(strip $${i}))
  423. .PHONY: farm${1}-clean
  424. farm${1}-clean: farm${1}-parse-clean farm${1}-render-clean
  425. .PHONY: farm${1}-parse-clean
  426. farm${1}-parse-clean: $$(foreach i,${2},stamp-parse-clean$$(strip $${i}))
  427. .PHONY: farm${1}-parse-touch
  428. farm${1}-parse-touch: $$(foreach i,${2},stamp-parse-touch$$(strip $${i}))
  429. .PHONY: farm${1}-render-clean
  430. farm${1}-render-clean: $$(foreach i,${2},stamp-render-clean$$(strip $${i}))
  431. .PHONY: farm${1}
  432. farm${1}: farm${1}-parse farm${1}-render
  433. endef
  434. .PHONY: farm-index
  435. farm-index: ${INDEX_STAMP}
  436. MAKE_MACHINE = $(eval $(call MAKE_MACHINE1,$(strip ${1}),$(strip ${2}),$(strip ${3})))
  437. define MAKE_MACHINE1
  438. $(call MAKE_FARM,${1}, $(shell j=$$((${1} - 1)); while [ $${j} -lt ${TOTAL_INSTANCES} ]; do echo $${j}; j=$$(($${j} + ${2})); done))
  439. endef
  440. MACHINE_LIST := $(shell i=1; while [ $${i} -le ${MACHINE_COUNT} ]; do echo $${i}; i=$$(($${i} + 1)); done)
  441. $(foreach i,${MACHINE_LIST},$(call MAKE_MACHINE,${i},${MACHINE_COUNT}))
  442. # end of WORKDIR/DESTDIR check above
  443. endif
  444. endif
  445. # Download the latest translations
  446. # ================================
  447. 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
  448. LICENSE_DIR = XML-Licenses
  449. # These items reference wiki articles since the process needs XML
  450. # data files, the macro below will export the xml and download it
  451. # directly from the sites.
  452. #
  453. # Any items left blank will revert to English version
  454. #
  455. # Note: the ones that link to deed.XX are html so cannot be used
  456. # with the present program (these will just use English).
  457. TERMS_da := Wikipedia:Ophavsret
  458. #LICENSE_da := http://creativecommons.org/licenses/by-sa/3.0/deed.da
  459. TERMS_de := Nutzungsbedingungen
  460. LICENSE_de := Wikipedia:Lizenzbestimmungen_Commons_Attribution-ShareAlike_3.0_Unported
  461. TERMS_en := Terms_of_Use
  462. LICENSE_en := Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_License
  463. TERMS_es := Términos_de_Uso
  464. #LICENSE_es := http://creativecommons.org/licenses/by-sa/3.0/deed.es
  465. TERMS_fi := Käyttöehdot
  466. LICENSE_fi := Wikipedia:Creative_Commons_Attribution-Share_Alike_3.0_Unported_-lisenssiehdot
  467. TERMS_fr := Conditions_d\'utilisation
  468. #LICENSE_fr := http://creativecommons.org/licenses/by-sa/3.0/deed.fr
  469. TERMS_ja := 利用規約
  470. LICENSE_ja := Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_License
  471. TERMS_nl := Gebruiksvoorwaarden
  472. #LICENSE_nl := http://creativecommons.org/licenses/by-sa/3.0/deed.nl
  473. TERMS_pt := Condições_de_Uso
  474. #LICENSE_pt := http://creativecommons.org/licenses/by-sa/3.0/deed.pt
  475. WIKIREADER_CREATE_NLS := http://www.thewikireader.com/create_nls.php
  476. WIKIMEDIA_EXPORT := http://wikimediafoundation.org/wiki/Special:Export
  477. LICENSE_EXTRA_SUFFIX := ?curonly=1&templates=1&wpDownload=1
  478. TERMS_EXTRA_SUFFIX := ?curonly=1&wpDownload=1
  479. # macro to retrieve files from various web sites
  480. define GET_FILES
  481. mkdir -p "${LICENSE_DIR}/${1}" ; \
  482. wget --output-document="-" "${WIKIREADER_CREATE_NLS}?lang=${1}" \
  483. | sed 's/[[:space:]]*$$//;/^$$/d' > "${LICENSE_DIR}/${1}/wiki.nls" ; \
  484. [ -n "${2}" ] && \
  485. wget --output-document="-" "${WIKIMEDIA_EXPORT}/${2}${TERMS_EXTRA_SUFFIX}" \
  486. | sed 's/[[:space:]]*$$//' > "${LICENSE_DIR}/${1}/terms.xml" ; \
  487. [ -n "${3}" ] && \
  488. wget --output-document="-" "http://${1}.wikipedia.org/wiki/Special:Export/${3}${LICENSE_EXTRA_SUFFIX}" \
  489. | sed 's/[[:space:]]*$$//;s/<title>Wikipedia:/<title>Wikipedia - /' > "${LICENSE_DIR}/${1}/license.xml" ; \
  490. true ;
  491. endef
  492. .PHONY: fetch-nls
  493. fetch-nls: $(foreach lang,${ALL_LANGUAGES},fetch-nls-${lang})
  494. # fetch one language e.g. fetch-nls-en
  495. fetch-nls-%:
  496. echo fetching nls files for: $*
  497. $(call GET_FILES,$*,${TERMS_$*},${LICENSE_$*})
  498. # install nls file
  499. .PHONY: nls-install
  500. nls-install: validate-destdir
  501. @find "${DESTDIR}" -type d | \
  502. ( while read dir ; \
  503. do \
  504. d=$$(basename "$${dir}") ; \
  505. for s in $${d} $${d%%pedia} ; \
  506. do \
  507. src="${LICENSE_DIR}/$${s}/wiki.nls" ; \
  508. dest="${DESTDIR_PATH}/$${d}" ; \
  509. if [ -f "$${src}" ] ; \
  510. then \
  511. echo copy: $${src} to: $${dest} ; \
  512. cp -p "$${src}" "$${dest}" ; \
  513. fi ; \
  514. done \
  515. done \
  516. )
  517. # Download the latest Mediawiki dump
  518. # ==================================
  519. .PHONY: getwikidump
  520. getwikidump:
  521. wget http://download.wikimedia.org/enwiki/latest/enwiki-latest-pages-articles.xml.bz2
  522. # Forth interpreter
  523. # =================
  524. .PHONY: forth
  525. forth: gcc mini-libc fatfs drivers
  526. ${MAKE} -C ${SAMO_LIB}/forth
  527. .PHONY: forth-install
  528. forth-install: forth
  529. ${MAKE} -C ${SAMO_LIB}/forth install DESTDIR="${DESTDIR_PATH}"
  530. # FLASH programmer that runs on the device
  531. # ========================================
  532. .PHONY: flash
  533. flash: gcc mini-libc fatfs drivers
  534. ${MAKE} -C ${SAMO_LIB}/flash
  535. .PHONY: flash-install
  536. flash-install: flash
  537. ${MAKE} -C ${SAMO_LIB}/flash install DESTDIR="${DESTDIR_PATH}"
  538. # Grifo small kernel
  539. # ==================
  540. .PHONY: grifo
  541. grifo: gcc mini-libc fatfs
  542. ${MAKE} -C ${SAMO_LIB}/grifo
  543. .PHONY: grifo-install
  544. grifo-install: grifo
  545. ${MAKE} -C ${SAMO_LIB}/grifo install DESTDIR="${DESTDIR_PATH}"
  546. # Master boot record
  547. # ==================
  548. define FindTTY
  549. for i in USBconsole ttyUSB2 ttyUSB1 ttyUSB0;
  550. do
  551. d="/dev/$${i}";
  552. if [ -e "$${d}" ];
  553. then
  554. echo -n $${d};
  555. exit 0;
  556. fi;
  557. done;
  558. echo -n /dev/TTY-NOT-FOUND;
  559. exit 1;
  560. endef
  561. define FindAUX
  562. for i in USBjtag;
  563. do
  564. d="/dev/$${i}";
  565. if [ -e "$${d}" ];
  566. then
  567. echo -n $${d};
  568. exit 0;
  569. fi;
  570. done;
  571. echo -n /dev/TTY-NOT-FOUND;
  572. exit 1;
  573. endef
  574. BOOTLOADER_TTY ?= $(shell ${FindTTY})
  575. BOOTLOADER_AUX ?= $(shell ${FindAUX})
  576. SERIAL_NUMBER ?= No Serial Number
  577. FLASH_UPDATE ?= NO
  578. .PHONY: print-mbr-tty
  579. print-mbr-tty:
  580. @echo BOOTLOADER_TTY = "${BOOTLOADER_TTY}"
  581. @echo BOOTLOADER_AUX = "${BOOTLOADER_AUX}"
  582. .PHONY: mbr
  583. mbr: gcc fatfs
  584. ${MAKE} -C ${SAMO_LIB}/mbr
  585. .PHONY: mbr-rs232
  586. mbr-rs232: gcc fatfs
  587. ${MAKE} -C ${SAMO_LIB}/mbr mbr-rs232
  588. .PHONY: jackknife
  589. jackknife:
  590. ${MAKE} -C ${HOST_TOOLS}/jackknife
  591. .PHONY: flash-mbr
  592. flash-mbr: mbr jackknife
  593. ${MAKE} -C ${SAMO_LIB}/mbr BOOTLOADER_TTY="${BOOTLOADER_TTY}" BOOTLOADER_AUX="${BOOTLOADER_AUX}" SERIAL_NUMBER="${SERIAL_NUMBER}" FLASH_UPDATE="${FLASH_UPDATE}" $@
  594. .PHONY: flash-test-jig
  595. flash-test-jig: mbr jackknife
  596. ${MAKE} -C ${SAMO_LIB}/mbr FLASH_TEST_JIG=YES BOOTLOADER_TTY="${BOOTLOADER_TTY}" BOOTLOADER_AUX="${BOOTLOADER_AUX}" SERIAL_NUMBER="${SERIAL_NUMBER}" flash-mbr
  597. .PHONY: mbr-install
  598. mbr-install: mbr
  599. ${MAKE} -C ${SAMO_LIB}/mbr install DESTDIR="${DESTDIR_PATH}"
  600. # list required packages
  601. # ======================
  602. .PHONY: requirements
  603. requirements: toolchain-requires
  604. ${MAKE} requires -C ${SAMO_LIB}/mini-libc
  605. ${MAKE} requires -C ${HOST_TOOLS}/jackknife
  606. #${MAKE} requires -C ${HOST_TOOLS}/hash-gen
  607. ${MAKE} requires -C ${HOST_TOOLS}/pcf2bmf
  608. ${MAKE} requires -C ${HOST_TOOLS}/flash07
  609. ${MAKE} requires -C ${HOST_TOOLS}/fonts
  610. ${MAKE} requires -C ${HOST_TOOLS}/offline-renderer
  611. ${MAKE} requires -C ${SAMO_LIB}/mbr
  612. ${MAKE} requires -C ${SAMO_LIB}/drivers
  613. ${MAKE} requires -C ${SAMO_LIB}/fatfs
  614. ${MAKE} requires -C ${SAMO_LIB}/forth
  615. ${MAKE} requires -C ${SAMO_LIB}/flash
  616. ${MAKE} requires -C ${SAMO_LIB}/grifo
  617. ${MAKE} requires -C ${SAMO_LIB}/mahatma
  618. # Clean up generated files
  619. # ========================
  620. .PHONY: complete-clean
  621. complete-clean: clean clean-toolchain
  622. ${RM} binutils-download gcc-download
  623. .PHONY: clean
  624. clean: clean-qt4-simulator clean-console-simulator
  625. ${MAKE} clean -C ${SAMO_LIB}/mini-libc
  626. ${MAKE} clean -C ${HOST_TOOLS}/jackknife
  627. #${MAKE} clean -C ${HOST_TOOLS}/hash-gen
  628. ${MAKE} clean -C ${HOST_TOOLS}/pcf2bmf
  629. ${MAKE} clean -C ${HOST_TOOLS}/flash07
  630. ${MAKE} clean -C ${HOST_TOOLS}/fonts
  631. ${MAKE} clean -C ${HOST_TOOLS}/offline-renderer
  632. ${MAKE} clean -C ${SAMO_LIB}/mbr
  633. ${MAKE} clean -C ${SAMO_LIB}/drivers
  634. ${MAKE} clean -C ${SAMO_LIB}/fatfs
  635. ${MAKE} clean -C ${SAMO_LIB}/forth
  636. ${MAKE} clean -C ${SAMO_LIB}/flash
  637. ${MAKE} clean -C ${SAMO_LIB}/grifo
  638. ${MAKE} clean -C ${SAMO_LIB}/mahatma
  639. ${RM} stamp-r-*
  640. .PHONY: clean-toolchain
  641. clean-toolchain:
  642. ${RM} -r ${HOST_TOOLS}/toolchain-install
  643. ${RM} -r ${HOST_TOOLS}/gcc-${GCC_VERSION}
  644. ${RM} -r ${HOST_TOOLS}/binutils-${BINUTILS_VERSION}
  645. ${RM} binutils-patch binutils
  646. ${RM} gcc-patch gcc
  647. .PHONY: clean-qt4-simulator
  648. clean-qt4-simulator:
  649. (cd ${HOST_TOOLS}/qt4-simulator; ${MAKE} distclean || true)
  650. .PHONY: clean-console-simulator
  651. clean-console-simulator:
  652. ${MAKE} clean -C ${HOST_TOOLS}/console-simulator
  653. # Update the Makefiles
  654. # ====================
  655. # Change the methos of includeing definitions by
  656. # copying part of Mk/definitions.mk into each Makefile
  657. # if it requires it.
  658. .PHONY: update-makefiles
  659. update-makefiles:
  660. @${SCRIPTS}/UpdateMakefiles --verbose \
  661. --source="${MK_DIR}/definitions.mk" \
  662. $(shell find "${ROOT_DIR}" -name Makefile)
  663. # Print information about some targets
  664. # ====================================
  665. .PHONY:help
  666. help:
  667. @echo
  668. @echo 'Some of the more useful targets:'
  669. @echo
  670. @echo ' all - compile all the source'
  671. @echo ' install - install forth, mahatma, fonts in DESTDIR'
  672. @echo ' index - convert XML_FILES to index files in DESTDIR'
  673. @echo ' parse - parse XML_FILES into one HTML file in WORKDIR'
  674. @echo ' render - render HTML in WORKDIR into one big data file in DESTDIR'
  675. @echo ' combine - combine temporary indices to one file in DESTDIR'
  676. # @echo ' hash - generate hash file in DESTDIR'
  677. @echo ' iprc - same as: index parse render combine'
  678. @echo ' farm<1..N> - parse/render XML_FILES into 3 data files in DESTDIR (use -j3)'
  679. @echo ' farm<1..N>-parse - parse XML_FILES into 3 HTML files in WORKDIR (use -j3)'
  680. @echo ' farm<1..N>-render - render WORKDIR HTML files into 3 data files in DESTDIR (use -j3)'
  681. @echo ' farm<1..N>-clean - remove stamp files to repeat process'
  682. @echo ' mbr - compile bootloader'
  683. @echo ' mbr-install - install flash.rom in DESTDIR'
  684. @echo ' mahatma - compile kernel'
  685. @echo ' mahatma-install - install mahatma as kernel in DESTDIR'
  686. @echo ' forth - compile forth'
  687. @echo ' forth-install - install forth files in DESTDIR'
  688. @echo ' flash - compile flash (programs flash.rom from SD Card'
  689. @echo ' flash-install - install flash programmer in DESTDIR'
  690. @echo ' fonts - compile fonts'
  691. @echo ' fonts-install - install font files in DESTDIR'
  692. @echo ' gcc - compile gcc toolchain'
  693. @echo ' flash-mbr - flash bootloader to the E07 board'
  694. @echo ' qt4-simulator - compile the Qt4 simulator'
  695. @echo ' sim4 sim4d - use the data file in DESTDIR and run the qt4-simulator (d => gdb)'
  696. @echo ' console-simulator - compile the console simulator'
  697. @echo ' requirements - detect missing packages'
  698. @echo ' clean - clean all programs and object files except the toochain'
  699. @echo ' clean-toolchain - clean just the toochain'
  700. @echo ' cleandirs - clean work/temp/image for current language'
  701. @echo ' createdirs - create work/temp/image for current language'
  702. @echo ' jig-install - copy flash program and image; forth and programs to SD Card'
  703. @echo ' p33 - terminal emulator (console debugging)'
  704. @echo ' fetch-nls - Fetch nls, texts and license files from web'
  705. @echo
  706. .PHONY:testhelp
  707. testhelp:
  708. ${MAKE} --print-data-base --question | \
  709. awk '/^[^.%][-A-Za-z0-9_]*:/ \
  710. { print substr($$1, 1, length($$1)-1) }' | \
  711. sort | \
  712. pr --omit-pagination --width=80 --columns=1
  713. # Display a make variable
  714. # =======================
  715. # use this like: make print-MAKE
  716. # which shows the value of ${MAKE}
  717. print-%:
  718. @echo $* is $($*)
  719. # Run teminal emulator script
  720. # ==========================
  721. .PHONY: p33
  722. p33:
  723. ${SCRIPTS}/p33