How to create a makefile?

Hi all,
I have a 'C' program called
childCommand.c 
I want to create a makefile for this program in UNIX environment. Can someone please guide me?
Thanks
Last edited on

When I type
$childCommand: childCommand.o

and hit enter it sayd
childCommand not found.
Whats that im missing?
Last edited on
http://scottmcpeak.com/autodepend/autodepend.html
I found this page very useful when creating makefiles that can handle dependencies automatically without having to update the makefile.
If you have created a makefile named Makefile you should only have to type make and press enter.
Last edited on
@Peter :Today only im learning about makefile. The link you have given is for advanced people like you.
These are the things I have done
1. I created a text file named "makefile"
2. Entered the following in it


childProcess.o: childProcess.c
	gcc -c childProcess.c

clean:
	rm *.o

3. Then in the terminal window I typed
 $make
and hit enter

After that,it displayed
gcc -c childProcess.c
in the terminal
Is that correct?
Last edited on
You are missing the executable
Yes that is correct but you are only compiling and not linking.

You need to add target for executable, add

1
2
childProcess: childProcess.o
    gcc -o childProcess childProcess.o 


If you do this you will have to
$ make chileProcess


or replace
1
2
childProcess.o: childProcess.c
	gcc -c childProcess.c


with
1
2
childProcess: childProcess.c
	gcc -o childProcess childProcess.c


General syntax for makefile is

target: dependencies
command
[optional commands]
Thanks
Peter
Codewalker
and
ne555
all for your great help. Now im cleared
Last edited on
Topic archived. No new replies allowed.