Makefile 7.4 KB

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