foo-append working with merger in muniversal?

Michael Dickens michaelld at macports.org
Mon Sep 13 19:41:04 PDT 2010


I've been hacking on py26-numpy to try to get +universal working.  I can say from my experiments that:

(1) MacPorts' installed gcc4[3-5] do not honor "-m32 -m64" at the same time; just one or the other.  The only way to get build for multiple architectures using this gcc is to build them separately and them use "lipo" to join any binary files.  Hence, the "muniversal" group must be used.

(2) The "muniversal" group does not know how to merge ".pyc" files -- byte-compiled Python.  As far as I can tell, the only difference between the i386 and x86_64 versions of .pyc files is a timestamp.  So, adding in a "switch" for "*.pyc" is quite simple.

(3) The "muniversal" group does all the fancy "arch" settings during the MacPorts' "configure" stage, but there is no such stage for any Python group; instead, everything happens during the MacPort's "build" phase.  Hence, the "arch" flags must be set as part of the build.env, not the configure.env.  Hence, the "merger_build_env" array from muniversal is required.

(4) Setting just "YYYFLAGS=-mXX" (where YYY is, e.g., "C", "CXX", "LD", OBJC" etc) via "merger_build_env " does not work, because (for example on my system): In 32-bit mode during what is effectively the 'configure' stage of setup.py, tests will be compiled as 32-bit, but linked without the "-m32" as whatever the native bit-age of gcc is (for me, 64-bit).  This means that (for me) the i386 compile will error out early on.  Hence, integrating the "-mXX" flag into CC, CXX, and F90 is required (in order for the -mXX flag to be present during testing as well as compiling).

I can get full i386 and x86_64 builds using the CLI with environment variables as above (using CC, CXX, F90, and LDFLAGS=-mXX), but I can't get this working using a Portfile, as described below. I'm hoping someone can shed some light on either what I'm doing wrong or if there's a bug in FOO-append &/| elsewhere.

In the py26-numpy Portfile, I added ("gcc_version" is set correctly per the variants):

===========
pre-build {
    if {[variant_exists universal] && [variant_isset universal]} {
        global array set merger_build_env {
            ppc     ""
            i386    ""
            ppc64   ""
            x86_64  ""
        }
        foreach arch ${universal_archs_to_use} {
            # sort of recreate what muniversal did for configure arch flags
            set archf [muniversal_get_arch_flag ${arch}]
            lappend merger_build_env(${arch}) \
                CC="${prefix}/bin/gcc-mp-${gcc_version} ${archf}" \
                CXX="${prefix}/bin/g++-mp-${gcc_version} ${archf}" \
                F90="${prefix}/bin/gfortran-mp-${gcc_version} ${archf}" \
                LDFLAGS="${archf}"
        }
    }
}
===========

and then in muniversal-1.0.tcl I augmented line 331-3 to printing debug info:

===========
            if { [info exists merger_build_env(${arch})] } {
                ui_msg "'merger_build_env(${arch})' is '$merger_build_env(${arch})'"
                ui_msg "pre : build.env is '${build.env}'"
                build.env-append $merger_build_env(${arch})
                ui_msg "post: build.env is '${build.env}'"
            }
===========

so that I can view the build environment (as believed by port during runtime).  When I do "sudo port -d build py26-numpy +universal", I get back (of relevance):

===========
DEBUG: Executing org.macports.build (py26-numpy)
--->  Building py26-numpy for architecture x86_64
'merger_build_env(x86_64)' is 'CC=\"/opt/local/bin/gcc-mp-4.4 -m64\" CXX=\"/opt/local/bin/g++-mp-4.4 -m64\" F90=\"/opt/local/bin/gfortran-mp-4.4 -m64\" LDFLAGS=\"-m64\"'
pre : build.env is 'ATLAS=/opt/local/lib LAPACK=/opt/local/lib BLAS=/opt/local/lib'
post: build.env is 'ATLAS=/opt/local/lib LAPACK=/opt/local/lib BLAS=/opt/local/lib {CC=\"/opt/local/bin/gcc-mp-4.4 -m64\" CXX=\"/opt/local/bin/g++-mp-4.4 -m64\" F90=\"/opt/local/bin/gfortran-mp-4.4 -m64\" LDFLAGS=\"-m64\"}'
DEBUG: Environment: CPATH='/opt/local/include' CC_PRINT_OPTIONS_FILE='/opt/local/var/macports/build/_opt_MacPorts_macports-trunk_dports_python_py26-numpy/work/.CC_PRINT_OPTIONS' LAPACK='/opt/local/lib' LIBRARY_PATH='/opt/local/lib' CC_PRINT_OPTIONS='YES' MACOSX_DEPLOYMENT_TARGET='10.6' ATLAS='/opt/local/lib' BLAS='/opt/local/lib'
===========

which says to me that my Portfile addition -is- working as expected, but that the build.env-append function -is not- working as expected.

Does anyone know what I'm doing incorrectly, and/or how to do this correctly?  I think if this change can be made to work, then this port will work as +universal.  Thanks in advance. - MLD


More information about the macports-dev mailing list