[23098] trunk/base

source_changes at macosforge.org source_changes at macosforge.org
Sat Mar 24 18:27:29 PDT 2007


Revision: 23098
          http://trac.macosforge.org/projects/macports/changeset/23098
Author:   pguyot at kallisys.net
Date:     2007-03-24 18:27:29 -0700 (Sat, 24 Mar 2007)

Log Message:
-----------
New options for configure flags (C|CPP|CXX|LD)FLAGS and logic to handle that
and backward compatibility.

This new code introduces some important changes.
(a) the default value for CFLAGS and CXXFLAGS is -O2. This means that ports
that previously defined CFLAGS with configure.env will now be compiled
optimized (instead of -O0) as they should have been, since -O2 is the autoconf
default value when the compiler is gcc.

(b) universal variants are now also compiled with -O2.

(c) +universal now works even if some CFLAGS were previously declared, thanks
to the environment parser that was added. I also dropped support for
configure.universal_env which does not make much sense, and added new options
for CPPFLAGS and CXXFLAGS (configure.universal_c(pp|xx)flags).

(d) we will be able to factorize the -L${prefix}/lib and -I${prefix}/include
as well as offer global preference for optimization (-O2) and debug (-g).

(e) we probably want to prefer the new options over configure.env and simplify
the logic at some point once ports no longer use configure.env for these flags.

The portfile(7) man page was modified to document these new options. Changes
for the universal options were also documented and the universal hooks section
was made a subsection of the new "configure options" section, which is more
coherent with the rest of the page.

All ports should still work, feel free to bug me otherwise :)
However, I do not know what gcc picks up when several -O options are passed and
ports that define an optimization flag (e.g. atk) in configure.env might
produce a different binary.

Modified Paths:
--------------
    trunk/base/doc/portfile.7
    trunk/base/src/port1.0/portconfigure.tcl
    trunk/base/src/port1.0/portmain.tcl
    trunk/base/src/port1.0/portutil.tcl

Modified: trunk/base/doc/portfile.7
===================================================================
--- trunk/base/doc/portfile.7	2007-03-25 01:05:14 UTC (rev 23097)
+++ trunk/base/doc/portfile.7	2007-03-25 01:27:29 UTC (rev 23098)
@@ -316,7 +316,7 @@
 basis.
 .br
 .Sy Example:
-.Dl configure.env CFLAGS=-O
+.Dl configure.env CPP=/usr/bin/cpp-4.0
 .It Va target Ns Ic .pre_args
 Additional arguments passed before the main arguments.
 .br
@@ -337,42 +337,6 @@
 .Sy Example:
 .Dl extract.post_args | tar xf -
 .El
-.Sh UNIVERSAL TARGET HOOKS
-For universal builds of configure-based ports, we also define specific target hooks. These can be overridden for specific ports. Please note that these hooks are used by the default universal variant and redefining the variant will make them useless. Please also note that problems may occur with the default code if a port already overrides LDFLAGS or CFLAGS (port(1) will display a warning in such a case).
-.Bl -tag -width lc
-.It Ic configure.universal_args
-Arguments appended to the configure script to build the port universal.
-.br
-.Sy Type:
-.Em optional
-.br
-.Sy Default:
-.Em --disable-dependency-tracking
-.It Ic configure.universal_cflags
-Value of the CFLAGS environment variable when invoking the configure script.
-.br
-.Sy Type:
-.Em optional
-.br
-.Sy Default:
-.Em -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc
-.It Ic configure.universal_ldflags
-Value of the LDFLAGS environment variable when invoking the configure script.
-.br
-.Sy Type:
-.Em optional
-.br
-.Sy Default:
-.Em -arch i386 -arch ppc
-.It Ic configure.universal_env
-Environment appended to the port-defined environment when invoking the configure script.
-.br
-.Sy Type:
-.Em optional
-.br
-.Sy Default:
-.Em CFLAGS="${configure.universal_cflags}" LDFLAGS="${configure.universal_ldflags}"
-.El
 .Sh RUNTIME VARIABLES
 Read-only access to the MacPorts configuration is provided.
 .Bl -tag -width lc
