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?
Creating a Makefile A Makefile typically starts with some variable definitions which are then followed by a set of target entries for building specific targets (typically .o & executable files in C and C++, and . class files in Java) or executing a set of command associated with a target label.
Make is Unix utility that is designed to start execution of a makefile. A makefile is a special file, containing shell commands, that you create and name makefile (or Makefile depending upon the system).
It's just a conventional name; all target denotes that if you invoke it, make will build all what's needed to make a complete build. This is usually a dummy target, which doesn't create any files, but merely depends on the other files.
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 ...
Try file inclusion. This is not part of the standard Makefile syntax (the one in the Single Unix v3 specification) but is widely supported. With GNU make, this looks like this:
include otherfile
With this, you could have an x86 Makefile like this:
ARCHFLAGS = -m64 -mtune=core2
include common.mk
and a PowerPC Makefile:
ARCHFLAGS = -mcpu=g3
include common.mk
and the bulk of your compilation rules will be in one file (common.mk
), using $(ARCHFLAGS)
where necessary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With