Reputation: 885
This is the first makefile I am making, I need you help to change it a little. Here is the makefile I have right now
VPATH = src
BUILD = build
BIN = bin
INCLUDE = C:\Users\sidhi\Desktop\Projects\sfml-snake\internalLibraries\include
$(shell mkdir -p build)
$(shell mkdir -p bin)
CC = g++
CFLAGS = -g -std=c++11
LIBS=-lsfml-graphics -lsfml-window -lsfml-system
G++_VER_LT48 := $(shell expr `$(CC) -dumpversion | cut -f1-2 -d.` \< 4.8 )
ifeq ("$(G++_VER_LT48)","1")
$(error old version of g++ not supported, upgrade to 4.8 or higher)
endif
default: bin/game
$(BIN)/game: $(BUILD)/main.o $(BUILD)/game.o $(BUILD)/food.o $(BUILD)/snake.o
$(CC) $(CFLAGS) -o $(BIN)/game $(BUILD)/main.o $(BUILD)/game.o $(BUILD)/food.o $(BUILD)/snake.o $(LIBS)
$(BUILD)/%.o: %.cpp
$(CC) -c $(CFLAGS) $< -o $@ -I $(INCLUDE)
I want to change it such that, all the files in the build/ directory gets added as a dependency. something like
bin/game: $(BUILD)/%.o
But that doesn't work.
Also, How can I include more path to the VPATH ?
Upvotes: 1
Views: 52
Reputation:
GNU Make has a number of useful built-in functions you can use to generate lists of files. For example, this:
SRCFILES := $(wildcard *.cpp)
creates a list of .cpp files in the current directory, and then this:
OBJFILES := $(patsubst %.cpp,%.o,$(SRCFILES))
performs an edit on that list to create a new list of the corresponding .o files.
Upvotes: 2
Reputation: 117
You could try something like:
OBJ=$(shell find $(PROJDIRS) -type f -name "*.o")
And then:
$(BIN)/game: OBJ
Hope this helps...
Upvotes: -1