Reputation: 1238
I am trying to write a make file that:
1) Turns the files myftpserver.c and myftpclient.c into myftpserver.o and myftpclient.o by just typing the command 'make'.
2)I'm also adding a 'clean' target for cleaning up the directory (removing all temporary files, object files and executable files)
3)using gcc compiler.
My current version is not working:
CC=gcc
myftpserver: myftpserver.o
$(CC) -o myftpserver.o
myftpclient: myftpclient.o
$(CC) -o myftpclient.o
clean: ? // not sure what to put here
This is my first time making a makefile. I've tried several other combinations but none seems to work. What am I doing wrong?
Upvotes: 2
Views: 108
Reputation: 20026
Make has rules built-in for basic C files, so you don't need to tell it how to build myftpserver.o
or myftpclient.o
. This Makefile should work correctly, and properly includes .PHONY
so the clean
rule won't get disabled in the presence of a file named "clean"
CC:=gcc
.PHONY: clean all
all: myftpserver myftpclient
myftpserver: myftpserver.o
myftpclient: myftpclient.o
clean:
rm -f *~ *.o myftpserver myftpclient
To test:
$ make --dry-run
gcc -c -o myftpserver.o myftpserver.c
gcc myftpserver.o -o myftpserver
gcc -c -o myftpclient.o myftpclient.c
gcc myftpclient.o -o myftpclient
Hope this helps!
Upvotes: 3
Reputation: 161
You want instructions for compiling your .o file, and the rm shell command to clean:
CC=gcc
myftpserver: myftpserver.o
$(CC) -o myftpserver myftpserver.o
myftpclient: myftpclient.o
$(CC) -o myftpclient myftpclient.o
myftpserver.o: myftpserver.c
$(CC) myftpserver.c
myftpclient.o: myftpclient.c
$(CC) myftpclient.c
clean:
rm -f *~ *# *.o myftpserver myftpclient
Upvotes: 0