Makefile 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. # Files
  2. HEADERS = $(wildcard include/*.h)
  3. SRC = $(wildcard src/*.c)
  4. # Project data
  5. NAME = ddt_core
  6. VERSION = 0.1.0
  7. TARBALL = ${NAME}-${VERSION}.tar
  8. # Compiler arguments
  9. CC = cc
  10. CFLAGS = -Wall -Wextra -pedantic -Iinclude
  11. # shared/static data
  12. DDIR = build-shared
  13. SDIR = build-static
  14. DOBJ = ${SRC:src/%.c=${DDIR}/%.o}
  15. SOBJ = ${SRC:src/%.c=${SDIR}/%.o}
  16. DOUT = lib/lib${NAME}.so
  17. SOUT = lib/lib${NAME}.a
  18. ### Rules ###
  19. # default rule
  20. default: static
  21. # compile both static and shared
  22. all: shared static
  23. # create shared library
  24. shared: ${DOUT}
  25. ${DOUT}: ${DOBJ}
  26. @mkdir -p lib
  27. ${CC} -shared -o $@ $^
  28. # create static library
  29. static: ${SOUT}
  30. ${SOUT}: ${SOBJ}
  31. @mkdir -p lib
  32. ar rcs $@ $^
  33. # install (default)
  34. install: install_static
  35. # install shared library
  36. install_shared: ${DOUT}
  37. @mkdir -p ${DESTDIR}${PREFIX}/include
  38. @install -m644 ${HEADERS} ${DESTDIR}${PREFIX}/include
  39. @echo installed headers in ${DESTDIR}${PREFIX}/include
  40. @mkdir -p ${DESTDIR}${PREFIX}/lib
  41. @install -m755 ${DOUT} ${DESTDIR}${PREFIX}/lib
  42. @echo installed library in ${DESTDIR}${PREFIX}/${DOUT}
  43. # install static library
  44. install_static: ${SOUT}
  45. @mkdir -p ${DESTDIR}${PREFIX}/include
  46. @install -m644 ${HEADERS} ${DESTDIR}${PREFIX}/include
  47. @echo installed headers in ${DESTDIR}${PREFIX}/include
  48. @mkdir -p ${DESTDIR}${PREFIX}/lib
  49. @install -m755 ${SOUT} ${DESTDIR}${PREFIX}/lib
  50. @echo installed library in ${DESTDIR}${PREFIX}/${SOUT}
  51. # uninstall (default)
  52. uninstall: uninstall_static
  53. # uninstall shared library (default)
  54. uninstall_shared:
  55. @rm -f ${HEADERS:%=${DESTDIR}${PREFIX}/%}
  56. @echo removed headers from ${DESTDIR}${PREFIX}/include
  57. @rm -f ${DESTDIR}${PREFIX}/${DOUT}
  58. @echo removed ${DESTDIR}${PREFIX}/${DOUT}
  59. # uninstall static library
  60. uninstall_static:
  61. @rm -f ${HEADERS:%=${DESTDIR}${PREFIX}/%}
  62. @echo removed headers from ${DESTDIR}${PREFIX}/include
  63. @rm -f ${DESTDIR}${PREFIX}/${SOUT}
  64. @echo removed ${DESTDIR}${PREFIX}/${SOUT}
  65. # clean directory
  66. clean:
  67. @-rm -rf ${DDIR} ${SDIR} lib
  68. @-rm -f ${TARBALL}
  69. @echo project cleaned
  70. tarball:
  71. @tar -cf ${TARBALL} include/ src/ configure LICENSE Makefile.in README.md
  72. @echo \'${TARBALL}\' created
  73. .PHONY : clean install uninstall tarball shared static
  74. # Re-compile when any header changes
  75. ${DOUT} ${SOUT}: ${HEADERS}
  76. # how to compile files for shared library
  77. ${DDIR}/%.o: src/%.c | ${DDIR}
  78. ${CC} ${CFLAGS} -fPIC -o $@ -c $<
  79. # how to compile files for static library
  80. ${SDIR}/%.o: src/%.c | ${SDIR}
  81. ${CC} ${CFLAGS} -o $@ -c $<
  82. # create folders
  83. ${DDIR}:
  84. mkdir ${DDIR}
  85. ${SDIR}:
  86. mkdir ${SDIR}