Makefile 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869
  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%H%M')
  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. echo VERSION: ${VERSION_TAG} >> "${VERSION_FILE}"
  98. find "${DESTDIR_PATH}" -type d -exec \
  99. sh -c "cd '{}' && ${RM} '${CHECKSUM_FILE}' && sha${SHA_LEVEL}sum * > '${CHECKSUM_FILE}'" ';'
  100. .PHONY: misc-files-install
  101. misc-files-install: validate-destdir
  102. ${RM} "${MISC_FILES}"/*~
  103. ${RM} "${LICENSES}"/*~
  104. cp -p "${MISC_FILES}"/* "${DESTDIR_PATH}"/
  105. cp -p "${LICENSES}"/* "${DESTDIR_PATH}"/
  106. .PHONY: validate-destdir
  107. validate-destdir:
  108. @if [ ! -d "${DESTDIR_PATH}" ] ; then echo DESTDIR: "'"${DESTDIR_PATH}"'" is not a directory ; exit 1; fi
  109. @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
  110. # Main program
  111. # ============
  112. .PHONY: mahatma
  113. mahatma: mini-libc fatfs
  114. ${MAKE} -C ${SAMO_LIB}/mahatma
  115. .PHONY: mahatma-install
  116. mahatma-install: mahatma validate-destdir
  117. ${MAKE} -C ${SAMO_LIB}/mahatma install DESTDIR="${DESTDIR_PATH}"
  118. # Libraries
  119. # =========
  120. .PHONY:mini-libc
  121. mini-libc: gcc
  122. ${MAKE} -C ${SAMO_LIB}/mini-libc/
  123. .PHONY: fatfs
  124. fatfs: mini-libc drivers
  125. ${MAKE} -C ${SAMO_LIB}/fatfs/
  126. .PHONY: drivers
  127. drivers: mini-libc
  128. ${MAKE} -C ${SAMO_LIB}/drivers/
  129. # GCC and Binutils toolchain
  130. # ==========================
  131. BINUTILS_FILE = ${DOWNLOAD_DIR}/${BINUTILS_PACKAGE}
  132. BINUTILS_SUM = ${SUM_DIR}/${BINUTILS_PACKAGE}.SHA256
  133. GCC_FILE = ${DOWNLOAD_DIR}/${GCC_PACKAGE}
  134. GCC_SUM = ${SUM_DIR}/${GCC_PACKAGE}.SHA256
  135. GET_FILE = $(eval $(call GET_FILE1,$(strip ${1}),$(strip ${2}),$(strip ${3}),$(strip ${4})))
  136. define GET_FILE1
  137. ${1}:
  138. @mkdir -p "$${DOWNLOAD_DIR}"
  139. @if ! ([ -f "${2}" ] && cd "$${DOWNLOAD_DIR}" && sha256sum --check "${3}") ; \
  140. then \
  141. ${RM} "${2}" ; \
  142. wget -c -O "${2}" "${4}"; \
  143. else \
  144. echo Already downloaded: ${2} ; \
  145. fi
  146. @${TOUCH} "$$@"
  147. endef
  148. $(call GET_FILE,binutils-download,${BINUTILS_FILE},${BINUTILS_SUM},${BINUTILS_URL})
  149. $(call GET_FILE,gcc-download,${GCC_FILE},${GCC_SUM},${GCC_URL})
  150. binutils-patch: binutils-download
  151. mkdir -p ${HOST_TOOLS}/toolchain-install
  152. ${RM} -r "${HOST_TOOLS}/binutils-${BINUTILS_PACKAGE}"
  153. tar -xvzf "${BINUTILS_FILE}" -C ${HOST_TOOLS}
  154. cd ${HOST_TOOLS} && \
  155. cd "binutils-${BINUTILS_VERSION}" && \
  156. for p in ../toolchain-patches/*-binutils-*.patch ; \
  157. do \
  158. patch -p1 < "$${p}" ; \
  159. done
  160. ${TOUCH} "$@"
  161. binutils: binutils-patch
  162. cd ${HOST_TOOLS} && \
  163. cd "binutils-${BINUTILS_VERSION}" && \
  164. mkdir -p build && \
  165. cd build && \
  166. CPPFLAGS="-D_FORTIFY_SOURCE=0" ../configure --prefix "${HOST_TOOLS}/toolchain-install" --target=c33-epson-elf && \
  167. CPPFLAGS="-D_FORTIFY_SOURCE=0" ${MAKE} && \
  168. ${MAKE} install
  169. ${TOUCH} "$@"
  170. gcc-patch: gcc-download
  171. mkdir -p ${HOST_TOOLS}/toolchain-install
  172. tar -xvzf "${GCC_FILE}" -C ${HOST_TOOLS}
  173. cd ${HOST_TOOLS} && \
  174. cd "gcc-${GCC_VERSION}" && \
  175. for p in ../toolchain-patches/*-gcc-*.patch ; \
  176. do \
  177. patch -p1 < "$${p}" ; \
  178. done
  179. ${TOUCH} "$@"
  180. gcc: binutils gcc-patch
  181. cd ${HOST_TOOLS} && \
  182. export PATH="${HOST_TOOLS}/toolchain-install/bin:${PATH}" && \
  183. cd "gcc-${GCC_VERSION}" && \
  184. mkdir -p build && \
  185. cd build && \
  186. CPPFLAGS="-D_FORTIFY_SOURCE=0" ../configure --prefix "${HOST_TOOLS}/toolchain-install" --target=c33-epson-elf --enable-languages=c && \
  187. CPPFLAGS="-D_FORTIFY_SOURCE=0" ${MAKE} && \
  188. ${MAKE} install
  189. ${TOUCH} "$@"
  190. # QT simulator
  191. # ============
  192. .PHONY: qt4-simulator
  193. qt4-simulator:
  194. cd ${HOST_TOOLS}/qt4-simulator && qmake-qt4 && ${MAKE}
  195. .PHONY: sim4
  196. sim4: qt4-simulator validate-destdir
  197. cd "${DESTDIR}" && ${HOST_TOOLS}/qt4-simulator/bin/wikisim ${ARTICLE}
  198. .PHONY: sim4d
  199. sim4d: qt4-simulator validate-destdir
  200. cd "${DESTDIR}" && gdb --args ${HOST_TOOLS}/qt4-simulator/bin/wikisim ${ARTICLE}
  201. .PHONY: console-simulator
  202. console-simulator:
  203. cd ${HOST_TOOLS}/console-simulator && ${MAKE}
  204. # Hash generator for search index
  205. # ===============================
  206. .PHONY: hash-gen
  207. hash-gen:
  208. cd ${HOST_TOOLS}/hash-gen && ${MAKE}
  209. # Font processing
  210. # ===============
  211. .PHONY: pcf2bmf
  212. pcf2bmf:
  213. cd ${HOST_TOOLS}/pcf2bmf && ${MAKE}
  214. .PHONY: fonts
  215. fonts: pcf2bmf
  216. cd ${HOST_TOOLS}/fonts && ${MAKE}
  217. .PHONY: fonts-install
  218. fonts-install: fonts validate-destdir
  219. cd ${HOST_TOOLS}/fonts && ${MAKE} DESTDIR="${DESTDIR_PATH}" install
  220. # Build the database from wiki XML files
  221. # ======================================
  222. XML_FILES_PATH = $(realpath ${XML_FILES})
  223. RENDER_BLOCK ?= 0
  224. TOTAL_HTML_FILES ?= 27
  225. # erase the working directories for the current language
  226. .PHONY: cleandirs
  227. cleandirs:
  228. @if [ -z "${DESTDIR_PATH}" ] ; then echo missing DESTDIR ; exit 1 ; fi
  229. @if [ -z "${WORKDIR_PATH}" ] ; then echo missing WORKDIR ; exit 1 ; fi
  230. @if [ -z "${TEMPDIR_PATH}" ] ; then echo missing TEMPDIR ; exit 1 ; fi
  231. ${RM} -r "${DESTDIR_PATH}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}"
  232. ${RM} -r "${TEMPDIR_PATH}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}"
  233. ${RM} -r "${WORKDIR_PATH}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}"
  234. # only create dirs (does not erase them)
  235. .PHONY: createdirs
  236. createdirs:
  237. @if [ -z "${DESTDIR_PATH}" ] ; then echo missing DESTDIR ; exit 1 ; fi
  238. @if [ -z "${WORKDIR_PATH}" ] ; then echo missing WORKDIR ; exit 1 ; fi
  239. @if [ -z "${TEMPDIR_PATH}" ] ; then echo missing TEMPDIR ; exit 1 ; fi
  240. ${MKDIR} "${DESTDIR_PATH}"
  241. ${MKDIR} "${DESTDIR_PATH}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}"
  242. ${MKDIR} "${WORKDIR_PATH}"
  243. ${MKDIR} "${WORKDIR_PATH}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}"
  244. ${MKDIR} "${TEMPDIR_PATH}"
  245. ${MKDIR} "${TEMPDIR_PATH}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}"
  246. .PHONY: index
  247. index: validate-destdir
  248. cd ${HOST_TOOLS}/offline-renderer && ${MAKE} index \
  249. WIKI_LANGUAGE="${WIKI_LANGUAGE}" WIKI_FILE_PREFIX="${WIKI_FILE_PREFIX}" \
  250. WIKI_DIR_SUFFIX="${WIKI_DIR_SUFFIX}" \
  251. XML_FILES="${XML_FILES_PATH}" RENDER_BLOCK="${RENDER_BLOCK}" \
  252. TOTAL_HTML_FILES="${TOTAL_HTML_FILES}" \
  253. TEMPDIR="${TEMPDIR_PATH}" \
  254. WORKDIR="${WORKDIR_PATH}" DESTDIR="${DESTDIR_PATH}"
  255. .PHONY: parse
  256. parse: validate-destdir
  257. cd ${HOST_TOOLS}/offline-renderer && ${MAKE} parse \
  258. WIKI_LANGUAGE="${WIKI_LANGUAGE}" WIKI_FILE_PREFIX="${WIKI_FILE_PREFIX}" \
  259. WIKI_DIR_SUFFIX="${WIKI_DIR_SUFFIX}" \
  260. XML_FILES="${XML_FILES_PATH}" RENDER_BLOCK="${RENDER_BLOCK}" \
  261. TOTAL_HTML_FILES="${TOTAL_HTML_FILES}" \
  262. TEMPDIR="${TEMPDIR_PATH}" \
  263. WORKDIR="${WORKDIR_PATH}" DESTDIR="${DESTDIR_PATH}"
  264. .PHONY: merge
  265. merge: validate-destdir
  266. cd ${HOST_TOOLS}/offline-renderer && ${MAKE} merge \
  267. WIKI_LANGUAGE="${WIKI_LANGUAGE}" WIKI_FILE_PREFIX="${WIKI_FILE_PREFIX}" \
  268. WIKI_DIR_SUFFIX="${WIKI_DIR_SUFFIX}" \
  269. XML_FILES="${XML_FILES_PATH}" RENDER_BLOCK="${RENDER_BLOCK}" \
  270. TOTAL_HTML_FILES="${TOTAL_HTML_FILES}" \
  271. TEMPDIR="${TEMPDIR_PATH}" \
  272. WORKDIR="${WORKDIR_PATH}" DESTDIR="${DESTDIR_PATH}"
  273. .PHONY: render
  274. render: fonts validate-destdir
  275. cd ${HOST_TOOLS}/offline-renderer && ${MAKE} render \
  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: combine
  283. combine: validate-destdir
  284. cd ${HOST_TOOLS}/offline-renderer && ${MAKE} combine \
  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: hash
  292. hash: validate-destdir hash-gen
  293. cd "${DESTDIR}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}" && ${HOST_TOOLS}/hash-gen/hash-gen \
  294. --pfx="${DESTDIR_PATH}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}/${WIKI_FILE_PREFIX}.pfx" \
  295. --fnd="${DESTDIR_PATH}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}/${WIKI_FILE_PREFIX}.fnd" \
  296. --hsh="${DESTDIR_PATH}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}/${WIKI_FILE_PREFIX}.hsh"
  297. # o run all stages (for testing small XML sample files)
  298. .PHONY: iprch
  299. iprch: index parse render combine hash
  300. # Build database using multiple machines
  301. # ======================================
  302. ifneq (,$(strip ${WORKDIR_PATH}))
  303. ifneq (,$(strip ${DESTDIR_PATH}))
  304. INDEX_STAMP := ${WORKDIR_PATH}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}/stamp-index
  305. PARSE_STAMP := ${WORKDIR_PATH}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}/stamp-parse
  306. RENDER_STAMP := ${WORKDIR_PATH}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}/stamp-render
  307. # ---------------------------------------------------------------------------------------
  308. # Get the number of articles from the indexer and compute how many articles per instance
  309. # ---------------------------------------------------------------------------------------
  310. MACHINE_COUNT ?= 9
  311. PARALLEL_BUILD ?= 3
  312. COUNTS_FILE = ${WORKDIR_PATH}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}/counts.text
  313. TOTAL_ARTICLES = $(shell awk '/^Articles:/{ print $$2 }' "${COUNTS_FILE}" 2>/dev/null || echo 0)
  314. TOTAL_INSTANCES := $(shell expr ${MACHINE_COUNT} '*' ${PARALLEL_BUILD})
  315. # 64 dat files is the maximum allowed
  316. CHECK := $(shell if [ ${TOTAL_INSTANCES} -gt 64 ]; then echo 0; else echo 1; fi )
  317. ifeq ($(strip ${CHECK}),0)
  318. $(error Too many machines or processes being used. Maximum is 64 total instances)
  319. endif
  320. MAX_BLOCK := $(shell expr ${TOTAL_INSTANCES} - 1)
  321. ARTICLES_PER_INSTANCE = $(shell expr ${TOTAL_ARTICLES} / ${TOTAL_INSTANCES})
  322. ITEMS = $(shell i=0; while [ $${i} -lt ${TOTAL_INSTANCES} ]; do echo $${i}; i=$$(($${i} + 1)); done)
  323. # check that the counts are correct to render all articles
  324. .PHONY: print-render-info
  325. print-render-info:
  326. @echo WORKDIR_PATH = ${WORKDIR_PATH}
  327. @echo DESTDIR_PATH = ${DESTDIR_PATH}
  328. @echo TEMPDIR_PATH = ${TEMPDIR_PATH}
  329. @echo XML_FILES_PATH = ${XML_FILES_PATH}
  330. @echo TOTAL_ARTICLES = ${TOTAL_ARTICLES}
  331. @echo MACHINE_COUNT = ${MACHINE_COUNT}
  332. @echo PARALLEL_BUILD = ${PARALLEL_BUILD}
  333. @echo TOTAL_INSTANCES = ${TOTAL_INSTANCES}
  334. @echo ARTICLES_PER_INSTANCE = ${ARTICLES_PER_INSTANCE}
  335. @echo ITEMS = ${ITEMS}
  336. @echo files = 0 .. ${MAX_BLOCK}
  337. # index
  338. ${INDEX_STAMP}:
  339. ${RM} "$@"
  340. cd ${HOST_TOOLS}/offline-renderer && ${MAKE} index \
  341. XML_FILES="${XML_FILES_PATH}" RENDER_BLOCK="${RENDER_BLOCK}" \
  342. WORKDIR="${WORKDIR_PATH}" DESTDIR="${DESTDIR_PATH}"
  343. ${TOUCH} "$@"
  344. .PHONY: index-clean
  345. index-clean:
  346. ${RM} "${INDEX_STAMP}" "${COUNTS_FILE}"
  347. ${RM} "${WORKDIR_PATH}"/*.db
  348. ${RM} "${WORKDIR_PATH}"/*.db.*
  349. # create the individual threads
  350. # makeblock 0..n
  351. MAKE_BLOCK = $(eval $(call MAKE_BLOCK1,$(strip ${1})))
  352. define MAKE_BLOCK1
  353. .PHONY: parse${1}
  354. parse${1}: ${PARSE_STAMP}${1}
  355. .PHONY: render${1}
  356. render${1}: ${RENDER_STAMP}${1}
  357. START_${1} = $$(shell expr ${1} '*' $${ARTICLES_PER_INSTANCE} + 1)
  358. COUNT_${1} = $$(shell if [ "${1}" -ge $$$$(($${TOTAL_INSTANCES} - 1)) ] ; then echo all; else echo $${ARTICLES_PER_INSTANCE}; fi)
  359. ${PARSE_STAMP}${1}: ${INDEX_STAMP}
  360. ${RM} "$$@"
  361. $${MAKE} RENDER_BLOCK='${1}' START='$${START_${1}}' COUNT='$${COUNT_${1}}' parse
  362. ${TOUCH} "$$@"
  363. ${RENDER_STAMP}${1}: ${PARSE_STAMP}${1}
  364. ${RM} "$$@"
  365. $${MAKE} RENDER_BLOCK='${1}' render
  366. ${TOUCH} "$$@"
  367. .PHONY: stamp-clean${1}
  368. stamp-clean${1}: stamp-parse-clean${1} stamp-render-clean${1}
  369. .PHONY: stamp-parse-clean${1}
  370. stamp-parse-clean${1}:
  371. ${RM} "${PARSE_STAMP}${1}"
  372. .PHONY: stamp-render-clean${1}
  373. stamp-render-clean${1}:
  374. ${RM} "${RENDER_STAMP}${1}"
  375. endef
  376. $(foreach i,${ITEMS},$(call MAKE_BLOCK,${i}))
  377. # Per machine rules
  378. MAKE_FARM = $(eval $(call MAKE_FARM1,$(strip ${1}),$(strip ${2}),$(strip ${3})))
  379. define MAKE_FARM1
  380. .PHONY: farm${1}-parse
  381. farm${1}-parse: $$(foreach i,${2},parse$$(strip $${i}))
  382. .PHONY: farm${1}-render
  383. farm${1}-render: $$(foreach i,${2},render$$(strip $${i}))
  384. .PHONY: farm${1}-clean
  385. farm${1}-clean: farm${1}-parse-clean farm${1}-render-clean
  386. .PHONY: farm${1}-parse-clean
  387. farm${1}-parse-clean: $$(foreach i,${2},stamp-parse-clean$$(strip $${i}))
  388. .PHONY: farm${1}-render-clean
  389. farm${1}-render-clean: $$(foreach i,${2},stamp-render-clean$$(strip $${i}))
  390. .PHONY: farm${1}
  391. farm${1}: farm${1}-parse farm${1}-render
  392. endef
  393. .PHONY: farm-index
  394. farm-index: ${INDEX_STAMP}
  395. MAKE_MACHINE = $(eval $(call MAKE_MACHINE1,$(strip ${1}),$(strip ${2}),$(strip ${3})))
  396. define MAKE_MACHINE1
  397. $(call MAKE_FARM,${1}, $(shell j=$$((${1} - 1)); while [ $${j} -lt ${TOTAL_INSTANCES} ]; do echo $${j}; j=$$(($${j} + ${2})); done))
  398. endef
  399. MACHINE_LIST := $(shell i=1; while [ $${i} -le ${MACHINE_COUNT} ]; do echo $${i}; i=$$(($${i} + 1)); done)
  400. $(foreach i,${MACHINE_LIST},$(call MAKE_MACHINE,${i},${MACHINE_COUNT}))
  401. # end of WORKDIR/DESTDIR check above
  402. endif
  403. endif
  404. # Download the latest translations
  405. # ================================
  406. 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
  407. LICENSE_DIR = XML-Licenses
  408. # These items reference wiki articles since the process needs XML
  409. # data files, the macro below will export the xml and download it
  410. # directly from the sites.
  411. #
  412. # Any items left blank will revert to English version
  413. #
  414. # Note: the ones that link to deed.XX are html so cannot be used
  415. # with the present program (these will just use English).
  416. TERMS_da := Wikipedia:Ophavsret
  417. #LICENSE_da := http://creativecommons.org/licenses/by-sa/3.0/deed.da
  418. TERMS_de := Nutzungsbedingungen
  419. LICENSE_de := Wikipedia:Lizenzbestimmungen_Commons_Attribution-ShareAlike_3.0_Unported
  420. TERMS_en := Terms_of_Use
  421. LICENSE_en := Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_License
  422. TERMS_es := Términos_de_Uso
  423. #LICENSE_es := http://creativecommons.org/licenses/by-sa/3.0/deed.es
  424. TERMS_fi := Käyttöehdot
  425. LICENSE_fi := Wikipedia:Creative_Commons_Attribution-Share_Alike_3.0_Unported_-lisenssiehdot
  426. TERMS_fr := Conditions_d\'utilisation
  427. #LICENSE_fr := http://creativecommons.org/licenses/by-sa/3.0/deed.fr
  428. TERMS_ja := 利用規約
  429. LICENSE_ja := Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_License
  430. TERMS_nl := Gebruiksvoorwaarden
  431. #LICENSE_nl := http://creativecommons.org/licenses/by-sa/3.0/deed.nl
  432. TERMS_pt := Condições_de_Uso
  433. #LICENSE_pt := http://creativecommons.org/licenses/by-sa/3.0/deed.pt
  434. WIKIREADER_CREATE_NLS := http://www.thewikireader.com/create_nls.php
  435. WIKIMEDIA_EXPORT := http://wikimediafoundation.org/wiki/Special:Export
  436. LICENSE_EXTRA_SUFFIX := ?curonly=1&templates=1&wpDownload=1
  437. TERMS_EXTRA_SUFFIX := ?curonly=1&wpDownload=1
  438. # macro to retrieve files from various web sites
  439. define GET_FILES
  440. mkdir -p "${LICENSE_DIR}/${1}" ; \
  441. wget --output-document="-" "${WIKIREADER_CREATE_NLS}?lang=${1}" \
  442. | sed 's/[[:space:]]*$$//;/^$$/d' > "${LICENSE_DIR}/${1}/wiki.nls" ; \
  443. [ -n "${2}" ] && \
  444. wget --output-document="-" "${WIKIMEDIA_EXPORT}/${2}${TERMS_EXTRA_SUFFIX}" \
  445. | sed 's/[[:space:]]*$$//' > "${LICENSE_DIR}/${1}/terms.xml" ; \
  446. [ -n "${3}" ] && \
  447. wget --output-document="-" "http://${1}.wikipedia.org/wiki/Special:Export/${3}${LICENSE_EXTRA_SUFFIX}" \
  448. | sed 's/[[:space:]]*$$//;s/<title>Wikipedia:/<title>Wikipedia - /' > "${LICENSE_DIR}/${1}/license.xml" ; \
  449. true ;
  450. endef
  451. .PHONY: fetch-nls
  452. fetch-nls: $(foreach lang,${ALL_LANGUAGES},fetch-nls-${lang})
  453. # fetch one language e.g. fetch-nls-en
  454. fetch-nls-%:
  455. echo fetching nls files for: $*
  456. $(call GET_FILES,$*,${TERMS_$*},${LICENSE_$*})
  457. # install nls file
  458. .PHONY: nls-install
  459. nls-install: validate-destdir
  460. @find "${DESTDIR}" -type d | \
  461. ( while read dir ; \
  462. do \
  463. d=$$(basename "$${dir}") ; \
  464. for s in $${d} $${d%%pedia} ; \
  465. do \
  466. src="${LICENSE_DIR}/$${s}/wiki.nls" ; \
  467. dest="${DESTDIR_PATH}/$${d}" ; \
  468. if [ -f "$${src}" ] ; \
  469. then \
  470. echo copy: $${src} to: $${dest} ; \
  471. cp -p "$${src}" "$${dest}" ; \
  472. fi ; \
  473. done \
  474. done \
  475. )
  476. # Download the latest Mediawiki dump
  477. # ==================================
  478. .PHONY: getwikidump
  479. getwikidump:
  480. wget http://download.wikimedia.org/enwiki/latest/enwiki-latest-pages-articles.xml.bz2
  481. # Forth interpreter
  482. # =================
  483. .PHONY: forth
  484. forth: gcc mini-libc fatfs drivers
  485. ${MAKE} -C ${SAMO_LIB}/forth
  486. .PHONY: forth-install
  487. forth-install: forth
  488. ${MAKE} -C ${SAMO_LIB}/forth install DESTDIR="${DESTDIR_PATH}"
  489. # FLASH programmer that runs on the device
  490. # ========================================
  491. .PHONY: flash
  492. flash: gcc mini-libc fatfs drivers
  493. ${MAKE} -C ${SAMO_LIB}/flash
  494. .PHONY: flash-install
  495. flash-install: flash
  496. ${MAKE} -C ${SAMO_LIB}/flash install DESTDIR="${DESTDIR_PATH}"
  497. # Grifo small kernel
  498. # ==================
  499. .PHONY: grifo
  500. grifo: gcc mini-libc fatfs
  501. ${MAKE} -C ${SAMO_LIB}/grifo
  502. .PHONY: grifo-install
  503. grifo-install: grifo
  504. ${MAKE} -C ${SAMO_LIB}/grifo install DESTDIR="${DESTDIR_PATH}"
  505. # Master boot record
  506. # ==================
  507. define FindTTY
  508. for i in USBconsole ttyUSB2 ttyUSB1 ttyUSB0;
  509. do
  510. d="/dev/$${i}";
  511. if [ -e "$${d}" ];
  512. then
  513. echo -n $${d};
  514. exit 0;
  515. fi;
  516. done;
  517. echo -n /dev/TTY-NOT-FOUND;
  518. exit 1;
  519. endef
  520. define FindAUX
  521. for i in USBjtag;
  522. do
  523. d="/dev/$${i}";
  524. if [ -e "$${d}" ];
  525. then
  526. echo -n $${d};
  527. exit 0;
  528. fi;
  529. done;
  530. echo -n /dev/TTY-NOT-FOUND;
  531. exit 1;
  532. endef
  533. BOOTLOADER_TTY ?= $(shell ${FindTTY})
  534. BOOTLOADER_AUX ?= $(shell ${FindAUX})
  535. SERIAL_NUMBER ?= No Serial Number
  536. FLASH_UPDATE ?= NO
  537. .PHONY: print-mbr-tty
  538. print-mbr-tty:
  539. @echo BOOTLOADER_TTY = "${BOOTLOADER_TTY}"
  540. @echo BOOTLOADER_AUX = "${BOOTLOADER_AUX}"
  541. .PHONY: mbr
  542. mbr: gcc fatfs
  543. ${MAKE} -C ${SAMO_LIB}/mbr
  544. .PHONY: mbr-rs232
  545. mbr-rs232: gcc fatfs
  546. ${MAKE} -C ${SAMO_LIB}/mbr mbr-rs232
  547. .PHONY: jackknife
  548. jackknife:
  549. ${MAKE} -C ${HOST_TOOLS}/jackknife
  550. .PHONY: flash-mbr
  551. flash-mbr: mbr jackknife
  552. ${MAKE} -C ${SAMO_LIB}/mbr BOOTLOADER_TTY="${BOOTLOADER_TTY}" BOOTLOADER_AUX="${BOOTLOADER_AUX}" SERIAL_NUMBER="${SERIAL_NUMBER}" FLASH_UPDATE="${FLASH_UPDATE}" $@
  553. .PHONY: flash-test-jig
  554. flash-test-jig: mbr jackknife
  555. ${MAKE} -C ${SAMO_LIB}/mbr FLASH_TEST_JIG=YES BOOTLOADER_TTY="${BOOTLOADER_TTY}" BOOTLOADER_AUX="${BOOTLOADER_AUX}" SERIAL_NUMBER="${SERIAL_NUMBER}" flash-mbr
  556. .PHONY: mbr-install
  557. mbr-install: mbr
  558. ${MAKE} -C ${SAMO_LIB}/mbr install DESTDIR="${DESTDIR_PATH}"
  559. # Clean up generated files
  560. # ========================
  561. .PHONY: complete-clean
  562. complete-clean: clean clean-toolchain
  563. ${RM} binutils-download gcc-download
  564. .PHONY: clean
  565. clean: clean-qt4-simulator clean-console-simulator
  566. ${MAKE} clean -C ${SAMO_LIB}/mini-libc
  567. ${MAKE} clean -C ${HOST_TOOLS}/jackknife
  568. ${MAKE} clean -C ${HOST_TOOLS}/hash-gen
  569. ${MAKE} clean -C ${HOST_TOOLS}/pcf2bmf
  570. ${MAKE} clean -C ${HOST_TOOLS}/flash07
  571. ${MAKE} clean -C ${HOST_TOOLS}/fonts
  572. ${MAKE} clean -C ${HOST_TOOLS}/offline-renderer
  573. ${MAKE} clean -C ${SAMO_LIB}/mbr
  574. ${MAKE} clean -C ${SAMO_LIB}/drivers
  575. ${MAKE} clean -C ${SAMO_LIB}/fatfs
  576. ${MAKE} clean -C ${SAMO_LIB}/forth
  577. ${MAKE} clean -C ${SAMO_LIB}/flash
  578. ${MAKE} clean -C ${SAMO_LIB}/grifo
  579. ${MAKE} clean -C ${SAMO_LIB}/mahatma
  580. ${RM} stamp-r-*
  581. .PHONY: clean-toolchain
  582. clean-toolchain:
  583. ${RM} -r ${HOST_TOOLS}/toolchain-install
  584. ${RM} -r ${HOST_TOOLS}/gcc-${GCC_VERSION}
  585. ${RM} -r ${HOST_TOOLS}/binutils-${BINUTILS_VERSION}
  586. ${RM} binutils-patch binutils
  587. ${RM} gcc-patch gcc
  588. .PHONY: clean-qt4-simulator
  589. clean-qt4-simulator:
  590. (cd ${HOST_TOOLS}/qt4-simulator; ${MAKE} distclean || true)
  591. .PHONY: clean-console-simulator
  592. clean-console-simulator:
  593. ${MAKE} clean -C ${HOST_TOOLS}/console-simulator
  594. # Update the Makefiles
  595. # ====================
  596. # Change the methos of includeing definitions by
  597. # copying part of Mk/definitions.mk into each Makefile
  598. # if it requires it.
  599. .PHONY: update-makefiles
  600. update-makefiles:
  601. @${SCRIPTS}/UpdateMakefiles --verbose \
  602. --source="${MK_DIR}/definitions.mk" \
  603. $(shell find "${ROOT_DIR}" -name Makefile)
  604. # Print information about some targets
  605. # ====================================
  606. .PHONY:help
  607. help:
  608. @echo
  609. @echo 'Some of the more useful targets:'
  610. @echo
  611. @echo ' all - compile all the source'
  612. @echo ' install - install forth, mahatma, fonts in DESTDIR'
  613. @echo ' index - convert XML_FILES to index files in DESTDIR'
  614. @echo ' parse - parse XML_FILES into one HTML file in WORKDIR'
  615. @echo ' render - render HTML in WORKDIR into one big data file in DESTDIR'
  616. @echo ' combine - combine temporary indices to one file in DESTDIR'
  617. @echo ' hash - generate hash file in DESTDIR'
  618. @echo ' farm<1..N> - parse/render XML_FILES into 3 data files in DESTDIR (use -j3)'
  619. @echo ' farm<1..N>-parse - parse XML_FILES into 3 HTML files in WORKDIR (use -j3)'
  620. @echo ' farm<1..N>-render - render WORKDIR HTML files into 3 data files in DESTDIR (use -j3)'
  621. @echo ' farm<1..N>-clean - remove stamp files to repeat process'
  622. @echo ' mbr - compile bootloader'
  623. @echo ' mbr-install - install flash.rom in DESTDIR'
  624. @echo ' mahatma - compile kernel'
  625. @echo ' mahatma-install - install mahatma as kernel in DESTDIR'
  626. @echo ' forth - compile forth'
  627. @echo ' forth-install - install forth files in DESTDIR'
  628. @echo ' flash - compile flash (programs flash.rom from SD Card'
  629. @echo ' flash-install - install flash programmer in DESTDIR'
  630. @echo ' fonts - compile fonts'
  631. @echo ' fonts-install - install font files in DESTDIR'
  632. @echo ' gcc - compile gcc toolchain'
  633. @echo ' flash-mbr - flash bootloader to the E07 board'
  634. @echo ' qt4-simulator - compile the Qt4 simulator'
  635. @echo ' sim4 sim4d - use the data file in DESTDIR and run the qt4-simulator (d => gdb)'
  636. @echo ' console-simulator - compile the console simulator'
  637. @echo ' clean - clean all programs and object files except the toochain'
  638. @echo ' clean-toolchain - clean just the toochain'
  639. @echo ' cleandirs - clean work/temp/image for current language'
  640. @echo ' createdirs - create work/temp/image for current language'
  641. @echo ' jig-install - copy flash program and image; forth and programs to SD Card'
  642. @echo ' p33 - terminal emulator (console debugging)'
  643. @echo ' fetch-nls - Fetch nls, texts and license files from web'
  644. @echo
  645. .PHONY:testhelp
  646. testhelp:
  647. ${MAKE} --print-data-base --question | \
  648. awk '/^[^.%][-A-Za-z0-9_]*:/ \
  649. { print substr($$1, 1, length($$1)-1) }' | \
  650. sort | \
  651. pr --omit-pagination --width=80 --columns=1
  652. # Display a make variable
  653. # =======================
  654. # use this like: make print-MAKE
  655. # which shows the value of ${MAKE}
  656. print-%:
  657. @echo $* is $($*)
  658. # Run teminal emulator script
  659. # ==========================
  660. .PHONY: p33
  661. p33:
  662. ${SCRIPTS}/p33