autoconf: Using System Type
1
1 14.3 Using the System Type
1 ==========================
1
1 In `configure.ac' the system type is generally used by one or more
1 `case' statements to select system-specifics. Shell wildcards can be
1 used to match a group of system types.
1
1 For example, an extra assembler code object file could be chosen,
1 giving access to a CPU cycle counter register. `$(CYCLE_OBJ)' in the
1 following would be used in a makefile to add the object to a program or
1 library.
1
1 AS_CASE([$host],
1 [alpha*-*-*], [CYCLE_OBJ=rpcc.o],
1 [i?86-*-*], [CYCLE_OBJ=rdtsc.o],
1 [CYCLE_OBJ=""]
1 )
1 AC_SUBST([CYCLE_OBJ])
1
1 `AC_CONFIG_LINKS' (⇒Configuration Links) is another good way
1 to select variant source files, for example optimized code for some
1 CPUs. The configured CPU type doesn't always indicate exact CPU types,
1 so some runtime capability checks may be necessary too.
1
1 case $host in
1 alpha*-*-*) AC_CONFIG_LINKS([dither.c:alpha/dither.c]) ;;
1 powerpc*-*-*) AC_CONFIG_LINKS([dither.c:powerpc/dither.c]) ;;
1 *-*-*) AC_CONFIG_LINKS([dither.c:generic/dither.c]) ;;
1 esac
1
1 The host system type can also be used to find cross-compilation tools
1 with `AC_CHECK_TOOL' (⇒Generic Programs).
1
1 The above examples all show `$host', since this is where the code is
1 going to run. Only rarely is it necessary to test `$build' (which is
1 where the build is being done).
1
1 Whenever you're tempted to use `$host' it's worth considering
1 whether some sort of probe would be better. New system types come along
1 periodically or previously missing features are added. Well-written
1 probes can adapt themselves to such things, but hard-coded lists of
1 names can't. Here are some guidelines,
1
1 * Availability of libraries and library functions should always be
1 checked by probing.
1
1 * Variant behavior of system calls is best identified with runtime
1 tests if possible, but bug workarounds or obscure difficulties
1 might have to be driven from `$host'.
1
1 * Assembler code is inevitably highly CPU-specific and is best
1 selected according to `$host_cpu'.
1
1 * Assembler variations like underscore prefix on globals or ELF
1 versus COFF type directives are however best determined by
1 probing, perhaps even examining the compiler output.
1
1 `$target' is for use by a package creating a compiler or similar.
1 For ordinary packages it's meaningless and should not be used. It
1 indicates what the created compiler should generate code for, if it can
1 cross-compile. `$target' generally selects various hard-coded CPU and
1 system conventions, since usually the compiler or tools under
1 construction themselves determine how the target works.
1