@@ -796,6 +760,80 @@
 .Sy Example:
 .Dl extract.cmd bzip2
 .El
+.Sh CONFIGURE OPTIONS
+MacPorts provide special support for configure flags (CFLAGS, LDFLAGS, CPPFLAGS, CXXFLAGS). Please note that the previous way to alter these flags (using configure.env) may become deprecated at some point. The following options are defined:
+.Bl -tag -width lc
+.It Ic configure.cflags
+Flags to put in the CFLAGS environment variable when invoking the configure script.
+.br
+.Sy Type:
+.Em optional
+.br
+.Sy Default:
+.Em -O2
+.br
+.Sy Example:
+.Dl configure.cflags-append -DHAS_LRINTF
+.It Ic configure.cppflags
+Flags to put in the CPPFLAGS environment variable when invoking the configure script.
+.br
+.Sy Type:
+.Em optional
+.It Ic configure.cxxflags
+Flags to put in the CXXFLAGS environment variable when invoking the configure script.
+.br
+.Sy Type:
+.Em optional
+.br
+.Sy Default:
+.Em -O2
+.It Ic configure.ldflags
+Flags to put in the LDFLAGS environment variable when invoking the configure script.
+.br
+.Sy Type:
+.Em optional
+.El
+.Ss UNIVERSAL TARGET HOOKS
+For universal builds of configure-based ports, we also define specific target hooks. These can be overridden for specific ports. Please note that these hooks are used by the default universal variant and redefining the variant will make them useless.
+.Bl -tag -width lc
+.It Ic configure.universal_args
+Arguments appended to the configure script to build the port universal.
+.br
+.Sy Type:
+.Em optional
+.br
+.Sy Default:
+.Em --disable-dependency-tracking
+.It Ic configure.universal_cflags
+Additional flags to put in the CFLAGS environment variable when invoking the configure script.
+.br
+.Sy Type:
+.Em optional
+.br
+.Sy Default:
+.Em -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc
+.It Ic configure.universal_cppflags
+Additional flags to put in the CPPFLAGS environment variable when invoking the configure script.
+.br
+.Sy Type:
+.Em optional
+.It Ic configure.universal_cxxflags
+Additional flags to put in the CXXFLAGS environment variable when invoking the configure script.
+.br
+.Sy Type:
+.Em optional
+.br
+.Sy Default:
+.Em -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc
+.It Ic configure.universal_ldflags
+Additional flags to put in the LDFLAGS environment variable when invoking the configure script.
+.br
+.Sy Type:
+.Em optional
+.br
+.Sy Default:
+.Em -arch i386 -arch ppc
+.El
 .Sh BUILD OPTIONS
 Execute necessary build commands.
 .Bl -tag -width lc

Modified: trunk/base/src/port1.0/portconfigure.tcl
===================================================================
--- trunk/base/src/port1.0/portconfigure.tcl	2007-03-25 01:05:14 UTC (rev 23097)
+++ trunk/base/src/port1.0/portconfigure.tcl	2007-03-25 01:27:29 UTC (rev 23098)
@@ -41,6 +41,7 @@
 # define options
 commands configure automake autoconf xmkmf libtool
 # defaults
+default configure.env ""
 default configure.pre_args {--prefix=${prefix}}
 default configure.cmd ./configure
 default configure.dir {${worksrcpath}}
@@ -50,12 +51,22 @@
 default xmkmf.dir {${worksrcpath}}
 default use_configure yes
 
+# Configure special environment variables.
+options configure.cflags configure.cppflags configure.cxxflags configure.ldflags
+# This could move to default debug/optimization flags at some point.
+# We probably want to add -L${prefix}/lib and -I${prefix}/include here.
+default configure.cflags	{-O2}
+default configure.cppflags	{}
+default configure.cxxflags	{-O2}
+default configure.ldflags	{}
+
 # Universal options & default values.
