Last active
July 1, 2023 20:55
-
-
Save samuelsmal/e43f2001cfc81fee18b6 to your computer and use it in GitHub Desktop.
Generic clang++ (or c++ for that matter) makefile with directory structure
This file contains 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
# Requires the following project directory structure: | |
# /bin | |
# /obj | |
# /src | |
# Use 'make remove' to clean up the hole project | |
# Name of target file | |
TARGET = foooooooobar | |
CXX = clang++ | |
CXXFLAGS = -std=c++11 \ | |
-Weverything -Wall -Wextra -Werror -Wpointer-arith -Wcast-qual \ | |
-Wno-missing-braces -Wempty-body -Wno-error=uninitialized \ | |
-Wno-error=deprecated-declarations \ | |
-pedantic-errors -pedantic \ | |
-Os | |
LD = clang++ -o | |
LDFLAGS = -Wall -pedantic | |
SRCDIR = src | |
OBJDIR = obj | |
BINDIR = bin | |
SOURCES := $(wildcard $(SRCDIR)/*.cpp) | |
INCLUDES := $(wildcard $(SRCDIR)/*.h) | |
OBJECTS := $(SOURCES:$(SRCDIR)/%.cpp=$(OBJDIR)/%.o) | |
RM = rm -f | |
$(BINDIR)/$(TARGET): $(OBJECTS) | |
@$(LD) $@ $(LDFLAGS) $(OBJECTS) | |
@echo "Linking complete!" | |
$(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.cpp | |
@$(CXX) $(CXXFLAGS) -c $< -o $@ | |
@echo "Compiled "$<" successfully!" | |
.PHONY: clean | |
clean: | |
@$(RM) $(OBJECTS) | |
@echo "Cleanup complete!" | |
.PHONY: remove | |
remove: clean | |
@$(RM) $(BINDIR)/$(TARGET) | |
@echo "Executable removed!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks /u/Leandros99, /u/skoink and /u/dangerbird2.