Makefile 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # m2-GTK4 - GNU Modula-2 bindings for GTK4
  2. GM2 ?= gm2
  3. GTKCFG := $(shell pkg-config --cflags gtk4 2>/dev/null)
  4. GTKLIBS := $(shell pkg-config --libs gtk4 2>/dev/null || echo -lgtk-4)
  5. # libadwaita is optional; added to the flags when present.
  6. ADWLIBS := $(shell pkg-config --libs libadwaita-1 2>/dev/null)
  7. GTKCFG += $(shell pkg-config --cflags libadwaita-1 2>/dev/null)
  8. GTKLIBS += $(ADWLIBS)
  9. GM2FLAGS ?= -fiso
  10. GIR ?= Gtk-4.0
  11. GIR_DIR ?= /usr/share/gir-1.0
  12. SRC_DIR := src
  13. LIB_DIR := lib
  14. BLD := build
  15. OBJDIR := $(BLD)/objs
  16. OBJS := $(OBJDIR)/GtkUtils.o $(OBJDIR)/GtkClosures.o
  17. INCLUDES := -I$(SRC_DIR) -I$(LIB_DIR)
  18. 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_application
  19. EXAMPLES := hello counter inputs containers actions headerbar editor layouts files views builder feedback styling popover dialogs
  20. # Include the libadwaita test/example only when libadwaita is installed.
  21. ifneq ($(ADWLIBS),)
  22. TESTS += test_adw
  23. EXAMPLES += adw
  24. endif
  25. .PHONY: all tests examples check clean gir gir-check gir-verify
  26. all: tests examples
  27. $(OBJDIR):
  28. mkdir -p $(OBJDIR)
  29. $(BLD)/tests:
  30. mkdir -p $(BLD)/tests
  31. $(BLD)/examples:
  32. mkdir -p $(BLD)/examples
  33. # The FOR "C" .def modules carry no code; only the pure-M2 helpers are
  34. # compiled to object files and linked into every program.
  35. $(OBJDIR)/GtkUtils.o: $(LIB_DIR)/GtkUtils.mod $(LIB_DIR)/GtkUtils.def | $(OBJDIR)
  36. $(GM2) $(INCLUDES) $(GM2FLAGS) -c $< -o $@
  37. $(OBJDIR)/GtkClosures.o: $(LIB_DIR)/GtkClosures.mod $(LIB_DIR)/GtkClosures.def | $(OBJDIR)
  38. $(GM2) $(INCLUDES) $(GM2FLAGS) -c $< -o $@
  39. tests: $(BLD)/tests $(OBJS) $(addprefix $(BLD)/tests/,$(TESTS))
  40. $(BLD)/tests/%: tests/%.mod $(OBJS) | $(BLD)/tests
  41. $(GM2) $(INCLUDES) $(GM2FLAGS) $(GTKCFG) $< $(OBJS) -o $@ $(GTKLIBS)
  42. examples: $(BLD)/examples $(OBJS) $(addprefix $(BLD)/examples/,$(EXAMPLES))
  43. $(BLD)/examples/%: examples/%.mod $(OBJS) | $(BLD)/examples
  44. $(GM2) $(INCLUDES) $(GM2FLAGS) $(GTKCFG) $< $(OBJS) -o $@ $(GTKLIBS)
  45. check: tests
  46. ./tests/run_tests.sh
  47. # Optional GIR -> .def generator (broad, auto-generated coverage).
  48. # make gir # Gtk-4.0 -> gen/
  49. # make gir GIR=Gio-2.0 # another namespace
  50. gir:
  51. python3 tools/gir2def.py $(GIR) --gir-dir $(GIR_DIR) -o gen
  52. # Generate and compile/link-check a sample of the output.
  53. gir-check:
  54. ./tools/run_gir_check.sh
  55. # Check that every generated identifier exists in the installed library.
  56. GIR_VERIFY ?= Gtk-4.0 GLib-2.0 Gio-2.0 Adw-1
  57. gir-verify:
  58. set -e; for ns in $(GIR_VERIFY); do \
  59. python3 tools/gir_verify.py $$ns --gir-dir $(GIR_DIR); \
  60. done
  61. clean:
  62. rm -rf $(BLD) gen