Search code examples
architecturegccmakefilepowerpc

How do I create a single makefile for both 32- and 64-bit?


I have a makefile that works transparently for Linux (x86_64) and OS X Intel (x86_64). This uses 64-bit specific GCC options.

Is there a way to adjust the makefile so that I could build for 32-bit and 64-bit OS X PPC (ppc, ppc64) without having to maintain separate, arch-specific makefiles — perhaps something like a pre-processor directive that can determine the architecture before building?


Solution

  • ARCH := $(shell getconf LONG_BIT)
    
    CPP_FLAGS_32 := -D32_BIT ...  Some 32 specific compiler flags ...
    CPP_FLAGS_64 := -D64_BIT
    
    CPP_FLAGS := $(CPP_FLAGS_$(ARCH))  ... all the other flags ...