mk.sh 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #!/bin/bash
  2. # eecc - Eclectic Engineer's Control Center
  3. # See LICENSE file for copyright and license details.
  4. tmp=$(mktemp)
  5. sed -e 's/ = /=/' < config.mk > $tmp
  6. . $tmp
  7. rm -f $tmp
  8. bindir=${DESTDIR}${PREFIX}/bin
  9. list_of_bins() {
  10. echo bin/eeabrt
  11. echo bin/eedmenu
  12. echo bin/eeget
  13. echo bin/eeiam
  14. echo bin/eeini
  15. echo bin/eeip
  16. echo bin/eeln
  17. echo bin/eepush
  18. echo bin/eerevert
  19. echo bin/eewatch
  20. echo bin/eewww
  21. }
  22. list_of_installed_bins() {
  23. list_of_bins | sed -e "s/bin/$(sed -e 's/\//\\\//g' <<<$bindir)/"
  24. }
  25. die() {
  26. for l in "$@"; do echo "$l" >&2; done
  27. exit 9
  28. }
  29. build1() {
  30. local srcpath dstpath
  31. srcpath=$1
  32. dstpath=${srcpath%.skel}
  33. perl -pe "
  34. s|__EECC_INI_PATH__|$EECC_INI_PATH_GLOBAL:\\\$HOME/$EECC_INI_PATH_USER|;
  35. s|__VERSION__|$(get_version)|;
  36. " < $srcpath > $dstpath
  37. echo $dstpath >> built.list
  38. }
  39. build() {
  40. local srcpath
  41. find -type f -name '*.skel' \
  42. | while read srcpath;
  43. do
  44. build1 "$srcpath"
  45. done
  46. }
  47. clean() {
  48. test -f built.list && {
  49. cat built.list | xargs rm -f
  50. rm -f built.list
  51. } || :
  52. }
  53. dist() {
  54. local version=$(get_version)
  55. local dirname=eecc-$version
  56. mkdir -p $dirname
  57. cp -R bin \
  58. config.mk \
  59. Makefile \
  60. README \
  61. LICENSE \
  62. setup \
  63. test \
  64. utils \
  65. $dirname
  66. sed -ie "s/^VERSION = .*/VERSION = $version/" $dirname/config.mk
  67. tar -cf $dirname.tar $dirname
  68. gzip $dirname.tar
  69. rm -rf $dirname
  70. }
  71. install() {
  72. mkdir -vp $bindir
  73. list_of_bins | xargs cp -vrt $bindir
  74. list_of_installed_bins | xargs chmod -v 755
  75. test -f .autoclean && clean || :
  76. }
  77. get_version() {
  78. local version=$VERSION
  79. local stage=$STAGE
  80. if git rev-parse HEAD >&/dev/null;
  81. then # we are in git repo... so we can get smart
  82. local lasttag=$(git tag | grep ^v | tail -n1)
  83. if ! git describe --tags --exact-match HEAD >&/dev/null;
  84. then # we are not at later commit than the last tag
  85. local sha=g$(git describe --always HEAD)
  86. fi
  87. if test "$(git diff --shortstat 2>/dev/null)" != "";
  88. then # thr tree is "dirty", i.e. has been edited
  89. local dirty=dirty
  90. fi
  91. version=${lasttag:1}
  92. case $stage:$sha:$dirty in
  93. ::) suffix="" ;;
  94. ::dirty) suffix="+$dirty" ;;
  95. :g*:) suffix="+$sha" ;;
  96. :g*:dirty) suffix="+$sha.dirty" ;;
  97. *::) suffix="-$stage" ;;
  98. *::dirty) suffix="-$stage+$dirty" ;;
  99. *:g*:) suffix="-$stage+$sha" ;;
  100. *:g*:dirty) suffix="-$stage+$sha.$dirty" ;;
  101. esac
  102. version=$version$suffix
  103. fi
  104. echo $version
  105. }
  106. run_test() {
  107. pushd test
  108. find -maxdepth 1 -type f \! -name '*.skel' | while read test;
  109. do
  110. chmod 0755 $test
  111. $test || exit $?
  112. done
  113. popd
  114. }
  115. uninstall() {
  116. list_of_installed_bins | xargs rm -vf
  117. }
  118. case $1 in
  119. build|clean|dist|install|install_manpages|manpages|uninstall)
  120. $1
  121. ;;
  122. test)
  123. run_test
  124. ;;
  125. *)
  126. echo "usage: $(basename $0) build|clean|dist|install|test|uninstall" >&2
  127. esac