diff --git a/c++/learning/Makefile b/c++/learning/Makefile index efc4dd3..2b3c8f1 100644 --- a/c++/learning/Makefile +++ b/c++/learning/Makefile @@ -1,18 +1,32 @@ CXX = g++ CXXFLAGS = -g -Wall -TARGET = main.out SRC = $(wildcard *.cpp) OBJ = $(SRC:.cpp=.o) -all: $(TARGET) +ifeq ($(OS),Windows_NT) + TARGET = main.exe + RM = del /Q +else + TARGET = main.out + RM = rm -f +endif -# Build target -$(TARGET): $(OBJ) - $(CXX) $(CXXFLAGS) $(OBJ) -o $(TARGET) +build: $(TARGET) ## build app -%.o: %.cpp - $(CXX) $(CXXFLAGS) -c $< -o $@ +run: build ## build and run app + @./$(TARGET) -# Clean target -clean: - rm -f $(TARGET) $(OBJ) +$(TARGET): $(OBJ) ## cbuild app + @$(CXX) $(CXXFLAGS) $(OBJ) -o $(TARGET) + +%.o: %.cpp ## compile .cpp files + @$(CXX) $(CXXFLAGS) -c $< -o $@ + +clean: ## remove intermediate build files and compiled application + @$(RM) $(TARGET) $(OBJ) + + +help: ## show usage and tasks (default) + @eval $$(sed -E -n 's/^([\*\.a-zA-Z0-9_-]+):.*?## (.*)$$/printf "\\033[36m%-30s\\033[0m %s\\n" "\1" "\2" ;/; ta; b; :a p' $(MAKEFILE_LIST)) +.DEFAULT_GOAL := help +.PHONY: help run clean build diff --git a/c++/learning/README.md b/c++/learning/README.md index f91ef58..4a96cf1 100644 --- a/c++/learning/README.md +++ b/c++/learning/README.md @@ -14,9 +14,8 @@ sudo apt -y install build-essential ## Building from code ```bash -# to build application -make - -# to remove intermediate build files and compiled application +# build and run app +make run +# remove intermediate build files and compiled application make clean ```