This is an incredibly simple question, but I\'m new to makefiles. I am trying to make a makefile that will compile two independent programs:
program1:
gc
SRC = a.cpp b.cpp
BIN = $(patsubst %.cpp,%,$(SRC))
all: $(BIN)
clean:
rm -f $(BIN)
.PHONY: all clean
make all
will do:
c++ a.cpp -o a
c++ b.cpp -o b
If you set CXX
and CXXFLAGS
variables make
will use them.
Do it like so
all: program1 program2
program1: program1.c
gcc -o program1 program1.c
program2: program2.c
gcc -o program2 program2.c
You said you don't want advanced stuff, but you could also shorten it like this based on some default rules.
all: program1 program2
program1: program1.c
program2: program2.c