Last active
October 20, 2023 15:18
-
-
Save urin/5971408 to your computer and use it in GitHub Desktop.
makefile - simple template to make an executable from *.cpp files.
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
COMPILER = g++ | |
CFLAGS = -g -MMD -MP -Wall -Wextra -Winit-self -Wno-missing-field-initializers | |
ifeq "$(shell getconf LONG_BIT)" "64" | |
LDFLAGS = | |
else | |
LDFLAGS = | |
endif | |
LIBS = | |
INCLUDE = -I./include | |
TARGET = ./bin/$(shell basename `readlink -f .`) | |
SRCDIR = ./source | |
ifeq "$(strip $(SRCDIR))" "" | |
SRCDIR = . | |
endif | |
SOURCES = $(wildcard $(SRCDIR)/*.cpp) | |
OBJDIR = ./obj | |
ifeq "$(strip $(OBJDIR))" "" | |
OBJDIR = . | |
endif | |
OBJECTS = $(addprefix $(OBJDIR)/, $(notdir $(SOURCES:.cpp=.o))) | |
DEPENDS = $(OBJECTS:.o=.d) | |
$(TARGET): $(OBJECTS) $(LIBS) | |
$(COMPILER) -o $@ $^ $(LDFLAGS) | |
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp | |
-mkdir -p $(OBJDIR) | |
$(COMPILER) $(CFLAGS) $(INCLUDE) -o $@ -c $< | |
all: clean $(TARGET) | |
clean: | |
-rm -f $(OBJECTS) $(DEPENDS) $(TARGET) | |
-include $(DEPENDS) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment