A Handy Makefile


#1

Here’s a handy Makefile I use:

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

all: create run

clear:
	rm copy
create:
	make copy
run:
	./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'
./copy
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?


#2

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.


#3

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

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