LinuxQuestions.org
Visit Jeremy's Blog.
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 11-11-2004, 12:07 PM   #1
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Rep: Reputation: 50
configure and Makefile


I am reading the man-pages for autoconf, autoscan, etc but I can't really understand how I can get my program to be installed by the usual "configure && make && make install"-steps.

Do I have to write configure.ac manually and what should be in it? Are there any good guides on how to create this? I would really like to make my program being able to be compiled and installed with these steps instead of using g++ as I do now. :P Since many of my friends are not programmers and that would make my program behave like any program in the compile/installation-process.

It seems that the first step is to create configure.ac and then run autoscan. After that I can't really figure out how ifnames are used and so on.

Please help, this is really confusing, giving me headache. :P


EDIT:
I found a great link to what seems to be a good tutorial about all this. Here it is

Last edited by Ephracis; 11-11-2004 at 12:57 PM.
 
Old 11-11-2004, 01:03 PM   #2
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 78
If your program is reasonably simple (ie: no compile time options) then you may not need the configure step.

Just create a Makefile to automate the gcc commands that build your app. Makefile syntax is quite easy to understand.
 
Old 11-11-2004, 01:10 PM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
I've never used "autoscan", which I guess may be useful.
But some time ago I've figured out the basic part of the procedure.
(and yes, it gave me a headache as well...)

