Skip to content

Commit

Permalink
feat: tweak simplest possible c++ setup to work under MinGW as well
Browse files Browse the repository at this point in the history
  • Loading branch information
matihost committed Dec 1, 2024
1 parent 8bd98d1 commit ecf6178
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
34 changes: 24 additions & 10 deletions c++/learning/Makefile
Original file line number Diff line number Diff line change
@@ -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
7 changes: 3 additions & 4 deletions c++/learning/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

0 comments on commit ecf6178

Please sign in to comment.