Next: , Previous: Checking for a module or function, Up: configure.ac


5.1.4 Writing test programs

One great benefit of Autoconf is the ability to embed test programs inside configure. The pyconfigure macros allow for this by defining Python as a language within Autoconf. You then would proceed to write test programs as you would in any other language that Autoconf supports like C.

     AC_LANG_PUSH(Python)[]
     AC_RUN_IFELSE([AC_LANG_PROGRAM([dnl
     # some code here
     import foo
     ], [dnl
         # some more code here
         foo.bar()
     ])], [ACTION-IF-SUCCESSFUL], [ACTION-IF-FAILED])
     AC_LANG_POP(Python)[]

The first argument to AC_LANG_PROGRAM is the so-called “prolog”, and typically will contain your import statements or function definitions. The second argument contains the main body of the program, which will be in the scope of an if __name__=="__main__": block. So, you must be sure to indent the code appropriately.