Makefile 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. # GtkSourceView 5 is optional too.
  9. SRCVLIBS := $(shell pkg-config --libs gtksourceview-5 2>/dev/null)
  10. # libspelling + libpanel are optional platform libraries.
  11. SPELLIBS := $(shell pkg-config --libs libspelling-1 2>/dev/null)
  12. PANELLIBS := $(shell pkg-config --libs libpanel-1 2>/dev/null)
  13. GLLIBS := $(shell pkg-config --libs gl 2>/dev/null)
  14. GTKCFG += $(shell pkg-config --cflags libadwaita-1 2>/dev/null)
  15. GTKCFG += $(shell pkg-config --cflags gtksourceview-5 2>/dev/null)
  16. GTKCFG += $(shell pkg-config --cflags libspelling-1 libpanel-1 2>/dev/null)
  17. GTKLIBS += $(ADWLIBS) $(SRCVLIBS) $(SPELLIBS) $(PANELLIBS) $(GLLIBS)
  18. GM2FLAGS ?= -fiso
  19. GIR ?= Gtk-4.0
  20. GIR_DIR ?= /usr/share/gir-1.0
  21. SRC_DIR := src
  22. LIB_DIR := lib
  23. BLD := build
  24. OBJDIR := $(BLD)/objs
  25. OBJS := $(OBJDIR)/GtkUtils.o $(OBJDIR)/GtkClosures.o $(OBJDIR)/m2gtkshim.o
  26. INCLUDES := -I$(SRC_DIR) -I$(LIB_DIR)
  27. 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
  28. 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
  29. # Include the libadwaita test/example only when libadwaita is installed.
  30. ifneq ($(ADWLIBS),)
  31. TESTS += test_adw
  32. EXAMPLES += adw adw_widgets adw_views
  33. endif
  34. # Include the GtkSourceView example when gtksourceview-5 is installed.
  35. ifneq ($(SRCVLIBS),)
  36. EXAMPLES += sourceview
  37. endif
  38. # Include the spell-checking example with GtkSourceView + libspelling.
  39. ifneq ($(SRCVLIBS)$(SPELLIBS),)
  40. EXAMPLES += spelling
  41. endif
  42. .PHONY: all tests examples demos check clean gir gir-check gir-verify
  43. all: tests examples demos
  44. $(OBJDIR):
  45. mkdir -p $(OBJDIR)
  46. $(BLD)/tests:
  47. mkdir -p $(BLD)/tests
  48. $(BLD)/examples:
  49. mkdir -p $(BLD)/examples
  50. # The FOR "C" .def modules carry no code; only the pure-M2 helpers are
  51. # compiled to object files and linked into every program.
  52. $(OBJDIR)/GtkUtils.o: $(LIB_DIR)/GtkUtils.mod $(LIB_DIR)/GtkUtils.def | $(OBJDIR)
  53. $(GM2) $(INCLUDES) $(GM2FLAGS) -c $< -o $@
  54. $(OBJDIR)/GtkClosures.o: $(LIB_DIR)/GtkClosures.mod $(LIB_DIR)/GtkClosures.def | $(OBJDIR)
  55. $(GM2) $(INCLUDES) $(GM2FLAGS) -c $< -o $@
  56. # C shim for GObject subclassing (custom GtkWidget / GdkPaintable).
  57. $(OBJDIR)/m2gtkshim.o: $(LIB_DIR)/m2gtkshim.c | $(OBJDIR)
  58. $(CC) $(GTKCFG) -c $< -o $@
  59. tests: $(BLD)/tests $(OBJS) $(addprefix $(BLD)/tests/,$(TESTS))
  60. $(BLD)/tests/%: tests/%.mod $(OBJS) | $(BLD)/tests
  61. $(GM2) $(INCLUDES) $(GM2FLAGS) $(GTKCFG) $< $(OBJS) -o $@ $(GTKLIBS)
  62. examples: $(BLD)/examples $(OBJS) $(addprefix $(BLD)/examples/,$(EXAMPLES))
  63. $(BLD)/examples/%: examples/%.mod $(OBJS) | $(BLD)/examples
  64. $(GM2) $(INCLUDES) $(GM2FLAGS) $(GTKCFG) $< $(OBJS) -o $@ $(GTKLIBS)
  65. # --- m2 gtk-demo (demos/) -------------------------------------------------
  66. DEMO_DIR := demos
  67. $(BLD)/demos:
  68. mkdir -p $(BLD)/demos
  69. $(OBJDIR)/DemoCatalog.o: $(DEMO_DIR)/DemoCatalog.mod $(DEMO_DIR)/DemoCatalog.def | $(OBJDIR)
  70. $(GM2) $(INCLUDES) -I$(DEMO_DIR) $(GM2FLAGS) -c $< -o $@
  71. $(OBJDIR)/DemoImpl.o: $(DEMO_DIR)/DemoImpl.mod $(DEMO_DIR)/DemoImpl.def | $(OBJDIR)
  72. $(GM2) $(INCLUDES) -I$(DEMO_DIR) $(GM2FLAGS) -c $< -o $@
  73. $(OBJDIR)/DemosBasic.o: $(DEMO_DIR)/DemosBasic.mod $(DEMO_DIR)/DemosBasic.def | $(OBJDIR)
  74. $(GM2) $(INCLUDES) -I$(DEMO_DIR) $(GM2FLAGS) -c $< -o $@
  75. $(OBJDIR)/DemosLayout.o: $(DEMO_DIR)/DemosLayout.mod $(DEMO_DIR)/DemosLayout.def | $(OBJDIR)
  76. $(GM2) $(INCLUDES) -I$(DEMO_DIR) $(GM2FLAGS) -c $< -o $@
  77. $(OBJDIR)/DemosText.o: $(DEMO_DIR)/DemosText.mod $(DEMO_DIR)/DemosText.def | $(OBJDIR)
  78. $(GM2) $(INCLUDES) -I$(DEMO_DIR) $(GM2FLAGS) -c $< -o $@
  79. $(OBJDIR)/DemosWindows.o: $(DEMO_DIR)/DemosWindows.mod $(DEMO_DIR)/DemosWindows.def | $(OBJDIR)
  80. $(GM2) $(INCLUDES) -I$(DEMO_DIR) $(GM2FLAGS) -c $< -o $@
  81. $(OBJDIR)/DemosInput.o: $(DEMO_DIR)/DemosInput.mod $(DEMO_DIR)/DemosInput.def | $(OBJDIR)
  82. $(GM2) $(INCLUDES) -I$(DEMO_DIR) $(GM2FLAGS) -c $< -o $@
  83. $(OBJDIR)/DemosChooser.o: $(DEMO_DIR)/DemosChooser.mod $(DEMO_DIR)/DemosChooser.def | $(OBJDIR)
  84. $(GM2) $(INCLUDES) -I$(DEMO_DIR) $(GM2FLAGS) -c $< -o $@
  85. $(OBJDIR)/DemosCanvas.o: $(DEMO_DIR)/DemosCanvas.mod $(DEMO_DIR)/DemosCanvas.def | $(OBJDIR)
  86. $(GM2) $(INCLUDES) -I$(DEMO_DIR) $(GM2FLAGS) -c $< -o $@
  87. $(OBJDIR)/GtkDemo.o: $(DEMO_DIR)/GtkDemo.mod $(DEMO_DIR)/GtkDemo.def | $(OBJDIR)
  88. $(GM2) $(INCLUDES) -I$(DEMO_DIR) $(GM2FLAGS) -c $< -o $@
  89. DEMO_OBJS := $(OBJDIR)/DemoCatalog.o $(OBJDIR)/DemoImpl.o $(OBJDIR)/DemosBasic.o \
  90. $(OBJDIR)/DemosLayout.o $(OBJDIR)/DemosText.o \
  91. $(OBJDIR)/DemosWindows.o $(OBJDIR)/DemosInput.o \
  92. $(OBJDIR)/DemosChooser.o $(OBJDIR)/DemosCanvas.o $(OBJDIR)/GtkDemo.o
  93. demos: $(BLD)/demos $(OBJS) $(DEMO_OBJS) $(BLD)/demos/m2gtkdemo
  94. $(BLD)/demos/m2gtkdemo: $(DEMO_DIR)/m2gtkdemo.mod $(OBJS) $(DEMO_OBJS) | $(BLD)/demos
  95. $(GM2) $(INCLUDES) -I$(DEMO_DIR) $(GM2FLAGS) $(GTKCFG) $< \
  96. $(OBJS) $(DEMO_OBJS) -o $@ $(GTKLIBS)
  97. check: tests
  98. ./tests/run_tests.sh
  99. # Optional GIR -> .def generator (broad, auto-generated coverage).
  100. # make gir # Gtk-4.0 -> gen/
  101. # make gir GIR=Gio-2.0 # another namespace
  102. gir:
  103. python3 tools/gir2def.py $(GIR) --gir-dir $(GIR_DIR) -o gen
  104. # Generate and compile/link-check a sample of the output.
  105. gir-check:
  106. ./tools/run_gir_check.sh
  107. # Check that every generated identifier exists in the installed library.
  108. GIR_VERIFY ?= Gtk-4.0 GLib-2.0 Gio-2.0 Adw-1 GtkSource-5 Gdk-4.0 Gsk-4.0 Spelling-1 Panel-1
  109. gir-verify:
  110. set -e; for ns in $(GIR_VERIFY); do \
  111. python3 tools/gir_verify.py $$ns --gir-dir $(GIR_DIR); \
  112. done
  113. clean:
  114. rm -rf $(BLD) gen