====== Simple makefile example using built-in default rules ====== Sometimes you just want a quick rule set to compile and build a simple project. This article provides the simplest form of makefile that you can use. ===== Simple makefile example ===== The makefile in this example assumes that your sources are in ./src and include files are in ./inc CFLAGS=-DFLAG1 -DFLAG2 CC=gcc INCLUDES=-I inc/ OBJS= src/file1.o src/file2.o #r!ls src/*.o | xargs %.o : %.c $(CC) -c $(CFLAGS) $(INCLUDES) $< -o $@ binary1: $(OBJS) src/binary1.o $(CC) $(CFLAGS) $(INCLUDES) src/binary1.o $(OBJS) -o binary1 binary2: $(OBJS) src/binary2.o $(CC) $(CFLAGS) $(INCLUDES) src/binary2.o $(OBJS) -o binary2 clean: rm -rf src/*.o binary1 binary2 {{tag>unix howto coding}} ~~DISCUSSION~~