# cpp-finally
# Copyright © 2024 František Kučera (Frantovo.cz, GlobalCode.info)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

CXX ?= g++
CXXFLAGS ?= -O2 -g3 -ggdb -Wall -Wno-sign-compare
CXXFLAGS += --std=c++20
CXXFLAGS += -fsanitize=undefined -fsanitize=address
LDFLAGS ?=

SRC = $(shell find -maxdepth 1 -name '*.cpp')
BIN = $(shell find -maxdepth 1 -name '*.cpp' | xargs basename -s .cpp)

all: $(BIN)

.PHONY: all run clean

clean:
	$(RM) $(BIN)

run: $(BIN)
	@echo "\e[1;32mHappy path without exceptions:\e[0m"
	@for bin in $(BIN); do ./$$bin     ; true; done
	@echo; echo
	@echo "\e[1;32mInterrupted by exceptions:\e[0m"
	@for bin in $(BIN); do ./$$bin fail; true; done

$(BIN): $(SRC)
	$(CXX) $(CXXFLAGS) -o $(@) $(@).cpp $(LDFLAGS)

# Blok finally při odchytávání výjimek: C++ vs. Java
# https://blog.frantovo.cz/c/395/
