Skip to content

Instantly share code, notes, and snippets.

@bismarckjunior
Last active September 16, 2018 15:27
Show Gist options
  • Save bismarckjunior/4eedc5bd36cec812b21b00f7ab1ee630 to your computer and use it in GitHub Desktop.
Save bismarckjunior/4eedc5bd36cec812b21b00f7ab1ee630 to your computer and use it in GitHub Desktop.
Makefile
#==============================================================================#
# Author: Bismarck Gomes <bismarckgomes@gmail.com> #
# #
# * #
# 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