A Handy Makefile

Here’s a handy Makefile I use:

me@debian:~/lcthw/code/ex13$ cat Makefile
CFLAGS = -Wall -g

all: create run

	rm copy
	make copy

in each exercise I copy the Ex.c file to copy.c and just run make.

me@debian:~/lcthw/code/ex13$ cp ex13.c copy.c
me@debian:~/lcthw/code/ex13$ make
make copy
make[1]: Entering directory '/home/me/lcthw/code/ex13'
cc -Wall -g    copy.c   -o copy
make[1]: Leaving directory '/home/me/lcthw/code/ex13'
state 0: California
state 1: Oregon
state 2: Washington
state 3: Texas

after each change to copy.c I run make to update the file
and the original stays intact :slight_smile:

What’s your Makefile?

1 Like

Looking good. You can use variables in the Makefile to make it possible to build anything without copy.c. See if you can figure it out and if not bug me.

That’s indeed nifty. Gives me more ideas for mine.

I just finished ex16 and I’ve lumped all my *.c files in the same folder so far. I keep a really simple makefile but with a handy cleanup:

all: clean ex16

CFLAGS=-Wall -g

	rm $(shell ls --hide="*.c" --hide="Makefile")