home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1997 November
/
PCWorld_1997-11_cd.bin
/
software
/
programy
/
komix
/
DATA.Z
/
makemake.tcl
< prev
next >
Wrap
Text File
|
1997-02-14
|
10KB
|
403 lines
#---------------------------------------------------------------------------
#
# Copyright (c) 1992-1995 by Cadre Technologies Inc.
#
# This software is furnished under a license and may be used only in
# accordance with the terms of such license and with the inclusion of
# the above copyright notice. This software or any other copies thereof
# may not be provided or otherwise made available to any other person.
# No title to and ownership of the software is hereby transferred.
#
# The information in this software is subject to change without notice
# and should not be construed as a commitment by Cadre Technologies Inc.
#
#---------------------------------------------------------------------------
#
# File : @(#)makemake.tcl /main/hindenburg/4 (1.12)
# Author : frmo
# Original date : 1-8-1992
# Description : makefile generator
#
#---------------------------------------------------------------------------
#
source [m4_path_name tcl cginit.tcl]
OTShRegister::tdbOp
require legacy.tcl
require make_msg.tcl
require wmt_util.tcl
require machdep.tcl
require makedefs.tcl
if {[info procs fstorage::dir] == ""} {
require fstorage.tcl
}
# Type en source info
#
global SRC_TYPES
global NO_SRC_TYPES
global TGT_TYPES
global SOURCES
# Make info
#
global make_tmpl_type
global make_type
# Client context
#
global clientContext; set clientContext [ClientContext::global]
global oldpath; set oldpath [pwd]
global path
# Main function
#
proc makemake {} {
m4_message $M_GEN_MAKEFILE
if {[set_path_to_uenv] == -1} {
return -1
}
if {[init_make_globs] == -1} {
return -1
}
read_file_types
set contents [convert_make_templ maketmpl.$make_tmpl_type]
if {[catch {set fp [fstorage::open makefile.$make_type w]} reason]} {
puts stderr $reason
m4_error $E_FILE_OPEN_WRITE makefile.$make_type
return -1
}
set sect [TextSection new]
expand_text $sect $contents
$sect write $fp
fstorage::close $fp
return 0
}
# Change path to user environment directory, remember old path
#
proc set_path_to_uenv {} {
global clientContext
global path
set sysV [$clientContext currentSystem]
if {[$sysV isNil]} {
m4_error E_UENV
return -1
} else {
set path [$sysV path]
if {[catch {cd $path} reason]} {
puts stderr $reason
m4_error $E_CHDIR $path
return -1
} else {
return 0
}
}
}
# Change path back to remembered old path
#
proc set_path_back {} {
global oldpath
if {$path != $oldpath} {
if {[catch {cd $oldpath} reason]} {
puts stderr $reason
m4_error $E_CHDIR $oldpath
}
}
}
# Determine the make globals: make_tmpl_type and make_type
#
proc init_make_globs {} {
global make_type; set make_type makefile
global make_tmpl_type; set make_tmpl_type maketmpl
return 0
}
# Determine types of all files and build the global type lists, also build
# source file list
#
proc read_file_types {} {
global SRC_TYPES; set SRC_TYPES ""
global NO_SRC_TYPES; set NO_SRC_TYPES ""
global TGT_TYPES; set TGT_TYPES ""
global SOURCES; set SOURCES ""
foreach file [lsort [fstorage::dir]] {
set type [nt_get_type $file]
switch [fstorage::getMakeType $type] {
source { set kind SRC ; lappend SOURCES $file }
target { set kind TGT }
default { set kind NO_SRC }
}
if {![info exist seen${kind}($type)]} {
set seen${kind}($type) 1
lappend ${kind}_TYPES $type
}
if {$kind == "TGT" && ![info exist seenNO_SRC($type)]} {
set seenNO_SRC($type) 1
lappend NO_SRC_TYPES $type
}
}
}
# Read 'file_name', convert the 2.1 style makemake macro's to tcl functions
# and return the result.
#
proc convert_make_templ {fullName} {
set result ""
set in_begin_end 0
set fileName [nt_get_name $fullName]
set fileType [nt_get_type $fullName]
set isTempFile 0
if {[$clientContext customFileExists $fileName $fileType "" 0]} {
set tmpFile [args_file {}]
$clientContext downLoadCustomFile $fileName $fileType "" $tmpFile
set fp [open $tmpFile]
set isTempFile 1
} else {
set fp [open [m4_path_name etc maketmpl]]
}
while {[gets $fp line] >= 0} {
# prevent sccs-ids from being processed
regsub -all {\(#\)} $line __the_sccs_id__ line
if [regsub -all {@BEGIN\(([^)]+)\)} $line \
"~\[mm_foreach_target \\1 \{" line] {
set in_begin_end 1
}
if [regsub -all {@END} $line "\}\]" line] {
set in_begin_end 0
}
regsub -all {@\(TARGET\)} $line "~\[mm_tgt_path\]" line
regsub -all {@\(TARGETNAME\)} $line "~\[mm_tgt_name\]" line
regsub -all {@\(TARGETDEP\)} $line "~\[mm_target_deps\]" line
regsub -all {@\(OBJ\)} $line "~\[mm_obj_name\]" line
regsub -all {@\(OBJECTS\)} $line "~\[mm_dependencies\]" line
regsub -all {@\(OBJECTS\.([^)]+)\)} $line \
"~\[mm_dependencies \$SRC_TYPES .\\1\]" line
regsub -all {@\(OBJECTS,([^)]+)\)} $line \
"~\[mm_dependencies \$SRC_TYPES .\\1 ,\]" line
regsub -all {@\(PDBPATH\)} $line \
"~\[mm_install_path \$target\]" line
regsub -all {@\(TARGETS\)} $line "~\[mm_files\]" line
regsub -all {@\(TARGETS\.([^)]+)\)} $line \
"~\[mm_files \$TGT_TYPES \\1_\]" line
regsub -all {@\(DEPENDENCIES\)} $line \
"~\[mm_all_deps\]" line
if {$in_begin_end} {
regsub -all {@\(([^.]+)\.([^)]+)\)} $line \
"~\[mm_dependencies \\1 .\\2\]" line
regsub -all {@\(([^)]+)\)} $line \
"~\[mm_dependencies \\1\]" line
} else {
regsub -all {@\(([^.]+)\.([^)]+)\)} $line \
"~\[mm_files \\1 \\2_\]" line
regsub -all {@\(([^)]+)\)} $line \
"~\[mm_files \\1\]" line
}
# restore sccs-ids
regsub -all __the_sccs_id__ $line "(#)" line
append result "$line\n"
}
close $fp
if {$isTempFile} {
unlink $tmpFile
}
return $result
}
# make file names out of a list of pdb name.type entries
#
proc file_names {list} {
set result ""
foreach file $list {
lappend result [fstorage::get_uenv_path $file]
}
return $result
}
# Expand 'text' for each target of type 'type'
#
proc mm_foreach_target {type_list text} {
upvar current_section current_section
foreach target [fstorage::dir $type_list] {
expand_text $current_section $text
}
}
# Return the dependencies of 'target' that have a type that is in 'typelist'.
# Format the dependencies by replacing their extension with 'ext' and
# separating them with 'sep'. The dependencies are kept in a global list
# so that a dependency list can be generated later
# Only add a dependency to the global list if 'ext' is in SRC_TYPES
#
proc mm_dependencies {{types -} {ext .$OBJ_EXT} {sep ""}} {
set all_deps ""
set result ""
if {$types == "-"} {
set all_deps $SOURCES
} else {
return $result
}
foreach dep $all_deps {
set depfile "[nt_get_name [fstorage::get_uenv_path $dep]]$ext"
append result "$sep $depfile"
}
return $result
}
# Legacy stuff
#
proc pdb_obj {cmd arg} {
if {$cmd != "get_pdb_path"} {
puts stderr "makemake: WARNING: `pdb_obj $cmd ...': function not\
supported (anymore)"
return
} else {
mm_install_path $arg
}
}
# Return the files of a certain type, possibly prefixed (sorted)
#
proc mm_files {{types -} {prefix ""}} {
if {$types == "-"} {
set types $TGT_TYPES
}
set result ""
if {$prefix == ""} {
set result [file_names [fstorage::dir $types]]
} else {
foreach file [file_names [fstorage::dir $types]] {
append result "$prefix$file "
}
}
return [lsort $result]
}
# Return a suitable name for an OBJ macro
#
proc mm_obj_name {} {
upvar target target
return "OBJ[nt_get_name $target][nt_get_type $target]"
}
# Return the name of the target
#
proc mm_tgt_name {} {
upvar target target
return [nt_get_name $target]
}
# Return the path to the target
#
proc mm_tgt_path {} {
upvar target target
return [fstorage::get_uenv_path $target]
}
# Return the path to the installation directory, depending on target
#
proc mm_install_path {target} {
#return [fstorage::get_uenv_path $arg absolute]
return $path
}
# Construct the ranlib command
#
# Requires 'proc processLibrary' to be defined in machdep.tcl
#
proc mm_process_lib {args} {
return [processLibrary $args]
}
# Return the X Window System include directory
#
# Requires 'proc XIncludeDir' to be defined in machdep.tcl
#
proc mm_x_include_dir {} {
return [XIncludeDir]
}
# Return an identification of the current platform.
#
# Result is a list with as first element the OS, as
# second element the OS version.
#
# Requires 'proc osIdentification' to be defined in machdep.tcl
#
proc mm_os_ident {} {
return [osIdentification]
}
# Return the libraries to linked to a TDB dependent application
#
# Already contains any -l and -L options needed.
#
# Requires 'proc dbmsLinkLibrary' to be defined in machdep.tcl
#
proc mm_dbms_libs {} {
return [dbmsLinkLibrary]
}
# Return the complete dependency list for all objects
#
proc mm_all_deps {} {
set result ""
if [file exists depend.h] {
read_file_into_text depend.h result
return $result
}
}
# Look for the customization u_makemake.tcl file
#
if {[$clientContext customFileExists u_makemake tcl "" 0]} {
require u_makemake.tcl
}
# Just call makemake
#
if [catch {makemake}] {
puts stderr $errorInfo
}
set_path_back