std.mk 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. include ../../config.mk
  2. TARG := $(notdir $(abspath $(dir $(firstword $(MAKEFILE_LIST)))))
  3. OFILES += ${TARG}.o
  4. HFILES += ../getopt_helper.h ../version.h ../metaargs_helper.h ../metaargs.h
  5. SUPPORTED_COMPILERS := gcc clang tcc
  6. src_files = $(wildcard ./*.c ./*.h)
  7. .PHONY: all
  8. all: ${TARG} ${SYM}
  9. .PHONY: clang-tidy-check
  10. clang-tidy-check: ${TARG}.c
  11. ${CLANG_TIDY} --quiet --warnings-as-errors='*' ${src_files}
  12. .PHONY: clang-format-check
  13. clang-format-check:
  14. ${CLANG_FORMAT} --dry-run -Werror ${src_files}
  15. define test_compiler
  16. make clean
  17. make CC='${1}' all
  18. endef
  19. .PHONY: test_compilers
  20. test_compilers:
  21. $(foreach _,${SUPPORTED_COMPILERS},$(call test_compiler,${_}))
  22. make clean
  23. .PHONY: check-all
  24. check-all: test_compilers clang-tidy-check clang-format-check
  25. ../getopt_helper.h: ../version.h
  26. ${OFILES}: ${HFILES} ${METALANG99INC}
  27. ${TARG}.o: CPPFLAGS += -DPROG_NAME='"${@:.o=}"'
  28. .c.o:
  29. $(CC) ${CFLAGS} ${CPPFLAGS} -c ${<} -o ${@}
  30. ${TARG}: ${OFILES}
  31. $(CC) ${CFLAGS} ${LDFLAGS} ${^} -o ${@}
  32. install: ${TARG} ${SYM}
  33. install -Dm755 -- ${TARG} ${DESTDIR}${PREFIX}/bin/${TARG}
  34. ifneq (,${SYM})
  35. for s in ${SYM}; do cp -fd -- "$$s" ${DESTDIR}${PREFIX}/bin/; done
  36. endif
  37. ${DESTDIR}${PREFIX}/bin:
  38. mkdir -p -- ${@}
  39. ifneq (,${SYM})
  40. ${SYM}: ${TARG}
  41. ln -s -- ${<} ${@}
  42. endif
  43. .PHONY: uninstall
  44. uninstall:
  45. rm -f -- ${DESTDIR}${PREFIX}/bin/${TARG}
  46. ifneq (,${SYM})
  47. rm -f -- $(addprefix ${DESTDIR}${PREFIX}/bin/,${SYM})
  48. endif
  49. .PHONY: clean
  50. clean:
  51. rm -f -- ${TARG} ${OFILES} ${SYM}