Files
lightgui/Makefile
T
cnmcdee 780853bdf2 make install + generator references installed headers
Widgets are header-only (common/ + core/ + components/, 1100
headers), so make install copies them to
PREFIX/include/lightgui (default /usr/local/include/lightgui).
The generator now emits that as the default WIDGETS_DIR /
LIGHTGUI_WIDGETS_DIR instead of the hardcoded /opt/lightgui/widgets;
the -DLIGHTGUI_WIDGETS_DIR / make WIDGETS_DIR override still works.
Verified: make install puts 1100 headers in place; a generated
project builds with -I/usr/local/include/lightgui only and its
Makefile/CMakeLists contain no /opt/lightgui reference.
2026-11-30 03:29:52 +00:00

89 lines
3.9 KiB
Makefile

CXX ?= g++
CXXFLAGS ?= -O2 -Wall -Wextra -std=c++17
GTKFLAGS := $(shell pkg-config --cflags gtk+-3.0)
GTKLIBS := $(shell pkg-config --libs gtk+-3.0)
# X11 + XFrame widgets for the unified canvas (src/xframe_canvas*.cpp):
# the canvas module includes <X11/...> and widgets/common/registry.h.
X11FLAGS := $(shell pkg-config --cflags x11)
X11LIBS := $(shell pkg-config --libs x11)
WIDGETS_INC := -Iwidgets
# Headers the XFrame canvas core depends on (outside src/).
WIDGET_HDRS := widgets/common/registry.h widgets/common/ico.h widgets/core/xframe_core.h
NPROC := $(shell nproc 2>/dev/null || echo 4)
# Short git commit, baked into the binary for Help -> About
# (LIGHTGUI_GIT_HASH); "unknown" when built outside a git checkout.
GIT_HASH := $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
# Parallel build, ON BY DEFAULT (standing requirement): the designer is
# compiled one .o per .cpp and linked, so a plain `make` / `make
# lightgui` / `make all` uses all NPROC cores with no -j flag to
# remember. SRCS is a wildcard, so a .cpp added to src/ later is
# compiled as its own .o automatically — no Makefile edit needed, and
# no future build silently falls back to a single core.
MAKEFLAGS += -j$(NPROC)
# LightGUI -- C++/GTK designer (src/) + XFrame widgets (widgets/).
# make build the lightgui binary and all widget demos
# make lightgui build ./lightgui only
# make widgets build widgets/build (all widget demos + palette + layout)
# make install install the XFrame widget headers (header-only) to
# $(PREFIX)/include/lightgui so generated apps build
# on any machine where LightGUI is installed
# make test run the layout -> LightGUI seam test (no display needed)
# make clean remove built artefacts
# ./ide start the designer (single process)
.PHONY: all lightgui widgets install test clean
# Install location for the XFrame widget headers. The widgets are
# header-only (common/ + core/ + components/), so `make install`
# just copies the headers; generated apps then build with
# -I$(PREFIX)/include/lightgui (see src/generator.cpp).
PREFIX ?= /usr/local
INCLUDEDIR ?= $(PREFIX)/include/lightgui
SRCS := $(wildcard src/*.cpp)
OBJS := $(SRCS:.cpp=.o)
# Headers the .o files depend on (any header change rebuilds them all;
# cheap, and it keeps the rule simple). The generated embedded headers
# are built by their own rules below when missing.
HDRS := $(wildcard src/*.h) ui/designer.ui
GENHDRS := src/indicators_embedded.h src/drawings_embedded.h
all: lightgui widgets
lightgui: $(OBJS) $(GENHDRS)
$(CXX) $(CXXFLAGS) -DLIGHTGUI_GIT_HASH='"$(GIT_HASH)"' -o $@ $(OBJS) $(GTKFLAGS) $(GTKLIBS) $(X11LIBS)
# One .o per .cpp (pattern rule — parallelises under -j).
src/%.o: src/%.cpp $(HDRS) $(GENHDRS) $(WIDGET_HDRS)
$(CXX) $(CXXFLAGS) -DLIGHTGUI_GIT_HASH='"$(GIT_HASH)"' -c $< -o $@ $(GTKFLAGS) $(X11FLAGS) $(WIDGETS_INC)
src/indicators_embedded.h: src/indicators.h tools/embed_indicators.sh
sh tools/embed_indicators.sh src/indicators.h $@
src/drawings_embedded.h: src/drawings.h tools/embed_drawings.sh
sh tools/embed_drawings.sh src/drawings.h $@
widgets:
cmake -S widgets -B widgets/build
# Clear MAKEFLAGS for the submake: the top-level -j in MAKEFLAGS
# would otherwise make it warn "-j forced in submake: resetting
# jobserver mode". cmake still gets -j explicitly, so the widgets
# still build on all cores.
MAKEFLAGS= cmake --build widgets/build -j$(NPROC)
install:
@echo "Installing LightGUI widget headers to $(INCLUDEDIR)"
@mkdir -p $(INCLUDEDIR)
@cd widgets && find common core components -name '*.h' | while read f; do \
install -D -m 644 "$$f" "$(INCLUDEDIR)/$$f"; \
done
@echo "Installed $$(find widgets/common widgets/core widgets/components -name '*.h' | wc -l) headers to $(INCLUDEDIR)"
test:
python3 widgets/tests/test_layout_to_lightgui.py
clean:
rm -f lightgui $(OBJS)
rm -rf widgets/build