Matt
Matt

Reputation: 22163

How can a Makefile determine the binary format the compiler will create?

Is it possible for a Makefile to determine what binary format the compiler is targeting (i.e. PE, ELF, Mach-O, etc.)? Maybe by running the compiler or assembler with certain options?

Or can I accurately determine this from the OS (by running uname -s or something of the sort)?

Upvotes: 0

Views: 122

Answers (1)

Tom Tromey
Tom Tromey

Reputation: 22589

This sort of thing is why configure scripts exist -- that is, to probe the build environment to determine useful information that isn't directly available in the language.

I wouldn't be surprised if there is already an autoconf macro to handle this. However, I didn't look.

The simplest way to accomplish what you want is to, first, compile the simplest possible program using the compiler and compiler options you want to test. Then, use the file command to see what sort of file this created. You can use sed or the like on the output to turn this into whatever symbol or string you want to pass to your real compilation.

If file is not to your taste, you could alternatively write a custom program to examine the output file to see what it is.

Upvotes: 2

Related Questions