# Taken from: https://stackoverflow.com/questions/2214575/passing-arguments-to-make-run # If the first argument is "new"... ifeq (new,$(firstword $(MAKECMDGOALS))) # use the rest as arguments for "new" NEW_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) # ...and turn them into do-nothing targets $(eval $(NEW_ARGS):;@:) endif BIN := $(shell basename $$(pwd)) PLUGINS := $(wildcard modules/*) MAKE += --no-print-directory MANSECTION := 1 MANPAGE := $(BIN).$(MANSECTION) SRCS := $(wildcard *.cpp) OBJS := $(subst .cpp,.o,$(SRCS)) DEPS := $(subst .cpp,.d,$(SRCS)) CXX ?= g++ PKG_CONFIG ?= pkg-config PREFIX ?= /usr/local BINDIR ?= $(PREFIX)/bin CONFIGDIR ?= $(PREFIX)/etc DATADIR ?= $(PREFIX)/share MANDIR ?= $(DATADIR)/man/man DOCDIR ?= $(DATADIR)/$(BIN)/doc RM := /bin/rm -f INSTALL := /usr/bin/install -c CXXFLAGS += -Wshadow -Wall -Wpedantic -Wextra -g -std=c++17 ifeq ($(DEBUG),1) CXXFLAGS += -D DEBUG -O0 else CXXFLAGS += -D NDEBUG -O3 endif LDLIBS := -lm -lscgui -lcairo -lscerror -lscstring -lscscreensaver -lscnumerics LDLIBS += $(shell pkg-config sdl2 --libs) CXXFLAGS += $(shell pkg-config sdl2 --cflags) UNAME_S := $(shell uname -s) ifeq ($(UNAME_S),Darwin) LDLIBS += -ldl endif ifeq ($(UNAME_S),Linux) LDLIBS += -ldl endif .PHONY: all clean install modules new all: $(BIN) modules $(BIN): $(OBJS) $(CXX) $(OBJS) $(LDFLAGS) -o $(BIN) $(LDLIBS) %.o %.d: %.cpp $(CXX) $(CXXFLAGS) -MMD -MP -MT $@ -MF $*.d -c $< -include $(DEPS) new: @./newmodule $(NEW_ARGS) modules: $(PLUGINS) mkdir -p plugins @for plug in $(PLUGINS) ;\ do \ cd $$plug && $(MAKE) && $(MAKE) install ;\ cd ../.. ;\ done clean: $(RM) $(OBJS) $(DEPS) $(BIN) $(RM) -r plugins @for plug in $(PLUGINS) ;\ do \ $(MAKE) -C $$plug clean ;\ done install: $(BIN) $(INSTALL) -d $(BINDIR) $(INSTALL) $(BIN) $(BINDIR) $(INSTALL) -d $(MANDIR)$(MANSECTION) $(INSTALL) -m 444 $(MANPAGE) $(MANDIR)$(MANSECTION) $(INSTALL) -d $(DATADIR)/$(BIN)/plugins $(INSTALL) -m 444 plugins/* $(DATADIR)/$(BIN)/plugins/