Last active
January 3, 2022 22:55
-
-
Save viniciusrplima/367bc34858f930fe9d6d612b97851957 to your computer and use it in GitHub Desktop.
Default Makefile to C++ programs in linux systems
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.PHONY: clean run | |
.DEFAULT: build | |
EXEC_FILE=launcher | |
CXX=g++ | |
SRC_DIR=./src | |
BUILD_DIR=./build | |
SRCS:=$(shell find $(SRC_DIR) -name *.cpp) | |
OBJS:=$(SRCS:%=$(BUILD_DIR)/%.o) | |
CPPINCS= # include paths | |
CPPLIBS= # extra libraries | |
build: $(EXEC_FILE) | |
$(EXEC_FILE): $(OBJS) | |
$(CXX) $(OBJS) -o $@ $(CPPLIBS) | |
$(BUILD_DIR)/%.cpp.o: %.cpp | |
-mkdir -p $(dir $@) | |
$(CXX) -c $< -o $@ $(CPPINCS) | |
clean: | |
-rm $(EXEC_FILE) $(OBJS) | |
run: build | |
./$(EXEC_FILE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment