Last active
September 16, 2018 15:27
-
-
Save bismarckjunior/4eedc5bd36cec812b21b00f7ab1ee630 to your computer and use it in GitHub Desktop.
Makefile
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
#==============================================================================# | |
# Author: Bismarck Gomes <[email protected]> # | |
# # | |
# * # | |
# L bin // Executable folder # | |
# L build // Objects (*.o) # | |
# L data // Example data # | |
# L doc // Documentation # | |
# L examples // Examples # | |
# L include // Public header files (*.h) # | |
# L lib // Library dependencies (*.so, *.dll) # | |
# L src // Source files (*.cpp) and private header files (*.h) # | |
# L test // Test code files # | |
# * makefile # | |
# * readme.md # | |
# # | |
# # Compile # | |
# $ make # | |
# # | |
# # Run # | |
# $ make run # | |
# # | |
# # Clean (just files) # | |
# $ make clean # | |
# # | |
# # Clean (files and folders) # | |
# $ make clobber # | |
#==============================================================================# | |
# Main variables | |
CC := g++ | |
SRCDIR := src | |
BUILDDIR := build | |
TARGET := bin/main | |
# Other variables | |
SOURCES := $(shell find $(SRCDIR) -type f -name *.cpp) | |
OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.cpp=.o)) | |
TARGETDIR := `dirname $(TARGET)` | |
CFLAGS := -g | |
LIB := | |
INC := $(addprefix -I ,$(shell find $(SRCDIR) -type d)) -I include | |
# Target rules | |
all: build | |
build: $(TARGET) | |
run: build | |
./$(TARGET) | |
clean: | |
rm -fr $(OBJECTS) $(TARGET) | |
clobber: | |
rm -fr $(BUILDDIR) $(TARGETDIR) | |
$(BUILDDIR)/%.o: $(SRCDIR)/%.cpp | |
@mkdir -p $(BUILDDIR); | |
$(CC) $(CFLAGS) $(INC) -c -o $@ $< | |
$(TARGET): $(OBJECTS) | |
@mkdir -p $(TARGETDIR); | |
$(CC) $^ -o $(TARGET) $(LIB) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment