mk-cabal-executable-file 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 [library 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 [ "${CATEGORY}x" = "x" ]; then
  20. CAT_LINE="-- category:"
  21. else
  22. CAT_LINE="category: ${CATEGORY}"
  23. fi
  24. function cabal_file {
  25. cat <<EOF
  26. name: ${EXENAME}
  27. version: 0.1.0.0
  28. -- synopsis:
  29. -- description:
  30. license: BSD3
  31. license-file: LICENSE
  32. author: ${USER}
  33. maintainer: ${USER}
  34. copyright: ©${YEAR} ${NAME}
  35. ${CAT_LINE}
  36. build-type: Simple
  37. cabal-version: >= 1.12
  38. executable ${EXENAME}
  39. hs-source-dirs: src
  40. main-is: Main.hs
  41. default-extensions: OverloadedStrings,
  42. ScopedTypeVariables
  43. ghc-options: -Wall
  44. build-depends: base >=4.7 && <4.9
  45. default-language: Haskell2010
  46. EOF
  47. }
  48. if [ "x${TGT}" = "x-" ]; then
  49. cabal_file
  50. else
  51. cabal_file >${TGT}
  52. fi