Tcl Source Code

View Ticket
Login
Ticket UUID: bc16203b0e1d11d0d6cee35d41a8218bd97364c1
Title: Allow programmatically adjustable optimization and debug flags
Type: Patch Version: all
Submitter: erikleunissen Created on: 2015-04-06 17:54:50
Subsystem: 53. Configuration and Build Tools Assigned To: max
Priority: 5 Medium Severity: Minor
Status: Open Last Modified: 2021-01-06 14:35:19
Resolution: None Closed By: nobody
    Closed on:
Description:
Allow programmatically adjustable optimization and debug flags
==============================================================

The build process based on autotools allows adjustment of the build configuration by providing custom values for some variables. Well-known examples are names for programs like CC, LD, AR, RANLIB, DLLTOOL, NM and RC, and program flags like: CPPFLAGS, CFLAGS, LDFLAGS. Regular methods to make such customizations programmatically, are the usage of a config.site script, or passing settings on the command-line for ./configure.

What currently doesn't work using these methods, is adjusting debug and optimization flags (to the compiler and linker). Also, these adjustment cannot be cleanly done through the CFLAGS and LDFLAGS variables because Makefile.in handles these variables in append mode, resulting in multiple debugging or optimization settings within a single compiler command line.

The attached patches enable the functionality for Tcl and Tk. They modify just the files tcl.m4 in the unix and win subdirectories. Macosx builds inherit the functionality from the patched unix directory.

Because tcl.m4 is modified, the configure scripts need to be regenerated. A newly generated ./configure picks up custom settings for CFLAGS_OPTIMIZE and CFLAGS_DEBUG, either from a config.site script or directly from the command line. Example invocations are provided below for win, unix and macosx builds. In any case, the resulting Makefile takes care of invoking the compiler and linker, using the custom optimization and debug flags as intended (tested).

Part of this patch removes some clutter and dirt related to the pertinent variables:
a. remove redundant explicit substitution of precious variables
b. for non-gcc win builds: assign preprocessor directives previously cluttering CFLAGS_OPTIMIZE and CFLAGS_DEBUG, to DEFS instead

The motivation for this patch is a personal need for programmatical adjustment of (just) the optimization flags to the compiler. Though I don't need it myself, I expect arguments for adjusting debug flags to be similar to those for optimization flags. The main reason to apply this functionality also to the linker flags, is the entirely analoguous handling of compiler and linker flags throughout the build configuration. Hence the scope.

The attached patches are based off the fossil trunk:
Tcl: [6f8d422627], 2015-04-04 11:47
Tk:  [22256943eb], 2015-03-24 19:13


Sincerely,

Erik Leunissen
--

Command line examples for customized build flags
================================================

[1] using a config.site script (unix and win builds):

> cat /wherever/you/stored/it/config.site
CFLAGS_DEBUG=-ggdb3
CFLAGS_OPTIMIZE=-O3

> CONFIG_SITE=/wherever/you/stored/it/config.site ./configure --disable-symbols

     (or use --enable-symbols instead, to select the custom debug settings)


[2] using command line arguments (unix and win builds):

> ./configure --enable-symbols CFLAGS_DEBUG=-ggdb3

or:

> ./configure --disable-symbols CFLAGS_OPTIMIZE=-O3


[3] macosx variant:

The presented customization method also works with macosx builds, which use the unix ./configure script for their purpose (and the unix patch applies in this case). However, a macosx build doesn't call ../unix/configure directly. It uses make as a wrapper command. Therefore, the macosx command lines are different from those for the win and unix builds. To produce customized debug and optimized builds for macosx (macosx supports building both in one go), one can do:

> make EXTRA_CONFIGURE_FLAGS="CONFIG_SITE=/wherever/you/stored/it/config.site"

or:

> make EXTRA_CONFIGURE_FLAGS="CFLAGS_DEBUG=-ggdb3 CFLAGS_OPTIMIZE=-O3"

-- end --
User Comments: erikleunissen added on 2021-01-06 14:35:19:
Any plans for proceeding with this ticket?

max added on 2015-05-28 12:51:21:
Looks OK to me.

Attachments: