- Compile each src/*.cpp to its own .o (pattern rule) then link, so the designer build parallelises under -j. - MAKEFLAGS += -j$(NPROC) makes parallelism the default: plain make / make lightgui / make all use all 8 cores with no -j to remember. - SRCS := $(wildcard src/*.cpp) so a .cpp added later is compiled as its own .o automatically, with no Makefile edit. - widgets target clears MAKEFLAGS for its submake to avoid the -j forced in submake jobserver warning (cmake still gets -j). - clean now also removes the .o files. Same flags, same -DLIGHTGUI_GIT_HASH, same binary name and targets. - Verified: clean make lightgui 36s (was 83s single-core), max 8 concurrent cc1plus, SELFTEST PASS, dummy new.cpp picked up automatically, full make clean, widgets target still works.
64 lines
2.6 KiB
Makefile
64 lines
2.6 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)
|
|
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 test run the layout -> LightGUI seam test (no display needed)
|
|
# make clean remove built artefacts
|
|
# ./ide start the combined IDE (designer + palette + layout)
|
|
.PHONY: all lightgui widgets test clean
|
|
|
|
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)
|
|
|
|
# One .o per .cpp (pattern rule — parallelises under -j).
|
|
src/%.o: src/%.cpp $(HDRS) $(GENHDRS)
|
|
$(CXX) $(CXXFLAGS) -DLIGHTGUI_GIT_HASH='"$(GIT_HASH)"' -c $< -o $@ $(GTKFLAGS)
|
|
|
|
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)
|
|
|
|
test:
|
|
python3 widgets/tests/test_layout_to_lightgui.py
|
|
|
|
clean:
|
|
rm -f lightgui $(OBJS)
|
|
rm -rf widgets/build
|