Build multiple sources into multiple targets in a directory
- by Taschetto
folks. I'm learning about GNU-Make and I have the following project structure:
~/projects
/sysCalls
ex1.c
ex2.c
ex3.c
ex4.c
ex5.c
ex6.c
ex7.c
Each .c source is very simple, has its own main function and must be built into a corresponding binary (preferably named after its source). But I want to build into a bin directory (added to my .gitignore file).
My current Makefile is:
CC := gcc
CFLAGS := -Wall -g
SRC := $(wildcard *.c)
TARGET := $(SRC:.c=)
all: bin $(TARGET)
mv $(TARGET) bin/
bin:
mkdir bin
clean:
rm -fr bin/
It works as expected, but always builds every source. And I don't like moving everything to bin "manually".
Any tips or ideas on how this Makefile could be improved?