Build multiple sources into multiple targets in a directory
Posted
by
Taschetto
on Stack Overflow
See other posts from Stack Overflow
or by Taschetto
Published on 2014-08-19T18:21:23Z
Indexed on
2014/08/19
22:20 UTC
Read the original article
Hit count: 164
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?
© Stack Overflow or respective owner