Makefile 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. WORKDIR_PATH := $(shell ${RESOLVEPATH} ${WORKDIR}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX})
  47. TEMPDIR_PATH := $(shell ${RESOLVEPATH} ${TEMPDIR}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX})
  48. PREFIX := $(shell ${RESOLVEPATH} ${DESTDIR}/${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}/${WIKI_FILE_PREFIX})
  49. ARTICLES := $(shell ${RESOLVEPATH} ${WORKDIR_PATH}/articles.db)
  50. COUNTS_FILE := $(shell ${RESOLVEPATH} ${WORKDIR_PATH}/counts.text)
  51. TEMPLATE_FILE := $(shell ${RESOLVEPATH} ${WORKDIR_PATH}/templates.db)
  52. OFFSETS := $(shell ${RESOLVEPATH} ${WORKDIR_PATH}/offsets.db)
  53. HTML_ARTICLES_PREFIX := $(shell ${RESOLVEPATH} ${WORKDIR_PATH}/articles-)
  54. HTML_ARTICLES := $(shell ${RESOLVEPATH} ${HTML_ARTICLES_PREFIX}${RENDER_BLOCK}.html)
  55. PYLZMA_DIR := pylzma-0.3.0
  56. MATH_DIR := mediawiki-offline/math
  57. MEDIAWIKI_MESSAGES_DIR := mediawiki-offline/languages/messages
  58. $(call REQUIRED_BINARY, sqlite3, sqlite3)
  59. $(call REQUIRED_BINARY, ocamlopt, ocaml)
  60. $(call REQUIRED_BINARY, tex, tetex-extra cjk-latex)
  61. $(call REQUIRED_BINARY, php, php5-cli)
  62. $(call REQUIRED_BINARY, dvipng, dvipng)
  63. $(call REQUIRED_PHP, pdo_sqlite, php5-sqlite)
  64. $(call REQUIRED_PHP, session, php5-session)
  65. $(call REQUIRED_PHP, ctype, php5-ctype)
  66. ifeq (yes,$(strip ${VERBOSE}))
  67. VERBOSE_ARG = --verbose
  68. endif
  69. ifeq (YES,$(strip ${VERBOSE}))
  70. VERBOSE_ARG = --verbose
  71. endif
  72. TARGETS = index parse render combine
  73. .PHONY: all
  74. all: ${TARGETS}
  75. .PHONY: check-xml
  76. check-xml:
  77. @if [ -z "${XML_FILES}" ] ; then echo XML_FILES is not set ; exit 1; fi
  78. .PHONY: check-dirs
  79. check-dirs:
  80. @if [ ! -d "${DESTDIR}" ] ; then echo DESTDIR: "'"${DESTDIR}"'" is not a directory ; exit 1; fi
  81. @if [ ! -d "${WORKDIR_PATH}" ] ; then echo WORKDIR_PATH: "'"${WORKDIR_PATH}"'" is not a directory ; exit 1; fi
  82. @[ -d "${TEMPDIR}" ] || ${MKDIR} "${TEMPDIR}"
  83. @if [ ! -d "${TEMPDIR}" ] ; then echo TEMPDIR: "'"${TEMPDIR}"'" is not a directory ; exit 1; fi
  84. .PHONY: check-fonts
  85. check-fonts:
  86. @if [ ! -d "${FONT_PATH}" ] ; then echo FONT_PATH: "'"${FONT_PATH}"'" is not a directory ; exit 1; fi
  87. .PHONY: check-html
  88. check-html:
  89. @if [ -z "${HTML_ARTICLES}" ] ; then echo HTML_ARTICLES is not set ; exit 1; fi
  90. .PHONY: index
  91. index: check-dirs check-xml RedirectedTo.py
  92. ./ArticleIndex.py ${VERBOSE_ARG} \
  93. --article-index="${ARTICLES}" \
  94. --article-offsets="${OFFSETS}" \
  95. --article-counts="${COUNTS_FILE}" \
  96. --templates="${TEMPLATE_FILE}" \
  97. --prefix="${PREFIX}" ${XML_FILES}
  98. HTML_FILES_COUNT := $(words $(wildcard ${WORKDIR_PATH}/*.html))
  99. .PHONY: merge
  100. merge:
  101. ifeq (0,$(strip $(shell [ "${HTML_FILES_COUNT}" -gt "${TOTAL_HTML_FILES}" ] ; echo $$?)))
  102. @echo merging: ${HTML_FILES_COUNT} to: ${TOTAL_HTML_FILES}
  103. @${RM} ${HTML_ARTICLES_PREFIX}*.html-UNMERGED
  104. @i=0 ; \
  105. while [ $${i} -lt ${HTML_FILES_COUNT} ] ; \
  106. do \
  107. f=${HTML_ARTICLES_PREFIX}$${i}.html ; \
  108. mv "$${f}" "$${f}-UNMERGED" ; \
  109. i=$$(($${i} + 1)) ; \
  110. done
  111. @i=0 ; in=0 ; out=0 ; \
  112. total=${TOTAL_HTML_FILES} ; count=${HTML_FILES_COUNT} ; \
  113. while [ $${out} -lt ${TOTAL_HTML_FILES} ] ; \
  114. do \
  115. step=$$(expr '(' 2 '*' $${count} / $${total} + 1 ')' / 2) ; \
  116. count=$$(($${count} - $${step})) ; \
  117. f_out=${HTML_ARTICLES_PREFIX}$${out}.html ; \
  118. ${RM} $${f_out} ; \
  119. echo -n generating: $${f_out} ; \
  120. while [ $${step} -gt 0 ] ; \
  121. do \
  122. f=${HTML_ARTICLES_PREFIX}$${in}.html-UNMERGED ; \
  123. echo -n " $${in}" ; \
  124. cat "$${f}" >> "$${f_out}" ; \
  125. in=$$(($${in} + 1)) ; \
  126. step=$$(($${step} - 1)) ; \
  127. done ; \
  128. echo ; \
  129. out=$$(($${out} + 1)) ; \
  130. total=$$(($${total} - 1)) ; \
  131. done
  132. else
  133. @echo Merge Ignored: insufficient files: ${HTML_FILES_COUNT} '<=' ${TOTAL_HTML_FILES}
  134. endif
  135. .PHONY: parse
  136. parse: check-dirs check-html math RedirectedTo.py
  137. ./ArticleParser.py ${VERBOSE_ARG} --xhtml="${HTML_ARTICLES}" \
  138. --language="${WIKI_LANGUAGE}" \
  139. --start="${START}" --count="${COUNT}" \
  140. --templates="${TEMPLATE_FILE}" \
  141. --parser-workdir="${WORKDIR_PATH}" \
  142. --parser-tempdir="${TEMPDIR_PATH}" \
  143. --article-offsets="${OFFSETS}"
  144. .PHONY: render
  145. render: pylzma check-dirs check-fonts check-html
  146. ./ArticleRenderer.py ${VERBOSE_ARG} --number="${RENDER_BLOCK}" \
  147. --font-path="${FONT_PATH}" \
  148. --article-index="${ARTICLES}" \
  149. --prefix="${PREFIX}" "${HTML_ARTICLES}"
  150. .PHONY: combine
  151. combine: check-dirs
  152. ./combine_idx.py ${VERBOSE_ARG} --prefix="${PREFIX}"
  153. # sudo apt-get install python-dev
  154. .PHONY: pylzma
  155. pylzma:
  156. for dir in /usr/lib/python* /usr/local/lib/python* /opt/lib/python* /usr/lib64/python* ; \
  157. do \
  158. [ -e "$${dir}/site-packages/pylzma.so" ] && exit 0 ; \
  159. [ -e "$${dir}/dist-packages/pylzma.so" ] && exit 0 ; \
  160. done ; \
  161. cd ${PYLZMA_DIR} && \
  162. python setup.py build && \
  163. sudo python setup.py install
  164. # create the #redirect regular expression
  165. RedirectedTo.py: FindAllRedirects.php ${MEDIAWIKI_MESSAGES_DIR}/*.php
  166. php5 FindAllRedirects.php ${MEDIAWIKI_MESSAGES_DIR}/*.php > "$@"
  167. # sudo apt-get install tetex-extra dvipng cjk-latex ocaml
  168. .PHONY: math
  169. math: stamp-math
  170. # use a lock to avoid multiple parallel builds of this program
  171. stamp-math:
  172. ${RM} "$@"
  173. ${LOCKF} "${@}" ${MAKE} -C "${MATH_DIR}"
  174. ${TOUCH} "$@"
  175. .PHONY: install
  176. install: all
  177. build:
  178. ${MKDIR} "$@"
  179. .PHONY: clean
  180. clean: pylzma-clean
  181. ${RM} -r build ${TARGETS} *.pyc *.pyo *.dat *.idx *.idx-tmp *.pfx *.fnd
  182. ${RM} stamp-*
  183. ${MAKE} -C "${MATH_DIR}" clean
  184. .PHONY: pylzma-clean
  185. pylzma-clean:
  186. cd ${PYLZMA_DIR} && \
  187. python setup.py clean && \
  188. ${RM} -r build
  189. include ${MK_DIR}/rules.mk