next up previous contents
Next: Bibliography Up: 12. Appendix: Portability Using Previous: 12.1 Portability Solutions

   
12.2 An Example Using Autoconf

Here is an example of how I intend to use Autoconf within FiST. The name of the VFS structure on most operating systems such as SunOS and Solaris is struct vfs and is defined <sys/vfs.h>. But on other systems such as FreeBSD, the name of the same structure is struct mount and is defined in <sys/mount.h>. Existing tests within Autoconf can find out if a C structure named vfs is defined in any of the system header files. If not found, the failure action code for looking up struct vfs would invoke the same test, but on a different name: it would look for struct mount. Once found, Autoconf will create a typedef which will be one of these two: typedef struct vfs vfs_t; or typedef struct mount vfs_t;. In addition, Autoconf will define one of #define HAVE_SYS_VFS_H or #define HAVE_SYS_MOUNT_H in the config.h file it creates. I would then write code that includes the correct header file and uses the typedef whenever I need to refer to the VFS structure. Figure fig-autoconf-vfs shows how I will write such VFS code.


  
Figure: VFS Sample Code Using Autoconf
4.2in

Figure: VFS Sample Code Using Autoconf


#ifdef HAVE_AC_CONFIG_H
/* include Autoconf-generated header */
# include "config.h"
#endif

#ifdef HAVE_SYS_VNODE_H
# include <sys/vnode.h>
#endif

#ifdef HAVE_SYS_MOUNT_H
# include <sys/mount.h>
#endif

int print_vfs(vfs_t *vfsp)
{
  /* code to print values within the vfs structure */
}





4in


#ifdef HAVE_AC_CONFIG_H
/* include Autoconf-generated header */
# include "config.h"
#endif

#ifdef HAVE_SYS_VNODE_H
# include <sys/vnode.h>
#endif

#ifdef HAVE_SYS_MOUNT_H
# include <sys/mount.h>
#endif

int print_vfs(vfs_t *vfsp)
{
  /* code to print values within the vfs structure */
}

In a similar manner I will write Autoconf tests that find and generalize more minute differences such as the different names used for fields within key C structures, whether an operating system has loadable kernel modules or not, what macros are used to dereference VFS and vnode pointers, and so on.

Autoconf can perform syntactic checks and limited tests for the correct use of certain symbols based on syntactic features. Autoconf, however, cannot solve purely semantic problems. Without additional help, it cannot discover the meaning of, say, two symbols with the same name across different operating systems that are used differently. Those cases unfortunately have to be specially handled. Nevertheless, Autoconf is a tool that will be able to figure out over 95% of the differences among operating systems automatically.


next up previous contents
Next: Bibliography Up: 12. Appendix: Portability Using Previous: 12.1 Portability Solutions
Erez Zadok
1999-12-07