diff --git a/.gitignore b/.gitignore index 304a599..a13acf4 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ locale/ taur +build/ diff --git a/Makefile b/Makefile index 947685b..ba474ae 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,27 @@ -CXX ?= g++ -PREFIX ?= /usr -LOCALEDIR ?= $(PREFIX)/share/locale -VARS ?= -DENABLE_NLS=1 - -VERSION = 0.6.4 -BRANCH = libalpm-test -SRC = $(sort $(wildcard src/*.cpp)) -OBJ = $(SRC:.cpp=.o) -LDFLAGS := -L./src/fmt -L./src/cpr -lcpr -lalpm -lfmt -lidn2 -lssh2 -lcurl -lssl -lcrypto -lpsl -lgssapi_krb5 -lzstd -lbrotlidec -lz -CXXFLAGS := -ggdb -pedantic -funroll-all-loops -march=native -isystem include -Wall -std=c++20 $(VARS) -DVERSION=\"$(VERSION)\" -DBRANCH=\"$(BRANCH)\" -DLOCALEDIR=\"$(LOCALEDIR)\" +CXX ?= g++ +PREFIX ?= /usr +LOCALEDIR ?= $(PREFIX)/share/locale +VARS ?= -DENABLE_NLS=1 +DEBUG ?= 1 + +VERSION = 0.6.4 +BRANCH = libalpm-test +SRC = $(sort $(wildcard src/*.cpp)) +OBJ = $(SRC:.cpp=.o) +LDFLAGS := -lcpr -lalpm -lfmt -lidn2 -lssh2 -lcurl -lssl -lcrypto -lpsl -lgssapi_krb5 -lzstd -lbrotlidec -lz +CXXFLAGS := -funroll-all-loops -mtune=generic -march=native -isystem include -std=c++20 $(VARS) -DVERSION=\"$(VERSION)\" -DBRANCH=\"$(BRANCH)\" -DLOCALEDIR=\"$(LOCALEDIR)\" + +# https://stackoverflow.com/a/1079861 +# WAY easier way to build debug and release builds +ifeq ($(DEBUG), 1) + BUILDDIR = build/debug + CXXFLAGS := -ggdb -pedantic -Wall $(CXXFLAGS) +else + BUILDDIR = build/release + CXXFLAGS := -O3 $(CXXFLAGS) +endif + +LDFLAGS := -L./$(BUILDDIR)/fmt -L./$(BUILDDIR)/cpr $(LDFLAGS) is_cpr_installed = $(shell ldconfig -p | grep libcpr > /dev/null && echo -n yes) @@ -19,37 +32,40 @@ ifneq ($(is_cpr_installed), yes) #git submodule init #git submodule update --init --recursive #git -C $@ checkout 3b15fa8 - mkdir -p src/cpr + mkdir -p $(BUILDDIR)/cpr cmake -S $@ -B $@/build -DCMAKE_BUILD_TYPE=Release -DCPR_BUILD_TESTS=OFF -DCPR_USE_SYSTEM_CURL=OFF -DBUILD_SHARED_LIBS=OFF cmake --build $@/build --parallel - mv -f $@/build/lib/*.a src/cpr/ + mv -f $@/build/lib/*.a $(BUILDDIR)/cpr # the absence of this one line didn't matter for a long time, despite it being critical, this caused toni to go mentally insane when trying to make changes to the way the project is being built. mv -f $@/build/cpr_generated_includes/cpr/cprver.h include/cpr/ #sudo cmake --install $@/build --prefix /usr endif fmt: -ifeq ($(wildcard src/fmt/libfmt.a),) - make -C src/fmt +ifeq ($(wildcard $(BUILDDIR)/fmt/libfmt.a),) + mkdir -p $(BUILDDIR)/fmt + make -C src/fmt BUILDDIR=$(BUILDDIR)/fmt endif toml: -ifeq ($(wildcard src/toml++/toml.o),) - make -C src/toml++ +ifeq ($(wildcard $(BUILDDIR)/toml++/toml.o),) + mkdir -p $(BUILDDIR)/toml++ + make -C src/toml++ BUILDDIR=$(BUILDDIR)/toml++ endif locale: scripts/make_mo.sh locale/ -taur: cpr fmt toml ${OBJ} - ${CXX} $(OBJ) src/toml++/toml.o $(CPPFLAGS) -o $@ $(LDFLAGS) +taur: cpr fmt toml $(OBJ) + mkdir -p $(BUILDDIR) + $(CXX) $(OBJ) $(BUILDDIR)/toml++/toml.o -o $(BUILDDIR)/taur $(LDFLAGS) clean: - rm -rf taur $(OBJ) cpr/build + rm -rf $(BUILDDIR)/taur $(OBJ) cpr/build # make -C src/fmt clean install: taur locale - install taur -Dm 755 -v $(DESTDIR)$(PREFIX)/bin/taur + install $(BUILDDIR)/taur -Dm 755 -v $(DESTDIR)$(PREFIX)/bin/taur find locale -type f -exec install -Dm 755 "{}" "$(DESTDIR)$(PREFIX)/share/{}" \; .PHONY: cpr taur clean fmt toml locale install all diff --git a/src/fmt/Makefile b/src/fmt/Makefile index 7e0e289..7decf23 100644 --- a/src/fmt/Makefile +++ b/src/fmt/Makefile @@ -14,9 +14,10 @@ fmt: format.cc os.cc $(CXX) $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -c os.cc -o os.cc.o ar qc libfmt.a os.cc.o format.cc.o ranlib libfmt.a + mv -f libfmt.a ../../$(BUILDDIR)/libfmt.a #$(CXX) -fPIC -O3 -DNDEBUG -shared -Wl,-soname,libfmt.so.10 -o libfmt.so format.cc.o os.cc.o clean: - rm -f *.o *.so *.a + rm -f *.o *.so *.a ../../$(BUILDDIR)/fmt/.*a .PHONY: clean all fmt diff --git a/src/toml++/Makefile b/src/toml++/Makefile index 1e63abe..227d9a8 100644 --- a/src/toml++/Makefile +++ b/src/toml++/Makefile @@ -6,9 +6,9 @@ CPPFLAGS = -I../../include -std=c++20 all: $(TARGET) $(TARGET): - ${CXX} $(SRC) $(CPPFLAGS) -c -o $@ + ${CXX} $(SRC) $(CPPFLAGS) -c -o ../../$(BUILDDIR)/$@ clean: - rm -rf $(TARGET) + rm -rf ../../$(BUILDDIR)/toml++/$(TARGET) .PHONY: $(TARGET) clean all