-options configure.universal_args configure.universal_cflags configure.universal_ldflags configure.universal_env
-default configure.universal_args	--disable-dependency-tracking
-default configure.universal_cflags	{"-isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc"}
-default configure.universal_ldflags	{"-arch i386 -arch ppc"}
-default configure.universal_env		{"CFLAGS=\"${configure.universal_cflags}\" LDFLAGS=\"${configure.universal_ldflags}\""}
+options configure.universal_args		configure.universal_cflags configure.universal_cppflags configure.universal_cxxflags configure.universal_ldflags configure.universal_env
+default configure.universal_args		--disable-dependency-tracking
+default configure.universal_cflags		{"-isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc"}
+default configure.universal_cppflags	{}
+default configure.universal_cxxflags	{"-isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc"}
+default configure.universal_ldflags		{"-arch i386 -arch ppc"}
 
 set_ui_prefix
 
@@ -67,7 +78,8 @@
 
 proc configure_main {args} {
     global [info globals]
-    global configure configure.args configure.dir automake automake.env automake.args automake.dir autoconf autoconf.env autoconf.args autoconf.dir xmkmf libtool portname worksrcpath prefix workpath UI_PREFIX use_configure use_autoconf use_automake use_xmkmf
+    global worksrcpath use_configure use_autoconf use_automake use_xmkmf
+    global configure.env configure.cflags configure.cppflags configure.cxxflags configure.ldflags
     
     if {[tbool use_automake]} {
 	# XXX depend on automake
@@ -84,18 +96,25 @@
     }
     
     if {[tbool use_xmkmf]} {
-	# XXX depend on xmkmf
-	if {[catch {system "[command xmkmf]"} result]} {
-	    return -code error "[format [msgcat::mc "%s failure: %s"] xmkmf $result]"
-	} else {
-	    # XXX should probably use make command abstraction but we know that
-	    # X11 will already set things up so that "make Makefiles" always works.
-	    system "cd ${worksrcpath} && make Makefiles"
-	}
-    } elseif {[tbool use_configure]} {
-	if {[catch {system "[command configure]"} result]} {
-	    return -code error "[format [msgcat::mc "%s failure: %s"] configure $result]"
-	}
+		# XXX depend on xmkmf
+		if {[catch {system "[command xmkmf]"} result]} {
+		    return -code error "[format [msgcat::mc "%s failure: %s"] xmkmf $result]"
+		} else {
+		    # XXX should probably use make command abstraction but we know that
+		    # X11 will already set things up so that "make Makefiles" always works.
+		    system "cd ${worksrcpath} && make Makefiles"
+		}
+	} elseif {[tbool use_configure]} {
+    	# Merge (ld|c|cpp|cxx)flags into the environment variable.
+    	parse_environment ${configure.env} parsed_env
+		append_list_to_environment_value parsed_env "CFLAGS" ${configure.cflags}
+		append_list_to_environment_value parsed_env "CPPFLAGS" ${configure.cppflags}
+		append_list_to_environment_value parsed_env "CXXFLAGS" ${configure.cxxflags}
+		append_list_to_environment_value parsed_env "LDFLAGS" ${configure.ldflags}
+		set configure.env [environment_array_to_string parsed_env]
+		if {[catch {system "[command configure]"} result]} {
+			return -code error "[format [msgcat::mc "%s failure: %s"] configure $result]"
+		}
     }
     return 0
 }

Modified: trunk/base/src/port1.0/portmain.tcl
===================================================================
--- trunk/base/src/port1.0/portmain.tcl	2007-03-25 01:05:14 UTC (rev 23097)
+++ trunk/base/src/port1.0/portmain.tcl	2007-03-25 01:27:29 UTC (rev 23098)
@@ -102,13 +102,13 @@
 			return -code error "Default universal variant only works with ports based on configure"
 		}
 		configure.args-append ${configure.universal_args}
