From c7d04e52c63b9c19a1f32f05759f39dba07ecaf8 Mon Sep 17 00:00:00 2001 From: Rene Rivera Date: Wed, 20 Nov 2002 00:44:43 +0000 Subject: [PATCH] "symlink" targets. [SVN r16332] --- src/tools/builtin.jam | 1 + src/tools/symlink.jam | 105 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 src/tools/symlink.jam diff --git a/src/tools/builtin.jam b/src/tools/builtin.jam index 189c9cde4..4b17524cb 100644 --- a/src/tools/builtin.jam +++ b/src/tools/builtin.jam @@ -18,6 +18,7 @@ import stage ; import prebuilt ; import toolset ; import errors : error ; +import symlink ; feature toolset : gcc : implicit propagated link-incompatible ; feature shared : false true : propagated ; diff --git a/src/tools/symlink.jam b/src/tools/symlink.jam new file mode 100644 index 000000000..10e1532e8 --- /dev/null +++ b/src/tools/symlink.jam @@ -0,0 +1,105 @@ +# Copyright (C) 2002, Rene Rivera. Permission to copy, use, modify, sell and +# distribute this software is granted provided this copyright notice appears in +# all copies. This software is provided "as is" without express or implied +# warranty, and with no claim as to its suitability for any purpose. + +# Defines the "symlink" special target. 'symlink' targets make symbolic links +# to the sources. + +import numbers ; +import targets ; +import virtual-target ; +import class ; +import property ; +import modules ; +import os ; + +count = 0 ; + +# The class representing "symlink" targets. +# +rule symlink-targets ( + project + : targets * + : sources * + ) +{ + # Generate a fake name for now. Need unnamed targets eventually. + local c = [ modules.peek symlink : count ] ; + modules.poke symlink : count : [ numbers.increment $(c) ] ; + local fake-name = symlink#$(c) ; + + basic-target.__init__ $(fake-name) : $(project) : $(sources) ; + + # Remember the targets to map the sources onto. Pad or truncate + # to fit the sources given. + self.targets = ; + for local source in $(sources) + { + if $(targets) + { + self.targets += $(targets[1]) ; + targets = $(targets[2-]) ; + } + else + { + self.targets += $(source) ; + } + } + + # The virtual targets corresponding to the given targets. + self.virtual-targets = ; + + rule construct ( source-targets * : properties * ) + { + local i = 1 ; + for local t in $(source-targets) + { + local s = $(self.targets[$(i)]) ; + local vt = [ class.new virtual-target $(s) : [ $(t).type ] : $(self.project) ] ; + $(vt).action [ class.new action $(vt) : $(t) : symlink.ln ] ; + self.virtual-targets += $(vt) ; + i = [ numbers.increment $(i) ] ; + } + return $(self.virtual-targets) ; + } +} +class.class symlink-targets : basic-target ; + +# Creates a symbolic link from a set of targets to a set of sources. +# The targets and sources map one to one. The symlinks generated are +# limited to be the ones given as the sources. That is, the targets +# are either padded or trimmed to equate to the sources. The padding +# is done with the name of the corresponding source. For example:: +# +# symlink : one two ; +# +# Is equal to:: +# +# symlink one two : one two ; +# +rule symlink ( + targets * + : sources * + ) +{ + local project = [ CALLER_MODULE ] ; + + return [ targets.main-target-alternative + [ class.new symlink-targets $(project) : $(targets) : $(sources) ] ] ; +} + +rule ln +{ + local os ; + if [ modules.peek : UNIX ] { os = UNIX ; } + else { os ?= [ os.name ] ; } + ln-$(os) $(<) : $(>) ; +} + +actions ln-UNIX +{ + if test -n '$(<:D)' ; then cd '$(<:D)' ; fi && ln -s '$(>)' '$(<:D=)' +} + +IMPORT $(__name__) : symlink : : symlink ;