git2tarxz.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/bin/sh
  2. # Create source tarball from cc65 git repo, with generated version
  3. # number. We don't want to include the whole git history in the tarball,
  4. # but we do want to build the git hash into the binary (for --version),
  5. # so there's a bit of extra stuff here.
  6. # Note that this script doesn't need to be run as root. It does
  7. # need to be able to write to the current directory it's run from.
  8. # Takes one optional argument, which is the commit or tag to create
  9. # a tarball of. With no arg, HEAD is used.
  10. PRGNAM=cc65
  11. CLONE_URL=https://github.com/$PRGNAM/$PRGNAM.git
  12. set -e
  13. GITDIR=$( mktemp -dt cc65.git.XXXXXX )
  14. rm -rf $GITDIR
  15. git clone $CLONE_URL $GITDIR
  16. CWD="$( pwd )"
  17. cd $GITDIR
  18. if [ "$1" != "" ]; then
  19. git reset --hard "$1" || exit 1
  20. fi
  21. GIT_SHA=$( git rev-parse --short HEAD )
  22. sed -i "1iGIT_SHA=$GIT_SHA" src/Makefile
  23. # 6878ede and earlier commits are missing a \ in src/Makefile, which
  24. # causes the git hash *not* to be part of --version output. Fix, if
  25. # needed.
  26. sed -i '/-DLD65_LIB[^\\]*$/s,$, \\,' src/Makefile
  27. DATE=$( git log --date=format:%Y%m%d --format=%cd | head -1 )
  28. VERFILE=src/common/version.c
  29. MAJOR=$( sed -n 's,#define\s\+VER_MAJOR\s\+\([0-9]\+\)U.*,\1,p' $VERFILE )
  30. MINOR=$( sed -n 's,#define\s\+VER_MINOR\s\+\([0-9]\+\)U.*,\1,p' $VERFILE )
  31. VERSION=${MAJOR}.${MINOR}_$DATE
  32. rm -rf .git
  33. find . -name .gitignore -print0 | xargs -0 rm -f
  34. # DIRTY HACK ALERT:
  35. # -current's linuxdoc-tools hates upstream's sgml docs, and it's not
  36. # obvious what's wrong (bug/regression in linuxdoc-tools? 14.2's worked
  37. # fine). I'm not interested in trying to fix the problem because I
  38. # fucking hate XML, and I especially hate the mess that's the Slackware
  39. # linuxdoc-tools (28 source tarballs, interdependent). So I'll just
  40. # include pre-generated (on 14.2) HTML docs in my self-hosted source
  41. # tarball.
  42. make -C doc html
  43. cd "$CWD"
  44. rm -rf $PRGNAM-$VERSION $PRGNAM-$VERSION.tar.xz
  45. mv $GITDIR $PRGNAM-$VERSION
  46. tar cvfJ $PRGNAM-$VERSION.tar.xz $PRGNAM-$VERSION
  47. echo
  48. echo "Created tarball: $PRGNAM-$VERSION.tar.xz"
  49. echo "VERSION=$VERSION"