Skip to content

Commit

Permalink
project: add debug and release builds
Browse files Browse the repository at this point in the history
  • Loading branch information
Toni500github committed May 15, 2024
1 parent 0f53190 commit 0585b79
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@

locale/
taur
build/
58 changes: 37 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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
3 changes: 2 additions & 1 deletion src/fmt/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/toml++/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0585b79

Please sign in to comment.