I have following makefile:
CC = g++
CFLAGS=-c -Wall
all: myProgram
myProgram: obj/main.o obj/Class1.o obj/Class2.o
$(CC) -o bin/myProgram obj/main.o obj/Class1.o obj/Class2.o
obj/main.o: main.cpp
$(CC) $(CFLAGS) main.cpp -o obj/main.o
obj/Class1.o: src/Class1.cpp
$(CC) $(CFLAGS) src/Class1.cpp -o obj/Class1.o
obj/Class2.o: src/Class2.cpp
$(CC) $(CFLAGS) src/Class2.cpp -o obj/Class2.o
The idea is I have such structure of files/directories:
/project
Makefile
main.cpp
/src
Class1.cpp
Class2.cpp
/obj
Class1.obj
Class2.obj
/bin
myProgram
/inc
Class1.h
Class2.h
The makefiles takes sources and object files in these directories and outputs them in /bin as myProgram
.
I know my makefile might not look very ideal but anyway. I want to learn how to create makefiles, so what do you recommend I add to my makefile, or learn additionally about makefiles as a next step to improve my knowledge? (I might be working on a project where I will need to know makefiles, so I am trying to learn them)