allow all cpp files in makefile

Im currently using this 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
27
28
29
CC=g++
CFLAGS=-c -I/usr/include/SDL2 -std=c++11 -Wall
LDFLAGS=
FLAGS=-lSDL2 -lSDL2_image
SRC_PATH=data
VPATH=${SRC_PATH}
SOURCES=main.cpp Control.cpp Character.cpp texture_manager.cpp
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=main
BINDIR=/usr/bin


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

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

clean:
	rm *.o $(EXECUTABLE)

install:
	#install -s $(EXECUTABLE) $(BINDIR)
	sudo cp -u $(EXECUTABLE) $(BINDIR)
uninstall:
	sudo rm $(BINDIR)/$(EXECUTABLE)


I have been tweaking it here and there to my linking. There is one problem still...
Every file i add, i need to add in the makefile as well. Is there a way that i can have only the root file main.cpp and not have to add in the inevitable tons of other source files to come? Is there a way to pull from main.cpp the included headers/files, and pull from them, etc.?
Last edited on
See https://www.gnu.org/software/make/manual/html_node/Wildcard-Function.html#Wildcard-Function

However, then you cannot have other *.cpp files in the same directory.


Look up CMake. It does not solve your problem directly, but offers more fun nevertheless.
Topic archived. No new replies allowed.