Makefile.sdk 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. #
  2. # Licensed to Cloudera, Inc. under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. Cloudera, Inc. licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. #
  18. #
  19. # A Makefile to be (optionally) included by any SDK applications.
  20. #
  21. # This Makefile assumes the following environment variables:
  22. # ROOT
  23. # Points to the root of the Hue installation. From here, we
  24. # can include $(ROOT)/Makefile.vars to access various variables.
  25. #
  26. # This Makefile (or any custom application Makefile) MUST provide the following
  27. # targets:
  28. # egg-info
  29. # Responsible for creating the egg-info directory for the application.
  30. #
  31. # ext-eggs
  32. # Responsible for creating a Python egg for each external Python
  33. # dependency. These eggs should be placed in the
  34. # $(APP_ROOT)/ext-py/<package>/dist directory.
  35. #
  36. # clean
  37. # Remove build products.
  38. #
  39. # sdist
  40. # Responsible for making a source distribution directory at
  41. # $(APP_ROOT)/build/sdist/$(APP_NAME).
  42. #
  43. # install-bdist
  44. # Responsible for installing a built distribution to a target directory,
  45. # as specified by $(INSTALL_DIR) and $(INSTALL_CONF_DIR).
  46. #
  47. include $(ROOT)/Makefile.vars
  48. APP_ROOT := $(realpath .)
  49. APP_NAME ?= $(notdir $(APP_ROOT))
  50. APP_VERSION ?= $(shell python setup.py --version)
  51. APP_FULL_NAME ?= $(APP_NAME)-$(APP_VERSION)
  52. BUILD_DIR := $(APP_ROOT)/build
  53. .PHONY: default
  54. default::
  55. @echo 'The build targets for $(APP_NAME) are: (*) is required'
  56. @echo ' compile : Compile $(APP_NAME)'
  57. @echo ' egg-info * : Create a python egg for $(APP_NAME)'
  58. @echo ' ext-eggs * : Create python eggs for external dependencies'
  59. @echo ' sdist * : Create a source distribution tree and tarball'
  60. @echo ' bdist : Create a built distribution tree'
  61. @echo ' install-bdist *: Install a built distribution to a target location'
  62. @echo ' env-install : Install into virtual-env'
  63. @echo ' ext-env-install: Install external dependencies into virtual-env'
  64. @echo ' ext-clean : Clean external dependencies'
  65. @echo ' clean * : Clean $(APP_NAME). Requires ext-clean'
  66. @echo ' distclean : Dist clean $(APP_NAME). Requires clean'
  67. .PHONY: egg
  68. egg-info: compile
  69. @echo '--- Making egg-info for $(APP_NAME)'
  70. @$(ENV_PYTHON) setup.py -q egg_info
  71. #
  72. # env-install
  73. # Install app into the virtual environment. Used by desktop core.
  74. #
  75. .PHONY: env-install
  76. env-install: compile ext-env-install
  77. @echo '--- Installing $(APP_NAME) into virtual-env'
  78. @$(ENV_PYTHON) setup.py develop -N -q
  79. # Hook to allow extra build steps (eg java builds)
  80. .PHONY: compile
  81. compile:
  82. ##############################
  83. # The following installs the external Python dependencies under the ext-py/
  84. # directory.
  85. EXT_PY_DIRS := $(wildcard ext-py/*)
  86. EXT_PYS := $(notdir $(EXT_PY_DIRS))
  87. ext_py_stamp = $(BUILD_DIR)/$(1)/$(2).stamp
  88. ##############################
  89. # Macros
  90. ##############################
  91. EXT_PY_EGG_TARGETS := $(EXT_PYS:%=$(call ext_py_stamp,%,egg))
  92. EXT_PY_CLEAN_TARGETS := $(EXT_PYS:%=$(call ext_py_stamp,%,clean))
  93. EXT_PY_ENV_INSTALL_TARGETS := $(EXT_PYS:%=$(call ext_py_stamp,%,env-install))
  94. $(EXT_PY_EGG_TARGETS): CUR_EXT_PY=$(notdir $(@D))
  95. $(EXT_PY_CLEAN_TARGETS): CUR_EXT_PY=$(notdir $(@D))
  96. $(EXT_PY_ENV_INSTALL_TARGETS): CUR_EXT_PY=$(notdir $(@D))
  97. #
  98. # ext-eggs
  99. # Builds a binary egg for any 3rd party package that are based on the
  100. # earlier distutils (rather than setuptools).
  101. #
  102. .PHONY: ext-eggs
  103. ext-eggs: $(EXT_PY_EGG_TARGETS)
  104. $(EXT_PY_EGG_TARGETS):
  105. @echo '--- Building egg for $(CUR_EXT_PY)'
  106. @cd ext-py/$(CUR_EXT_PY) && $(ENV_PYTHON) \
  107. -c '__import__("setuptools.sandbox").sandbox.run_setup("setup.py", __import__("sys").argv[1:])' \
  108. bdist_egg
  109. @mkdir -p $(BUILD_DIR)/$(CUR_EXT_PY) && touch $@
  110. #
  111. # ext-clean
  112. # Clean the 3rd party package. This will NOT uninstall it from Desktop.
  113. #
  114. .PHONY: ext-clean
  115. ext-clean: $(EXT_PY_CLEAN_TARGETS)
  116. $(EXT_PY_CLEAN_TARGETS):
  117. @echo '--- Cleaning $(CUR_EXT_PY)'
  118. @rm -Rf $(BUILD_DIR)/$(CUR_EXT_PY)
  119. @cd ext-py/$(CUR_EXT_PY) && rm -Rf dist build temp *.egg-info
  120. @find ext-py/$(CUR_EXT_PY) -name \*.egg-info -o -name \*.py[co] -prune -exec rm -Rf {} \;
  121. #
  122. # ext-env-install
  123. # Install all 3rd party packages into the Desktop environment. Used by
  124. # desktop core. We look for egg files in two locations:
  125. # (1) ext-py/<pkg>/dist/*.egg
  126. # (2) ext-eggs/*.egg
  127. #
  128. .PHONY: ext-env-install
  129. ext-env-install: ext-eggs $(EXT_PY_ENV_INSTALL_TARGETS)
  130. @for i in $(wildcard ext-eggs/*.egg) ; do \
  131. echo "--- Installing $$i into virtual environment" ; \
  132. $(ENV_EASY_INSTALL) -N $$i 2> /dev/null ; \
  133. done
  134. $(EXT_PY_ENV_INSTALL_TARGETS):
  135. @echo '--- Installing $(CUR_EXT_PY) into virtual environment'
  136. @# If there are no binary eggs, maybe this package decided
  137. @# it wasn't necessary. If the build had failed, the command that produced
  138. @# the egg should have thrown an error.
  139. @cd ext-py/$(CUR_EXT_PY) && [ ! -e dist ] || $(ENV_EASY_INSTALL) -N dist/*egg 2>/dev/null
  140. .PHONY: clean
  141. clean:: ext-clean
  142. @echo --- Cleaning $(APP_NAME)
  143. @# Use SYS_PYTHON because ENV_PYTHON may not be available.
  144. @$(SYS_PYTHON) setup.py clean || :
  145. @rm -Rf $(BUILD_DIR) dist
  146. @find . -name \*.egg-info -prune -exec rm -Rf {} \;
  147. @find . -name \*.py[co] -exec rm -f {} \;
  148. .PHONY: distclean
  149. distclean:: clean
  150. #####################################
  151. # Distribution builds
  152. #####################################
  153. # Items that should not be included in the source/built distribution.
  154. # Apps can list this in their own Makefile before including this file
  155. # in order to exclude their own sources, non-distributables, etc.
  156. # This list is rsync friendly.
  157. COMMON_EXCLUDES := \
  158. --exclude=build \
  159. --exclude=\*.py[co] \
  160. --exclude=.\*.sw[op] \
  161. --exclude=~\* \
  162. --exclude=.gitignore \
  163. --exclude=tag
  164. SDIST_EXCLUDES += $(COMMON_EXCLUDES)
  165. BDIST_EXCLUDES += $(COMMON_EXCLUDES) --exclude=ext-py
  166. SDIST_DIR := $(BUILD_DIR)/sdist/$(APP_FULL_NAME)
  167. BDIST_DIR := $(BUILD_DIR)/bdist/$(APP_FULL_NAME)
  168. SDIST_TGZ := $(BUILD_DIR)/sdist/$(APP_FULL_NAME).tgz
  169. #
  170. # sdist
  171. # Simply copy the essential sources to the target directory.
  172. #
  173. .PHONY: sdist
  174. sdist:
  175. @echo '--- Making source distribution at $(SDIST_DIR)'
  176. @rm -rf $(SDIST_DIR)
  177. @mkdir -p $(SDIST_DIR)
  178. @# Copy sources of our app
  179. @rsync -a ./ $(SDIST_DIR)/ $(SDIST_EXCLUDES)
  180. @$(MAKE) -C $(SDIST_DIR) clean
  181. @# Also make a tarball
  182. @tar -C $(SDIST_DIR)/.. -czf $(SDIST_TGZ) $(APP_FULL_NAME)
  183. @echo "--- Created $(SDIST_TGZ)"
  184. #
  185. # bdist
  186. # Like sdist. For ext-py, we copy the eggs only (into a separate ext-eggs
  187. # directory). Apps with non-python source (e.g. Java, C) should also
  188. # exclude the source files.
  189. #
  190. .PHONY: bdist
  191. bdist: ext-eggs compile
  192. @echo '--- Making built distribution at $(BDIST_DIR)'
  193. @rm -rf $(BDIST_DIR)
  194. @mkdir -p $(BDIST_DIR)
  195. @# Copy built sources of our app
  196. @rsync -a ./ $(BDIST_DIR)/ $(BDIST_EXCLUDES)
  197. @# Copy thirdparty eggs into the ext-eggs dir
  198. @mkdir -p $(BDIST_DIR)/ext-eggs
  199. @if test -n '$(wildcard ext-py/*/dist)' ; then \
  200. find ext-py/*/dist -type f -name '*.egg' -exec cp {} $(BDIST_DIR)/ext-eggs \; ; \
  201. fi
  202. #
  203. # install-bdist
  204. # Install the built distribution in $(INSTALL_DIR), and any conf file in
  205. # $(INSTALL_CONF_DIR). NOTE that this does NOT install the app into the
  206. # virtual environment.
  207. #
  208. .PHONY: install-bdist
  209. install-bdist: bdist
  210. @echo "--- Install built distribution for $(APP_NAME) at $(INSTALL_DIR)"
  211. @mkdir -p $(INSTALL_DIR)
  212. @rsync -a $(BDIST_DIR)/ $(INSTALL_DIR)
  213. ifneq ($(wildcard conf),) # if there are conf files
  214. @echo "--- Installing $(APP_NAME) configuration into $(INSTALL_CONF_DIR)"
  215. @mkdir -p $(INSTALL_CONF_DIR)
  216. for conffile in $(INSTALL_DIR)/conf/* ; do \
  217. filename=$$(basename $$conffile) ; \
  218. if [ -f $(INSTALL_CONF_DIR)/$$filename ]; then \
  219. echo "Moving aside old config $(INSTALL_CONF_DIR)/$$filename" ; \
  220. mv $(INSTALL_CONF_DIR)/$$filename{,.save.$(shell date +"%Y%m%d.%H%M%S")} ; \
  221. fi ; \
  222. mv $$conffile $(INSTALL_CONF_DIR)/$$filename ; \
  223. done
  224. @# Remove the conf dir from the install location since we've placed the confs in the
  225. @# right spot
  226. @rmdir $(INSTALL_DIR)/conf
  227. endif