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 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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 _tmpdir-mk _tmpdir-rm
  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. # This can come from Jenkins
  28. ifndef BUILD_TAG
  29. export BUILD_TAG := $(shell git rev-parse --short HEAD)
  30. endif
  31. # We don't want to use /run/user/$UID because it runs out of space too easilly
  32. export TMPDIR = /tmp/tmp-status-react-$(BUILD_TAG)
  33. # this has to be specified for both the Node.JS server process and the Qt process
  34. export REACT_SERVER_PORT ?= 5001
  35. # Our custom config is located in nix/nix.conf
  36. export NIX_CONF_DIR = $(PWD)/nix
  37. # Defines which variables will be kept for Nix pure shell, use semicolon as divider
  38. export _NIX_KEEP ?= TMPDIR,BUILD_ENV,STATUS_GO_SRC_OVERRIDE
  39. export _NIX_ROOT = /nix
  40. # legacy TARGET_OS variable support
  41. ifdef TARGET_OS
  42. export TARGET ?= $(TARGET_OS)
  43. endif
  44. # MacOS root is read-only, read nix/README.md for details
  45. UNAME_S := $(shell uname -s)
  46. ifeq ($(UNAME_S),Darwin)
  47. export NIX_IGNORE_SYMLINK_STORE=1
  48. export _NIX_ROOT = /opt/nix
  49. endif
  50. #----------------
  51. # Nix targets
  52. #----------------
  53. # WARNING: This has to be located right before the targets
  54. ifdef IN_NIX_SHELL
  55. SHELL := env bash
  56. else
  57. SHELL := ./nix/scripts/shell.sh
  58. endif
  59. shell: ##@prepare Enter into a pre-configured shell
  60. ifndef IN_NIX_SHELL
  61. @ENTER_NIX_SHELL
  62. else
  63. @echo "${YELLOW}Nix shell is already active$(RESET)"
  64. endif
  65. nix-gc: ##@nix Garbage collect all packages older than 20 days from /nix/store
  66. nix-collect-garbage --delete-old --delete-older-than 20d
  67. nix-clean: ##@nix Remove all status-react build artifacts from /nix/store
  68. nix/scripts/clean.sh
  69. nix-purge: SHELL := /bin/sh
  70. nix-purge: ##@nix Completely remove the complete Nix setup
  71. sudo rm -rf $(_NIX_ROOT)/* ~/.nix-profile ~/.nix-defexpr ~/.nix-channels ~/.cache/nix ~/.status .nix-gcroots
  72. nix-add-gcroots: export TARGET := default
  73. nix-add-gcroots: ##@nix Add Nix GC roots to avoid status-react expressions being garbage collected
  74. scripts/add-nix-gcroots.sh
  75. nix-update-gradle: ##@nix Update maven nix expressions based on current gradle setup
  76. nix/mobile/android/maven-and-npm-deps/maven/generate-nix.sh
  77. nix-update-lein: export TARGET := lein
  78. nix-update-lein: ##@nix Update maven nix expressions based on current lein setup
  79. nix/tools/lein/generate-nix.sh nix/lein
  80. nix-update-gems: export TARGET := lein
  81. nix-update-gems: ##@nix Update Ruby gems in fastlane/Gemfile.lock and fastlane/gemset.nix
  82. fastlane/update.sh
  83. nix-update-pods: export TARGET := ios
  84. nix-update-pods: ##@nix Update CocoaPods in ios/Podfile.lock
  85. cd ios && pod update
  86. #----------------
  87. # General targets
  88. #----------------
  89. _fix-node-perms: SHELL := /bin/sh
  90. _fix-node-perms: ##@prepare Fix permissions so that directory can be cleaned
  91. $(shell test -d node_modules && chmod -R 744 node_modules)
  92. $(shell test -d node_modules.tmp && chmod -R 744 node_modules.tmp)
  93. _tmpdir-mk: SHELL := /bin/sh
  94. _tmpdir-mk: ##@prepare Create a TMPDIR for temporary files
  95. @mkdir -p "$(TMPDIR)"
  96. # Make sure TMPDIR exists every time make is called
  97. -include _tmpdir-mk
  98. _tmpdir-rm: SHELL := /bin/sh
  99. _tmpdir-rm: ##@prepare Remove TMPDIR
  100. rm -fr "$(TMPDIR)"
  101. clean: SHELL := /bin/sh
  102. clean: _fix-node-perms _tmpdir-rm ##@prepare Remove all output folders
  103. git clean -dxf
  104. watchman-clean: export TARGET := watchman
  105. watchman-clean: ##@prepare Delete repo directory from watchman
  106. watchman watch-del $${STATUS_REACT_HOME}
  107. disable-githooks: SHELL := /bin/sh
  108. disable-githooks: ##@prepare Disables lein githooks
  109. @rm -f ${env.WORKSPACE}/.git/hooks/pre-commit && \
  110. sed -i'~' -e 's|\[rasom/lein-githooks|;; [rasom/lein-githooks|' \
  111. -e 's|:githooks|;; :githooks|' \
  112. -e 's|:pre-commit|;; :pre-commit|' project.clj; \
  113. rm project.clj~
  114. pod-install: export TARGET := ios
  115. pod-install: ##@prepare Run 'pod install' to install podfiles and update Podfile.lock
  116. cd ios && pod install; cd --
  117. #----------------
  118. # Release builds
  119. #----------------
  120. release: release-android release-ios ##@build build release for Android and iOS
  121. release-android: export TARGET ?= android
  122. release-android: export BUILD_ENV ?= prod
  123. release-android: export BUILD_TYPE ?= nightly
  124. release-android: export BUILD_NUMBER ?= 9999
  125. release-android: export STORE_FILE ?= $(HOME)/.gradle/status-im.keystore
  126. release-android: export ANDROID_ABI_SPLIT ?= false
  127. release-android: export ANDROID_ABI_INCLUDE ?= armeabi-v7a;arm64-v8a;x86
  128. release-android: ##@build build release for Android
  129. scripts/release-android.sh
  130. release-ios: export TARGET ?= ios
  131. release-ios: export BUILD_ENV ?= prod
  132. release-ios: watchman-clean ##@build build release for iOS release
  133. @git clean -dxf -f target/ios && \
  134. $(MAKE) jsbundle-ios && \
  135. scripts/copy-translations.sh && \
  136. xcodebuild -workspace ios/StatusIm.xcworkspace -scheme StatusIm -configuration Release -destination 'generic/platform=iOS' -UseModernBuildSystem=N clean archive
  137. release-desktop: export TARGET ?= $(HOST_OS)
  138. release-desktop: ##@build build release for desktop release based on TARGET
  139. @$(MAKE) jsbundle-desktop && \
  140. scripts/copy-translations.sh && \
  141. scripts/build-desktop.sh; \
  142. $(MAKE) watchman-clean
  143. release-windows-desktop: export TARGET ?= windows
  144. release-windows-desktop: ##@build build release for windows desktop release
  145. @$(MAKE) jsbundle-desktop && \
  146. scripts/copy-translations.sh && \
  147. scripts/build-desktop.sh; \
  148. $(MAKE) watchman-clean
  149. prod-build-android: jsbundle-android ##@legacy temporary legacy alias for jsbundle-android
  150. @echo "${YELLOW}This a deprecated target name, use jsbundle-android.$(RESET)"
  151. jsbundle-android: SHELL := /bin/sh
  152. jsbundle-android: export TARGET ?= android
  153. jsbundle-android: export BUILD_ENV ?= prod
  154. jsbundle-android: ##@jsbundle Compile JavaScript and Clojure into index.android.js
  155. # Call nix-build to build the 'targets.mobile.android.jsbundle' attribute and copy the index.android.js file to the project root
  156. @git clean -dxf ./index.$(TARGET).js
  157. nix/scripts/build.sh targets.mobile.android.jsbundle && \
  158. mv result/index.$(TARGET).js ./
  159. prod-build-ios: jsbundle-ios ##@legacy temporary legacy alias for jsbundle-ios
  160. @echo "${YELLOW}This a deprecated target name, use jsbundle-ios.$(RESET)"
  161. jsbundle-ios: export TARGET ?= ios
  162. jsbundle-ios: export BUILD_ENV ?= prod
  163. jsbundle-ios: ##@jsbundle Compile JavaScript and Clojure into index.ios.js
  164. @git clean -dxf -f ./index.$(TARGET).js && \
  165. lein jsbundle-ios && \
  166. node prepare-modules.js
  167. prod-build-desktop: jsbundle-desktop ##@legacy temporary legacy alias for jsbundle-desktop
  168. @echo "${YELLOW}This a deprecated target name, use jsbundle-desktop.$(RESET)"
  169. jsbundle-desktop: export TARGET ?= $(HOST_OS)
  170. jsbundle-desktop: export BUILD_ENV ?= prod
  171. jsbundle-desktop: ##@jsbundle Compile JavaScript and Clojure into index.desktop.js
  172. git clean -qdxf -f ./index.desktop.js desktop/ && \
  173. lein jsbundle-desktop && \
  174. node prepare-modules.js
  175. #--------------
  176. # REPL
  177. # -------------
  178. _watch-%: ##@watch Start development for device
  179. $(eval SYSTEM := $(word 2, $(subst -, , $@)))
  180. $(eval DEVICE := $(word 3, $(subst -, , $@)))
  181. clj -R:dev build.clj watch --platform $(SYSTEM) --$(SYSTEM)-device $(DEVICE)
  182. watch-ios-real: export TARGET := ios
  183. watch-ios-real: _watch-ios-real ##@watch Start development for iOS real device
  184. watch-ios-simulator: export TARGET := ios
  185. watch-ios-simulator: _watch-ios-simulator ##@watch Start development for iOS simulator
  186. watch-android-real: export TARGET := android
  187. watch-android-real: _watch-android-real ##@watch Start development for Android real device
  188. watch-android-avd: export TARGET := android
  189. watch-android-avd: _watch-android-avd ##@watch Start development for Android AVD
  190. watch-android-genymotion: export TARGET ?= android
  191. watch-android-genymotion: _watch-android-genymotion ##@watch Start development for Android Genymotion
  192. watch-desktop: export TARGET ?= $(HOST_OS)
  193. watch-desktop: ##@watch Start development for Desktop
  194. clj -R:dev build.clj watch --platform desktop
  195. desktop-server: export TARGET ?= $(HOST_OS)
  196. desktop-server:
  197. node ubuntu-server.js
  198. #--------------
  199. # Run
  200. # -------------
  201. _run-%:
  202. $(eval SYSTEM := $(word 2, $(subst -, , $@)))
  203. npx react-native run-$(SYSTEM)
  204. # TODO: Migrate this to a Nix recipe, much the same way as nix/mobile/android/targets/release-android.nix
  205. run-android: export TARGET := android
  206. run-android: ##@run Run Android build
  207. npx react-native run-android --appIdSuffix debug
  208. run-desktop: export TARGET ?= $(HOST_OS)
  209. run-desktop: _run-desktop ##@run Run Desktop build
  210. SIMULATOR=
  211. run-ios: export TARGET := ios
  212. run-ios: ##@run Run iOS build
  213. ifneq ("$(SIMULATOR)", "")
  214. npx react-native run-ios --simulator="$(SIMULATOR)"
  215. else
  216. npx react-native run-ios
  217. endif
  218. #--------------
  219. # Tests
  220. #--------------
  221. lint: export TARGET := lein
  222. lint: ##@test Run code style checks
  223. lein cljfmt check
  224. test: export TARGET := lein
  225. test: ##@test Run tests once in NodeJS
  226. lein with-profile test doo node test once
  227. test-auto: export TARGET := lein
  228. test-auto: ##@test Run tests in interactive (auto) mode in NodeJS
  229. lein with-profile test doo node test
  230. coverage: ##@test Run tests once in NodeJS generating coverage
  231. @scripts/run-coverage.sh
  232. #--------------
  233. # Other
  234. #--------------
  235. react-native-desktop: export TARGET ?= $(HOST_OS)
  236. react-native-desktop: export _NIX_PURE ?= true
  237. react-native-desktop: ##@other Start react native packager
  238. @scripts/start-react-native.sh
  239. react-native-android: export TARGET := android
  240. react-native-android: export _NIX_PURE ?= true
  241. react-native-android: ##@other Start react native packager for Android client
  242. @scripts/start-react-native.sh
  243. react-native-ios: export TARGET := ios
  244. react-native-ios: export _NIX_PURE ?= true
  245. react-native-ios: ##@other Start react native packager for Android client
  246. @scripts/start-react-native.sh
  247. geth-connect: export TARGET := adb
  248. geth-connect: ##@other Connect to Geth on the device
  249. adb forward tcp:8545 tcp:8545 && \
  250. build/bin/geth attach http://localhost:8545
  251. android-clean: ##@prepare Clean Gradle state
  252. git clean -dxf -f ./android/app/build
  253. [ -d android/.gradle ] && cd android && ./gradlew clean
  254. android-ports: export TARGET := adb
  255. android-ports: ##@other Add proxies to Android Device/Simulator
  256. adb reverse tcp:8081 tcp:8081 && \
  257. adb reverse tcp:3449 tcp:3449 && \
  258. adb reverse tcp:4567 tcp:4567 && \
  259. adb forward tcp:5561 tcp:5561
  260. android-devices: export TARGET := adb
  261. android-devices: ##@other Invoke adb devices
  262. adb devices
  263. android-logcat: export TARGET := adb
  264. android-logcat: ##@other Read status-react logs from Android phone using adb
  265. adb logcat | grep -e RNBootstrap -e ReactNativeJS -e ReactNative -e StatusModule -e StatusNativeLogs -e 'F DEBUG :' -e 'Go :' -e 'GoLog :' -e 'libc :'
  266. android-install: export TARGET := adb
  267. android-install: export BUILD_TYPE ?= release
  268. android-install:
  269. adb install result/app-$(BUILD_TYPE).apk
  270. _list: SHELL := /bin/sh
  271. _list:
  272. @$(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 '^$@$$'
  273. _unknown-startdev-target-%: SHELL := /bin/sh
  274. _unknown-startdev-target-%:
  275. @ echo "Unknown target device '$*'. Supported targets:"; \
  276. ${MAKE} _list | grep "watch-" | sed s/watch-/startdev-/; \
  277. exit 1
  278. _startdev-%: SHELL := /bin/sh
  279. _startdev-%:
  280. $(eval SYSTEM := $(word 2, $(subst -, , $@)))
  281. $(eval DEVICE := $(word 3, $(subst -, , $@)))
  282. @ if [ -z "$(DEVICE)" ]; then \
  283. $(MAKE) watch-$(SYSTEM) || $(MAKE) _unknown-startdev-target-$@; \
  284. else \
  285. $(MAKE) watch-$(SYSTEM)-$(DEVICE) || $(MAKE) _unknown-startdev-target-$@; \
  286. fi
  287. startdev-android-avd: export TARGET = android
  288. startdev-android-avd: _startdev-android-avd
  289. startdev-android-genymotion: export TARGET = android
  290. startdev-android-genymotion: _startdev-android-genymotion
  291. startdev-android-real: export TARGET = android
  292. startdev-android-real: _startdev-android-real
  293. startdev-desktop: export TARGET ?= $(HOST_OS)
  294. startdev-desktop: _startdev-desktop
  295. startdev-ios-real: export TARGET = ios
  296. startdev-ios-real: _startdev-ios-real
  297. startdev-ios-simulator: export TARGET = ios
  298. startdev-ios-simulator: _startdev-ios-simulator