mk-cabal-file 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/bin/bash -e
  2. if [ $# -eq 0 ]; then
  3. LIBNAME="$(basename $(pwd))"
  4. TGT="-"
  5. elif [ $# -eq 1 ]; then
  6. LIBNAME="$1"
  7. TGT='-'
  8. elif [ $# -eq 2 ]; then
  9. LIBNAME="$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 [ -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: ${LIBNAME}
  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. library
  49. -- exposed-modules:
  50. ghc-options: -Wall
  51. build-depends: base >=4.7 && <4.10
  52. default-language: Haskell2010
  53. default-extensions: OverloadedStrings,
  54. ScopedTypeVariables
  55. EOF
  56. }
  57. if [ "x${TGT}" = "x-" ]; then
  58. cabal_file
  59. else
  60. cabal_file >${TGT}
  61. fi