simple console-based event calendar
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
3.0KB

  1. #!/bin/sh
  2. # kinda brittle, this, but mostly works
  3. # just don't use names with whitespaces
  4. target='every'
  5. srcdir='src'
  6. sources=`find $srcdir -type f -name '*.c' | sed -e "s/$srcdir\/\(.*\).c/\1.c/"`
  7. objdir='build'
  8. objects=`find $srcdir -type f -name '*.c' | sed -e "s/$srcdir\/\(.*\).c/\1.o/"`
  9. cc='cc'
  10. cflags='-Wall -O2'
  11. cflagsdebug='-std=c99 -Wall -pedantic -ggdb3 -O0 -DDEBUG'
  12. prefix='/usr/local'
  13. rls_objects=`printf %s "$objects" | sed -e "s/^/$objdir\/release\//" | tr '\n' ' '`
  14. dbg_objects=`printf %s "$objects" | sed -e "s/^/$objdir\/debug\//" | tr '\n' ' '`
  15. dgen='gcc'
  16. if [ ! `2>/dev/null which gcc` ]; then
  17. if [ ! `2>/dev/null which clang` ]; then
  18. echo 'err: could not find a suitable ' \
  19. 'compiler for calculating dependencies'
  20. return 1
  21. fi
  22. dgen='clang'
  23. fi
  24. if [ -f 'Makefile' ]; then
  25. make clean
  26. fi
  27. {
  28. printf %s\\n '.POSIX:'
  29. printf %s\\n '.SUFFIXES:'
  30. printf %s\\n ''
  31. printf %s\\n "CC = $cc"
  32. printf %s\\n "CFLAGS = $cflags"
  33. printf %s\\n "CFLAGSDEBUG = $cflagsdebug"
  34. printf %s\\n "PREFIX = $prefix"
  35. printf %s\\n ''
  36. printf %s\\n "all: $target"
  37. printf %s\\n ''
  38. printf %s\\n "debug: dbg_$target"
  39. printf %s\\n ''
  40. printf %s\\n "install: all"
  41. printf %s\\n ' mkdir -p $(DESTDIR)$(PREFIX)/bin'
  42. printf %s\\n ' mkdir -p $(DESTDIR)$(PREFIX)/share/man/man1'
  43. printf %s\\n " cp -f $target \$(DESTDIR)\$(PREFIX)/bin"
  44. printf %s\\n " gzip < ${target}.1 > \$(DESTDIR)\$(PREFIX)/share/man/man1/${target}.1.gz"
  45. printf %s\\n ''
  46. printf %s\\n "$target: ${objdir}/release $rls_objects"
  47. printf %s\\n " \$(CC) \$(LDFLAGS) -o $target $rls_objects \$(LDLIBS)"
  48. printf %s\\n ''
  49. printf %s\\n "dbg_$target: ${objdir}/debug $dbg_objects"
  50. printf %s\\n " \$(CC) \$(LDFLAGS) -o dbg_$target $dbg_objects \$(LDLIBS)"
  51. printf %s\\n ''
  52. printf %s\\n "${objdir}/release:"
  53. printf %s\\n " mkdir -p ${objdir}/release"
  54. printf %s\\n ''
  55. printf %s\\n "${objdir}/debug:"
  56. printf %s\\n " mkdir -p ${objdir}/debug"
  57. printf %s\\n ''
  58. printf %s\\n 'src/version.h:'
  59. printf %s\\n ' printf "%s\n%s\n\n%s%s%s\n\n%s\n" \'
  60. printf %s\\n ' "#ifndef EVERY_VERSION_H" \'
  61. printf %s\\n ' "#define EVERY_VERSION_H" \'
  62. printf %s\\n " \"#define VERSION \\\"$target-\" \"`git describe --always --tags`\" \"\\\"\" \\"
  63. printf %s\\n ' "#endif" > src/version.h'
  64. printf %s\\n ''
  65. printf %s\\n "$sources" | (while IFS= read -r s; do
  66. $dgen $CFLAGS -MM -MG -MT ${objdir}/release/`printf %s $s | sed -e 's/\.c$/\.o/'` "$srcdir/$s" | sed -e "s/version.h/$srcdir\/version.h/"
  67. printf %s\\n " \$(CC) -c \$(CFLAGS) -o ${objdir}/release/`printf %s $s | sed -e 's/\.c$/\.o/'` ${srcdir}/$s"
  68. done)
  69. printf %s\\n ''
  70. printf %s\\n "$sources" | (while IFS= read -r s; do
  71. $dgen $CFLAGS -MM -MG -MT ${objdir}/debug/`printf %s $s | sed -e 's/\.c$/\.o/'` "$srcdir/$s" | sed -e "s/version.h/$srcdir\/version.h/"
  72. printf %s\\n " \$(CC) -c \$(CFLAGSDEBUG) -o ${objdir}/debug/`printf %s $s | sed -e 's/\.c$/\.o/'` ${srcdir}/$s"
  73. done)
  74. printf %s\\n ''
  75. printf %s\\n 'clean:'
  76. printf %s\\n ' rm -f src/version.h'
  77. printf %s\\n " rm -f $target"
  78. printf %s\\n " rm -f dbg_$target"
  79. printf %s\\n " rm -rf $objdir"
  80. } > Makefile