You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Makefile 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. .PHONY: nix-add-gcroots clean nix-clean disable-githooks react-native-android react-native-ios react-native-desktop test release _list _fix-node-perms
  2. help: SHELL := /bin/sh
  3. help: ##@other Show this help
  4. @perl -e '$(HELP_FUN)' $(MAKEFILE_LIST)
  5. # This is a code for automatic help generator.
  6. # It supports ANSI colors and categories.
  7. # To add new item into help output, simply add comments
  8. # starting with '##'. To add category, use @category.
  9. GREEN := $(shell tput -Txterm setaf 2)
  10. RED := $(shell tput -Txterm setaf 1)
  11. WHITE := $(shell tput -Txterm setaf 7)
  12. YELLOW := $(shell tput -Txterm setaf 3)
  13. RESET := $(shell tput -Txterm sgr0)
  14. HELP_FUN = \
  15. %help; \
  16. while(<>) { push @{$$help{$$2 // 'options'}}, [$$1, $$3] if /^([a-zA-Z\-]+)\s*:.*\#\#(?:@([a-zA-Z\-]+))?\s(.*)$$/ }; \
  17. print "Usage: make [target]\n\n"; \
  18. for (sort keys %help) { \
  19. print "${WHITE}$$_:${RESET}\n"; \
  20. for (@{$$help{$$_}}) { \
  21. $$sep = " " x (32 - length $$_->[0]); \
  22. print " ${YELLOW}$$_->[0]${RESET}$$sep${GREEN}$$_->[1]${RESET}\n"; \
  23. }; \
  24. print "\n"; \
  25. }
  26. HOST_OS := $(shell uname | tr '[:upper:]' '[:lower:]')
  27. # Defines which variables will be kept for Nix pure shell, use semicolon as divider
  28. export _NIX_KEEP ?= BUILD_ENV
  29. export NIX_CONF_DIR = $(PWD)/nix
  30. # We don't want to use /run/user/$UID because it runs out of space too easilly
  31. export TMPDIR = /tmp
  32. export REACT_SERVER_PORT ?= 5001 # any value different from default 5000 will work; this has to be specified for both the Node.JS server process and the Qt process
  33. #----------------
  34. # Nix targets
  35. #----------------
  36. # WARNING: This has to be located right before the targets
  37. ifdef IN_NIX_SHELL
  38. SHELL := env bash
  39. else
  40. SHELL := ./nix/shell.sh
  41. endif
  42. shell: ##@prepare Enter into a pre-configured shell
  43. ifndef IN_NIX_SHELL
  44. @ENTER_NIX_SHELL
  45. else
  46. @echo "${YELLOW}Nix shell is already active$(RESET)"
  47. endif
  48. nix-clean: ##@nix Remove all status-react build artifacts from /nix/store
  49. nix/clean.sh
  50. nix-purge: SHELL := /bin/sh
  51. nix-purge: ##@nix Completely remove the complete Nix setup
  52. sudo rm -rf /nix ~/.nix-profile ~/.nix-defexpr ~/.nix-channels ~/.cache/nix ~/.status .nix-gcroots
  53. nix-add-gcroots: export TARGET_OS := none
  54. nix-add-gcroots: ##@nix Add Nix GC roots to avoid status-react expressions being garbage collected
  55. scripts/add-nix-gcroots.sh
  56. nix-update-npm: export TARGET_OS := none
  57. nix-update-npm: ##@nix Update node2nix expressions based on current package.json
  58. nix/desktop/realm-node/generate-nix.sh
  59. nix-update-gradle: ##@nix Update maven nix expressions based on current gradle setup
  60. nix/mobile/android/maven-and-npm-deps/maven/generate-nix.sh
  61. nix-update-lein: export TARGET_OS := none
  62. nix-update-lein: ##@nix Update maven nix expressions based on current lein setup
  63. nix/tools/lein/generate-nix.sh nix/lein
  64. update-gems-nix: export TARGET_OS := android
  65. update-gems-nix: ##@nix Update Ruby gems in fastlane/Gemfile.lock and fastlane/gemset.nix
  66. fastlane/update.sh
  67. #----------------
  68. # General targets
  69. #----------------
  70. _fix-node-perms: SHELL := /bin/sh
  71. _fix-node-perms: ##@prepare Fix permissions so that directory can be cleaned
  72. $(shell test -d node_modules && chmod -R 744 node_modules)
  73. $(shell test -d node_modules.tmp && chmod -R 744 node_modules.tmp)
  74. clean: SHELL := /bin/sh
  75. clean: _fix-node-perms ##@prepare Remove all output folders
  76. git clean -dxf -f
  77. watchman-clean: export _NIX_ATTR := targets.watchman.shell
  78. watchman-clean: ##@prepare Delete repo directory from watchman
  79. watchman watch-del $${STATUS_REACT_HOME}
  80. disable-githooks: SHELL := /bin/sh
  81. disable-githooks: ##@prepare Disables lein githooks
  82. @rm -f ${env.WORKSPACE}/.git/hooks/pre-commit && \
  83. sed -i'~' -e 's|\[rasom/lein-githooks|;; [rasom/lein-githooks|' \
  84. -e 's|:githooks|;; :githooks|' \
  85. -e 's|:pre-commit|;; :pre-commit|' project.clj; \
  86. rm project.clj~
  87. #----------------
  88. # Release builds
  89. #----------------
  90. release: release-android release-ios ##@build build release for Android and iOS
  91. release-android: export TARGET_OS ?= android
  92. release-android: export BUILD_ENV ?= prod
  93. release-android: export BUILD_TYPE ?= nightly
  94. release-android: export BUILD_NUMBER ?= 9999
  95. release-android: export NDK_ABI_FILTERS ?= armeabi-v7a;arm64-v8a;x86
  96. release-android: export STORE_FILE ?= ~/.gradle/status-im.keystore
  97. release-android: ##@build build release for Android
  98. nix/build.sh targets.mobile.$(TARGET_OS).release \
  99. --arg env '{NDK_ABI_FILTERS="$(NDK_ABI_FILTERS)";}' \
  100. --argstr build-type $(BUILD_TYPE) \
  101. --argstr build-number $(BUILD_NUMBER) \
  102. --argstr keystore-file $(STORE_FILE) \
  103. --option extra-sandbox-paths $(STORE_FILE)
  104. release-ios: export TARGET_OS ?= ios
  105. release-ios: export BUILD_ENV ?= prod
  106. release-ios: watchman-clean ##@build build release for iOS release
  107. # Open XCode inside the Nix context
  108. @git clean -dxf -f target/ios && \
  109. $(MAKE) jsbundle-ios && \
  110. echo "Build in XCode, see https://status.im/build_status/ for instructions" && \
  111. scripts/copy-translations.sh && \
  112. open ios/StatusIm.xcworkspace
  113. release-desktop: export TARGET_OS ?= $(HOST_OS)
  114. release-desktop: ##@build build release for desktop release based on TARGET_OS
  115. @$(MAKE) jsbundle-desktop && \
  116. scripts/copy-translations.sh && \
  117. scripts/build-desktop.sh; \
  118. $(MAKE) watchman-clean
  119. release-windows-desktop: export TARGET_OS ?= windows
  120. release-windows-desktop: ##@build build release for windows desktop release
  121. @$(MAKE) jsbundle-desktop && \
  122. scripts/copy-translations.sh && \
  123. scripts/build-desktop.sh; \
  124. $(MAKE) watchman-clean
  125. prod-build-android: jsbundle-android ##@legacy temporary legacy alias for jsbundle-android
  126. @echo "${YELLOW}This a deprecated target name, use jsbundle-android.$(RESET)"
  127. jsbundle-android: SHELL := /bin/sh
  128. jsbundle-android: export TARGET_OS ?= android
  129. jsbundle-android: export BUILD_ENV ?= prod
  130. jsbundle-android: ##@jsbundle Compile JavaScript and Clojure into index.android.js
  131. # Call nix-build to build the 'targets.mobile.jsbundle' attribute and copy the index.android.js file to the project root
  132. @git clean -dxf ./index.$(TARGET_OS).js
  133. nix/build.sh targets.mobile.jsbundle && \
  134. mv result/index.$(TARGET_OS).js ./
  135. prod-build-ios: jsbundle-ios ##@legacy temporary legacy alias for jsbundle-ios
  136. @echo "${YELLOW}This a deprecated target name, use jsbundle-ios.$(RESET)"
  137. jsbundle-ios: export TARGET_OS ?= ios
  138. jsbundle-ios: export BUILD_ENV ?= prod
  139. jsbundle-ios: ##@jsbundle Compile JavaScript and Clojure into index.ios.js
  140. @git clean -dxf -f ./index.$(TARGET_OS).js && \
  141. lein jsbundle-ios && \
  142. node prepare-modules.js
  143. prod-build-desktop: jsbundle-desktop ##@legacy temporary legacy alias for jsbundle-desktop
  144. @echo "${YELLOW}This a deprecated target name, use jsbundle-desktop.$(RESET)"
  145. jsbundle-desktop: export TARGET_OS ?= $(HOST_OS)
  146. jsbundle-desktop: export BUILD_ENV ?= prod
  147. jsbundle-desktop: ##@jsbundle Compile JavaScript and Clojure into index.desktop.js
  148. git clean -qdxf -f ./index.desktop.js desktop/ && \
  149. lein jsbundle-desktop && \
  150. node prepare-modules.js
  151. #--------------
  152. # REPL
  153. # -------------
  154. _watch-%: ##@watch Start development for device
  155. $(eval SYSTEM := $(word 2, $(subst -, , $@)))
  156. $(eval DEVICE := $(word 3, $(subst -, , $@)))
  157. clj -R:dev build.clj watch --platform $(SYSTEM) --$(SYSTEM)-device $(DEVICE)
  158. watch-ios-real: export TARGET_OS ?= ios
  159. watch-ios-real: _watch-ios-real ##@watch Start development for iOS real device
  160. watch-ios-simulator: export TARGET_OS ?= ios
  161. watch-ios-simulator: _watch-ios-simulator ##@watch Start development for iOS simulator
  162. watch-android-real: export TARGET_OS ?= android
  163. watch-android-real: _watch-android-real ##@watch Start development for Android real device
  164. watch-android-avd: export TARGET_OS ?= android
  165. watch-android-avd: _watch-android-avd ##@watch Start development for Android AVD
  166. watch-android-genymotion: export TARGET_OS ?= android
  167. watch-android-genymotion: _watch-android-genymotion ##@watch Start development for Android Genymotion
  168. watch-desktop: export TARGET_OS ?= $(HOST_OS)
  169. watch-desktop: ##@watch Start development for Desktop
  170. clj -R:dev build.clj watch --platform desktop
  171. desktop-server: export TARGET_OS ?= $(HOST_OS)
  172. desktop-server:
  173. node ubuntu-server.js
  174. #--------------
  175. # Run
  176. # -------------
  177. _run-%:
  178. $(eval SYSTEM := $(word 2, $(subst -, , $@)))
  179. npx react-native run-$(SYSTEM)
  180. # TODO: Migrate this to a Nix recipe, much the same way as nix/mobile/android/targets/release-android.nix
  181. run-android: export TARGET_OS ?= android
  182. run-android: ##@run Run Android build
  183. npx react-native run-android --appIdSuffix debug
  184. run-desktop: export TARGET_OS ?= $(HOST_OS)
  185. run-desktop: _run-desktop ##@run Run Desktop build
  186. SIMULATOR=
  187. run-ios: export TARGET_OS ?= ios
  188. run-ios: ##@run Run iOS build
  189. ifneq ("$(SIMULATOR)", "")
  190. npx react-native run-ios --simulator="$(SIMULATOR)"
  191. else
  192. npx react-native run-ios
  193. endif
  194. #--------------
  195. # Tests
  196. #--------------
  197. test: export _NIX_ATTR := targets.leiningen.shell
  198. test: ##@test Run tests once in NodeJS
  199. lein with-profile test doo node test once
  200. test-auto: export _NIX_ATTR := targets.leiningen.shell
  201. test-auto: ##@test Run tests in interactive (auto) mode in NodeJS
  202. lein with-profile test doo node test
  203. coverage: ##@test Run tests once in NodeJS generating coverage
  204. @scripts/run-coverage.sh
  205. #--------------
  206. # Other
  207. #--------------
  208. react-native-desktop: export TARGET_OS ?= $(HOST_OS)
  209. react-native-desktop: export _NIX_PURE ?= true
  210. react-native-desktop: ##@other Start react native packager
  211. @scripts/start-react-native.sh
  212. react-native-android: export TARGET_OS ?= android
  213. react-native-android: export _NIX_PURE ?= true
  214. react-native-android: ##@other Start react native packager for Android client
  215. @scripts/start-react-native.sh
  216. react-native-ios: export TARGET_OS ?= ios
  217. react-native-ios: export _NIX_PURE ?= true
  218. react-native-ios: ##@other Start react native packager for Android client
  219. @scripts/start-react-native.sh
  220. geth-connect: export _NIX_ATTR := targets.mobile.android.adb.shell
  221. geth-connect: export TARGET_OS ?= android
  222. geth-connect: ##@other Connect to Geth on the device
  223. adb forward tcp:8545 tcp:8545 && \
  224. build/bin/geth attach http://localhost:8545
  225. android-ports: export _NIX_ATTR := targets.mobile.android.adb.shell
  226. android-ports: export TARGET_OS ?= android
  227. android-ports: ##@other Add proxies to Android Device/Simulator
  228. adb reverse tcp:8081 tcp:8081 && \
  229. adb reverse tcp:3449 tcp:3449 && \
  230. adb reverse tcp:4567 tcp:4567 && \
  231. adb forward tcp:5561 tcp:5561
  232. android-logcat: export _NIX_ATTR := targets.mobile.android.adb.shell
  233. android-logcat: export TARGET_OS ?= android
  234. android-logcat: ##@other Read status-react logs from Android phone using adb
  235. adb logcat | grep -e StatusModule -e ReactNativeJS -e StatusNativeLogs
  236. android-install: export _NIX_ATTR := targets.mobile.android.adb.shell
  237. android-install: export TARGET_OS ?= android
  238. android-install: export BUILD_TYPE ?= release
  239. android-install:
  240. adb install result/app.apk
  241. _list: SHELL := /bin/sh
  242. _list:
  243. @$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$'
  244. _unknown-startdev-target-%: SHELL := /bin/sh
  245. _unknown-startdev-target-%:
  246. @ echo "Unknown target device '$*'. Supported targets:"; \
  247. ${MAKE} _list | grep "watch-" | sed s/watch-/startdev-/; \
  248. exit 1
  249. _startdev-%:
  250. $(eval SYSTEM := $(word 2, $(subst -, , $@)))
  251. $(eval DEVICE := $(word 3, $(subst -, , $@)))
  252. @ if [ -z "$(DEVICE)" ]; then \
  253. $(MAKE) watch-$(SYSTEM) || $(MAKE) _unknown-startdev-target-$@; \
  254. else \
  255. $(MAKE) watch-$(SYSTEM)-$(DEVICE) || $(MAKE) _unknown-startdev-target-$@; \
  256. fi
  257. startdev-android-avd: export TARGET_OS = android
  258. startdev-android-avd: _startdev-android-avd
  259. startdev-android-genymotion: export TARGET_OS = android
  260. startdev-android-genymotion: _startdev-android-genymotion
  261. startdev-android-real: export TARGET_OS = android
  262. startdev-android-real: _startdev-android-real
  263. startdev-desktop: export TARGET_OS ?= $(HOST_OS)
  264. startdev-desktop: _startdev-desktop
  265. startdev-ios-real: export TARGET_OS = ios
  266. startdev-ios-real: _startdev-ios-real
  267. startdev-ios-simulator: export TARGET_OS = ios
  268. startdev-ios-simulator: _startdev-ios-simulator