From 4743f30485daf841283c059307f2b260e5648424 Mon Sep 17 00:00:00 2001 From: "Jan Chren (rindeal)" Date: Sat, 19 Oct 2019 00:14:10 +0200 Subject: [PATCH] Makefile: make it packaging friendly --- src/main/cpp/Makefile | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/src/main/cpp/Makefile b/src/main/cpp/Makefile index bf4cb82..72479c6 100644 --- a/src/main/cpp/Makefile +++ b/src/main/cpp/Makefile @@ -1,22 +1,32 @@ -# set CXX to g++ if not set -CXX ?= g++ +PROGNAME = tiv -# append necessary arguments -override CPPFLAGS += -std=c++17 -Wall -fpermissive -fexceptions -O2 -override LDFLAGS += -lstdc++fs -pthread -s +OBJECTS = tiv.o -all: tiv +CXX ?= g++ +CXXFLAGS ?= -O2 -fpermissive +INSTALL ?= install +INSTALL_PROGRAM ?= $(INSTALL) -D -tiv.o: tiv.cpp CImg.h - $(CXX) $(CPPFLAGS) -c tiv.cpp -o $@ +# https://www.gnu.org/prep/standards/html_node/Directory-Variables.html#Directory-Variables +prefix ?= /usr/local +exec_prefix ?= $(prefix) +bindir ?= $(exec_prefix)/bin -tiv : tiv.o - $(CXX) $^ -o $@ $(LDFLAGS) +override CXXFLAGS += -std=c++17 -Wall -fexceptions +override LDFLAGS += -pthread +override LDLIBS += -lstdc++fs + +all: $(PROGNAME) + +tiv.o: CImg.h + +$(PROGNAME): $(OBJECTS) + $(CXX) $(LDFLAGS) $^ -o $@ $(LOADLIBES) $(LDLIBS) -.PHONY: all install clean install: all - test -d $(DESTDIR)/usr/local/bin || mkdir -p $(DESTDIR)/usr/local/bin - cp tiv $(DESTDIR)/usr/local/bin/tiv + $(INSTALL_PROGRAM) $(PROGNAME) $(DESTDIR)$(bindir)/$(PROGNAME) clean: - rm -f tiv tiv.o + $(RM) -f $(PROGNAME) *.o + +.PHONY: all install clean