LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-16-2003, 01:51 AM   #1
pessanimahi
LQ Newbie
 
Registered: Sep 2003
Posts: 18

Rep: Reputation: 0
makefile


How to create a makefile. how to write the script in the makefile.

-----------
maheshkumar reddy.p
 
Old 09-16-2003, 02:48 AM   #2
SaTaN
Member
 
Registered: Aug 2003
Location: Suprisingly in Heaven
Posts: 223

Rep: Reputation: 33
//Filename ::usingFoobar.c
Code:
 
#include <stdio.h>
int main()
{
	foo();
	bar();
}
//Filename::bar.c
Code:
void bar(void)
{
                printf("I am in bar\n");
}
//Filename ::foo.c
Code:
void foo(void)
{
                printf("I am in foo\n");
}
//Contents of makefile

output: bar.o foo.o usingFoobar.o
cc -o output bar.o foo.o usingFoobar.o
bar.o: bar.c
cc -c bar.c
foo.o: foo.c
cc -c foo.c
usingFoobar.o: usingFoobar.c
cc -c usingFoobar.c

Now the command "make" will create all the corresponding
executables.

./output will give output as

I am in foo
I am in bar

<edit>
Check this out if want to know more abt itMakefileLectures

Last edited by SaTaN; 09-16-2003 at 02:57 AM.
 
Old 09-16-2003, 02:54 AM   #3
JoKa
LQ Newbie
 
Registered: Aug 2003
Location: Belarus
Distribution: Mandrake 9.0
Posts: 2

Rep: Reputation: 0
Run
info make
and see section Makefiles
If you use KDE you can access it through KDE HelpCenter
infopages - GNU Packages - make - Makefiles
If you can't do it write to me (joka@tut.by) I can send this infopage in text (html) form.
 
Old 09-16-2003, 03:08 AM   #4
shishir
Member
 
Registered: Jul 2003
Location: bangalore . india
Distribution: openSUSE 10.3
Posts: 251

Rep: Reputation: 33
there is this really great gmake manual available at

http://www.gnu.org/manual/make/

must read for a makefile....

dont really need the whole thing..you can read some chapters on need basis...great stuff
 
Old 09-16-2003, 03:14 AM   #5
cxel91a
Member
 
Registered: May 2001
Posts: 61

Rep: Reputation: 15
This information is from the text, Linux Application Development.

You can create and assigned a variable with a list of object files.

OBJS = foo.o bar.o

You can also create a variable with a path to any libaries you might need.

LDLIBS = -L/usr/local/lib/ -lc # Used -L to search of lib and -l to
# link with to a specific lib

foo: $(OBJS)
gcc -o foo $(OBJS) $(LDLIBS) (Tab on this line)

# Note: The $() is used to expand variables.
# foo is a target that depends on the list of
# of object files. You don't need to create
# the objects if you have a foo.c & bar.c in
# the directory.

install: foo
install -m 644 foo /usr/bin ( Tab on this line )

# This will install the target foo to /usr/bin
 
Old 09-16-2003, 09:39 AM   #6
sureshsaragadam
LQ Newbie
 
Registered: Sep 2003
Location: Visakhapatnam
Distribution: Red Hat Linux 9
Posts: 24

Rep: Reputation: 15
Hi pessanimahi

How to create a makefile?

Mr Mahi you dont have to do any thing to create a make file
Just create a file with file name "makefile" and do what you need to do . . . foo , bar

that is your makefile !

what actually i do with make make file ?
you does nothing but you prepare your application to run on platform you run make.

Like already mentioned by cxel91a

-> LDLIBS = -L/usr/local/lib/ -lc
-> -L to search of lib
-> -l to link with to a specific lib

your applicaiton may need many libraries or Include files can be specified with in makefile to create binaries of your applicaiton

there are many stadard lables in make file like

ALL:
...........
..........

INSTALL:
.............
..............

UNINSTALL:
............
.............
...............

CLEAN:
..............

...........





this make file will give error if specified libraries are not available during the 'make' of your application

make is the command to run the make file from shell

you can use

make
make install
make clean
make realclean
make uninstall
...
...

is is very easy to go with makefile

You can even configure your applicaiton or product before installing it to the system,

what call can be done on shell can be included in MAKEFILE you created just naming it simply as makefile

Go throuth some sample makefiles you will get real fact
 
Old 09-17-2003, 03:34 AM   #7
pessanimahi
LQ Newbie
 
Registered: Sep 2003
Posts: 18

Original Poster
Rep: Reputation: 0
Thank you to all for giving this needfull information...

-----------
pessanimahi
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to modify makefile.in or makefile.am QiangWan Linux - Newbie 1 05-17-2005 12:07 PM
how to get (makefile -f makefile )output into the textview widget in Pygtk sailu_mvn Programming 3 02-28-2005 04:57 AM
@ in makefile m_a61 Linux - General 2 09-08-2004 08:09 AM
generate Makefile from Makefile.in without calling ./configure ? chris78 Programming 2 05-02-2004 01:23 PM
makefile moonloader Programming 4 01-05-2004 07:26 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration