0

I want to check whether the operating system used is 32 bit or 64 bit inside an automake(.am) file.

Udit Sanghi
  • 21
  • 1
  • 8
  • 1
    Autoconf should perform the test and set a flag for Automake. Autoconf is just a shell script environment, so you only need to perform the same command line test you would from a terminal. Then use `AM_CONDITIONAL` in Autoconf to set the flag for Automake. Or you could use the host triplet and set the flag. Also, Intel compatibles have three arch variants, not two - [i386 (or i686), amd64 and X32](https://stackoverflow.com/q/7635013/608639). – jww Oct 31 '18 at 14:18
  • Is CMake related with your problem? If not, remove `cmake` tag, please. – Tsyvarev Oct 31 '18 at 14:45

1 Answers1

2

configure is usually pretty good at figuring out what OS/architecture it's running on, and exposes this information through a few macros: AC_CANONICAL_BUILD, AC_CANONICAL_HOST, and AC_CANONICAL_TARGET.

The end user of configure can override this guess by adding flags to the invocation of configure. The definition of what "build", "host", and "target" may be found on that link as well.

I'm not sure which OS or CPU you are caring about. The build machine is where you are running software compilation. It may be the same as the host machine where the output of build compilation is run. So I guess you care about the host, so...

configure.ac

...
AC_CANONICAL_HOST
HOST_OS=""
AS_CASE([$host_cpu],
        [x86_64|aarch64*|mips64*|ppc64*|sparc64],
        [
            HOST_OS="64"
        ],
        [i?86|arm*|mips*|ppc*|sparc],
        [
            HOST_OS="32"
        ])

AC_SUBST([HOST_OS])

Makefile.am

foo_CPPFLAGS = -DHOST_OS=$(HOST_OS)
ldav1s
  • 15,885
  • 2
  • 53
  • 56
  • 1
    This does not help to find out whether a MIPS, Sparc, PowerPC, or any other non-Intel compatible system is 32 or 64 bit. – ndim Dec 04 '18 at 22:30