pw/Makefile

71 lines
1.4 KiB
Makefile
Raw Normal View History

2021-11-05 16:47:27 +01:00
include premake.make
BIN := $(shell basename $$(pwd))
2022-06-18 15:52:07 +02:00
MANSECTION ?= 1
2021-11-05 16:47:27 +01:00
MANPAGE := $(BIN).$(MANSECTION)
SRCS := $(notdir $(wildcard src/*.cpp))
OBJS := $(SRCS:.cpp=.o)
2023-03-23 19:25:37 +01:00
DEPS := $(SRCS:.cpp=.d)
2021-11-05 16:47:27 +01:00
BUILDDIR := build/intermediates/
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
2022-06-18 15:52:07 +02:00
MANDIR ?= $(PREFIX)/man/man
2021-11-05 16:47:27 +01:00
CONFIGDIR ?= $(PREFIX)/etc
DATADIR ?= $(PREFIX)/share
DOCDIR ?= $(DATADIR)/$(BIN)/doc
CXX ?= g++
RM := /bin/rm -rf
INSTALL := /usr/bin/install -c
CXXFLAGS += -Wshadow -Wall -Wpedantic -Wextra -g -std=c++17
2021-11-05 16:47:27 +01:00
ifeq ($(DEBUG),1)
CXXFLAGS += -D DEBUG -O0
CONFIG := debug
else
CXXFLAGS += -D NDEBUG -O3
CONFIG := release
endif
OUTDIR := build/$(CONFIG)/
vpath %.cpp src
vpath %.d $(BUILDDIR)
vpath %.o $(BUILDDIR)
.PHONY: all clean install prebuild test dist-clean
all: prebuild $(OUTDIR)$(BIN)
prebuild:
@mkdir -p $(BUILDDIR) $(OUTDIR)
2023-02-09 17:04:21 +01:00
$(OUTDIR)$(BIN): $(OBJS)
2024-03-28 15:25:09 +01:00
$(CXX) -o $(OUTDIR)$(BIN) $(LDFLAGS) $(addprefix $(BUILDDIR),$(OBJS)) $(LDLIBS)
2021-11-05 16:47:27 +01:00
@ln -sf $(OUTDIR)$(BIN) $(BIN)
2023-02-09 17:04:21 +01:00
%.o %.d: %.cpp
2021-11-05 16:47:27 +01:00
$(CXX) $(CXXFLAGS) -MMD -MP -MT $@ -MF $*.d -c $<
@mv $@ $*.d $(BUILDDIR)
2023-03-23 19:25:37 +01:00
-include $(addprefix $(BUILDDIR), $(DEPS))
2021-11-05 16:47:27 +01:00
test:
$(MAKE) -C tests && tests/tests
clean:
$(RM) $(BUILDDIR)
$(MAKE) -C tests clean
dist-clean:
$(RM) build $(BIN)
$(MAKE) -C tests clean
2022-06-18 15:52:07 +02:00
install:
2021-11-05 16:47:27 +01:00
$(INSTALL) -d $(BINDIR)
$(INSTALL) $(OUTDIR)$(BIN) $(BINDIR)
$(INSTALL) -d $(MANDIR)$(MANSECTION)
$(INSTALL) -m 0644 $(MANPAGE) $(MANDIR)$(MANSECTION)