Skip to content

Commit

Permalink
improved Makefile
Browse files Browse the repository at this point in the history
added ability to build in Release mode as well as Debug mode. To build in Debug run `make [...] DEBUG=1`
By default, `make [...]` will build as a Release
  • Loading branch information
alexlnkp committed Apr 15, 2024
1 parent 24dcb6d commit 78f34c5
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@
# 'make clean' removes all .o and executable files
#

# Debug mode is disabled by default. To build in debug, use `make DEBUG=1`
DEBUG=

# CXX compiler to use
CXX = g++

LIBRARIES := libcurl

CXXFLAGS := `pkg-config --cflags $(LIBRARIES)` -std=c++20 -O3 -Wall -Wextra -g
CFLAGS_DEBUG=-g
CFLAGS_RELEASE=-O3

CXXFLAGS_COMMON := `pkg-config --cflags $(LIBRARIES)` -std=c++20 -Wall -Wextra
CXXFLAGS_DEBUG := $(CXXFLAGS_COMMON) $(CFLAGS_DEBUG)
CXXFLAGS_RELEASE := $(CXXFLAGS_COMMON) $(CFLAGS_RELEASE)

LFLAGS = `pkg-config --libs $(LIBRARIES)`

OUTPUT := output
Expand Down Expand Up @@ -54,7 +63,16 @@ DEPS := $(OBJECTS:.o=.d)

OUTPUTMAIN := $(call FIXPATH,$(OUTPUT)/$(MAIN))

ifeq ($(DEBUG), 1)
CXXFLAGS:=$(CXXFLAGS) $(CXXFLAGS_DEBUG)
MODESTR := Debug
else
CXXFLAGS:=$(CXXFLAGS) $(CXXFLAGS_RELEASE)
MODESTR := Release
endif

all: $(OUTPUT) $(MAIN)
$(info Building in $(MODESTR) mode)
@echo Executing 'all' complete!

$(OUTPUT):
Expand All @@ -68,7 +86,8 @@ $(MAIN): $(OBJECTS)
.cpp.o:
$(CXX) $(CXXFLAGS) $(INCLUDES) -c -MMD $< -o $@

.PHONY: clean
.PHONY: clean run

clean:
$(RM) $(OUTPUTMAIN)
$(RM) $(call FIXPATH,$(OBJECTS))
Expand Down

0 comments on commit 78f34c5

Please sign in to comment.