build-woff2.sh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #!/bin/sh
  2. # ///////////////////////////////////////////////////////////////////
  3. #
  4. # build-woff2.sh
  5. # A shell script that builds the Hack woff2 web fonts from ttf files
  6. # Copyright 2018 Christopher Simpkins
  7. # MIT License
  8. #
  9. # Usage: ./build-woff2.sh (--install-dependencies)
  10. # Arguments:
  11. # --install-dependencies (optional) - installs all
  12. # build dependencies prior to the build script execution
  13. #
  14. # NOTE: If you change the source, you must build new ttf files
  15. # with build.sh PRIOR to execution of this script.
  16. # This script builds directly from previous ttf builds,
  17. # not source files.
  18. #
  19. # ///////////////////////////////////////////////////////////////////
  20. # The woff2 git clone directory.
  21. BUILD="$HOME"
  22. INST="$HOME/woff2"
  23. # woff2 executable path
  24. WOFF2_BIN="$BUILD/woff2/woff2_compress"
  25. # The font build directory paths and file paths for the woff builds
  26. TTF_BUILD="build/ttf"
  27. WOFF_BUILD="build/web/fonts"
  28. REGULAR_TTF="Hack-Regular.ttf"
  29. REGULAR_PRE="Hack-Regular.woff2"
  30. REGULAR_WOFF="hack-regular.woff2"
  31. BOLD_TTF="Hack-Bold.ttf"
  32. BOLD_PRE="Hack-Bold.woff2"
  33. BOLD_WOFF="hack-bold.woff2"
  34. ITALIC_TTF="Hack-Italic.ttf"
  35. ITALIC_PRE="Hack-Italic.woff2"
  36. ITALIC_WOFF="hack-italic.woff2"
  37. BOLDITALIC_TTF="Hack-BoldItalic.ttf"
  38. BOLDITALIC_PRE="Hack-BoldItalic.woff2"
  39. BOLDITALIC_WOFF="hack-bolditalic.woff2"
  40. # test for number of arguments
  41. if [ $# -gt 1 ]
  42. then
  43. echo "Inappropriate arguments included in your command." 1>&2
  44. echo "Usage: ./build-woff2.sh (--install-dependencies)" 1>&2
  45. exit 1
  46. fi
  47. # Optional build dependency install request with syntax `./build-web.sh --install-dependencies`
  48. if [ "$1" = "--install-dependencies" ]
  49. then
  50. # define the current directory (Hack repository)
  51. CUR_DIR=$(pwd)
  52. if test -d "$INST" -o -f "$INST"; then
  53. echo "Build directory \`$INST' must not exist."
  54. exit 1
  55. fi
  56. cd "$BUILD" || exit 1
  57. echo "#####"
  58. echo "git clone woff2 project"
  59. echo "#####"
  60. # clone the Source Foundry fork of the woff2 repo
  61. # contains fix for OS X build bug - https://github.com/google/woff2/issues/73
  62. # recursive flag to clone the brotli submodule within the woff2 repo
  63. git clone --recursive https://github.com/source-foundry/woff2.git
  64. cd "$INST" || exit 1
  65. echo "#####"
  66. echo "Build woff2"
  67. echo "#####"
  68. make clean all
  69. # make Hack repository the current directory again following the build
  70. cd "$CUR_DIR" || exit 1
  71. fi
  72. if [ -f "$WOFF2_BIN" ]; then
  73. echo "Beginning web font build with $WOFF2_BIN"
  74. else
  75. echo "Unable to locate woff2_compress on path $WOFF2_BIN. Please attempt a manual install of this build dependency and then repeat your build attempt." 1>&2
  76. exit 1
  77. fi
  78. # Build woff2 files from ttf files
  79. # regular set
  80. if ! "$WOFF2_BIN" "$TTF_BUILD/$REGULAR_TTF"; then
  81. echo "Failed to build woff2 from $REGULAR_TTF." 1>&2
  82. exit 1
  83. else
  84. echo "Regular woff2 font set successfully built from $REGULAR_TTF"
  85. fi
  86. # bold set
  87. if ! "$WOFF2_BIN" "$TTF_BUILD/$BOLD_TTF"; then
  88. echo "Failed to build woff2 from $BOLD_TTF" 1>&2
  89. exit 1
  90. else
  91. echo "Bold woff2 set successfully built from $BOLD_TTF"
  92. fi
  93. # italic set
  94. if ! "$WOFF2_BIN" "$TTF_BUILD/$ITALIC_TTF"; then
  95. echo "Failed to build woff2 from $ITALIC_TTF" 1>&2
  96. exit 1
  97. else
  98. echo "Italic woff2 set successfully built from $ITALIC_TTF"
  99. fi
  100. # bold italic set
  101. if ! "$WOFF2_BIN" "$TTF_BUILD/$BOLDITALIC_TTF"; then
  102. echo "Failed to build woff2 from $BOLDITALIC_TTF" 1>&2
  103. exit 1
  104. else
  105. echo "Bold Italic woff2 set successfully built from $BOLDITALIC_TTF"
  106. fi
  107. echo "Moving woff2 files to build directory..."
  108. # create directory if it does not exist
  109. # (occurs with git + empty directories)
  110. if ! [ -d "$WOFF_BUILD" ]; then
  111. mkdir $WOFF_BUILD
  112. fi
  113. # move woff2 files to appropriate build directory
  114. mv "$TTF_BUILD/$REGULAR_PRE" "$WOFF_BUILD/$REGULAR_WOFF"
  115. mv "$TTF_BUILD/$BOLD_PRE" "$WOFF_BUILD/$BOLD_WOFF"
  116. mv "$TTF_BUILD/$ITALIC_PRE" "$WOFF_BUILD/$ITALIC_WOFF"
  117. mv "$TTF_BUILD/$BOLDITALIC_PRE" "$WOFF_BUILD/$BOLDITALIC_WOFF"
  118. echo " "
  119. if [ -f "$WOFF_BUILD/$REGULAR_WOFF" ]; then
  120. echo "Regular woff2 build path: $WOFF_BUILD/$REGULAR_WOFF"
  121. fi
  122. if [ -f "$WOFF_BUILD/$BOLD_WOFF" ]; then
  123. echo "Bold woff2 build path: $WOFF_BUILD/$BOLD_WOFF"
  124. fi
  125. if [ -f "$WOFF_BUILD/$ITALIC_WOFF" ]; then
  126. echo "Italic woff2 build path: $WOFF_BUILD/$ITALIC_WOFF"
  127. fi
  128. if [ -f "$WOFF_BUILD/$BOLDITALIC_WOFF" ]; then
  129. echo "Bold Italic woff2 build path: $WOFF_BUILD/$BOLDITALIC_WOFF"
  130. fi