Makefile 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. # -*- coding: utf-8; mode: makefile-gmake -*-
  2. .DEFAULT_GOAL=help
  3. # START Makefile setup
  4. export GIT_URL=https://github.com/asciimoo/searx
  5. export GIT_BRANCH=master
  6. export SEARX_URL=https://searx.me
  7. export DOCS_URL=https://asciimoo.github.io/searx
  8. # END Makefile setup
  9. include utils/makefile.include
  10. PYOBJECTS = searx
  11. DOC = docs
  12. PY_SETUP_EXTRAS ?= \[test\]
  13. include utils/makefile.python
  14. include utils/makefile.sphinx
  15. all: clean install
  16. PHONY += help-min help-all help
  17. help: help-min
  18. @echo ''
  19. @echo 'to get more help: make help-all'
  20. help-min:
  21. @echo ' test - run developer tests'
  22. @echo ' docs - build documentation'
  23. @echo ' docs-live - autobuild HTML documentation while editing'
  24. @echo ' run - run developer instance'
  25. @echo ' install - developer install (./local)'
  26. @echo ' uninstall - uninstall (./local)'
  27. @echo ' gh-pages - build docs & deploy on gh-pages branch'
  28. @echo ' clean - drop builds and environments'
  29. @echo ' project - re-build generic files of the searx project'
  30. @echo ' buildenv - re-build environment files (aka brand)'
  31. @echo ' themes - re-build build the source of the themes'
  32. @echo ' docker - build Docker image'
  33. @echo ' node.env - download & install npm dependencies locally'
  34. @echo ''
  35. @echo 'environment'
  36. @echo ' SEARX_URL = $(SEARX_URL)'
  37. @echo ' GIT_URL = $(GIT_URL)'
  38. @echo ' DOCS_URL = $(DOCS_URL)'
  39. @echo ''
  40. @$(MAKE) -e -s make-help
  41. help-all: help-min
  42. @echo ''
  43. @$(MAKE) -e -s python-help
  44. @echo ''
  45. @$(MAKE) -e -s docs-help
  46. PHONY += install
  47. install: buildenv pyenvinstall
  48. PHONY += uninstall
  49. uninstall: pyenvuninstall
  50. PHONY += clean
  51. clean: pyclean docs-clean node.clean test.clean
  52. $(call cmd,common_clean)
  53. PHONY += run
  54. run: buildenv pyenvinstall
  55. $(Q) ( \
  56. sed -i -e "s/debug : False/debug : True/g" ./searx/settings.yml ; \
  57. sleep 2 ; \
  58. xdg-open http://127.0.0.1:8888/ ; \
  59. sleep 3 ; \
  60. sed -i -e "s/debug : True/debug : False/g" ./searx/settings.yml ; \
  61. ) &
  62. $(PY_ENV)/bin/python ./searx/webapp.py
  63. # docs
  64. # ----
  65. sphinx-doc-prebuilds:: buildenv pyenvinstall prebuild-includes
  66. PHONY += docs
  67. docs: sphinx-doc-prebuilds sphinx-doc
  68. $(call cmd,sphinx,html,docs,docs)
  69. PHONY += docs-live
  70. docs-live: sphinx-doc-prebuilds sphinx-live
  71. $(call cmd,sphinx_autobuild,html,docs,docs)
  72. PHONY += prebuild-includes
  73. prebuild-includes:
  74. $(Q)mkdir -p $(DOCS_BUILD)/includes
  75. $(Q)./utils/searx.sh doc | cat > $(DOCS_BUILD)/includes/searx.rst
  76. $(Q)./utils/filtron.sh doc | cat > $(DOCS_BUILD)/includes/filtron.rst
  77. $(Q)./utils/morty.sh doc | cat > $(DOCS_BUILD)/includes/morty.rst
  78. $(GH_PAGES)::
  79. @echo "doc available at --> $(DOCS_URL)"
  80. # update project files
  81. # --------------------
  82. PHONY += project engines.languages useragents.update buildenv
  83. project: buildenv useragents.update engines.languages
  84. engines.languages: pyenvinstall
  85. $(Q)echo "fetch languages .."
  86. $(Q)$(PY_ENV_ACT); python utils/fetch_languages.py
  87. $(Q)echo "update searx/data/engines_languages.json"
  88. $(Q)mv engines_languages.json searx/data/engines_languages.json
  89. $(Q)echo "update searx/languages.py"
  90. $(Q)mv languages.py searx/languages.py
  91. useragents.update: pyenvinstall
  92. $(Q)echo "Update searx/data/useragents.json with the most recent versions of Firefox."
  93. $(Q)$(PY_ENV_ACT); python utils/fetch_firefox_version.py
  94. buildenv:
  95. $(Q)echo "build searx/brand.py"
  96. $(Q)echo "GIT_URL = '$(GIT_URL)'" > searx/brand.py
  97. $(Q)echo "GIT_BRANCH = '$(GIT_BRANCH)'" >> searx/brand.py
  98. $(Q)echo "ISSUE_URL = 'https://github.com/asciimoo/searx/issues'" >> searx/brand.py
  99. $(Q)echo "SEARX_URL = '$(SEARX_URL)'" >> searx/brand.py
  100. $(Q)echo "DOCS_URL = '$(DOCS_URL)'" >> searx/brand.py
  101. $(Q)echo "PUBLIC_INSTANCES = 'https://searx.space'" >> searx/brand.py
  102. $(Q)echo "build utils/brand.env"
  103. $(Q)echo "export GIT_URL='$(GIT_URL)'" > utils/brand.env
  104. $(Q)echo "export GIT_BRANCH='$(GIT_BRANCH)'" >> utils/brand.env
  105. $(Q)echo "export ISSUE_URL='https://github.com/asciimoo/searx/issues'" >> utils/brand.env
  106. $(Q)echo "export SEARX_URL='$(SEARX_URL)'" >> utils/brand.env
  107. $(Q)echo "export DOCS_URL='$(DOCS_URL)'" >> utils/brand.env
  108. $(Q)echo "export PUBLIC_INSTANCES='https://searx.space'" >> utils/brand.env
  109. # node / npm
  110. # ----------
  111. node.env: buildenv
  112. $(Q)./manage.sh npm_packages
  113. node.clean:
  114. $(Q)echo "CLEAN locally installed npm dependencies"
  115. $(Q)rm -rf \
  116. ./node_modules \
  117. ./package-lock.json \
  118. ./searx/static/themes/oscar/package-lock.json \
  119. ./searx/static/themes/oscar/node_modules \
  120. ./searx/static/themes/simple/package-lock.json \
  121. ./searx/static/themes/simple/node_modules
  122. # build themes
  123. # ------------
  124. PHONY += themes.bootstrap themes themes.oscar themes.simple themes.legacy themes.courgette themes.pixart
  125. themes: buildenv themes.bootstrap themes.oscar themes.simple themes.legacy themes.courgette themes.pixart
  126. quiet_cmd_lessc = LESSC $3
  127. cmd_lessc = PATH="$$(npm bin):$$PATH" \
  128. lessc --clean-css="--s1 --advanced --compatibility=ie9" "searx/static/$2" "searx/static/$3"
  129. quiet_cmd_grunt = GRUNT $2
  130. cmd_grunt = PATH="$$(npm bin):$$PATH" \
  131. grunt --gruntfile "$2"
  132. themes.oscar: node.env
  133. $(Q)echo '[!] build oscar theme'
  134. $(call cmd,grunt,searx/static/themes/oscar/gruntfile.js)
  135. themes.simple: node.env
  136. $(Q)echo '[!] build simple theme'
  137. $(call cmd,grunt,searx/static/themes/simple/gruntfile.js)
  138. themes.legacy: node.env
  139. $(Q)echo '[!] build legacy theme'
  140. $(call cmd,lessc,themes/legacy/less/style-rtl.less,themes/legacy/css/style-rtl.css)
  141. $(call cmd,lessc,themes/legacy/less/style.less,themes/legacy/css/style.css)
  142. themes.courgette: node.env
  143. $(Q)echo '[!] build courgette theme'
  144. $(call cmd,lessc,themes/courgette/less/style.less,themes/courgette/css/style.css)
  145. $(call cmd,lessc,themes/courgette/less/style-rtl.less,themes/courgette/css/style-rtl.css)
  146. themes.pixart: node.env
  147. $(Q)echo '[!] build pixart theme'
  148. $(call cmd,lessc,themes/pix-art/less/style.less,themes/pix-art/css/style.css)
  149. themes.bootstrap: node.env
  150. $(call cmd,lessc,less/bootstrap/bootstrap.less,css/bootstrap.min.css)
  151. # docker
  152. # ------
  153. PHONY += docker
  154. docker: buildenv
  155. $(Q)./manage.sh docker_build
  156. docker.push: buildenv
  157. $(Q)./manage.sh docker_build push
  158. # gecko
  159. # -----
  160. PHONY += gecko.driver
  161. gecko.driver:
  162. $(PY_ENV_ACT); ./manage.sh install_geckodriver
  163. # test
  164. # ----
  165. PHONY += test test.sh test.pylint test.pep8 test.unit test.coverage test.robot
  166. test: buildenv test.pylint test.pep8 test.unit gecko.driver test.robot
  167. ifeq ($(PY),2)
  168. test.pylint:
  169. @echo "LINT skip liniting py2"
  170. else
  171. # TODO: balance linting with pylint
  172. test.pylint: pyenvinstall
  173. $(call cmd,pylint,\
  174. searx/preferences.py \
  175. searx/testing.py \
  176. searx/engines/gigablast.py \
  177. )
  178. endif
  179. # ignored rules:
  180. # E402 module level import not at top of file
  181. # W503 line break before binary operator
  182. # ubu1604: uses shellcheck v0.3.7 (from 04/2015), no longer supported!
  183. test.sh:
  184. shellcheck -x -s bash utils/brand.env
  185. shellcheck -x utils/lib.sh
  186. shellcheck -x utils/filtron.sh
  187. shellcheck -x utils/searx.sh
  188. shellcheck -x utils/morty.sh
  189. shellcheck -x utils/lxc.sh
  190. shellcheck -x utils/lxc-searx.env
  191. shellcheck -x .config.sh
  192. test.pep8: pyenvinstall
  193. @echo "TEST pep8"
  194. $(Q)$(PY_ENV_ACT); pep8 --exclude='searx/static, searx/engines/gigablast.py' --max-line-length=120 --ignore "E402,W503" searx tests
  195. test.unit: pyenvinstall
  196. @echo "TEST tests/unit"
  197. $(Q)$(PY_ENV_ACT); python -m nose2 -s tests/unit
  198. test.coverage: pyenvinstall
  199. @echo "TEST unit test coverage"
  200. $(Q)$(PY_ENV_ACT); \
  201. python -m nose2 -C --log-capture --with-coverage --coverage searx -s tests/unit \
  202. && coverage report \
  203. && coverage html \
  204. test.robot: pyenvinstall gecko.driver
  205. @echo "TEST robot"
  206. $(Q)$(PY_ENV_ACT); PYTHONPATH=. python searx/testing.py robot
  207. test.clean:
  208. @echo "CLEAN intermediate test stuff"
  209. $(Q)rm -rf geckodriver.log .coverage coverage/
  210. # travis
  211. # ------
  212. travis.codecov:
  213. $(Q)$(PY_ENV_BIN)/python -m pip install codecov
  214. .PHONY: $(PHONY)