Makefile 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. # Copyright (c) 2009 Openmoko Inc.
  2. #
  3. # This program is free software: you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation, either version 3 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. # +++START_UPDATE_MAKEFILE: Start of auto included code
  16. # The text between the +++ and --- tags is copied by the
  17. # UpdateMakefiles script. Do not remove or change these tags.
  18. # ---
  19. # Autodetect root directory
  20. define FIND_ROOT_DIR
  21. while : ; do \
  22. d=$$(pwd) ; \
  23. [ -d "$${d}/samo-lib" ] && echo $${d} && exit 0 ; \
  24. [ X"/" = X"$${d}" ] && echo ROOT_DIRECTORY_NOT_FOUND && exit 1 ; \
  25. cd .. ; \
  26. done
  27. endef
  28. ROOT_DIR := $(shell ${FIND_ROOT_DIR})
  29. # Directory of Makefile includes
  30. MK_DIR := ${ROOT_DIR}/samo-lib/Mk
  31. # Include the initial Makefile setup
  32. include ${MK_DIR}/definitions.mk
  33. # ---END_UPDATE_MAKEFILE: End of auto included code
  34. # which block to render
  35. RENDER_BLOCK ?= 0
  36. START ?= 1
  37. COUNT ?= all
  38. TOTAL_HTML_FILES ?= 64
  39. DESTDIR ?= .
  40. FONT_PATH ?= $(shell ${REALPATH} ${HOST_TOOLS}/fonts)
  41. WORKDIR ?= /tmp
  42. TEMPDIR ?= ${WORKDIR}/tmp
  43. WIKI_FILE_PREFIX ?= wiki
  44. WIKI_LANGUAGE ?= en
  45. WIKI_DIR_SUFFIX ?= pedia
  46. ENABLE_LANGUAGES_LINKS ?= YES
  47. ENABLE_IMAGES ?= YES
  48. ARTICLES_PER_BLOCK ?= 32
  49. ARTICLE_BLOCK_SIZE ?= 262144
  50. WORKDIR_PATH := $(shell ${RESOLVEPATH} ${WORKDIR}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX})
  51. TEMPDIR_PATH := $(shell ${RESOLVEPATH} ${TEMPDIR}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX})
  52. PREFIX := $(shell ${RESOLVEPATH} ${DESTDIR}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}/${WIKI_FILE_PREFIX})
  53. ARTICLES := $(shell ${RESOLVEPATH} ${WORKDIR_PATH}/articles.db)
  54. COUNTS_FILE := $(shell ${RESOLVEPATH} ${WORKDIR_PATH}/counts.text)
  55. TEMPLATE_FILE := $(shell ${RESOLVEPATH} ${WORKDIR_PATH}/templates.db)
  56. OFFSETS := $(shell ${RESOLVEPATH} ${WORKDIR_PATH}/offsets.db)
  57. HTML_ARTICLES_PREFIX := $(shell ${RESOLVEPATH} ${WORKDIR_PATH}/articles-)
  58. HTML_ARTICLES := $(shell ${RESOLVEPATH} ${HTML_ARTICLES_PREFIX}${RENDER_BLOCK}.html)
  59. PYLZMA_DIR := pylzma-0.3.0
  60. MATH_DIR := mediawiki-offline/math
  61. MEDIAWIKI_MESSAGES_DIR := mediawiki-offline/languages/messages
  62. $(call REQUIRED_BINARY, sqlite3, sqlite3)
  63. $(call REQUIRED_BINARY, ocamlopt, ocaml)
  64. $(call REQUIRED_BINARY, tex, cjk-latex)
  65. $(call REQUIRED_BINARY, php, php5-cli)
  66. $(call REQUIRED_BINARY, dvipng, dvipng)
  67. $(call REQUIRED_PHP, pdo_sqlite, php5-sqlite)
  68. $(call REQUIRED_PHP, session, php5-session)
  69. $(call REQUIRED_PHP, ctype, php5-ctype)
  70. ifeq (yes,$(strip ${VERBOSE}))
  71. VERBOSE_ARG = --verbose
  72. endif
  73. ifeq (YES,$(strip ${VERBOSE}))
  74. VERBOSE_ARG = --verbose
  75. endif
  76. TRUNCATE_ARG = --truncate-title
  77. ifneq (yes,$(strip ${ENABLE_LANGUAGE_LINKS}))
  78. TRUNCATE_ARG =
  79. endif
  80. ifneq (YES,$(strip ${ENABLE_LANGUAGE_LINKS}))
  81. TRUNCATE_ARG =
  82. endif
  83. TARGETS = index parse render combine
  84. .PHONY: all
  85. all: ${TARGETS}
  86. .PHONY: check-xml
  87. check-xml:
  88. @if [ -z "${XML_FILES}" ] ; then echo XML_FILES is not set ; exit 1; fi
  89. .PHONY: check-dirs
  90. check-dirs:
  91. @if [ ! -d "${DESTDIR}" ] ; then echo DESTDIR: "'"${DESTDIR}"'" is not a directory ; exit 1; fi
  92. @if [ ! -d "${WORKDIR_PATH}" ] ; then echo WORKDIR_PATH: "'"${WORKDIR_PATH}"'" is not a directory ; exit 1; fi
  93. @[ -d "${TEMPDIR}" ] || ${MKDIR} "${TEMPDIR}"
  94. @if [ ! -d "${TEMPDIR}" ] ; then echo TEMPDIR: "'"${TEMPDIR}"'" is not a directory ; exit 1; fi
  95. .PHONY: check-fonts
  96. check-fonts:
  97. @if [ ! -d "${FONT_PATH}" ] ; then echo FONT_PATH: "'"${FONT_PATH}"'" is not a directory ; exit 1; fi
  98. .PHONY: check-html
  99. check-html:
  100. @if [ -z "${HTML_ARTICLES}" ] ; then echo HTML_ARTICLES is not set ; exit 1; fi
  101. .PHONY: index
  102. index: check-dirs check-xml stamp-RedirectedTo.py stamp-PinyinTable.py
  103. ./ArticleIndex.py ${VERBOSE_ARG} \
  104. --article-index="${ARTICLES}" \
  105. --article-offsets="${OFFSETS}" \
  106. --article-counts="${COUNTS_FILE}" \
  107. --templates="${TEMPLATE_FILE}" \
  108. --language="${WIKI_LANGUAGE}" \
  109. --prefix="${PREFIX}" ${TRUNCATE_ARG} ${XML_FILES}
  110. HTML_FILES_COUNT := $(words $(wildcard ${WORKDIR_PATH}/*.html))
  111. .PHONY: merge
  112. merge:
  113. ifeq (0,$(strip $(shell [ "${HTML_FILES_COUNT}" -gt "${TOTAL_HTML_FILES}" ] ; echo $$?)))
  114. @echo merging: ${HTML_FILES_COUNT} to: ${TOTAL_HTML_FILES}
  115. @${RM} ${HTML_ARTICLES_PREFIX}*.html-UNMERGED
  116. @i=0 ; \
  117. while [ $${i} -lt ${HTML_FILES_COUNT} ] ; \
  118. do \
  119. f=${HTML_ARTICLES_PREFIX}$${i}.html ; \
  120. mv "$${f}" "$${f}-UNMERGED" ; \
  121. i=$$(($${i} + 1)) ; \
  122. done
  123. @i=0 ; in=0 ; out=0 ; \
  124. total=${TOTAL_HTML_FILES} ; count=${HTML_FILES_COUNT} ; \
  125. while [ $${out} -lt ${TOTAL_HTML_FILES} ] ; \
  126. do \
  127. step=$$(expr '(' 2 '*' $${count} / $${total} + 1 ')' / 2) ; \
  128. count=$$(($${count} - $${step})) ; \
  129. f_out=${HTML_ARTICLES_PREFIX}$${out}.html ; \
  130. ${RM} $${f_out} ; \
  131. echo -n generating: $${f_out} ; \
  132. while [ $${step} -gt 0 ] ; \
  133. do \
  134. f=${HTML_ARTICLES_PREFIX}$${in}.html-UNMERGED ; \
  135. echo -n " $${in}" ; \
  136. cat "$${f}" >> "$${f_out}" ; \
  137. in=$$(($${in} + 1)) ; \
  138. step=$$(($${step} - 1)) ; \
  139. done ; \
  140. echo ; \
  141. out=$$(($${out} + 1)) ; \
  142. total=$$(($${total} - 1)) ; \
  143. done
  144. else
  145. @echo Merge Ignored: insufficient files: ${HTML_FILES_COUNT} '<=' ${TOTAL_HTML_FILES}
  146. endif
  147. .PHONY: parse
  148. parse: check-dirs check-html stamp-math stamp-RedirectedTo.py
  149. ./ArticleParser.py ${VERBOSE_ARG} --xhtml="${HTML_ARTICLES}" \
  150. --language="${WIKI_LANGUAGE}" \
  151. --start="${START}" --count="${COUNT}" \
  152. --templates="${TEMPLATE_FILE}" \
  153. --parser-workdir="${WORKDIR_PATH}" \
  154. --parser-tempdir="${TEMPDIR_PATH}" \
  155. --article-offsets="${OFFSETS}"
  156. .PHONY: render
  157. render: check-dirs check-fonts check-html stamp-PinyinTable.py
  158. ./ArticleRenderer.py ${VERBOSE_ARG} --number="${RENDER_BLOCK}" \
  159. --font-path="${FONT_PATH}" \
  160. --article-index="${ARTICLES}" \
  161. --prefix="${PREFIX}" \
  162. --language-links="${ENABLE_LANGUAGES_LINKS}" \
  163. --images="${ENABLE_IMAGES}" \
  164. --articles="${ARTICLES_PER_BLOCK}" \
  165. --block-size="${ARTICLE_BLOCK_SIZE}" \
  166. "${HTML_ARTICLES}"
  167. .PHONY: combine
  168. combine: check-dirs
  169. ./combine_idx.py ${VERBOSE_ARG} --prefix="${PREFIX}"
  170. # sudo apt-get install python-dev
  171. .PHONY: pylzma
  172. pylzma:
  173. cd ${PYLZMA_DIR} && \
  174. python setup.py build && \
  175. sudo python setup.py install
  176. # create the #redirect regular expression
  177. CLEAN_TARGETS += RedirectedTo.py
  178. RedirectedTo.py: FindAllRedirects.php ${MEDIAWIKI_MESSAGES_DIR}/*.php
  179. php5 FindAllRedirects.php ${MEDIAWIKI_MESSAGES_DIR}/*.php > "$@"
  180. # create Pinyin table for index program
  181. PINYIN_TABLE = pinyin-data/pinyin_table.txt
  182. CLEAN_TARGETS += PinyinTable.py
  183. PinyinTable.py: CreatePinyinTable.py
  184. ./CreatePinyinTable.py --input="${PINYIN_TABLE}" --output="$@"
  185. # sudo apt-get install tetex-extra dvipng cjk-latex ocaml
  186. .PHONY: math
  187. math:
  188. ${MAKE} -C "${MATH_DIR}"
  189. # use a lock to avoid multiple parallel builds of specific programs
  190. # i.e depend on "stamp-program" instead of "program"
  191. # so that the actual build will be serialised in a recursive call to make
  192. stamp-%:
  193. ${LOCKF} "$@" ${MAKE} "${@:stamp-%=%}"
  194. ${TOUCH} "$@"
  195. .PHONY: install
  196. install: all
  197. build:
  198. ${MKDIR} "$@"
  199. .PHONY: clean
  200. clean: pylzma-clean
  201. ${RM} -r build ${TARGETS} ${CLEAN_TARGETS} *.pyc *.pyo *.dat *.idx *.idx-tmp *.pfx *.fnd
  202. ${RM} stamp-*
  203. ${MAKE} -C "${MATH_DIR}" clean
  204. .PHONY: pylzma-clean
  205. pylzma-clean:
  206. cd ${PYLZMA_DIR} && \
  207. python setup.py clean && \
  208. ${RM} -r build
  209. include ${MK_DIR}/rules.mk