LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 12-27-2009, 11:05 PM   #16
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940

Many thanks to u for enlightening me !
 
Old 12-28-2009, 07:57 PM   #17
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
I wonder if anyone can suggest a simple autotools tutorial?
 
Old 12-28-2009, 09:53 PM   #18
GooseYArd
Member
 
Registered: Jul 2009
Location: Reston, VA
Distribution: Slackware, Ubuntu, RHEL
Posts: 183

Rep: Reputation: 46
Quote:
Originally Posted by MTK358 View Post
I wonder if anyone can suggest a simple autotools tutorial?
you want http://sources.redhat.com/autobook/
 
Old 12-29-2009, 11:23 AM   #19
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
I tried reading and it still seems too complicated for me. I would like to see a diagram of what files I have to write, their syntax, and how to build a project that consists of a few source files and uses a library (i.e. #include <pthread.h>).
 
Old 12-29-2009, 01:43 PM   #20
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by MTK358 View Post
I wonder if anyone can suggest a simple autotools tutorial?

http://www.lrde.epita.fr/~adl/autotools.html ->
http://www.lrde.epita.fr/~adl/dl/autotools.pdf - slides.

But the whole thing isn't simple because it reflects real world mess.

Also, free your mind from 'make' and remember that the main challenge is building dependency tree which can be automated only for limited category of task.

Even in simple case like

Code:
#ifdef FOO
#include "foo.h"
#else
#include "bar.h"
#endif
where FOO is defined not in another file, but on command line (e.g. a 'configure' argument) you can't know for sure on which of the two 'foo.h', 'bar.h' files your target depends.

The situation is even more hopeless if some portions of code are autogenerated by other tools and/or in not C/C++ only projects.

'make' as a tool comparing file modification dates and running commands is very secondary in the whole picture.

Last edited by Sergei Steshenko; 12-29-2009 at 07:06 PM.
 
Old 12-29-2009, 06:06 PM   #21
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
autoconf is the more difficult one to get going. automake is painfully easy, and libtool is just a script you copy to your project so automake will work for libraries.

automake requires Makefile.am files, which merely define variables to tell it what to build out of what, and it will generate a Makefile.in, a makefile template. autoconf requires configure.ac, which tells it what tests to run (e.g. check for a header) and what makefiles to make. It creates a configure script, which runs the requested tests, determines how to call the compiler, etc., on the machine it's being run on, then inserts its findings into the Makefile.in to create a makefile. Once you have your Makefile.am, you can run autoscan to create configure.scan, a "guessed" configure.ac.
Kevin Barry
 
Old 12-30-2009, 07:33 AM   #22
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
I am reading the GNU Make manual and I decided to try to make a "universal" Makefile that uses the compiler to figure out dependencies. This seems to work, but I need to figure out how to make it tolerate having sources in another directory.

Code:
compiler = gcc
cflags = -ggdb
getdepsflag = -MM
sources = main.c hello.c
objects = $(sources:.c=.o)

hello: $(objects)
	$(compiler) $(cflags) $(objects)

%.o: %.c %.d

%.d: %.c
	$(compiler) $(getdepsflag) $< > $@
	echo -ne '\t' >> $@
	echo '$(compiler) $(cflags) $$< -o $$@' >> $@

-include $(sources:.c=.d)

.PHONY = clean

clean:
	rm *.[od]
 
Old 12-30-2009, 02:11 PM   #23
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
autoconf and libtool are set up once for the project, no matter how large. At worst, you'll have to add a line to configure.ac to check for an additional system header or lib or add a line to specify another makefile to generate, but that's about it. After that, you just write a Makefile.am like this:
http://svn.berlios.de/wsvn/rservr/tr...ho/Makefile.am
http://svn.berlios.de/wsvn/rservr/tr...ex/Makefile.am

Note that the first has 9 direct local includes and who knows how many secondary, none of which are in the same directory as the .c file, and gcc isn't necessary to determine what they are, allowing this to compile on nearly all *nix. Packaging is also taken care of.
Kevin Barry
 
Old 12-30-2009, 05:22 PM   #24
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by MTK358 View Post
I am reading the GNU Make manual and I decided to try to make a "universal" Makefile that uses the compiler to figure out dependencies. This seems to work, but I need to figure out how to make it tolerate having sources in another directory.
See the vpath directive.

Not trying to put you down, but I think my earlier posted makefile does everything yours does while being cleaner and simpler. In particular I would recommend using -MMD instead of -MM, since it saves time (eg: doesn't make dependencies when running make clean).
 
Old 12-30-2009, 07:15 PM   #25
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
I was trying to read the GNU make manual to figure out how it works, because I even still hardly understand the syntax.

I don't even see how your Makefile even creates the .d files!

And I am still thinking whether I should be using something like CMake or autotools, but they are so complicated that they make almost no sense whatsoever to me. And in case I might want to eventually share a program it might be more important to use a build system.

Last edited by MTK358; 12-30-2009 at 07:20 PM.
 
Old 12-30-2009, 08:24 PM   #26
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by MTK358 View Post
I don't even see how your Makefile even creates the .d files!
Passing -MMD to gcc causes it to create the .d files while it compiles. automake does it the same way.

Quote:
And I am still thinking whether I should be using something like CMake or autotools, but they are so complicated that they make almost no sense whatsoever to me. And in case I might want to eventually share a program it might be more important to use a build system.
At the start your programs will be simple so you can use a simple makefile. You can learn about more complicated systems later, when you have more programming experience and the makefile system doesn't provide enough features to build the more complex programs you are working on. Some people share programs without using autoconf, for instance the wmii window manager is built with just make, no autoconf.
 
Old 12-31-2009, 07:41 AM   #27
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by ntubski View Post
Passing -MMD to gcc causes it to create the .d files while it compiles. automake does it the same way.
So the -MM flag causes it to print out a Makefile line, and -MMD causes it to create a .d file that has a gcc command with the same flags?

Quote:
Originally Posted by ntubski View Post
At the start your programs will be simple so you can use a simple makefile. You can learn about more complicated systems later, when you have more programming experience and the makefile system doesn't provide enough features to build the more complex programs you are working on. Some people share programs without using autoconf, for instance the wmii window manager is built with just make, no autoconf.
So it's OK if everyone's using gcc?

And is it really hard to convert a project consisting of a large amount of source files to a different build system?

Also I wonder what is the remommended way of organizing the different types of files? I know .c and .h files should go to src, what about .o, .d, and executable files?

Last edited by MTK358; 12-31-2009 at 07:46 AM.
 
Old 12-31-2009, 08:14 AM   #28
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Quote:
Originally Posted by MTK358 View Post
So it's OK if everyone's using gcc?

And is it really hard to convert a project consisting of a large amount of source files to a different build system?

Also I wonder what is the remommended way of organizing the different types of files? I know .c and .h files should go to src, what about .o, .d, and executable files?
libc is usually more of a portability problem than gcc; however, I've had code "break" from one version of gcc to the next because of changes in compiler strictness. I wouldn't assume you'll get a predictable result across all versions of gcc.

Once you wrap your head around autotools and get autoconf intstalled into the project it's really easy to convert. The problem with setting up autoconf is it requires certain placeholder files (e.g. README) to be there and there are a few things I never remember that I have to look up. It's a one-time thing for the project, though, which is why I always have to look it up (info autoconf is as good a place as any.) You really don't need to put much in configure.ac if you don't want to, if you hadn't planned on checking for headers and libraries. With Makefile.am, you need to remember that it's all relative to the build directory (where ./configure is run from,) not the location of Makefile.am. Other than that, you wtire a lot less than you would writing the makefile by hand, even with the method you're trying to use (if you included all the install/uninstall code.)
Kevin Barry
 
Old 12-31-2009, 09:42 AM   #29
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
The main problem is that many of the tutorials I find just don't work. I try to do what is says but it gives errors.

Also many of the tutorials either use one source file or use things like yacc, etc that I don't understand and my project won't use.

Why isn't there just a simple tutorial that just uses more than 1 source file and actually works?
 
Old 12-31-2009, 11:50 AM   #30
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by MTK358 View Post
The main problem is that many of the tutorials I find just don't work. I try to do what is says but it gives errors.

Also many of the tutorials either use one source file or use things like yacc, etc that I don't understand and my project won't use.

Why isn't there just a simple tutorial that just uses more than 1 source file and actually works?
As I already wrote, complexity of tutorials reflects real world mess.
 
  


Reply



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
LXer: Automatically writing makefiles with Automake LXer Syndicated Linux News 0 06-04-2008 04:11 PM
LXer: Automatically generate PHP documentation from Subversion with phpDocumentor LXer Syndicated Linux News 0 11-05-2007 11:41 AM
How to generate Prerequisites automatically for makefile Greatrebel Programming 1 03-07-2007 09:32 AM
(bash) echo "#!/bin/bash" event not found - trying to generate profiles automatically jimieee Programming 9 05-03-2006 10:24 AM
Dynamically generate a webage and update it automatically using RSS xbaez Programming 7 01-31-2006 10:47 PM

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

All times are GMT -5. The time now is 03:48 PM.

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
Open Source Consulting | Domain Registration