|
The mkconfigure script generates a ./configure script from a
configure.in file. Our configure scripts offer a similar user interface
than GNU-style configure scripts, but the internals are different. Our
configure.in allows special directives (see the
mkconfigure manual for a complete
list), along with Bourne shell code fragments that will be inserted as-is
in the configure script.
# Register some configure options specific to our application.
REGISTER("--enable-threads", "Thread support [default: no]")
REGISTER("--enable-gui", "Graphical user interface [default: yes]")
# Name and version of the application, written to config/progname.h
# and config/version.h. This is completely optional.
HDEFINE(PROGNAME, "MyApp")
HDEFINE(VERSION, "1.0")
# Check for a C compiler. If one exists, ${HAVE_CC} will be set.
CHECK(cc)
# Check for OpenGL. If it works, then ${HAVE_OPENGL} will be set.
CHECK(opengl)
# OpenGL is required by our program, so we fail if it is not found.
if [ "${HAVE_OPENGL}" = "no" ]; then
echo "Sorry, this program requires OpenGL."
exit 1
fi
# The MDEFINE() directive sets a makefile define.
if [ "${enable_gui}" != "no" ]; then
MDEFINE(PROG_TYPE, "gui")
else
MDEFINE(PROG_TYPE, "cli")
fi
# Define THREADS if --enable-threads was given.
if [ "${enable_threads}" = "yes" ]; then
HDEFINE(THREADS, 1)
else
HDEFINE(THREADS, 0)
fi
The REGISTER() directives create new options to ./configure.
If the user passes the --with-foo option, "${with_foo}" will be
set to "yes". If the user passes --without-foo, it will be set
to "no".
The next two directives define PROGNAME and VERSION. They are not
required but they are useful when it comes to packaging.
The HDEFINE() directive generates header files such as
./config/progname.h and ./config/version.h.
The CHECK() directives performs a test. The BSDBuild distribution
includes a number of
built-in tests
for different libraries and programs.
The cc test checks for a C compiler, and opengl checks for an
OpenGL library.
All tests define a number of variables following a standard naming
convention, such as HAVE_FOO, FOO_LIBS and
FOO_CFLAGS.
In this case, our sample application requires OpenGL in order to work,
so we fail if the opengl test returned a HAVE_OPENGL
value of "no".
The CHECK(opengl) test, assuming it was successful, will define the
make variables OPENGL_CFLAGS and OPENGL_LIBS, and we will be able
to use them directly in our makefiles, like this:
CFLAGS+= ${OPENGL_CFLAGS}
LIBS+= ${OPENGL_LIBS}
The next piece of code sets the make variable $PROG_TYPE using the
MDEFINE() directive. This variable will be visible throughout our
makefiles. This particular variable ($PROG_TYPE) happens to be
recognized by build.prog.mk.
Note that there is a subtle difference between a test like:
if [ "${enable_threads}" = "yes" ]
and a test like:
if [ "${enable_threads}" != "no" ]
The first test will evaluate to true if and only if the user has
explicitely provided the --enable-threads option.
The second test will evaluate to true unless the user has explicitely
passed --disable-threads.
To generate the configure script, execute:
$ cat configure.in | mkconfigure > configure
$ chmod 755 configure
|