makedpkg.in 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #!/bin/sh
  2. set -u
  3. set -e
  4. trap onexit INT
  5. trap onexit TERM
  6. trap onexit EXIT
  7. TMPDIR=
  8. SUDO=
  9. onexit()
  10. {
  11. if [ ! "$TMPDIR" = "" ]; then
  12. $SUDO rm -rf $TMPDIR
  13. fi
  14. }
  15. uid()
  16. {
  17. id | cut -f2 -d = | cut -f1 -d \(;
  18. }
  19. safedirmove ()
  20. {
  21. if [ "$1" = "$2" ]; then
  22. return 0
  23. fi
  24. if [ "$1" = "" -o ! -d "$1" ]; then
  25. echo safedirmove: source dir $1 is not valid
  26. return 1
  27. fi
  28. if [ "$2" = "" -o -e "$2" ]; then
  29. echo safedirmove: dest dir $2 is not valid
  30. return 1
  31. fi
  32. if [ "$3" = "" -o -e "$3" ]; then
  33. echo safedirmove: tmp dir $3 is not valid
  34. return 1
  35. fi
  36. mkdir -p $3
  37. mv $1/* $3/
  38. rmdir $1
  39. mkdir -p $2
  40. mv $3/* $2/
  41. rmdir $3
  42. return 0
  43. }
  44. makedeb()
  45. {
  46. SUPPLEMENT=$1
  47. DIRNAME=$PKGNAME
  48. if [ $SUPPLEMENT = 1 ]; then
  49. PKGNAME=$PKGNAME\32
  50. DEBARCH=amd64
  51. fi
  52. umask 022
  53. rm -f $PKGNAME\_$VERSION\_$DEBARCH.deb
  54. TMPDIR=`mktemp -d /tmp/$PKGNAME-build.XXXXXX`
  55. mkdir $TMPDIR/DEBIAN
  56. if [ $SUPPLEMENT = 1 ]; then
  57. make install DESTDIR=$TMPDIR
  58. rm -rf $TMPDIR$BINDIR
  59. if [ "$DATAROOTDIR" != "$PREFIX" ]; then
  60. rm -rf $TMPDIR$DATAROOTDIR
  61. fi
  62. if [ "$JAVADIR" != "" ]; then
  63. rm -rf $TMPDIR$JAVADIR
  64. fi
  65. rm -rf $TMPDIR$DOCDIR
  66. rm -rf $TMPDIR$INCLUDEDIR
  67. rm -rf $TMPDIR$MANDIR
  68. else
  69. make install DESTDIR=$TMPDIR
  70. if [ "$PREFIX" = "@CMAKE_INSTALL_DEFAULT_PREFIX@" -a "$DOCDIR" = "@CMAKE_INSTALL_DEFAULT_PREFIX@/doc" ]; then
  71. safedirmove $TMPDIR/$DOCDIR $TMPDIR/usr/share/doc/$PKGNAME-$VERSION $TMPDIR/__tmpdoc
  72. ln -fs /usr/share/doc/$DIRNAME-$VERSION $TMPDIR$DOCDIR
  73. fi
  74. fi
  75. SIZE=`du -s $TMPDIR | cut -f1`
  76. (cat pkgscripts/deb-control | sed s/{__PKGNAME}/$PKGNAME/g \
  77. | sed s/{__ARCH}/$DEBARCH/g | sed s/{__SIZE}/$SIZE/g \
  78. > $TMPDIR/DEBIAN/control)
  79. /sbin/ldconfig -n $TMPDIR$LIBDIR
  80. $SUDO chown -Rh root:root $TMPDIR/*
  81. dpkg -b $TMPDIR $PKGNAME\_$VERSION\_$DEBARCH.deb
  82. }
  83. PKGNAME=@PKGNAME@
  84. VERSION=@VERSION@
  85. DEBARCH=@DEBARCH@
  86. PREFIX=@CMAKE_INSTALL_PREFIX@
  87. BINDIR=@CMAKE_INSTALL_FULL_BINDIR@
  88. DATAROOTDIR=@CMAKE_INSTALL_FULL_DATAROOTDIR@
  89. DOCDIR=@CMAKE_INSTALL_FULL_DOCDIR@
  90. INCLUDEDIR=@CMAKE_INSTALL_FULL_INCLUDEDIR@
  91. JAVADIR=@CMAKE_INSTALL_FULL_JAVADIR@
  92. LIBDIR=@CMAKE_INSTALL_FULL_LIBDIR@
  93. MANDIR=@CMAKE_INSTALL_FULL_MANDIR@
  94. if [ ! `uid` -eq 0 ]; then
  95. SUDO=sudo
  96. fi
  97. makedeb 0
  98. if [ "$DEBARCH" = "i386" ]; then makedeb 1; fi
  99. exit