diff options
author | 2024-03-13 18:54:36 +0600 | |
---|---|---|
committer | 2024-03-13 18:54:36 +0600 | |
commit | 6658af9911170425e918b49b0ebd83ad0d04ad7f (patch) | |
tree | 8cf45613649244d545cb5a8f600cf4d311835698 | |
parent | 671e2cb61cc4b264a774ca538eb3e6673def8a28 (diff) | |
download | entropy-calc-6658af9911170425e918b49b0ebd83ad0d04ad7f.tar.gz entropy-calc-6658af9911170425e918b49b0ebd83ad0d04ad7f.zip |
Create makefile
Signed-off-by: Mubashshir <ahmubashshir@gmail.com>
-rw-r--r-- | Makefile | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6a4bf4f --- /dev/null +++ b/Makefile @@ -0,0 +1,104 @@ +# if $CXX is not set, guess default `cxx'. It has to be in system +CXX ?= cxx +# compile options +CXXFLAGS ?= -Os -Wall -Wpedantic -Wextra +# link options +LDFLAGS ?= -s + +target ?= debug +<<targets>> := debug release +# addons +with ?= gmp +without ?= +<<addons>> := gmp + +# Echo function +<< := echo +ifneq ($(shell eval 'echo -e'),-e) + << += -e +endif + +<<debug-dir> = Debug +<<release-dir>>= Release +<<target>> = $(firstword $(filter $(<<targets>>),$(target))) +ifeq ($(<<target>>),release) + <<tdir>> = Release +else + <<tdir>> = Debug +endif + +# optional addons +<<with>> = $(sort $(filter-out $(without),$(filter $(<<addons>>),$(with)))) +# project configs +CXXFLAGS += -I$(PWD)/headers -I$(PWD)/ + +# rebuild on optional deps change +ifneq ($(filter gmp,$(<<with>>)),) + ifneq ($(shell pkg-config --exists gmp gmpxx && echo exists),) + PKGS += gmpxx gmp + CFLAGS += -D_USE_GMP + endif +endif + +ifneq ($(PKGS),) + CXXFLAGS += $(shell pkg-config --cflags $(PKGS)) + LDFLAGS += $(shell pkg-config --libs $(PKGS)) +endif + +<<sources>> := \ + main.cpp \ + headers/allElements.cpp \ + headers/readElementState.cpp + + +<<objects>> := $(<<sources>>:%=obj/$(<<tdir>>)/%.o) + +# Output file name +ifeq ($(filter $(shell uname -o),Msys Cygwin),) + BINARY ?= entropy-calculator +else + ifeq ($(MSYSTEM_CARCH),i686) + BINARY ?= entropy-calculator.exe + else + BINARY ?= entropy-calculator64.exe + endif +endif + +<<bindep>> = bin/$(<<tdir>>)/.$(BINARY).dep +<<binpth>> = bin/$(<<tdir>>)/$(BINARY) +<<->> := $(shell mkdir -p $(dir $(<<binpth>>))) +# Use $(<<bindep>>) file to track backend change +<<depends>> = $(sort $(<<with>>)) +ifneq ($(sort $(file < $(<<bindep>>))),$(<<depends>>)) + <<null>> := $(file > $(<<bindep>>),$(<<depends>>)) +endif +undefine <<depends>> <<null>> <<->> +# using some makefile sorcery + +all: $(<<binpth>>) + +obj/$(<<tdir>>)/%.o: % + @$(<<) " CXX\t" $(<:src/%=%) + @mkdir -p $(shell dirname $(@)) + @$(CXX) -c $(<) -o $(@) $(CXXFLAGS) + +$(<<binpth>>): $(<<objects>>) + @if test -n "$(<<with>>)"; then $(<<) "WITH\t" $(<<with>>);fi + @$(<<) "LINK\t" "$(BINARY)$(^:obj/%=\\n\\t + %)" + @$(CXX) $(^) -o $(@) $(LDFLAGS) + +install: $(<<binpth>>) + install -Dm0755 $(<) $(DESTDIR)$(PREFIX)/$(BINDIR)/$(BINARY) + +uninstall: + sudo $(RM) -f $(DESTDIR)$(PREFIX)/$(BINDIR)/$(BINARY) + +clean: + @$(<<) " RM\t" "$(BINARY)$(<<objects>>:obj/%=\\n\\t + %)" + @$(RM) -f $(<<objects>>) $(<<binpth>>) $(<<bindep>>) + +test: $(BINARY) + ./$(BINARY) + +$(<<objects>>): $(<<bindep>>) +.PHONY: all clean install uninstall test |