LinuxQuestions.org
Review your favorite Linux distribution.
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 08-03-2004, 11:04 PM   #1
trotters78
LQ Newbie
 
Registered: Aug 2004
Location: Japan
Distribution: Fedora Core 2/ FreeBSD 4.9
Posts: 12

Rep: Reputation: 0
Compiling using automake and autoconfig on both BSD and Linux


I need to port source code from FreeBSD to LINUX (Fedora Core 2).
I have been reading the forum but i could not find any questions similiar to this.

Compatibility issues arises due to BSD ports and NetLink API.
And also Socket Structures.

A good way will be to use #ifdef and #end to comment away code that the compiling platform does not use. And use ./config to help me determine which path of #ifdef to take and what kind of code to use.

I am very new to linux and also to libtools such as Automake and Autoconfig.

Can anyone guide me or suggest good sites for me to read up on?
What configurations should i specifically look out for when writing my configure.in file? What outputs from autoconf will help me differentiate whether the platform is BSD or LINUX?

Thanks in advance
Daryl
 
Old 08-04-2004, 01:08 AM   #2
max_sipos
Member
 
Registered: Jul 2004
Posts: 96

Rep: Reputation: 15
I don't know anything about your problem but you might want to try out this book:

GNU Autoconf, Automake and LibTool by Gary V. Vaughan, Ben Elliston, Tom Tromey and Ian Lance Taylor

There is an online browsable version @ http://sources.redhat.com/autobook/

--
Maksim Sipos
 
Old 08-04-2004, 08:03 PM   #3
trotters78
LQ Newbie
 
Registered: Aug 2004
Location: Japan
Distribution: Fedora Core 2/ FreeBSD 4.9
Posts: 12

Original Poster
Rep: Reputation: 0
Thank you for your reply.
Let me rephrase my problem.

To make my code portable, I would use the following

#ifdef _IS_BSD_PLATFORM_
//BSD platform Code
#else
// Linux platform Code
#endif

My problem is, how can i use automake and autoconfig to create the Constant _IS_BSD_PLATFORM_ in my "config.h" file? Able to sense using "./config" to find out if it is a Linux or BSD OS platform?
What macros should i use for "configure.ac" to create a Constant like _IS_BSD_PLATFORM_? What is the correct way?

At the moment, I am able to write simple Makefiles and just learnt how to create configure.ac using autoscan. However, I do not have sufficient knowledge to do the above.

Can someone kindly guide me?
Anybody has any examples?

Thank you in advance

Daryl
 
Old 08-05-2004, 08:56 AM   #4
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
I haven't used autoconf/automake enough to know exactly how to do what you want, but generally you check for certain features you need to use rather than what system it is on. That makes it more portable because you are checking for specifically the difference that you know of.

So, for instance you said there was a struct that was different between BSD and Linux? If so, create a macro to check for that struct difference and set a variable based on the results of the macro. Many of the autoconf macros generally do something like create a small program on the fly with the feature you are testing, try to compile it and then set a variable based on the success or failure of the compile.

Take a look at some of the macros in the GNU Autoconf Macro Archive to get some examples... What you want may even already be in the archive.

Hope that helps

Last edited by deiussum; 08-05-2004 at 08:57 AM.
 
Old 08-06-2004, 12:10 AM   #5
skoona
Member
 
Registered: Mar 2004
Location: Indiana, USA
Distribution: Fedora, CentOS, Ubuntu, OS/X, Raspbian
Posts: 90

Rep: Reputation: 18
I know enough to say yours will not be an easy answer, and the advice given to this point is correct - i.e. look for features.

I am still struggling with autoconf/automake myself. Here is how I started.

