views:

980

answers:

2

The solution in

http://stackoverflow.com/questions/1272357/how-to-compile-a-32-bit-binary-on-a-64-bit-linux-machine-with-gcc-cmake

is not possible because i use 3rd party software and other stuff which is using the CFLAGS variable already. And patching their makefiles is not allowed - says my boss.

So i have to find another way to enforce it. Maybe some magic with symbolic links redirecting a call to gcc to a 32bit version of the compiler (hoping that the default target is not detected dynamically).

+3  A: 

You are not allowed to change CFLAGS in your environment, but is there any reason you are cannot override it temporarily for the build?

For an autotool-based package, I would first try:

CFLAGS="-m32" ./configure [opts]
make
make install

A well-written configure.ac file should respect your CFLAGS variable and append to it, without requiring you to modify the package source.

Update

Assuming, then, that you can't redefine your CC variable, either, I would play some path tricks. Make a shell script in ${HOME}/gcc32 called gcc with the following (untested):

#!/bin/sh
/usr/bin/gcc -m32 "$@"

Then prepend this to your path when you want to build 32-bit:

export PATH=${HOME}/gcc32:${PATH}

Obvious modifications will support g++, icc, or any other compiler.

jvasak
Unfortunately the makefile itself sets CFLAGS and even worse it is doing this based on a cascade of if conditions. So i can't easily factor this into my outside CFLAGS definition. The makefile writer should have used another variable name and left CFLAGS for its intended purpose but this is the code as it is.
Lothar
Incorporated this new info in the update above
jvasak
You need to use an absolute path, otherwise you will get infinite recursion.
Michael Aaron Safyan
You are corect. Fixed.
jvasak
A: 

Let's assume that gcc and friends are located in "/usr/bin". Let us also assume that you have a folder called "~/.local/bin" that is in your path. You can create a bash script named "gcc" in "~/.local/bin" like:

#! /bin/bash
/usr/bin/gcc -m32 $@

You can similarly create a "g++" script with the content as follows:

#! /bin/bash
/usr/bin/g++ -m32 $@

Basically, keep doing this for "c++", "cc", "as", "ld", etc. as needed. Make the scripts executable. Make sure that "~/.local/bin" is in your PATH environment variable BEFORE "/usr/bin". If that is the case, then when the makefile invokes the compiler (assuming they used relative paths), your scripts will be invoked, instead.

Michael Aaron Safyan