Name

Property define_proc — Use a fragment of Tcl code to output additional data to configuration header files.

Synopsis

cdl_option <name> {
  define_proc <Tcl script>
  …
}

Description

For most configuration options it is sufficient to have an entry in the configuration header file of the form:

#define <name> <value>

In some cases it is desirable to perform some more complicated processing when generating a configuration header file. There are a number of CDL properties for this, including define_format and if_define. The most flexible is define_proc: this allows the component writer to specify a Tcl script that gets invoked whenever the configuration system generates the header file for the owning package. The script can output anything to the header file, for example it could generate a C data structure based on various configuration values.

At the point that the define_proc script is invoked there will be two channels to open files, accessible via Tcl variables: cdl_header is a channel to the current package's own header file for example pkgconf/kernel.h; cdl_system_header is a channel to the global configuration file pkgconf/system.h. A typical define_proc script will use the puts command to output data to one of these channels.

define_proc properties only take effect if the current option is active and enabled. The default behavior of the configuration system for an option with the bool flavor corresponds to the following define_proc:

cdl_option XXX {
  …
  define_proc {
  puts $cdl_header "#define XXX 1"
  }
}
[Warning]Warning

In the current implementation it is not possible for a define_proc property to examine the current values of various configuration options and adapt accordingly. This is a major limitation, and will be addressed in future versions of the configuration tools.

Example

cdl_package CYGPKG_HAL_ARM_PID {
  display       "ARM PID evaluation board"
  parent        CYGPKG_HAL_ARM
  define_header hal_arm_pid.h
  include_dir   cyg/hal
  hardware
  define_proc {
    puts $::cdl_system_header "#define CYGBLD_HAL_TARGET_H   <pkgconf/hal_arm.h>"
    puts $::cdl_system_header "#define CYGBLD_HAL_PLATFORM_H <pkgconf/hal_arm_pid.h>"
    puts $::cdl_header ""
    puts $::cdl_header "#define HAL_PLATFORM_CPU    \"ARM 7TDMI\""
    puts $::cdl_header "#define HAL_PLATFORM_BOARD  \"PID\""
    puts $::cdl_header "#define HAL_PLATFORM_EXTRA  \"\""
    puts $::cdl_header ""
  }
  …
}