HiveBrain v1.2.0
Get Started
← Back to all entries
patterncppMinor

Makefile for refactored recursive breadth first search Knight Tour

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
tourmakefilesearchbreadthrefactoredrecursivefirstforknight

Problem

This is my first hand crafted makefile in quite a while. I thought it might be useful for anyone who wants to review the Knights Tour - Improved Refactored Recursive Breadth First Search.

I believe there is a lot of room for improvement on this makefile.

The C++ source code as well as the makefile can be found on github.

```
RM := rm -rf

OBJ_DIR := obj

BIN_DIR := bin

SRC_DIR := # src/

DIRS := $(OBJ_DIR) $(BIN_DIR)

EXECUTABLES := KnightMovesRefactored

# All Target
all: $(DIRS) $(EXECUTABLES)

# Add inputs and outputs from these tool invocations to the build variables
OBJS += $(OBJ_DIR)/KMBoardLocation.o $(OBJ_DIR)/KMMove.o $(OBJ_DIR)/KMMoveFilters.o \
$(OBJ_DIR)/KMOutputData.o $(OBJ_DIR)/KMPath.o $(OBJ_DIR)/KnightMoves.o \
$(OBJ_DIR)/KnightMovesImplementation.o

obj/%.o: $(SRC_DIR)%.cpp
@echo 'Building file: $<'
@echo 'Invoking: GCC C++ Compiler'
g++ -std=c++0x -D__cplusplus=201103L -O3 -Wall -c -o "$@" "$<" # Production
# g++ -std=c++0x -D__cplusplus=201103L -O0 -g3 -Wall -c -o "$@" "$<" # Debug
@echo 'Finished building: $<'
@echo ' '

obj/KMBoardLocation.o: $(SRC_DIR)KMBoardLocation.cpp $(SRC_DIR)KnightMoves.h \
$(SRC_DIR)KMMethodLimitations.h $(SRC_DIR)KMBaseData.h \
$(SRC_DIR)KMBoardLocation.h $(SRC_DIR)KMBoardDimensionConstants.h

obj/KMMove.o: $(SRC_DIR)KMMove.cpp $(SRC_DIR)KMMove.h $(SRC_DIR)KMBoardLocation.h \
$(SRC_DIR)KMBoardDimensionConstants.h

obj/KMMoveFilters.o: $(SRC_DIR)KMMoveFilters.cpp \
$(SRC_DIR)KMBoardDimensionConstants.h $(SRC_DIR)KMMoveFilters.h \
$(SRC_DIR)KnightMoves.h $(SRC_DIR)KMMethodLimitations.h $(SRC_DIR)KMBaseData.h \
$(SRC_DIR)KMMove.h $(SRC_DIR)KMBoardLocation.h

obj/KMOutputData.o: $(SRC_DIR)KMOutputData.cpp $(SRC_DIR)KMOutputData.h \
$(SRC_DIR)KMPath.h $(SRC_DIR)KMBoardLocation.h $(SRC_DIR)KMMove.h \
$(SRC_DIR)KnightMoves.h $(SRC_DIR)KMMethodLimitations.h $(SRC_DIR)KMBaseData.h

obj/KMPath.o: $(SRC_DIR)KMPath.cpp $(SRC_DIR)KMPath.h $(SRC_DIR)KMBoardLocation.h \
$(SRC_DIR)KMMove.h $(SRC_D

Solution

I am too lazy to use just make and write Makefiles by hand. I would use some build system like:

  • autotools



  • cmake



  • Boost.Build



What I would definitely not do by hand is keeping header dependencies for compilation units in Makefile. If for some reason you don't want to use any build system you might at least utilize g++ to generate this.

Check g++ -M and/or this questions:

  • https://stackoverflow.com/questions/11855386/using-g-with-mmd-in-makefile-to-automatically-generate-dependencies



  • https://stackoverflow.com/questions/20476377/how-to-get-g-to-list-paths-to-all-included-files



Are you sure you need this list of empty targets?

$(SRC_DIR)KnightMoves.h:

$(SRC_DIR)KMMethodLimitations.h:

...

Code Snippets

$(SRC_DIR)KnightMoves.h:

$(SRC_DIR)KMMethodLimitations.h:

...

Context

StackExchange Code Review Q#133050, answer score: 2

Revisions (0)

No revisions yet.