Makefile 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #
  2. # Makefile for QR Code generator (C)
  3. #
  4. # Copyright (c) Project Nayuki. (MIT License)
  5. # https://www.nayuki.io/page/qr-code-generator-library
  6. #
  7. # Permission is hereby granted, free of charge, to any person obtaining a copy of
  8. # this software and associated documentation files (the "Software"), to deal in
  9. # the Software without restriction, including without limitation the rights to
  10. # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  11. # the Software, and to permit persons to whom the Software is furnished to do so,
  12. # subject to the following conditions:
  13. # - The above copyright notice and this permission notice shall be included in
  14. # all copies or substantial portions of the Software.
  15. # - The Software is provided "as is", without warranty of any kind, express or
  16. # implied, including but not limited to the warranties of merchantability,
  17. # fitness for a particular purpose and noninfringement. In no event shall the
  18. # authors or copyright holders be liable for any claim, damages or other
  19. # liability, whether in an action of contract, tort or otherwise, arising from,
  20. # out of or in connection with the Software or the use or other dealings in the
  21. # Software.
  22. #
  23. # ---- Configuration options ----
  24. # External/implicit variables:
  25. # - CC: The C compiler, such as gcc or clang.
  26. # - CFLAGS: Any extra user-specified compiler flags (can be blank).
  27. # Recommended compiler flags:
  28. CFLAGS += -std=c99 -O
  29. # Extra flags for diagnostics:
  30. # CFLAGS += -g -Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -fsanitize=undefined,address
  31. # ---- Controlling make ----
  32. # Clear default suffix rules
  33. .SUFFIXES:
  34. # Don't delete object files
  35. .SECONDARY:
  36. # Stuff concerning goals
  37. .DEFAULT_GOAL = all
  38. .PHONY: all clean
  39. # ---- Targets to build ----
  40. LIB = qrcodegen
  41. LIBFILE = lib$(LIB).a
  42. LIBOBJ = qrcodegen.o
  43. MAINS = qrcodegen-demo qrcodegen-test
  44. # Build all binaries
  45. all: $(LIBFILE) $(MAINS)
  46. # Delete build output
  47. clean:
  48. rm -f -- $(LIBOBJ) $(LIBFILE) $(MAINS:=.o) $(MAINS)
  49. rm -rf .deps
  50. # Executable files
  51. %: %.o $(LIBFILE)
  52. $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -L . -l $(LIB)
  53. # Special executable
  54. qrcodegen-test: qrcodegen-test.c $(LIBOBJ:%.o=%.c)
  55. $(CC) $(CFLAGS) $(LDFLAGS) -DQRCODEGEN_TEST -o $@ $^
  56. # The library
  57. $(LIBFILE): $(LIBOBJ)
  58. $(AR) -crs $@ -- $^
  59. # Object files
  60. %.o: %.c .deps/timestamp
  61. $(CC) $(CFLAGS) -c -o $@ -MMD -MF .deps/$*.d $<
  62. # Have a place to store header dependencies automatically generated by compiler
  63. .deps/timestamp:
  64. mkdir -p .deps
  65. touch .deps/timestamp
  66. # Make use of said dependencies if available
  67. -include .deps/*.d