Using configure scripts with FlasCC

FlasCC supports the use of configure scripts to aid in building cross-platform C and C++ libraries for use in Flash-based projects. This post will show how FlasCC is able to build the Expat XML parser library using Expat’s GNU build system-generated configure script.

How do configure scripts work? A configure script is typically a Bash script that performs various operations to gather information about the target environment before generating an environment-specific makefile. It may check for the existence of particular utilities or libraries, probe the compiler for supported features, inspect header files, compile and execute small test programs, etc.

An example test program might be something like:

/* test program to ascertain this platform's pointer size */
int main()
  printf("%d\n", sizeof(void *));
  return 0;

In most environments, any such operations are straightforward. The native utilities, header files, and compiler can be used to answer any questions the configure script might have.

How does the FlasCC toolchain support these kinds of techniques? FlasCC has a feature called “vm projectors” that allows building native executables in which the compiled C/C++ code executes within the same ActionScript Virtual Machine (AVM) used by the Flash Player and the AIR Runtime, thereby having all of the characteristics of the FlasCC environment rather than the native one. So the short test program above, compiled as a vm projector, will output the size of a pointer in the FlasCC environment regardless of the pointer size of the native environment.

In fact, this “vm projector mode” is the default mode for FlasCC’s gcc and g++ compilers – it requires no extra switches. This means that, in many cases, the only step necessary to successfully use configure scripts with FlasCC is to ensure that the PATH environment variable is set up to ensure that FlasCC’s gcc and g++ are found before any native compilers.

Sample steps for configuring, building, and testing the open source Expat XML parsing library follow.

  1. Download Expat sources here
  2. Unpackage sources
    tar xf expat-2.1.0.tar.gz
  3. Configure Expat
    cd expat-2.1.0
    PATH=/path/to/flascc/sdk/usr/bin:$PATH ./configure --prefix=/path/to/flascc/sdk/usr

    Note that the paths will have to be modified to reflect your installation of the FlasCC SDK. The --prefix options tells the configuration script where you want header files, libraries, etc. installed. Since we’re building Expat for FlasCC, we want these artifacts installed in the FlasCC SDK itself.

    Optionally, adding CFLAGS=-O4 to the command will increase the aggressiveness of optimizations done as well as enable LTO (Link Time Optimization)

  4. Build the library
    PATH=/path/to/flascc/sdk/usr/bin:$PATH make
  5. Install the library
    PATH=/path/to/flascc/sdk/usr/bin:$PATH make install
  6. Check the installation
    PATH=/path/to/flascc/sdk/usr/bin:$PATH make check

    At the end of the make check command’s output, you should see something like the following:
    Expat version: expat_2.1.0
    100%: Checks: 50, Failed: 0
    Expat version: expat_2.1.0
    100%: Checks: 50, Failed: 0

Now your FlasCC SDK includes a working set of header files and libraries for Expat that can be used to build SWFs. A simple Flash-based Expat sample is included here and can be compiled with a command like:
/path/to/flascc/sdk/usr/bin/gcc expatTest.c -lexpat -emit-swf -o expatTest.swf

Here is the resulting SWF.

Comments are closed.