/Makefile

https://github.com/tchon/popcorn-js · Makefile · 269 lines · 174 code · 68 blank · 27 comment · 9 complexity · fd0f91be8f5b48f4d2849215c5d2a8a9 MD5 · raw file

  1. PREFIX = .
  2. BUILD_DIR = ${PREFIX}/build
  3. DIST_DIR = ${PREFIX}/dist
  4. PLUGINS_DIR = ${PREFIX}/plugins
  5. PARSERS_DIR = ${PREFIX}/parsers
  6. PLAYERS_DIR = ${PREFIX}/players
  7. EFFECTS_DIR = $(PREFIX)/effects
  8. MODULES_DIR = $(PREFIX)/modules
  9. # Version number used in naming release files. Defaults to git commit sha.
  10. VERSION ?= $(shell git show -s --pretty=format:%h)
  11. RHINO ?= java -jar ${BUILD_DIR}/js.jar
  12. CLOSURE_COMPILER = ${BUILD_DIR}/google-compiler-20100917.jar
  13. compile = @@${MINJAR} $(1) \
  14. --compilation_level SIMPLE_OPTIMIZATIONS \
  15. --js_output_file $(2)
  16. # minify
  17. MINJAR ?= java -jar ${CLOSURE_COMPILER}
  18. # source
  19. POPCORN_SRC = ${PREFIX}/popcorn.js
  20. # distribution files
  21. POPCORN_DIST = ${DIST_DIR}/popcorn.js
  22. POPCORN_MIN = ${DIST_DIR}/popcorn.min.js
  23. # modules
  24. MODULES_DIST = ${DIST_DIR}/popcorn.modules.js
  25. MODULES_MIN = ${DIST_DIR}/popcorn.modules.min.js
  26. # plugins
  27. PLUGINS_DIST = ${DIST_DIR}/popcorn.plugins.js
  28. PLUGINS_MIN = ${DIST_DIR}/popcorn.plugins.min.js
  29. # plugins
  30. PARSERS_DIST = ${DIST_DIR}/popcorn.parsers.js
  31. PARSERS_MIN = ${DIST_DIR}/popcorn.parsers.min.js
  32. # players
  33. PLAYERS_DIST = ${DIST_DIR}/popcorn.players.js
  34. PLAYERS_MIN = ${DIST_DIR}/popcorn.players.min.js
  35. # effects
  36. EFFECTS_DIST = $(DIST_DIR)/popcorn.effects.js
  37. EFFECTS_MIN = $(DIST_DIR)/popcorn.effects.min.js
  38. # Grab all popcorn.<plugin-name>.js files from plugins dir
  39. PLUGINS_SRC := $(filter-out %unit.js, $(shell find ${PLUGINS_DIR} -name 'popcorn.*.js' -print))
  40. # Grab all popcorn.<plugin-name>.js files from parsers dir
  41. PARSERS_SRC := $(filter-out %unit.js, $(shell find ${PARSERS_DIR} -name 'popcorn.*.js' -print))
  42. # Grab all popcorn.<player-name>.js files from players dir
  43. PLAYERS_SRC := $(filter-out %unit.js, $(shell find ${PLAYERS_DIR} -name 'popcorn.*.js' -print))
  44. # Grab all popcorn.<effect-name>.js files from effects dir
  45. EFFECTS_SRC := $(filter-out %unit.js, $(shell find $(EFFECTS_DIR) -name 'popcorn.*.js' -print))
  46. # Grab all popcorn.<Module-name>.js files from modules dir
  47. MODULES_SRC := $(filter-out %unit.js, $(shell find $(MODULES_DIR) -name 'popcorn.*.js' -print))
  48. # Grab all popcorn.<plugin-name>.unit.js files from plugins dir
  49. PLUGINS_UNIT := $(shell find ${PLUGINS_DIR} -name 'popcorn.*.unit.js' -print)
  50. # Grab all popcorn.<parser-name>.unit.js files from parsers dir
  51. PARSERS_UNIT := $(shell find ${PARSERS_DIR} -name 'popcorn.*.unit.js' -print)
  52. # Grab all popcorn.<player-name>.unit.js files from players dir
  53. PLAYERS_UNIT := $(shell find ${PLAYERS_DIR} -name 'popcorn.*.unit.js' -print)
  54. # Grab all popcorn.<effects>.unit.js files from effects dir
  55. EFFECTS_UNIT := $(shell find $(EFFECTS_DIR) -name 'popcorn.*.unit.js' -print)
  56. # Grab all popcorn.<module-name>.unit.js files from modules dir
  57. MODULES_UNIT := $(shell find $(MODULES_DIR) -name 'popcorn.*.unit.js' -print)
  58. # popcorn + plugins
  59. POPCORN_COMPLETE_LIST := --js ${POPCORN_SRC} \
  60. $(shell for js in ${MODULES_SRC} ; do echo --js $$js ; done) \
  61. $(shell for js in ${PLUGINS_SRC} ; do echo --js $$js ; done) \
  62. $(shell for js in ${PARSERS_SRC} ; do echo --js $$js ; done) \
  63. $(shell for js in ${PLAYERS_SRC} ; do echo --js $$js ; done)
  64. POPCORN_COMPLETE_DIST = ${DIST_DIR}/popcorn-complete.js
  65. POPCORN_COMPLETE_MIN = ${DIST_DIR}/popcorn-complete.min.js
  66. # Create a versioned license header for js files we ship
  67. add_license = cat $(PREFIX)/LICENSE_HEADER | sed -e 's/@VERSION/${VERSION}/' > $(1).__hdr__ ; \
  68. cat $(1).__hdr__ $(1) >> $(1).__tmp__ ; rm -f $(1).__hdr__ ; \
  69. mv $(1).__tmp__ $(1)
  70. # Create a version parameter for Popcorn
  71. add_version = cat $(1) | sed -e 's/@VERSION/${VERSION}/' > $(1).__tmp__ ; \
  72. mv $(1).__tmp__ $(1)
  73. # Run the file through jslint
  74. run_lint = @@$(RHINO) build/jslint-check.js $(1)
  75. all: setup popcorn plugins parsers players effects complete min
  76. @@echo "Popcorn build complete. To create a testing mirror, run: make testing."
  77. check: lint lint-plugins lint-parsers lint-players lint-effects
  78. ${DIST_DIR}:
  79. @@mkdir -p ${DIST_DIR}
  80. popcorn: ${POPCORN_DIST}
  81. ${POPCORN_DIST}: $(POPCORN_SRC) | $(DIST_DIR)
  82. @@echo "Building" $(POPCORN_DIST)
  83. @@cp $(POPCORN_SRC) $(POPCORN_DIST)
  84. @@$(call add_license, $(POPCORN_DIST))
  85. @@$(call add_version, $(POPCORN_DIST))
  86. min: setup ${POPCORN_MIN} ${MODULES_MIN} ${PLUGINS_MIN} ${PARSERS_MIN} ${PLAYERS_MIN} $(EFFECTS_MIN) ${POPCORN_COMPLETE_MIN}
  87. ${POPCORN_MIN}: ${POPCORN_DIST}
  88. @@echo "Building" ${POPCORN_MIN}
  89. @@$(call compile, --js $(POPCORN_DIST), $(POPCORN_MIN))
  90. @@$(call add_license, $(POPCORN_MIN))
  91. @@$(call add_version, $(POPCORN_MIN))
  92. ${POPCORN_COMPLETE_MIN}: ${POPCORN_SRC} ${MODULES_SRC} ${PLUGINS_SRC} ${PARSERS_SRC} $(EFFECTS_SRC) ${DIST_DIR}
  93. @@echo "Building" ${POPCORN_COMPLETE_MIN}
  94. @@$(call compile, $(POPCORN_COMPLETE_LIST), $(POPCORN_COMPLETE_MIN))
  95. @@$(call add_license, $(POPCORN_COMPLETE_MIN))
  96. @@$(call add_version, $(POPCORN_COMPLETE_MIN))
  97. modules: setup ${MODULES_DIST}
  98. ${MODULES_MIN}: ${MODULES_DIST}
  99. @@echo "Building" ${MODULES_MIN}
  100. @@$(call compile, $(shell for js in ${MODULES_SRC} ; do echo --js $$js ; done), ${MODULES_MIN})
  101. ${MODULES_DIST}: ${MODULES_SRC} ${DIST_DIR}
  102. @@echo "Building ${MODULES_DIST}"
  103. @@cat ${MODULES_SRC} > ${MODULES_DIST}
  104. plugins: ${PLUGINS_DIST}
  105. ${PLUGINS_MIN}: ${PLUGINS_DIST}
  106. @@echo "Building" ${PLUGINS_MIN}
  107. @@$(call compile, $(shell for js in ${PLUGINS_SRC} ; do echo --js $$js ; done), ${PLUGINS_MIN})
  108. ${PLUGINS_DIST}: ${PLUGINS_SRC} ${DIST_DIR}
  109. @@echo "Building ${PLUGINS_DIST}"
  110. @@cat ${PLUGINS_SRC} > ${PLUGINS_DIST}
  111. parsers: ${PARSERS_DIST}
  112. ${PARSERS_MIN}: ${PARSERS_DIST}
  113. @@echo "Building" ${PARSERS_MIN}
  114. @@$(call compile, $(shell for js in ${PARSERS_SRC} ; do echo --js $$js ; done), ${PARSERS_MIN})
  115. ${PARSERS_DIST}: ${PARSERS_SRC} ${DIST_DIR}
  116. @@echo "Building ${PARSERS_DIST}"
  117. @@cat ${PARSERS_SRC} > ${PARSERS_DIST}
  118. players: ${PLAYERS_DIST}
  119. ${PLAYERS_MIN}: ${PLAYERS_DIST}
  120. @@echo "Building" ${PLAYERS_MIN}
  121. @@$(call compile, $(shell for js in ${PLAYERS_SRC} ; do echo --js $$js ; done), ${PLAYERS_MIN})
  122. ${PLAYERS_DIST}: ${PLAYERS_SRC} ${DIST_DIR}
  123. @@echo "Building ${PLAYERS_DIST}"
  124. @@cat ${PLAYERS_SRC} > ${PLAYERS_DIST}
  125. effects: $(EFFECTS_DIST)
  126. $(EFFECTS_MIN): $(EFFECTS_DIST)
  127. @@echo "Building" $(EFFECTS_MIN)
  128. @@$(call compile, $(shell for js in $(EFFECTS_SRC) ; do echo --js $$js ; done), $(EFFECTS_MIN))
  129. $(EFFECTS_DIST): $(EFFECTS_SRC) $(DIST_DIR)
  130. @@echo "Building $(EFFECTS_DIST)"
  131. @@cat $(EFFECTS_SRC) > $(EFFECTS_DIST)
  132. complete: setup ${POPCORN_SRC} ${MODULES_SRC} ${PARSERS_SRC} ${PLUGINS_SRC} ${PLAYERS_SRC} $(EFFECTS_SRC) ${DIST_DIR}
  133. @@echo "Building popcorn + modules + plugins + parsers + players + effects..."
  134. @@cat ${POPCORN_SRC} ${MODULES_SRC} ${PLUGINS_SRC} ${PARSERS_SRC} ${PLAYERS_SRC} $(EFFECTS_SRC) > $(POPCORN_COMPLETE_DIST)
  135. @@$(call add_license, $(POPCORN_COMPLETE_DIST))
  136. @@$(call add_version, $(POPCORN_COMPLETE_DIST))
  137. lint:
  138. @@echo "Checking Popcorn against JSLint..."
  139. @@$(call run_lint,popcorn.js)
  140. lint-core-tests:
  141. @@echo "Checking core unit tests against JSLint..."
  142. @@$(call run_lint,test/popcorn.unit.js)
  143. lint-modules:
  144. @@echo "Checking all modules against JSLint..."
  145. @@$(call run_lint,$(MODULES_SRC))
  146. lint-plugins:
  147. @@echo "Checking all plugins against JSLint..."
  148. @@$(call run_lint,$(PLUGINS_SRC))
  149. lint-parsers:
  150. @@echo "Checking all parsers against JSLint..."
  151. @@$(call run_lint,$(PARSERS_SRC))
  152. lint-players:
  153. @@echo "Checking all players against JSLint..."
  154. @@$(call run_lint,$(PLAYERS_SRC))
  155. lint-effects:
  156. @@echo "Checking all effects against JSLint..."
  157. @@$(call run_lint,$(EFFECTS_SRC))
  158. lint-modules-tests:
  159. @@echo "Checking modules unit tests against JSLint..."
  160. @@$(call run_lint,$(MODULES_UNIT))
  161. lint-plugin-tests:
  162. @@echo "Checking plugin unit tests against JSLint..."
  163. @@$(call run_lint,$(PLUGINS_UNIT))
  164. lint-parser-tests:
  165. @@echo "Checking parser unit tests against JSLint..."
  166. @@$(call run_lint,$(PARSERS_UNIT))
  167. lint-effects-tests:
  168. @@echo "Checking effectsr unit tests against JSLint..."
  169. @@$(call run_lint,$(EFFECTS_UNIT))
  170. lint-player-tests:
  171. @@echo "Checking player unit tests against JSLint..."
  172. @@$(call run_lint,$(PLAYERS_UNIT))
  173. lint-unit-tests: lint-modules-tests lint-plugin-tests lint-parser-tests lint-player-tests lint-effects-tests
  174. @@echo "completed"
  175. # Create a mirror copy of the tree in dist/ using popcorn-complete.js
  176. # in place of popcorn.js.
  177. TESTING_MIRROR := ${DIST_DIR}/testing-mirror
  178. # Prefer plugin code in popcorn-complete.js but don't overrwrite *unit.js files
  179. overwrite_js = @@for js in $$(find ${1} \( -name "*.js" -a \! -name "*.unit.js" \)) ; \
  180. do echo '/* Stub, see popcorn.js instead */' > $$js ; \
  181. done
  182. testing: complete
  183. @@echo "Building testing-mirror in ${TESTING_MIRROR}"
  184. @@mkdir -p ${TESTING_MIRROR}
  185. @@find ${PREFIX} \( -name '.git' -o -name 'dist' \) -prune -o -print | cpio -pd --quiet ${TESTING_MIRROR}
  186. # Remove unneeded files for testing, so it's clear this isn't the tree
  187. @@rm -fr ${TESTING_MIRROR}/AUTHORS ${TESTING_MIRROR}/LICENSE ${TESTING_MIRROR}/LICENSE_HEADER \
  188. ${TESTING_MIRROR}/Makefile ${TESTING_MIRROR}/readme.md
  189. @@touch "${TESTING_MIRROR}/THIS IS A TESTING MIRROR -- READ-ONLY"
  190. $(call overwrite_js, ${TESTING_MIRROR}/modules)
  191. $(call overwrite_js, ${TESTING_MIRROR}/plugins)
  192. $(call overwrite_js, ${TESTING_MIRROR}/players)
  193. $(call overwrite_js, ${TESTING_MIRROR}/parsers)
  194. $(call overwrite_js, ${TESTING_MIRROR}/effects)
  195. @@cp ${POPCORN_COMPLETE_DIST} ${TESTING_MIRROR}/popcorn.js
  196. clean:
  197. @@echo "Removing Distribution directory:" ${DIST_DIR}
  198. @@rm -rf ${DIST_DIR}
  199. setup:
  200. @@echo "Updating submodules..."
  201. @@git submodule update --init