program structure using a makefile

Currently my program is structured like:
1
2
3
4
5
6
7
8
program/
    makefile
    main.cpp
    ...cpp_files
    ...header_files
    resources/
        images/
            ...image_files


but i want to structure it like:
1
2
3
4
5
6
7
8
9
10
program/
    makefile
    data/
        main.cpp
        ...cpp_files
        include/
            ...header_files
        resources/
            images/
                ...image_files


Currently i can compile it OK, but the method is very messy. For example: i have to access my image files as "data/resources/images/waver.png", preceeded with "data", when the cpp file that calls that image is in data. So it makes it confusing. Or in my makefile i have to access all the cpp files preceeded with data as well.
SOURCES=data/main.cpp data/Control.cpp data/Character.cpp data/texture_manager.cpp
as opposed to:
SOURCES=main.cpp Control.cpp Character.cpp texture_manager.cpp

Is there a way i can change directory into the data file from my makefile so the starting point is within data/?

my makefile:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
CC=g++
CFLAGS=-c -I/usr/include/SDL2 -std=c++11 -Wall
LDFLAGS=
FLAGS=-lSDL2 -lSDL2_image
SOURCES=data/main.cpp data/Control.cpp data/Character.cpp data/texture_manager.cpp
DATA=data
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=main
BINDIR=/usr/bin

all: $(SOURCES) $(EXECUTABLE)
        
$(EXECUTABLE): $(OBJECTS)
	$(CC) $(LDFLAGS) $(OBJECTS) -o $@ $(FLAGS)

.cpp.o:
	$(CC) $(CFLAGS) $< -o $@ $(FLAGS)

clean:
	rm $(DATA)/*.o $(EXECUTABLE)

install:
	#install -s $(EXECUTABLE) $(BINDIR)
	sudo cp -u $(EXECUTABLE) $(BINDIR)
uninstall:
	sudo rm $(BINDIR)/$(EXECUTABLE) */
Last edited on
i think i migfht of found the answer with VPATH in my makefile
1
2
3
SRC_PATH=data
VPATH=${SRC_PATH}
SOURCES=main.cpp Control.cpp Character.cpp texture_manager.cpp

This fixes this issue apparently, but the path to the image files still need to preceed with "data". Is there another method that will also help with this?
Topic archived. No new replies allowed.