Makefile 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  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. # ----- Toolchain configuration data --------------------------------------
  20. GCC_VERSION=3.3.2
  21. GCC_PACKAGE=gcc-${GCC_VERSION}.tar.gz
  22. GCC_URL=ftp://ftp.gnu.org/gnu/gcc/${GCC_PACKAGE}
  23. BINUTILS_VERSION=2.10.1
  24. BINUTILS_PACKAGE=binutils-${BINUTILS_VERSION}.tar.gz
  25. BINUTILS_URL= \
  26. ftp://ftp.gnu.org/gnu/binutils/${BINUTILS_PACKAGE}
  27. SAMO_LIB := $(shell readlink -m ./samo-lib)
  28. HOST_TOOLS := $(shell readlink -m ./host-tools)
  29. LICENSES := $(shell readlink -m ./Licenses)
  30. MISC_FILES := ${SAMO_LIB}/misc-files
  31. DOWNLOAD_DIR=${HOST_TOOLS}/toolchain-download
  32. SUM_DIR=${HOST_TOOLS}/toolchain-sums
  33. export PATH := ${HOST_TOOLS}/toolchain-install/bin:${PATH}
  34. CONFIG_FILE := "samo-lib/include/config.h"
  35. CONFIG_FILE_DEFAULT := "samo-lib/include/config.h-default"
  36. CONFIG_FILE_EXISTS := $(shell [ -f ${CONFIG_FILE} ] && echo 1)
  37. ifeq (${CONFIG_FILE_EXISTS},)
  38. $(shell cp ${CONFIG_FILE_DEFAULT} ${CONFIG_FILE})
  39. endif
  40. # ----- configuration data --------------------------------------
  41. ALL_TARGETS =
  42. ALL_TARGETS += mbr
  43. ALL_TARGETS += jackknife
  44. ALL_TARGETS += forth
  45. ALL_TARGETS += flash
  46. ALL_TARGETS += mahatma
  47. ALL_TARGETS += qt4-simulator
  48. ALL_TARGETS += hash-gen
  49. ALL_TARGETS += pcf2bmf
  50. ALL_TARGETS += fonts
  51. .PHONY: all
  52. all: ${ALL_TARGETS}
  53. # ----- installation ------------------------------------------
  54. DESTDIR_PATH := $(shell readlink -m "${DESTDIR}")
  55. WORKDIR_PATH := $(shell readlink -m "${WORKDIR}")
  56. VERSION_TAG ?= $(shell date '+%Y%m%d%H%M')
  57. VERSION_FILE := ${DESTDIR_PATH}/version.txt
  58. SHA_LEVEL := 256
  59. CHECKSUM_FILE := ${DESTDIR_PATH}/sha${SHA_LEVEL}.txt
  60. .PHONY: install
  61. install: validate-destdir forth-install mahatma-install fonts-install misc-files-install version
  62. .PHONY: version
  63. version: validate-destdir
  64. @if [ -z "${VERSION_TAG}" ] ; then echo VERSION_TAG: "'"${VERSION_TAG}"'" is not valid ; exit 1; fi
  65. ${RM} "${VERSION_FILE}" "${CHECKSUM_FILE}" "${DESTDIR_PATH}"/*.idx-tmp "${DESTDIR_PATH}"/*~
  66. echo VERSION: ${VERSION_TAG} >> "${VERSION_FILE}"
  67. cd "${DESTDIR_PATH}" && sha${SHA_LEVEL}sum * >> "${CHECKSUM_FILE}"
  68. .PHONY: misc-files-install
  69. misc-files-install: validate-destdir
  70. ${RM} "${MISC_FILES}"/*~
  71. ${RM} "${LICENSES}"/*~
  72. cp -p "${MISC_FILES}"/* "${DESTDIR_PATH}"/
  73. cp -p "${LICENSES}"/* "${DESTDIR_PATH}"/
  74. .PHONY: validate-destdir
  75. validate-destdir:
  76. @if [ ! -d "${DESTDIR_PATH}" ] ; then echo DESTDIR: "'"${DESTDIR_PATH}"'" is not a directory ; exit 1; fi
  77. .PHONY: sd-image
  78. sd-image: validate-destdir
  79. # ----- main program ------------------------------------------
  80. .PHONY: mahatma
  81. mahatma: mini-libc fatfs
  82. ${MAKE} -C samo-lib/mahatma
  83. .PHONY: mahatma-install
  84. mahatma-install: mahatma validate-destdir
  85. ${MAKE} -C samo-lib/mahatma install DESTDIR="${DESTDIR_PATH}"
  86. # ----- lib stuff -------------------------------------------
  87. .PHONY:mini-libc
  88. mini-libc: gcc
  89. ${MAKE} -C samo-lib/mini-libc/
  90. .PHONY: fatfs
  91. fatfs: mini-libc drivers
  92. ${MAKE} -C samo-lib/fatfs/
  93. .PHONY: drivers
  94. drivers: mini-libc
  95. ${MAKE} -C samo-lib/drivers/
  96. # ----- toolchain stuff --------------------------------------
  97. BINUTILS_FILE = ${DOWNLOAD_DIR}/${BINUTILS_PACKAGE}
  98. BINUTILS_SUM = ${SUM_DIR}/${BINUTILS_PACKAGE}.SHA256
  99. GCC_FILE = ${DOWNLOAD_DIR}/${GCC_PACKAGE}
  100. GCC_SUM = ${SUM_DIR}/${GCC_PACKAGE}.SHA256
  101. GET_FILE = $(eval $(call GET_FILE1,$(strip ${1}),$(strip ${2}),$(strip ${3}),$(strip ${4})))
  102. define GET_FILE1
  103. ${1}:
  104. @mkdir -p "$${DOWNLOAD_DIR}"
  105. @if ! ([ -f "${2}" ] && cd "$${DOWNLOAD_DIR}" && sha256sum --check "${3}") ; \
  106. then \
  107. ${RM} "${2}" ; \
  108. wget -c -O "${2}" "${4}"; \
  109. else \
  110. echo Already downloaded: ${2} ; \
  111. fi
  112. @touch "$$@"
  113. endef
  114. $(call GET_FILE,binutils-download,${BINUTILS_FILE},${BINUTILS_SUM},${BINUTILS_URL})
  115. $(call GET_FILE,gcc-download,${GCC_FILE},${GCC_SUM},${GCC_URL})
  116. binutils-patch: binutils-download
  117. mkdir -p host-tools/toolchain-install
  118. rm -rf "host-tools/binutils-${BINUTILS_PACKAGE}"
  119. tar -xvzf "${BINUTILS_FILE}" -C host-tools/
  120. cd host-tools && \
  121. cd "binutils-${BINUTILS_VERSION}" && \
  122. cat ../toolchain-patches/0001-binutils-EPSON-changes-to-binutils.patch | patch -p1 && \
  123. cat ../toolchain-patches/0002-binutils-EPSON-make-it-compile-hack-for-recent-gcc.patch | patch -p1
  124. touch "$@"
  125. binutils: binutils-patch
  126. cd host-tools && \
  127. cd "binutils-${BINUTILS_VERSION}" && \
  128. mkdir -p build && \
  129. cd build && \
  130. CPPFLAGS="-D_FORTIFY_SOURCE=0" ../configure --prefix "${HOST_TOOLS}/toolchain-install" --target=c33-epson-elf && \
  131. CPPFLAGS="-D_FORTIFY_SOURCE=0" ${MAKE} && \
  132. ${MAKE} install
  133. touch "$@"
  134. gcc-patch: gcc-download
  135. mkdir -p host-tools/toolchain-install
  136. tar -xvzf "${GCC_FILE}" -C host-tools/
  137. cd host-tools && \
  138. cd "gcc-${GCC_VERSION}" && \
  139. cat ../toolchain-patches/0001-gcc-EPSON-modified-sources.patch | patch -p1 && \
  140. cat ../toolchain-patches/0002-gcc-Force-that-the-assembly-of-libgcc-complies-wit.patch | patch -p1 && \
  141. cat ../toolchain-patches/0003-gcc-Use-the-C-implementations-for-division-and-mod.patch | patch -p1
  142. touch "$@"
  143. gcc: binutils gcc-patch
  144. cd host-tools && \
  145. export PATH="${HOST_TOOLS}/toolchain-install/bin:${PATH}" && \
  146. cd "gcc-${GCC_VERSION}" && \
  147. mkdir -p build && \
  148. cd build && \
  149. CPPFLAGS="-D_FORTIFY_SOURCE=0" ../configure --prefix "${HOST_TOOLS}/toolchain-install" --target=c33-epson-elf --enable-languages=c && \
  150. CPPFLAGS="-D_FORTIFY_SOURCE=0" ${MAKE} && \
  151. ${MAKE} install
  152. touch "$@"
  153. .PHONY: qt4-simulator
  154. qt4-simulator: mahatma
  155. cd host-tools/qt4-simulator && qmake-qt4 && ${MAKE}
  156. .PHONY: console-simulator
  157. console-simulator: mahatma
  158. cd host-tools/console-simulator && ${MAKE}
  159. # ----- hash-gen --------------------------------------
  160. .PHONY: hash-gen
  161. hash-gen:
  162. cd host-tools/hash-gen && ${MAKE}
  163. # ----- pcf2bmf --------------------------------------
  164. .PHONY: pcf2bmf
  165. pcf2bmf:
  166. cd host-tools/pcf2bmf && ${MAKE}
  167. # ----- fonts --------------------------------------
  168. .PHONY: fonts
  169. fonts: pcf2bmf
  170. cd host-tools/fonts && ${MAKE}
  171. .PHONY: fonts-install
  172. fonts-install: fonts validate-destdir
  173. cd host-tools/fonts && ${MAKE} DESTDIR="${DESTDIR_PATH}" install
  174. # ----- build the database --------------------------------------
  175. XML_FILES_PATH := $(foreach f,${XML_FILES},$(shell readlink -m "${f}"))
  176. RENDER_BLOCK ?= 0
  177. .PHONY: index
  178. index: validate-destdir
  179. cd host-tools/offline-renderer && ${MAKE} index \
  180. XML_FILES="${XML_FILES_PATH}" RENDER_BLOCK="${RENDER_BLOCK}" \
  181. WORKDIR="${WORKDIR_PATH}" DESTDIR="${DESTDIR_PATH}"
  182. .PHONY: parse
  183. parse: validate-destdir
  184. cd host-tools/offline-renderer && ${MAKE} parse \
  185. XML_FILES="${XML_FILES_PATH}" RENDER_BLOCK="${RENDER_BLOCK}" \
  186. WORKDIR="${WORKDIR_PATH}" DESTDIR="${DESTDIR_PATH}"
  187. .PHONY: render
  188. render: fonts validate-destdir
  189. cd host-tools/offline-renderer && ${MAKE} render \
  190. XML_FILES="${XML_FILES_PATH}" RENDER_BLOCK="${RENDER_BLOCK}" \
  191. WORKDIR="${WORKDIR_PATH}" DESTDIR="${DESTDIR_PATH}"
  192. .PHONY: combine
  193. combine: validate-destdir
  194. cd host-tools/offline-renderer && ${MAKE} combine \
  195. XML_FILES="${XML_FILES_PATH}" RENDER_BLOCK="${RENDER_BLOCK}" \
  196. WORKDIR="${WORKDIR_PATH}" DESTDIR="${DESTDIR_PATH}"
  197. .PHONY: hash
  198. hash: validate-destdir hash-gen
  199. cd "${DESTDIR}" && ${HOST_TOOLS}/hash-gen/hash-gen \
  200. --pfx="${DESTDIR_PATH}/pedia.pfx" \
  201. --fnd="${DESTDIR_PATH}/pedia.fnd" \
  202. --hsh="${DESTDIR_PATH}/pedia.hsh"
  203. stamp-r-index:
  204. rm -f "$@"
  205. cd host-tools/offline-renderer && ${MAKE} index \
  206. XML_FILES="${XML_FILES_PATH}" RENDER_BLOCK="${RENDER_BLOCK}" \
  207. WORKDIR="${WORKDIR_PATH}" DESTDIR="${DESTDIR_PATH}"
  208. touch "$@"
  209. .PHONY: clean-index
  210. clean-index:
  211. rm -f stamp-r-index
  212. MAKE_BLOCK = $(eval $(call MAKE_BLOCK1,$(strip ${1}),$(strip ${2}),$(strip ${3})))
  213. define MAKE_BLOCK1
  214. .PHONY: parse${1}
  215. parse${1}: stamp-r-index stamp-r-parse${1}
  216. .PHONY: render${1} fonts parse${1}
  217. render${1}: stamp-r-render${1}
  218. stamp-r-parse${1}:
  219. rm -f "$$@"
  220. $${MAKE} RENDER_BLOCK=${1} START=${2} COUNT=${3} parse
  221. touch "$$@"
  222. #.NOTPARALLEL: stamp-r-render${1}
  223. stamp-r-render${1}:
  224. rm -f "$$@"
  225. $${MAKE} RENDER_BLOCK=${1} render
  226. touch "$$@"
  227. .PHONY: stamp-r-clean${1}
  228. stamp-r-clean${1}:
  229. rm -f stamp-r-parse${1} stamp-r-render${1}
  230. endef
  231. # ------------------------------------------------
  232. # set this to make even distibution over 27 blocks
  233. # need a better way of setting this
  234. # ------------------------------------------------
  235. ARTICLE_COUNT_K ?= 114
  236. MACHINE_COUNT = 9
  237. PARALLEL_BUILD = 3
  238. MAX_BLOCK := $(shell expr ${MACHINE_COUNT} '*' ${PARALLEL_BUILD} - 1)
  239. # the first(0) and last(MAX_BLOCK) are special
  240. $(call MAKE_BLOCK,0,1,$(shell expr ${ARTICLE_COUNT_K} '*' 1000 - 1))
  241. ITEMS := $(shell i=1; while [ $${i} -lt ${MAX_BLOCK} ]; do echo $${i}; i=$$(($${i} + 1)); done)
  242. $(foreach i,${ITEMS},$(call MAKE_BLOCK,${i},$(shell expr ${i} '*' ${ARTICLE_COUNT_K})k,${ARTICLE_COUNT_K}k))
  243. $(call MAKE_BLOCK,${MAX_BLOCK},$(shell expr ${MAX_BLOCK} '*' ${ARTICLE_COUNT_K})k,all)
  244. MAKE_FARM = $(eval $(call MAKE_FARM1,$(strip ${1}),$(strip ${2}),$(strip ${3})))
  245. define MAKE_FARM1
  246. .PHONY: farm${1}-parse
  247. farm${1}-parse: $$(foreach i,${2},parse$$(strip $${i}))
  248. .PHONY: farm${1}-render
  249. farm${1}-render: $$(foreach i,${2},render$$(strip $${i}))
  250. .PHONY: farm${1}-clean
  251. farm${1}-clean: $$(foreach i,${2},stamp-r-clean$$(strip $${i}))
  252. .PHONY: farm${1}
  253. farm${1}: farm${1}-parse farm${1}-render
  254. endef
  255. MAKE_MACHINE = $(eval $(call MAKE_MACHINE1,$(strip ${1}),$(strip ${2}),$(strip ${3})))
  256. define MAKE_MACHINE1
  257. $(call MAKE_FARM,${1}, $(shell expr ${1} - 1) $(shell expr ${1} - 1 + ${2}) $(shell expr ${1} - 1 + 2 '*' ${2}))
  258. endef
  259. MACHINE_LIST := $(shell i=1; while [ $${i} -le ${MACHINE_COUNT} ]; do echo $${i}; i=$$(($${i} + 1)); done)
  260. $(foreach i,${MACHINE_LIST},$(call MAKE_MACHINE,${i},${MACHINE_COUNT}))
  261. # ----- wiki Dump --------------------------------------
  262. .PHONY: getwikidump
  263. getwikidump:
  264. wget http://download.wikimedia.org/enwiki/latest/enwiki-latest-pages-articles.xml.bz2
  265. # ----- forth -----------------------------------------------
  266. # forth interpreter
  267. .PHONY: forth
  268. forth: gcc mini-libc fatfs drivers
  269. ${MAKE} -C samo-lib/forth
  270. .PHONY: forth-install
  271. forth-install: forth
  272. ${MAKE} -C samo-lib/forth install DESTDIR="${DESTDIR_PATH}"
  273. # ----- flash -----------------------------------------------
  274. # flash programmer that runs on the device
  275. .PHONY: flash
  276. flash: gcc mini-libc fatfs drivers
  277. ${MAKE} -C samo-lib/flash
  278. # ----- mbr -------------------------------------------------
  279. # master boot record
  280. define FindTTY
  281. for i in USBconsole ttyUSB2 ttyUSB1 ttyUSB0;
  282. do
  283. d="/dev/$${i}";
  284. if [ -e "$${d}" ];
  285. then
  286. echo -n $${d};
  287. exit 0;
  288. fi;
  289. done;
  290. echo -n /dev/TTY-NOT-FOUND;
  291. exit 1;
  292. endef
  293. define FindAUX
  294. for i in USBjtag;
  295. do
  296. d="/dev/$${i}";
  297. if [ -e "$${d}" ];
  298. then
  299. echo -n $${d};
  300. exit 0;
  301. fi;
  302. done;
  303. echo -n /dev/TTY-NOT-FOUND;
  304. exit 1;
  305. endef
  306. BOOTLOADER_TTY ?= $(shell ${FindTTY})
  307. BOOTLOADER_AUX ?= $(shell ${FindAUX})
  308. SERIAL_NUMBER ?= No Serial Number
  309. .PHONY: print-mbr-tty
  310. print-mbr-tty:
  311. @echo BOOTLOADER_TTY = "${BOOTLOADER_TTY}"
  312. @echo BOOTLOADER_AUX = "${BOOTLOADER_AUX}"
  313. .PHONY: mbr
  314. mbr: gcc fatfs
  315. ${MAKE} -C samo-lib/mbr
  316. .PHONY: mbr-rs232
  317. mbr-rs232: gcc fatfs
  318. ${MAKE} -C samo-lib/mbr mbr-rs232
  319. .PHONY: jackknife
  320. jackknife:
  321. ${MAKE} -C host-tools/jackknife
  322. .PHONY: flash-mbr
  323. flash-mbr: mbr jackknife
  324. ${MAKE} -C samo-lib/mbr BOOTLOADER_TTY="${BOOTLOADER_TTY}" BOOTLOADER_AUX="${BOOTLOADER_AUX}" SERIAL_NUMBER="${SERIAL_NUMBER}" $@
  325. # ----- clean and help --------------------------------------
  326. .PHONY: complete-clean
  327. complete-clean: clean clean-toolchain
  328. rm -f binutils-download gcc-download
  329. .PHONY: clean
  330. clean: clean-qt4-simulator clean-console-simulator
  331. ${MAKE} clean -C samo-lib/mini-libc
  332. ${MAKE} clean -C host-tools/jackknife
  333. ${MAKE} clean -C host-tools/hash-gen
  334. ${MAKE} clean -C host-tools/pcf2bmf
  335. ${MAKE} clean -C host-tools/flash07
  336. ${MAKE} clean -C host-tools/fonts
  337. ${MAKE} clean -C host-tools/offline-renderer
  338. ${MAKE} clean -C samo-lib/mbr
  339. ${MAKE} clean -C samo-lib/drivers
  340. ${MAKE} clean -C samo-lib/fatfs
  341. ${MAKE} clean -C samo-lib/forth
  342. ${MAKE} clean -C samo-lib/flash
  343. ${MAKE} clean -C samo-lib/mahatma
  344. ${RM} stamp-r-*
  345. .PHONY: clean-toolchain
  346. clean-toolchain:
  347. rm -rf host-tools/toolchain-install
  348. rm -rf host-tools/gcc-${GCC_VERSION}host-tools/toolchain-patches/
  349. rm -rf host-tools/binutils-${BINUTILS_VERSION}
  350. rm -f binutils-patch binutils
  351. rm -f gcc-patch gcc
  352. .PHONY: clean-qt4-simulator
  353. clean-qt4-simulator:
  354. (cd host-tools/qt4-simulator; ${MAKE} distclean || true)
  355. .PHONY: clean-console-simulator
  356. clean-console-simulator:
  357. ${MAKE} clean -C host-tools/console-simulator
  358. .PHONY:help
  359. help:
  360. @echo
  361. @echo 'Some of the more useful targets:'
  362. @echo
  363. @echo ' all - compile all the source'
  364. @echo ' install - install forth, mahatma, fonts in DESTDIR'
  365. @echo ' index - convert XML_FILES to index files in DESTDIR'
  366. @echo ' parse - render XML_FILES into one big data files in DESTDIR'
  367. @echo ' combine - combine temporary indices to one file in DESTDIR'
  368. @echo ' farm<1..8> - parse/render XML_FILES into 3 data files in DESTDIR (use -j3)'
  369. @echo ' farm<1..8>-parse - parse XML_FILES into 3 HTML files in WORKDIR (use -j3)'
  370. @echo ' farm<1..8>-render - render WORKDIR HTML files into 3 data files in DESTDIR (use -j3)'
  371. @echo ' farm<1..8>-clean - remove stamp files to repeat process'
  372. @echo ' mbr - compile bootloader'
  373. @echo ' mahatma - compile kernel'
  374. @echo ' mahatma-install - install mahatma as kernel in DESTDIR'
  375. @echo ' forth - compile forth'
  376. @echo ' forth-install - install forth files in DESTDIR'
  377. @echo ' fonts - compile fonts'
  378. @echo ' fonts-install - install font files in DESTDIR'
  379. @echo ' mbr - compile bootloader'
  380. @echo ' gcc - compile gcc toolchain'
  381. @echo ' flash-mbr - flash bootloader to the E07 board'
  382. @echo ' qt4-simulator - compile the Qt4 simulator'
  383. @echo ' console-simulator - compile the console simulator'
  384. @echo ' clean - clean everything except the toochain'
  385. @echo ' clean-toolchain - clean just the toochain'
  386. @echo ' sd - copy kernel, forth and programs to SD Card'
  387. @echo ' p33 - terminal emulator (console debugging)'
  388. @echo
  389. .PHONY:testhelp
  390. testhelp:
  391. ${MAKE} --print-data-base --question | \
  392. awk '/^[^.%][-A-Za-z0-9_]*:/ \
  393. { print substr($$1, 1, length($$1)-1) }' | \
  394. sort | \
  395. pr --omit-pagination --width=80 --columns=1
  396. .PHONY: sd
  397. sd:
  398. ./samo-lib/scripts/MakeSD all
  399. .PHONY: p33
  400. p33:
  401. ./samo-lib/scripts/p33