-		if {[info exists configure.env] && [regexp "(^| )(LD|C)FLAGS=" ${configure.env}]} {
-			ui_warn "This port already overrides CFLAGS or LDFLAGS. The universal variant may break it."
-		}
 		if {![file exists /Developer/SDKs/MacOSX10.4u.sdk/]} {
-			ui_warn "MacOS X 10.4 universal SDK is not installed (are we running on 10.3? did you forget to install it?) and building with +universal will very likely fail"
+			return -code error "MacOS X 10.4 universal SDK is not installed (are we running on 10.3? did you forget to install it?) and building with +universal will very likely fail"
 		}
-		configure.env-append ${configure.universal_env}
+		configure.cflags-append ${configure.universal_cflags}
+		configure.cppflags-append ${configure.universal_cppflags}
+		configure.cxxflags-append ${configure.universal_cxxflags}
+		configure.ldflags-append ${configure.universal_ldflags}
 	}
 }
 

Modified: trunk/base/src/port1.0/portutil.tcl
===================================================================
--- trunk/base/src/port1.0/portutil.tcl	2007-03-25 01:05:14 UTC (rev 23097)
+++ trunk/base/src/port1.0/portutil.tcl	2007-03-25 01:27:29 UTC (rev 23098)
@@ -401,6 +401,87 @@
     }
 }
 
+########### Environment utility functions ###########
+
+# Parse an environment string, returning a list of key/value pairs.
+proc parse_environment {environment_str parsed_environment} {
+	upvar 1 ${parsed_environment} env_array
+	set the_environment ${environment_str}
+	while {[regexp "^(?: *)(\[^= \]+)=(\\\\?(\"|'|))(\[^\"'\].*?)\\2(?: +|$)(.*)$" ${the_environment} matchVar key delimiter_full delimiter value remaining]} {
+		set the_environment ${remaining}
+		set env_array(${key}) ${delimiter}${value}${delimiter}
+	}
+}
+
+# Append to the value in the parsed environment.
+# Leave the environment untouched if the value is empty.
+proc append_to_environment_value {parsed_environment key value} {
+	upvar 1 ${parsed_environment} env_array
+
+	if {[string length $value] == 0} {
+		return
+	}
+
+	if {[info exists env_array($key)]} {
+		set original_value $env_array($key)
+		set original_delim ""
+		if {[regexp {^("|')(.*)\1$} ${original_value} matchVar original_delim matchedValue]} {
+			set original_value $matchedValue
+		}
+		set append_delim ""
+		set append_value $value
+		if {[regexp {^("|')(.*)\1$} $append_value matchVar append_delim matchedValue]} {
+			set append_value $matchedValue
+		}
+	
+		# Always honor original delimiter when appending, unless there isn't any.
+		if {[string length $original_delim] == 0} {
+			if {[string length $append_delim] == 0} {
+				set new_delim "'"
+			} else {
+				set new_delim $append_delim
+			}
+		} else {
+			set new_delim $original_delim
+		}
+		
+		set space " "
+		set env_array($key) ${new_delim}${original_value}${space}${append_value}${new_delim}
+	} else {
+		set env_array($key) $value
+	}
+}
+
+# Append several items to a value in the parsed environment.
+proc append_list_to_environment_value {parsed_environment key vallist} {
+	upvar 1 ${parsed_environment} env_array
+
+	foreach {value} $vallist {
+		append_to_environment_value env_array $key $value
+	}
+}
+
+# Rebuild the environment as a string.
+proc environment_array_to_string {parsed_environment} {
+	upvar 1 ${parsed_environment} env_array
+	set theString ""
+	foreach {key value} [array get env_array] {
+		set added_delim "'"
+		if {[regexp {^("|').*\1$} ${value} matchVar original_delim]} {
+			set added_delim ""
+		}
+		set value "${added_delim}${value}${added_delim}"
+
+		if {$theString == ""} {
+			set theString "$key=$value"
+		} else {
+			set theString "${theString} $key=$value"
+		}
+	}
+	
+	return $theString
+}
+
 ########### Distname utility functions ###########
 
 # Given a distribution file name, return the appended tag

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20070324/7e6f0be1/attachment.html


More information about the macports-changes mailing list