Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 83 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,33 +1,97 @@
# Makefile do projeto de processamento de imagem - ITP 2019.1
# Note:
# Copied from: https://gist.github.com/maurizzzio/de8908f67923091982c8c8136a063ea6
# Generic Makefile example for a C++ project
#
CXX ?= gcc

# pastas do projeto
SRCDIR = ./src
INCDIR = ./include
BINDIR = ./bin
# path #
SRC_PATH = src
BUILD_PATH = build
BIN_PATH = $(BUILD_PATH)/bin
DOCS_PATH = docs

# compilador e flags
CC = gcc
CFLAGS = -Wall -lm
# executable #
BIN_NAME = proj

# nome do projeto (executavel)
PROJ_NAME = proj
# extensions #
SRC_EXT = cpp

all: proj
# code lists #
# Find all source files in the source directory, sorted by
# most recently modified
SOURCES = $(shell find $(SRC_PATH) -name '*.$(SRC_EXT)' | sort -k 1nr | cut -f2-)
# Set the object file names, with the source directory stripped
# from the path, and the build path prepended in its place
OBJECTS = $(SOURCES:$(SRC_PATH)/%.$(SRC_EXT)=$(BUILD_PATH)/%.o)
# Set the dependency files that will be used to add header dependencies
DEPS = $(OBJECTS:.o=.d)

proj: bin_folder
$(CC) $(SRCDIR)/*.c $(CFLAGS) -I $(INCDIR) -o $(BINDIR)/$(PROJ_NAME)
@ln -sfv $(BINDIR)/$(PROJ_NAME) $(PROJ_NAME) # cria um link simbólico
@echo "Compilado com sucesso! Para executar digite ./$(PROJ_NAME) imagem.ppm"
# flags #
OPTIMIZE = -O03
DEBUG = -g -D BACKTRACKING_PLAYER
COMPILE_FLAGS = -Wall -Wextra -g -lm
INCLUDES = -I include/
#INCLUDES = -I include/ -I /usr/local/include
# Space-separated pkg-config libraries used by this project
LIBS =

.PHONY: default_target
default_target: release

.PHONY: debug
debug: export CXXFLAGS := $(CXXFLAGS) $(COMPILE_FLAGS) $(DEBUG)
debug: dirs
@$(MAKE) all

bin_folder:
@mkdir -p $(BINDIR)
.PHONY: release
release: export CXXFLAGS := $(CXXFLAGS) $(COMPILE_FLAGS) $(OPTIMIZE)
release: dirs
@$(MAKE) all

.PHONY: dirs
dirs:
@echo "Creating directories"
@mkdir -p $(dir $(OBJECTS))
@mkdir -p $(BIN_PATH)

.PHONY: clean
clean:
@rm -f $(PROJ_NAME)
@rm -rf $(BINDIR)
@echo "Deleting $(BIN_NAME) symlink"
@$(RM) $(BIN_NAME)
@echo "Deleting directories"
@$(RM) -r $(BUILD_PATH)
@$(RM) -r $(BIN_PATH)
@$(RM) -r $(DOCS_PATH)
@echo "Binários excluidos com sucesso!"

# checks the executable and symlinks to the output
.PHONY: all
all: project docs

.PHONY: project
project: $(BIN_PATH)/$(BIN_NAME)
@echo "Making symlink: $(BIN_NAME) -> $<"
@$(RM) $(BIN_NAME)
@ln -s $(BIN_PATH)/$(BIN_NAME) $(BIN_NAME)
@echo "Compilado com sucesso! Para executar digite ./$(PROJ_NAME) imagem.ppm"

# Creation of the executable
$(BIN_PATH)/$(BIN_NAME): $(OBJECTS)
@echo " "
@echo "Linking: $@"
$(CXX) $(OBJECTS) -o $@

# Add dependency files, if they exist
-include $(DEPS)

# Creates a Doxygen file
docs:
@echo "Generating Documentation"
@doxygen config

# Source file rules
# After the first compilation they will be joined with the rules from the
# dependency files to provide header dependencies
$(BUILD_PATH)/%.o: $(SRC_PATH)/%.$(SRC_EXT)
@echo "Compiling: $< -> $@"
$(CXX) $(CXXFLAGS) $(INCLUDES) -MP -MMD -c $< -o $@