Makefile 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. # m2-GTK4 - GNU Modula-2 bindings for GTK4
  2. GM2 ?= gm2
  3. CC ?= gcc
  4. GTKCFG := $(shell pkg-config --cflags gtk4 2>/dev/null)
  5. GTKLIBS := $(shell pkg-config --libs gtk4 2>/dev/null || echo -lgtk-4)
  6. # libadwaita is optional; added to the flags when present.
  7. ADWLIBS := $(shell pkg-config --libs libadwaita-1 2>/dev/null)
  8. GLLIBS := $(shell pkg-config --libs gl 2>/dev/null)
  9. GTKCFG += $(shell pkg-config --cflags libadwaita-1 2>/dev/null)
  10. GTKLIBS += $(ADWLIBS) $(GLLIBS)
  11. GM2FLAGS ?= -fiso
  12. GIR ?= Gtk-4.0
  13. GIR_DIR ?= /usr/share/gir-1.0
  14. SRC_DIR := src
  15. LIB_DIR := lib
  16. BLD := build
  17. OBJDIR := $(BLD)/objs
  18. OBJS := $(OBJDIR)/GtkUtils.o $(OBJDIR)/GtkClosures.o $(OBJDIR)/m2gtkshim.o
  19. INCLUDES := -I$(SRC_DIR) -I$(LIB_DIR)
  20. TESTS := test_glib test_version test_widgets test_inputs test_inputs2 test_containers test_containers2 test_actions test_closure test_headerbar test_gio test_gerror test_filedialog test_views test_builder test_utility test_css test_popover test_dialogs test_models test_cairo test_drawing test_gestures test_models2 test_widgets3 test_shim test_shim2 test_shim3 test_dnd test_media test_gl test_print test_text test_expr test_constraints test_shortcuts test_snapshot test_lastwidgets test_application
  21. EXAMPLES := hello counter inputs containers actions headerbar editor layouts files views builder feedback styling popover dialogs drawing demo gestures customwidget customlayout media clipboard gl richtext snapshot
  22. # Include the libadwaita test/example only when libadwaita is installed.
  23. ifneq ($(ADWLIBS),)
  24. TESTS += test_adw
  25. EXAMPLES += adw
  26. endif
  27. .PHONY: all tests examples demos check clean gir gir-check gir-verify
  28. all: tests examples demos
  29. $(OBJDIR):
  30. mkdir -p $(OBJDIR)
  31. $(BLD)/tests:
  32. mkdir -p $(BLD)/tests
  33. $(BLD)/examples:
  34. mkdir -p $(BLD)/examples
  35. # The FOR "C" .def modules carry no code; only the pure-M2 helpers are
  36. # compiled to object files and linked into every program.
  37. $(OBJDIR)/GtkUtils.o: $(LIB_DIR)/GtkUtils.mod $(LIB_DIR)/GtkUtils.def | $(OBJDIR)
  38. $(GM2) $(INCLUDES) $(GM2FLAGS) -c $< -o $@
  39. $(OBJDIR)/GtkClosures.o: $(LIB_DIR)/GtkClosures.mod $(LIB_DIR)/GtkClosures.def | $(OBJDIR)
  40. $(GM2) $(INCLUDES) $(GM2FLAGS) -c $< -o $@
  41. # C shim for GObject subclassing (custom GtkWidget / GdkPaintable).
  42. $(OBJDIR)/m2gtkshim.o: $(LIB_DIR)/m2gtkshim.c | $(OBJDIR)
  43. $(CC) $(GTKCFG) -c $< -o $@
  44. tests: $(BLD)/tests $(OBJS) $(addprefix $(BLD)/tests/,$(TESTS))
  45. $(BLD)/tests/%: tests/%.mod $(OBJS) | $(BLD)/tests
  46. $(GM2) $(INCLUDES) $(GM2FLAGS) $(GTKCFG) $< $(OBJS) -o $@ $(GTKLIBS)
  47. examples: $(BLD)/examples $(OBJS) $(addprefix $(BLD)/examples/,$(EXAMPLES))
  48. $(BLD)/examples/%: examples/%.mod $(OBJS) | $(BLD)/examples
  49. $(GM2) $(INCLUDES) $(GM2FLAGS) $(GTKCFG) $< $(OBJS) -o $@ $(GTKLIBS)
  50. # --- m2 gtk-demo (demos/) -------------------------------------------------
  51. DEMO_DIR := demos
  52. $(BLD)/demos:
  53. mkdir -p $(BLD)/demos
  54. $(OBJDIR)/DemoImpl.o: $(DEMO_DIR)/DemoImpl.mod $(DEMO_DIR)/DemoImpl.def | $(OBJDIR)
  55. $(GM2) $(INCLUDES) -I$(DEMO_DIR) $(GM2FLAGS) -c $< -o $@
  56. $(OBJDIR)/GtkDemo.o: $(DEMO_DIR)/GtkDemo.mod $(DEMO_DIR)/GtkDemo.def | $(OBJDIR)
  57. $(GM2) $(INCLUDES) -I$(DEMO_DIR) $(GM2FLAGS) -c $< -o $@
  58. demos: $(BLD)/demos $(OBJS) $(OBJDIR)/DemoImpl.o $(OBJDIR)/GtkDemo.o $(BLD)/demos/m2gtkdemo
  59. $(BLD)/demos/m2gtkdemo: $(DEMO_DIR)/m2gtkdemo.mod $(OBJS) $(OBJDIR)/DemoImpl.o $(OBJDIR)/GtkDemo.o | $(BLD)/demos
  60. $(GM2) $(INCLUDES) -I$(DEMO_DIR) $(GM2FLAGS) $(GTKCFG) $< \
  61. $(OBJS) $(OBJDIR)/DemoImpl.o $(OBJDIR)/GtkDemo.o -o $@ $(GTKLIBS)
  62. check: tests
  63. ./tests/run_tests.sh
  64. # Optional GIR -> .def generator (broad, auto-generated coverage).
  65. # make gir # Gtk-4.0 -> gen/
  66. # make gir GIR=Gio-2.0 # another namespace
  67. gir:
  68. python3 tools/gir2def.py $(GIR) --gir-dir $(GIR_DIR) -o gen
  69. # Generate and compile/link-check a sample of the output.
  70. gir-check:
  71. ./tools/run_gir_check.sh
  72. # Check that every generated identifier exists in the installed library.
  73. GIR_VERIFY ?= Gtk-4.0 GLib-2.0 Gio-2.0 Adw-1
  74. gir-verify:
  75. set -e; for ns in $(GIR_VERIFY); do \
  76. python3 tools/gir_verify.py $$ns --gir-dir $(GIR_DIR); \
  77. done
  78. clean:
  79. rm -rf $(BLD) gen