mk-cabal-executable-file 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/bin/bash -e
  2. if [ $# -eq 0 ]; then
  3. EXENAME="$(basename $(pwd))"
  4. TGT="-"
  5. elif [ $# -eq 1 ]; then
  6. EXENAME="$1"
  7. TGT='-'
  8. elif [ $# -eq 2 ]; then
  9. EXENAME="$1"
  10. TGT="$2"
  11. else
  12. echo "USAGE: $0 [executable name]" >&2
  13. exit 99
  14. fi
  15. NAME=$(git config user.name)
  16. EMAIL=$(git config user.email)
  17. USER="${NAME} <${EMAIL}>"
  18. YEAR=$(date '+%Y')
  19. if [ -z "${CATEGORY}" ]; then
  20. CAT_FIELD="-- category:"
  21. else
  22. CAT_FIELD="category: ${CATEGORY}"
  23. fi
  24. if [ -z "${SYNOPSIS}" ]; then
  25. SYN_FIELD="-- synopsis:"
  26. else
  27. SYN_FIELD="synopsis: ${SYNOPSIS}"
  28. fi
  29. if [ -z "${DESCRIPTION}" ]; then
  30. DESCR_FIELD="-- description:"
  31. else
  32. DESCR_FIELD="description: ${DESCRIPTION}"
  33. fi
  34. function cabal_file {
  35. cat <<EOF
  36. name: ${EXENAME}
  37. version: 0.1.0.0
  38. ${SYN_FIELD}
  39. ${DESCR_FIELD}
  40. license: BSD3
  41. license-file: LICENSE
  42. author: ${USER}
  43. maintainer: ${USER}
  44. copyright: ©${YEAR} ${NAME}
  45. ${CAT_FIELD}
  46. build-type: Simple
  47. cabal-version: >= 1.14
  48. executable ${EXENAME}
  49. hs-source-dirs: src
  50. main-is: Main.hs
  51. default-extensions: OverloadedStrings,
  52. ScopedTypeVariables
  53. ghc-options: -Wall
  54. build-depends: base >=4.7 && <4.10
  55. default-language: Haskell2010
  56. EOF
  57. }
  58. if [ "x${TGT}" = "x-" ]; then
  59. cabal_file
  60. else
  61. cabal_file >${TGT}
  62. fi