Makefile.sdk 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. EGG_INFO_DIR := $(APP_ROOT)/src/$(APP_NAME).egg-info
  54. .PHONY: default
  55. default::
  56. @echo 'The build targets for $(APP_NAME) are: (*) is required'
  57. @echo ' compile : Compile $(APP_NAME)'
  58. @echo ' egg-info * : Create a python egg for $(APP_NAME)'
  59. @echo ' ext-eggs * : Create python eggs for external dependencies'
  60. @echo ' sdist * : Create a source distribution tree and tarball'
  61. @echo ' bdist : Create a built distribution tree'
  62. @echo ' install-bdist *: Install a built distribution to a target location'
  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 $(EGG_INFO_DIR)
  69. $(EGG_INFO_DIR): $(APP_ROOT)/setup.py
  70. @echo '--- Making egg-info for $(APP_NAME)'
  71. @$(ENV_PYTHON) setup.py -q egg_info
  72. # Hook to allow extra build steps (eg java builds)
  73. .PHONY: compile
  74. compile:
  75. ##############################
  76. # The following installs the external Python dependencies under the ext-py/
  77. # directory.
  78. EXT_PY_DIRS := $(wildcard ext-py/*)
  79. EXT_PYS := $(notdir $(EXT_PY_DIRS))
  80. ext_py_stamp = $(BUILD_DIR)/$(1)/$(2).stamp
  81. ##############################
  82. # Macros
  83. ##############################
  84. EXT_PY_EGG_TARGETS := $(EXT_PYS:%=$(call ext_py_stamp,%,egg))
  85. EXT_PY_CLEAN_TARGETS := $(EXT_PYS:%=$(call ext_py_stamp,%,clean))
  86. EXT_PY_ENV_INSTALL_TARGETS := $(EXT_PYS:%=$(call ext_py_stamp,%,env-install))
  87. $(EXT_PY_EGG_TARGETS): CUR_EXT_PY=$(notdir $(@D))
  88. $(EXT_PY_CLEAN_TARGETS): CUR_EXT_PY=$(notdir $(@D))
  89. $(EXT_PY_ENV_INSTALL_TARGETS): CUR_EXT_PY=$(notdir $(@D))
  90. #
  91. # ext-eggs
  92. # Builds a binary egg for any 3rd party package that are based on the
  93. # earlier distutils (rather than setuptools).
  94. #
  95. .PHONY: ext-eggs
  96. ext-eggs: $(EXT_PY_EGG_TARGETS)
  97. $(EXT_PY_EGG_TARGETS):
  98. @echo '--- Building egg for $(CUR_EXT_PY)'
  99. @cd ext-py/$(CUR_EXT_PY) && $(ENV_PYTHON) \
  100. -c '__import__("setuptools.sandbox").sandbox.run_setup("setup.py", __import__("sys").argv[1:])' \
  101. bdist_egg
  102. @mkdir -p $(@D) && touch $@
  103. #
  104. # ext-clean
  105. # Clean the 3rd party package. This will NOT uninstall it from Desktop.
  106. #
  107. .PHONY: ext-clean
  108. ext-clean: $(EXT_PY_CLEAN_TARGETS)
  109. $(EXT_PY_CLEAN_TARGETS):
  110. @echo '--- Cleaning $(CUR_EXT_PY)'
  111. @rm -Rf $(BUILD_DIR)/$(CUR_EXT_PY)
  112. @cd ext-py/$(CUR_EXT_PY) && rm -Rf dist build temp *.egg-info
  113. @find ext-py/$(CUR_EXT_PY) -name \*.egg-info -o -name \*.py[co] -prune -exec rm -Rf {} \;
  114. #
  115. # ext-env-install
  116. # Install all 3rd party packages into the Desktop environment. Used by
  117. # desktop core. We look for egg files in two locations:
  118. # (1) ext-py/<pkg>/dist/*.egg
  119. # (2) ext-eggs/*.egg
  120. #
  121. .PHONY: ext-env-install
  122. ext-env-install: ext-eggs $(EXT_PY_ENV_INSTALL_TARGETS)
  123. @for i in $(wildcard ext-eggs/*.egg) ; do \
  124. echo "--- Installing $$i into virtual environment" ; \
  125. $(ENV_EASY_INSTALL) -N $$i 2> /dev/null ; \
  126. done
  127. $(EXT_PY_ENV_INSTALL_TARGETS):
  128. @echo '--- Installing $(CUR_EXT_PY) into virtual environment'
  129. @# If there are no binary eggs, maybe this package decided
  130. @# it wasn't necessary. If the build had failed, the command that produced
  131. @# the egg should have thrown an error.
  132. @cd ext-py/$(CUR_EXT_PY) && [ ! -e dist ] || $(ENV_EASY_INSTALL) -N dist/*egg 2>/dev/null
  133. @mkdir -p $(@D) && touch $@
  134. .PHONY: clean
  135. clean:: ext-clean
  136. @echo --- Cleaning $(APP_NAME)
  137. @# Use SYS_PYTHON because ENV_PYTHON may not be available.
  138. @$(SYS_PYTHON) setup.py clean || :
  139. @rm -Rf $(BUILD_DIR) dist
  140. @find . -name \*.egg-info -prune -exec rm -Rf {} \;
  141. @find . -name \*.py[co] -exec rm -f {} \;
  142. .PHONY: distclean
  143. distclean:: clean
  144. #####################################
  145. # Distribution builds
  146. #####################################
  147. # Items that should not be included in the source/built distribution.
  148. # Apps can list this in their own Makefile before including this file
  149. # in order to exclude their own sources, non-distributables, etc.
  150. # This list is rsync friendly.
  151. COMMON_EXCLUDES := \
  152. --exclude=build \
  153. --exclude=\*.py[co] \
  154. --exclude=.\*.sw[op] \
  155. --exclude=~\* \
  156. --exclude=.gitignore \
  157. --exclude=tag
  158. SDIST_EXCLUDES += $(COMMON_EXCLUDES)
  159. BDIST_EXCLUDES += $(COMMON_EXCLUDES) --exclude=ext-py
  160. SDIST_DIR := $(BUILD_DIR)/sdist/$(APP_FULL_NAME)
  161. BDIST_DIR := $(BUILD_DIR)/bdist/$(APP_FULL_NAME)
  162. SDIST_TGZ := $(BUILD_DIR)/sdist/$(APP_FULL_NAME).tgz
  163. #
  164. # sdist
  165. # Simply copy the essential sources to the target directory.
  166. #
  167. .PHONY: sdist
  168. sdist:
  169. @echo '--- Making source distribution at $(SDIST_DIR)'
  170. @rm -rf $(SDIST_DIR)
  171. @mkdir -p $(SDIST_DIR)
  172. @# Copy sources of our app
  173. @rsync -a ./ $(SDIST_DIR)/ $(SDIST_EXCLUDES)
  174. @$(MAKE) -C $(SDIST_DIR) clean
  175. @# Also make a tarball
  176. @tar -C $(SDIST_DIR)/.. -czf $(SDIST_TGZ) $(APP_FULL_NAME)
  177. @echo "--- Created $(SDIST_TGZ)"
  178. #
  179. # bdist
  180. # Like sdist. For ext-py, we copy the eggs only (into a separate ext-eggs
  181. # directory). Apps with non-python source (e.g. Java, C) should also
  182. # exclude the source files.
  183. #
  184. .PHONY: bdist
  185. bdist: ext-eggs compile
  186. @echo '--- Making built distribution at $(BDIST_DIR)'
  187. @rm -rf $(BDIST_DIR)
  188. @mkdir -p $(BDIST_DIR)
  189. @# Copy built sources of our app
  190. @rsync -a ./ $(BDIST_DIR)/ $(BDIST_EXCLUDES)
  191. @# Copy thirdparty eggs into the ext-eggs dir
  192. @mkdir -p $(BDIST_DIR)/ext-eggs
  193. @if test -n '$(wildcard ext-py/*/dist)' ; then \
  194. find ext-py/*/dist -type f -name '*.egg' -exec cp {} $(BDIST_DIR)/ext-eggs \; ; \
  195. fi
  196. #
  197. # install-bdist
  198. # Install the built distribution in $(INSTALL_DIR), and any conf file in
  199. # $(INSTALL_CONF_DIR). NOTE that this does NOT install the app into the
  200. # virtual environment.
  201. #
  202. .PHONY: install-bdist
  203. install-bdist: bdist
  204. @echo "--- Install built distribution for $(APP_NAME) at $(INSTALL_DIR)"
  205. @mkdir -p $(INSTALL_DIR)
  206. @rsync -a $(BDIST_DIR)/ $(INSTALL_DIR)
  207. ifneq ($(wildcard conf),) # if there are conf files
  208. @echo "--- Installing $(APP_NAME) configuration into $(INSTALL_CONF_DIR)"
  209. @mkdir -p $(INSTALL_CONF_DIR)
  210. for conffile in $(INSTALL_DIR)/conf/* ; do \
  211. filename=$$(basename $$conffile) ; \
  212. if [ -f $(INSTALL_CONF_DIR)/$$filename ]; then \
  213. echo "Moving aside old config $(INSTALL_CONF_DIR)/$$filename" ; \
  214. mv $(INSTALL_CONF_DIR)/$$filename{,.save.$(shell date +"%Y%m%d.%H%M%S")} ; \
  215. fi ; \
  216. mv $$conffile $(INSTALL_CONF_DIR)/$$filename ; \
  217. done
  218. @# Remove the conf dir from the install location since we've placed the confs in the
  219. @# right spot
  220. @rmdir $(INSTALL_DIR)/conf
  221. endif