Here's a recipe for the most basic, but complete, example of a "Hello world" program I can think of:
  • Create a directory for the "hello"-project, and change to that directory:
    Code:
    mkdir hello
    cd hello
  • Create a "hello.c" file:
    Code:
    /* hello.c */
    
    #include <stdio.h>
    
    int main()
    {
        printf("Hello\n");
        return 0;
    }
  • Create a "configure.ac" file:
    Code:
    AC_INIT([Hello], [0.1], [you@somwhere.net], [hello])
    AC_CONFIG_SRCDIR([hello.c])
    AM_INIT_AUTOMAKE
    AC_PROG_CC
    AC_PROG_INSTALL
    AC_CONFIG_FILES([Makefile])
    AC_OUTPUT
  • Create a "Makefile.am" file:
    Code:
    bin_PROGRAMS = hello
    hello_SOURCES = hello.c
  • Now run these commands from the shell (order is more or less important, and you may want to put this in a script "reconf.sh" or whatever):
    Code:
    touch NEWS README AUTHORS ChangeLog
    aclocal
    automake -a
    autoconf
    You'll now have a working configure script.
  • Run this to create a source tarball:
    Code:
    ./configure
    make distcheck
    You now have a file "hello-0.1.tar.gz" ready for distribution. "make distcheck" also tests unpacking, configuring, compiling and installing in a temporary directory, which is cleaned up automatically . If you just want to make the package, use "make dist", which is much faster (but doesn't do any testing)
On my (small) website, there is a little bigger autotools example. It uses a config.h, it includes a custom --with-foo switch for the configure-script to enable linking against a (non-existant) "libfoo.so", and a way to #define the datadirectory in config.h (the directory where xpm's, themes or whatever data the program needs), so the program "knows" where to find its data files.

If you're interested, get it here
 
Old 11-11-2004, 01:58 PM   #4
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Original Poster
Rep: Reputation: 50
Thank you a lot. I will read some more. The thing now is to understand WHY you are writing that in configure.ac and Makefile.am. I need to understand what to write in these files and why write it.

I will check out your link later, am currently reading about the "Autoconf language", having troubles even to understand that, it's a little bit harder when english isn't my primary language. :P

Thanks alot!
 
Old 11-14-2004, 10:59 AM   #5
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Original Poster
Rep: Reputation: 50
I have now a program that uses Qt libraries. When I compile manually I do this:

moc on all three .h-files (moc -o moc_file.cc file.h)
Create all object-file (g++ -c -I/usr/lib/qt/include/ -o file.o file.cc), this include the new moc_-files.
Create the binary by linking them together (g++ -L/usr/lib/qt/lib/ -lqt-mt -o bin <all .o-files>)

Notice that I have to specify Qt's include and library, and at the last linking I also use "-lqt-mt". This and running the headers through moc, how can I tell autoconf to do that?

I want configure to check if Qt is installed and compile these files correctly.

Code:
$ ls
cannon.cc  cannon.h  gamebrd.cc  gamebrd.h  lcdrange.cc  lcdrange.h  main.cc
$ moc -o moc_lcdrange.cc lcdrange.h
$ moc -o moc_cannon.cc cannon.h    
$ moc -o moc_gamebrd.cc gamebrd.h 
$ g++ -c -I/usr/lib/qt/include/ -o moc_lcdrange.o moc_lcdrange.cc 
$ g++ -c -I/usr/lib/qt/include/ -o lcdrange.o lcdrange.cc         
$ g++ -c -I/usr/lib/qt/include/ -o moc_cannon.o moc_cannon.cc 
$ g++ -c -I/usr/lib/qt/include/ -o cannon.o cannon.cc         
$ g++ -c -I/usr/lib/qt/include/ -o moc_gamebrd.o moc_gamebrd.cc 
$ g++ -c -I/usr/lib/qt/include/ -o gamebrd.o gamebrd.cc         
$ g++ -c -I/usr/lib/qt/include/ -o main.o main.cc       
$ g++ -L/usr/lib/qt/lib/ -lqt-mt -o cannon moc_lcdrange.o moc_cannon.o moc_gamebrd.o lcdrange.o cannon.o gamebrd.o main.o

Last edited by Ephracis; 11-14-2004 at 11:00 AM.
 
Old 11-15-2004, 06:16 AM   #6
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Qt is a bit of a problem, because the MOC-stuff is unusual. I've tried to fix this myself once by making a FIND_QT m4 module, but succeeded only partly. See http://qleuren.sf.net/ for this. But this works only with Qt2, so it can be considered broken.

It's probably better to get the m4 module "bnv_have_qt" from the autconf-archive, and include it in your package. How to do this (including a m4 module), see the link I posted before, as it includes the simple "ac_define_dir.m4" as an example.

Get "bnv_have_qt" from http://ac-archive.sourceforge.net/In...v_have_qt.html
(I still need to use this for my http://qleuren.sf.net/ instead of my own broken one).

Last edited by Hko; 11-15-2004 at 06:18 AM.
 
Old 11-16-2004, 02:04 PM   #7
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Original Poster
Rep: Reputation: 50
I check it out and it was very easy to get working. Now my configure can check if Qt is installed but I still have problems with the Makefile.

I noticed that when configure was done the docs on bnv_have_qt said that these vars was defined:
QT_CXXFLAGS
QT_LIBS
QT_MOC
QT_UIC
QT_DIR
How shall I use these in Makefile.am so make will compile everything the "right" way (moc the .h-files, create objects, link the objects)?

Here are an example of the files I have:
  • myclass.h
  • myclass.cc
  • main.cc

Now I normaly moc the myclass.h, make object-files from the two sources and the moc'ed file and finally link all together to a binary file. I want this to be done by "make".
 
Old 11-16-2004, 02:41 PM   #8
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Try something like this in your Makefile.am:
Code:
bin_PROGRAMS = programname
programname_SOURCES = main.cc myclass.cc myclass.h
META_SOURCES = myclas.moc.cc 
nodist_programname_SOURCES = $(META_SOURCES)
CLEANFILES = $(META_SOURCES)

programname_LDADD = $(QT_LIBS)
AM_CXXFLAGS = $(QT_CXXFLAGS)
programname_LDFLAGS = $(QT_DIR)    
# Or maybe:  programname_LDFLAGS = $(QT_DIR/lib)

%.moc.cc : %.h
        $(QT_MOC) $< -o $@
# ^^^ tab!
There may be some GNU-make dependant stuff in this. Not sure.

Last edited by Hko; 11-16-2004 at 02:44 PM.
 
  


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
configure doesn't create a Makefile (with anjuta) crashmakerMX Programming 5 06-24-2005 04:48 PM
Create my own configure and Makefile Ephracis Linux - Software 1 10-11-2004 08:00 PM
what are 'makefile', 'configure'? LongName Programming 3 08-27-2004 09:08 PM
Problem generating a working makefile from configure: MadCactus Linux - Software 0 08-20-2004 08:51 AM
generate Makefile from Makefile.in without calling ./configure ? chris78 Programming 2 05-02-2004 12:23 PM

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

All times are GMT -5. The time now is 08:17 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