Makefile 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. # The idea here is to be able to re-generate the exact Javascript
  2. # files as they exist in git. This means munging whitespace in weird
  3. # ways, using specific versions of various JS minimizers...
  4. # Dependencies:
  5. # - bsdtar
  6. # - coreutils
  7. # - gitget <https://git.parabola.nu/packages/libretools.git/tree/src/gitget/gitget>
  8. # - java (for closure-compiler)
  9. # - node (for UglifyJS 1)
  10. # - npm (for UglifyJS 2)
  11. # - patch
  12. # - perl
  13. # - pngcrush
  14. # - sed
  15. # - wget
  16. # Where are we?
  17. dl-cache = ../download-cache
  18. www = $(dl-cache)/www
  19. bin = $(dl-cache)/bin
  20. # What versions of 3rd party libraries are we using?
  21. jquery-ver=1.8.3
  22. bootstrap-ver=2.1.1
  23. tablesorter-ver=2.7
  24. d3-ver=3.0.6
  25. konami-ver=c0f686e647765860ff4d2fcb7b48122785432b75
  26. # What files do we make?
  27. branding-images = \
  28. sitestatic/favicon.ico sitestatic/silhouette.png \
  29. sitestatic/archnavbar/archlogo.png \
  30. sitestatic/archnavbar/archlogo.svg \
  31. sitestatic/logos/apple-touch-icon-114x114.png \
  32. sitestatic/logos/apple-touch-icon-144x144.png \
  33. sitestatic/logos/apple-touch-icon-57x57.png \
  34. sitestatic/logos/apple-touch-icon-72x72.png \
  35. sitestatic/logos/icon-transparent-64x64.png
  36. targets = \
  37. $(branding-images) \
  38. sitestatic/rss.png \
  39. sitestatic/rss@2x.png \
  40. sitestatic/bootstrap-typeahead.js \
  41. sitestatic/homepage.js \
  42. sitestatic/jquery-$(jquery-ver).min.js \
  43. sitestatic/jquery.tablesorter-$(tablesorter-ver).js \
  44. sitestatic/jquery.tablesorter-$(tablesorter-ver).min.js \
  45. sitestatic/konami.min.js \
  46. visualize/static/d3-$(d3-ver).js \
  47. visualize/static/d3-$(d3-ver).min.js \
  48. retro/static/2013/bootstrap-typeahead.min.1aacd3d7f4db.js \
  49. retro/static/2013/konami.min.e165c814457d.js
  50. # The base rules
  51. all: $(targets)
  52. .PHONY: all
  53. js-basenames = $(sort $(patsubst %.min,%,$(patsubst %.js,%,$(filter %.js,$(targets)))))
  54. generated = $(sort $(targets) $(foreach f,$(js-basenames),$f.js $f.min.js))
  55. clean:
  56. rm -f -- $(generated)
  57. .PHONY: clean
  58. # Make directories
  59. $(dl-cache) $(dl-cache)/unzip $(bin):
  60. mkdir -p '$@'
  61. # Don't clean up the pre-minified files
  62. .SECONDARY:
  63. # Turn on sane error handling
  64. .DELETE_ON_ERROR:
  65. .PHONY: FORCE
  66. # How to download files
  67. mangle = $(subst %,^25,$(subst :,^3A,$(subst =,^3D,$(subst ^,^5E,$1))))
  68. unmangle = $(subst ^5E,^,$(subst ^3D,=,$(subst ^3A,:,$(subst ^25,%,$1))))
  69. $(www)/http/%:
  70. mkdir -p '$(@D)'
  71. wget 'http://$(call unmangle,$*)' -O '$@'
  72. test -f '$@' && touch '$@'
  73. $(www)/https/%:
  74. mkdir -p '$(@D)'
  75. wget 'https://$(call unmangle,$*)' -O '$@'
  76. test -f '$@' && touch '$@'
  77. $(www)/git/%: FORCE
  78. mkdir -p '$(@D)'
  79. gitget checkout 'git://$(call unmangle,$*)' '$@' || { rm -rf -- '$@'; false; }
  80. test -d '$@' || { rm -rf -- '$@'; false; }
  81. # The meat of the Makefile
  82. # Downloaded images
  83. $(dl-cache)/unzip/Feedicons_v.2/%: $(www)/https/web.archive.org/web/20120514074507/http^3A//www.zeusboxstudio.com/file_download/1/Feedicons_v.2.zip
  84. mkdir -p '$(@D)'
  85. bsdtar xfO $< 'Feedicons v.2/$*' > '$@'
  86. sitestatic/rss.png: $(dl-cache)/unzip/Feedicons_v.2/RSS_16.png
  87. cp $< $@
  88. sitestatic/rss@2x.png: $(dl-cache)/unzip/Feedicons_v.2/RSS_32.png
  89. pngcrush $< $@
  90. $(dl-cache)/unzip/parabola-artwork: $(www)/git/projects.parabola.nu/artwork.git\#branch=official/2013 | $(dl-cache)/unzip
  91. cp -rT '$<' '$@'
  92. make -C '$@'
  93. $(dl-cache)/unzip/parabola-artwork/%: $(dl-cache)/unzip/parabola-artwork
  94. test -e $@ && touch $@
  95. $(foreach i,$(branding-images),$(eval $i: $$(dl-cache)/unzip/parabola-artwork/$(notdir $i); install -Dm644 $$< $$@))
  96. # Non-minified JavaScript
  97. sitestatic/bootstrap-typeahead.js: sitestatic/%: $(www)/https/raw.github.com/twitter/bootstrap/v$(bootstrap-ver)/js/% Makefile.d/%.patch
  98. cp $< $@
  99. patch -i Makefile.d/$*.patch $@
  100. sitestatic/jquery-$(jquery-ver).js: sitestatic/%: $(www)/http/code.jquery.com/%
  101. cp $< $@
  102. sitestatic/jquery.tablesorter-$(tablesorter-ver).js: $(www)/https/raw.github.com/Mottie/tablesorter/v$(tablesorter-ver)/js/jquery.tablesorter.js
  103. cp $< $@
  104. sitestatic/konami.js: sitestatic/%: $(www)/https/raw.github.com/snaptortoise/konami-js/$(konami-ver)/% Makefile.d/%.patch
  105. cp $< $@
  106. patch -i Makefile.d/$*.patch $@
  107. visualize/static/d3-$(d3-ver).js: %: $(www)/https/raw.github.com/mbostock/d3/v$(d3-ver)/d3.js
  108. cp $< $@
  109. # JavaScript minification
  110. JSMIN = { sed -n '1,/\*\//p' $1; uglifyjs --mangle --compress < $1; } > $2
  111. %.min.js: %.js
  112. $(call JSMIN,$<,$@)
  113. # Files that make use of that minified JavaScript
  114. retro/static/2013/konami.min.e165c814457d.js: sitestatic/konami.min.js
  115. cp $< $@
  116. retro/static/2013/bootstrap-typeahead.min.1aacd3d7f4db.js: sitestatic/bootstrap-typeahead.min.js
  117. @# Trim trailing semicolon and newline
  118. < $< sed 's/;$$//' | perl -pe 'chomp if eof' > $@
  119. sitestatic/homepage.js: sitestatic/bootstrap-typeahead.min.js sitestatic/konami.min.js Makefile.d/homepage.js.in
  120. { \
  121. echo '/* bootstrap-typeahead.min.js: */' && \
  122. cat sitestatic/bootstrap-typeahead.min.js && \
  123. echo && \
  124. echo '/* konami.min.js: */' && \
  125. sed -e 's,^\s*,,' -e 's,^return.*,&;,' sitestatic/konami.min.js && \
  126. echo && \
  127. echo '/* Main homepage.js content: */' && \
  128. cat Makefile.d/homepage.js.in ; \
  129. } > $@