Project files for building a JUCE app with Anjuta/autoconf

2 posts / 0 new
Last post
NiallM
Offline
Last seen: 1 year 1 month ago
Joined: 6 Sep 2004 - 10:28
Project files for building a JUCE app with Anjuta/autoconf

Following on from this thread, here's project files for building a simple JUCE app with Anjuta, or just using autoconf on its own:

http://www.niallmoody.com/downloads/JuceExampleProject-0.10.tar.gz (318kB)

It'll build an empty JUCE window using my usual settings. The README should tell you everything you need to know, but I'll do a quick rundown of the relevant files. There are basically three files to worry about when creating an autoconf-based project (Anjuta just provides a GUI wrapper to autoconf, really, so everything here applies to it too); configure.ac, Makefile.am, and src/Makefile.am (assuming you're using the standard(?) *nix directory scheme, anyway). Generally you'd run aclocal, autoconf, and automake on them, which would generate a configure script and some Makefile.in's, before running the configure script itself to generate the actual Makefiles (tailored somewhat to your computer), and finally running make itself.

configure.ac:

dnl Process this file with autoconf to produce a configure script.
dnl Created by Anjuta application wizard.

AC_INIT(JuceExampleProject, 0.10)

AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)
AM_CONFIG_HEADER(config.h)
AM_MAINTAINER_MODE

AC_ISC_POSIX
AC_PROG_CXX
AM_PROG_CC_STDC
AC_HEADER_STDC

AM_PROG_LIBTOOL


AC_PATH_XTRA

if test $no_x; then
	AC_MSG_ERROR([The path for the X11 files not found!
	Make sure you have X and it's headers and libraries(the -devel packages in Linux) installed.])
fi

dnl Check for freetype
AC_CHECK_FT2(7.0.1 , 
	[CXXFLAGS="$CXXFLAGS $FT2_CFLAGS"
		LIBS="$FT2_LIBS $LIBS"],
	[AC_MSG_ERROR(cannot find freetype!)])

dnl Check for pthreads
AC_CHECK_LIB(pthread,
	pthread_create,
	,
	[AC_MSG_ERROR(cannot find libpthread!)])

dnl Check for xinerama
AC_CHECK_LIB(Xinerama,
	XineramaQueryVersion,
	,
	[AC_MSG_ERROR(cannot find libXinerama!)])

dnl Check for opengl
AC_CHECK_LIB(GL,
	glBegin,
	,
	[AC_MSG_ERROR(cannot find libGL!)])

dnl Check for JUCE
AC_ARG_WITH(JUCE,
	[AC_HELP_STRING([--with-JUCE],
		[path to JUCE [default=../../juce]])],
	[CXXFLAGS="$CXXFLAGS -I$withval"
		LDFLAGS="$LDFLAGS -L$withval/bin -ljuce"],
	[CXXFLAGS="$CXXFLAGS -I../../juce"
		LDFLAGS="$LDFLAGS -L../../juce/bin -ljuce"])

AC_OUTPUT([
Makefile
src/Makefile
])

This is used to generate the configure script, which will in turn generate Makefiles for your project when run. As you can see, this file was originally generated by Anjuta, but I've added a bunch of checks to ensure all the necessary libraries get linked in. It's fairly simple stuff; AC_CHECK_LIB checks if the required library exists on your system, and if it does, adds -l to your LDFLAGS. By default the configure script will assume JUCE is in the app's parent directory, but the AC_ARG_WITH macro lets you set which directory it's in when you run the configure script (e.g. ./configure --with-JUCE=/home/niall/juce).

Makefile.am:

## Process this file with automake to produce Makefile.in
## Created by Anjuta

SUBDIRS = src 

JuceExampleProjectdocdir = ${prefix}/doc/JuceExampleProject
JuceExampleProjectdoc_DATA = \
	README\
	COPYING\
	AUTHORS\
	ChangeLog\
	INSTALL\
	NEWS

EXTRA_DIST = $(JuceExampleProjectdoc_DATA) \
	JuceExampleProject.anjuta

# 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


Makefile.am is used to generate the root Makefile. Again, it's auto-generated by Anjuta (complete with spelling mistake :lol:) - I've only added a single line ("JuceExampleProject.anjuta") to ensure the Anjuta project file gets included in the tarball when you run 'make dist'. If you have any non-source, non-documentation files you want to include in the tarball, this is where you put them.

src/Makefile.am:

## Process this file with automake to produce Makefile.in

## Created by Anjuta

INCLUDES = \
	$(X_CFLAGS) \
	-DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \
	-DPACKAGE_SRC_DIR=\""$(srcdir)"\" \
	-DPACKAGE_DATA_DIR=\""$(datadir)"\" 

AM_CXXFLAGS =\
	 -DRelease\
	 -DLINUX\
	 -DNDEBUG\
	 -Wall\
	 -g

bin_PROGRAMS = JuceExampleProject

JuceExampleProject_SOURCES = \
	App.h             \
	MainWindow.h             \
	App.cpp

JuceExampleProject_LDFLAGS = 

JuceExampleProject_LDADD = \
	$(X_PRE_LIBS) \
	$(X_LIBS) \
	$(X_EXTRA_LIBS)

This is used to generate the Makefile for the src directory, and it's here where the rest of the compiler settings get set. Again it's generated by Anjuta, and when you add any source files to your project in Anjuta, they'll get added to the list 'JuceExampleProject_SOURCES' (which you'd do by hand if you were just using plain autoconf). I've added the preprocessor macros JUCE needs to 'AM_CXXFLAGS', and added the stuff needed to build against the X libs to 'INCLUDES' and 'JuceExampleProject_LDADD'.

Some links:
autoconf manual
automake manual

Anyway, hope this is helpful. See the readme for some more instructions.

Also, I'm not an autoconf expert, so let me know if I've done things in a funny way...

- Niall.

stodge
Offline
Last seen: 4 years 6 months ago
Joined: 27 Nov 2007 - 19:50

That worked - thanks. I'll have to dig in and see what was different about my link command. I'm still confused...

Thanks