Makefile 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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_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 check clean gir gir-check gir-verify
  28. all: tests examples
  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. check: tests
  51. ./tests/run_tests.sh
  52. # Optional GIR -> .def generator (broad, auto-generated coverage).
  53. # make gir # Gtk-4.0 -> gen/
  54. # make gir GIR=Gio-2.0 # another namespace
  55. gir:
  56. python3 tools/gir2def.py $(GIR) --gir-dir $(GIR_DIR) -o gen
  57. # Generate and compile/link-check a sample of the output.
  58. gir-check:
  59. ./tools/run_gir_check.sh
  60. # Check that every generated identifier exists in the installed library.
  61. GIR_VERIFY ?= Gtk-4.0 GLib-2.0 Gio-2.0 Adw-1
  62. gir-verify:
  63. set -e; for ns in $(GIR_VERIFY); do \
  64. python3 tools/gir_verify.py $$ns --gir-dir $(GIR_DIR); \
  65. done
  66. clean:
  67. rm -rf $(BLD) gen