1. make sure your source tree has a "src" directory, if not create one copy your source into it and tweak your local includes so your program still compiles.
2. SAVE your make files IN ANOTHER DIRECTORY, in case they get clobbered.
3. execute "$ autoscan" in your programs root directory, and rename configure.scan to configure.in. edit configure.in where needed. mostly program name, version, etc.
4. find a "autogen.sh" script from an existing program (any program) and copy it into you programs root directory. autogen.sh is generic
5. edit PKG_NAME="prog_name" in autogen.sh, around line number 5, to your programs name. (note: hold on - autogen.sh will run, autoscan, autoheader, autoconf, automake,...)
6. create a "./configure.in", "./Makefile.am", "./src/Makefile.am", (use configure.in from #3)
7. NOTE: These are the core files - consider saving a copy somewhere else...
8. execute "./autogen.sh" -- when its done you should have a fairly complete set of config... files that can be tweaked. However, you should only edit the core files - since autogen.sh will recreate all the other files.

I will post the core files in another post that I used FOR A SHARED LIBRARY -- NOT A PROGRAM. It may have some examples that will help sort out things, since programs are easier.

Let me know.

Last edited by skoona; 08-06-2004 at 05:10 PM.
 
Old 08-06-2004, 12:28 AM   #6
skoona
Member
 
Registered: Mar 2004
Location: Indiana, USA
Distribution: Fedora, CentOS, Ubuntu, OS/X, Raspbian
Posts: 90

Rep: Reputation: 18
Post autoconf/automake starter set for shared library

Code:
FILENAME: ./configure.in
-------------------------------------
dnl   -- pkgdir/configure.in -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ(2.59)
AC_INIT(gkrellfah2, 0.9.8, "James Scott Jr <skoona@users.sourceforge.net>", gkrellfah2-0.9.8-0.tar.bz2)
AM_INIT_AUTOMAKE(gkrellfah2, 0.9.8)
AC_CONFIG_SRCDIR(src/gkrellfah2.c)
AM_CONFIG_HEADER(config.h)
## AM_MAINTAINER_MODE                             ## -- won't regen configs/makefiles if set unless --flag

dnl -- Checks for programs.
AC_PROG_CC
AC_ISC_POSIX
AC_GNU_SOURCE
AM_PROG_CC_STDC
AM_PROG_LIBTOOL
AC_ARG_PROGRAM                   ## looking change libr's install name from libNAME to NAME

dnl -- Checks for libraries.
PKG_CHECK_MODULES(GTK, gtk+-2.0 gdk-2.0,,exit)
AC_SUBST(GTK_LIBS)
AC_SUBST(GTK_CFLAGS)

dnl -- Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADER(tgmath.h)
## AC_CHECK_HEADER( gkrellm.h,,exit )            ## why doesn't it find anything
AC_CHECK_FILE( /usr/local/include/gkrellm2/gkrellm.h,[echo "Using local Gkrellm2 header"],\
 [if test -e "/usr/include/gkrellm2/gkrellm.h"; then echo "Using system gkrellm2 headers"; else exit; fi;])

dnl -- Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL

# Checks for library functions.
AC_FUNC_CLOSEDIR_VOID
AC_FUNC_STAT
AC_FUNC_STRFTIME
AC_CHECK_FUNCS([memset pow regcomp rint strdup strstr])

dnl -- Setting/Overwriting  output variables
AC_SUBST(libdir,/usr/local/lib/gkrellm2/plugins)                   ## hardwire output dir

dnl -- Create these output files
AC_OUTPUT([Makefile src/Makefile])
-------------------------------------

FILENAME: ./Makefile.am
-------------------------------------
## Process this file with automake to produce Makefile.in
## Located in directory ./gkrellfah2 

SUBDIRS = src

libgkrellfah2docdir = ${prefix}/doc/gkrellfah2

libgkrellfah2doc_DATA = README COPYING ChangeLog TODO NEWS AUTHORS

EXTRA_DIST = $(libgkrellfah2doc_DATA)

# Copy all the spec files. Of cource, only one is actually used.
dist-hook:
	for specfile in *.spec; do \
		if test -f $$specfile; then \
			cp -p $$specfile $(distdir); \
		fi \
	done
-------------------------------------

FILENAME: ./src/Makefile.am
-------------------------------------
## Process this file with automake to produce Makefile.in

## Located in directory gkrellfah2/src 
## pkglib_ translates to /usr/local/lib/gkrellfah2
## lib_ translates to /usr/local/lib

SUBDIRS = 

INCLUDES = $(GTK_CFLAGS) -I/usr/local/include/gkrellm2

## AM_CFLAGS =  -Wall -O3 -march=athlon-xp -g 

lib_LTLIBRARIES = libgkrellfah2.la

libgkrellfah2_la_SOURCES = gkrellfah2.c queue.c build_ptable.c pixmaps/krell_pcpu.xpm gkrellfah2.h ptable.h

## libgkrellfah2_la_HEADERS = gkrellfah2.h ptable.h              ## -- They would get installed if placed here

libgkrellfah2_la_CFLAGS =  -Wall -O3 -march=athlon-xp -g  $(AM_CFLAGS)

libgkrellfah2_la_LDFLAGS = -fPIC -W1 -shared 

libgkrellfah2_la_LIBADD = $(GTK_LIBS)
-------------------------------------
Additional Comment: At least one, if not all, of your C source files should #include "../config.h" as its first include. Also, to answer one of your questions; how to define a label in configure... that will end up in a config.h that your program can test?

AC_DEFINE_UNQUOTED(HEADER_NAME, header_value) --- adds HEADER_NAME=header_value to the config.h file
AC_SUBST(header_name) -- export header_name to the makefile environment

James,
 
Old 08-06-2004, 01:30 AM   #7
trotters78
LQ Newbie
 
Registered: Aug 2004
Location: Japan
Distribution: Fedora Core 2/ FreeBSD 4.9
Posts: 12

Original Poster
Rep: Reputation: 0
Hi Skoona,

Thanks for your prompt reply.
Yes, indeed, when portability issues come, it becomes a tricky issue.
With much luck I have mananged to find out the macro that will determine whether the system type is Linux or BSD.

I would like to share my findings with the community.

Here it is:
The trick is to use the macro AC_CANONICAL_HOST() in the configure.ac.
The "$host_os" variable will contain the type of the system.
Use the macro AC_DEFINE([HEADER_NAME],[header_value],[Description]) to write the header into the config.h.
With that, I was able to turn the platform flag on and off on different machines.

Skoona, I think your configure.in is a very good reference for newbies like me.
Thank you.
Pardon me, but i am wondering why did u use these two sets of functions when u could just simply use AC_DEFINE?
AC_DEFINE_UNQUOTED(HEADER_NAME, header_value) AC_SUBST(header_name)

I am now trying out other checks on structs and functions. Similiarly, I will post findings and problems if i have any.

Thanks to Skoona, deiussum and max_sipos.

Daryl
 
Old 08-06-2004, 01:50 AM   #8
skoona
Member
 
Registered: Mar 2004
Location: Indiana, USA
Distribution: Fedora, CentOS, Ubuntu, OS/X, Raspbian
Posts: 90

Rep: Reputation: 18
AC_DEFINE is the same as AC_DEFINE_UNQUOTED, without the quotes. Example; when you want a result of say - #define VERSION 9.5 - versus - #define VERSION "9.5" - , into the config.h file.

AC_SUBST(environ_name), I use it when I want ro force a value into a resulting Makefile's environment, my code above shows a AC_SUBST(libdir, ...) which I used to force the name of an install directory. There may be an easier way; but I got tired of looking and that worked.


the two macros are used for different things.

Glad, it helped.

Hey max_sipos! Thanks for the pointer to the book. Wish I had it last week when I started this adventure.

Last edited by skoona; 08-06-2004 at 08:12 AM.
 
  


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
Can't install autoconfig Deltabweb Mandriva 2 07-10-2005 10:46 PM
Scribus installation problem, sez I need automake 1.6 when automake 1.9 is istalled Rockgod2099 Linux - Software 13 11-14-2004 06:37 PM
autoconfig for x server? dacosta Debian 2 06-27-2004 02:26 PM
problem compiling with autoconf and automake feetyouwell Linux - Software 0 06-07-2004 10:41 PM
slackware 9 asking for automake 1.6 while i have automake 1.7 gtgoku Slackware 1 10-19-2003 08:59 AM

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

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