Makefile 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # Pre-Scheme Makefile
  2. CC=gcc
  3. FORMAT=clang-format -i
  4. PRESCHEME=prescheme
  5. CFLAGS=-O2 -g -Wall
  6. CFLAGS+=$(shell pkg-config --cflags prescheme)
  7. LDLIBS+=$(shell pkg-config --libs prescheme)
  8. SDL2_CFLAGS=$(shell pkg-config --cflags sdl2)
  9. SDL2_LDLIBS=$(shell pkg-config --libs sdl2)
  10. SOURCES= packages.scm \
  11. lib/ps-string.scm \
  12. lib/ps-vector.scm \
  13. lib/ps-utils.scm \
  14. lib/ps-grid.scm \
  15. lib/ps-sdl2.scm
  16. TARGETS= hello \
  17. append \
  18. vecfun \
  19. recfun \
  20. btree \
  21. game-of-life \
  22. prime-sum
  23. all: $(TARGETS)
  24. %.c: %.scm $(SOURCES)
  25. rm -f $@
  26. ( echo ",batch"; \
  27. echo "(prescheme-compiler '$* '(\"packages.scm\") 'ps-init \"$@\""; \
  28. echo " '(header \"#include \\\"include/ps-init.h\\\"\")"; \
  29. echo " '(copy (ps-vector vector-unfold1))"; \
  30. echo " '(copy (ps-vector vector-unfold2))"; \
  31. echo " '(copy (ps-vector vector-unfold3))"; \
  32. echo " '(copy (ps-vector vector-fold1))"; \
  33. echo " '(copy (ps-vector vector-fold2))"; \
  34. echo " '(copy (ps-vector vector-fold3))"; \
  35. echo " '(copy (ps-vector vector-map1!))"; \
  36. echo " '(copy (ps-vector vector-map2!))"; \
  37. echo " '(copy (ps-vector vector-map3!))"; \
  38. echo " '(copy (ps-vector vector-map1))"; \
  39. echo " '(copy (ps-vector vector-map2))"; \
  40. echo " '(copy (ps-vector vector-map3))"; \
  41. echo " '(copy (ps-vector vector-for-each1))"; \
  42. echo " '(copy (ps-vector vector-for-each2))"; \
  43. echo " '(copy (ps-vector vector-for-each3))"; \
  44. echo " '(copy (ps-vector vector-fill!))"; \
  45. echo ")"; \
  46. echo ",exit" ) \
  47. | $(PRESCHEME)
  48. $(FORMAT) $@
  49. game-of-life.c: game-of-life.scm $(SOURCES)
  50. rm -f $@
  51. ( echo ",batch"; \
  52. echo "(prescheme-compiler '$* '(\"packages.scm\") 'ps-init \"$@\""; \
  53. echo " '(header \"#include \\\"include/ps-init.h\\\"\")"; \
  54. echo " '(header \"#include \\\"include/ps-sdl2.h\\\"\")"; \
  55. echo " '(header \"#include <time.h>\")"; \
  56. echo " '(copy (ps-grid grid-index))"; \
  57. echo " '(copy (ps-grid grid-fold))"; \
  58. echo " '(copy (ps-grid grid-for-each))"; \
  59. echo " '(copy (ps-grid grid-update!))"; \
  60. echo " '(copy (ps-grid grid-unfold))"; \
  61. echo ")"; \
  62. echo ",exit" ) \
  63. | $(PRESCHEME)
  64. $(FORMAT) $@
  65. game-of-life.o: game-of-life.c
  66. $(CC) $(CPPFLAGS) $(CFLAGS) $(SDL2_CFLAGS) -c $^ -o $@
  67. game-of-life: game-of-life.o
  68. $(CC) $(LDFLAGS) $^ $(LDLIBS) $(SDL2_LDLIBS) -o $@
  69. clean:
  70. rm -f $(TARGETS)
  71. rm -f $(TARGETS:=.o)
  72. rm -f $(TARGETS:=.c)
  73. .PRECIOUS: $(TARGETS:=.c)
  74. .INTERMEDIATE: game-of-life.o
  75. .PHONY: all clean