Reputation: 1218
I have a project that targets multiple different architectures. For example, I have a header file 'fpr.h' that deals with floating point registers. These headers exist in:
arch/amd64/fpr.h
arch/ppc32/fpr.h
...
I have an architecture dependent file 'foo.c' that needs to include fpr.h. Obviously, I only want the header for the target architecture to be included but I'm not sure what the best way to do this is. I'm trying to use autotools for my build system but I don't see any suggested way to do this.
Any suggestions?
Upvotes: 0
Views: 841
Reputation: 6548
One way is to use the C preprocessor:
#define PP_STRINGIZE_(x) #x
#define PP_STRINGIZE(x) PP_STRINGIZE_(x)
#define ARCH_HEADER(h) PP_STRINGIZE(arch/ARCH/h)
#include ARCH_HEADER(fpr.h)
You can provide the ARCH
definition on compiler command line:
gcc -DARCH="amd64" foo.c
Upvotes: 1
Reputation: 127428
one way to do this is to put all of the architecture-specific headers in architecture-specific directories, and then select the appropriate directory based on the architecture to put on your include search path.
Upvotes: 0
Reputation: 70909
Have autotools set a build define.
Have the C files rewritten to include the correct header depending on the setting of the define
#ifdef HAVE_PPC_FPR_H
#include <arch/ppc32/fpr.h>
#endif
#ifdef HAVE_AMD64_FPR_H
#include <arch/amd64/fpr.h>
#endif
You can use AC_CHECK_HEADER multiple times in autoconf to detect each header file, but remember to omit writing a failure in the "action if not found" section. In the "action if found" section, it is advisable to not only set the necessary define, but to also set a define that the floating point header was found. That way you can embed after your checks a test to see if FPR_FOUND is not set, which you could then use to fail the configuration before the building actually starts.
Upvotes: 1
Reputation: 363567
One way is to let the autoconf script detect the architecture and set up a symlink arch/target
that points to the right directory of architecture-specific headers, then #include <arch/target/fpr.h>
. Making this work with out-of-place builds may be tricky, though.
Another way to do this is to set up an arch/target
directory by hand and populate it with files like fpr.h.in
that get preprocessed by M4 to refer to the actual architecture-specific header.
Upvotes: 1