1rule SymLink 2{ 3 # SymLink <target> : <source> : <makeDefaultDependencies> ; 4 # Links <target> to <source>. 5 # <source> is the exact link contents. No binding is done. 6 # <makeDefaultDependencies> If true, <target> will be made a dependency 7 # of the `all' pseudo target, i.e. it will be made by default, and removed 8 # on `jam clean'. 9 10 local target = $(1) ; 11 local source = $(2) ; 12 local makeDefaultDependencies = $(3) ; 13 if ! $(makeDefaultDependencies) { 14 makeDefaultDependencies = true ; 15 } 16 LINKCONTENTS on $(target) = $(source) ; 17 SymLink1 $(target) ; 18 if $(makeDefaultDependencies) = true { 19 LocalDepends files : $(target) ; 20 LocalClean clean : $(target) ; 21 } 22} 23 24actions SymLink1 25{ 26 $(RM) "$(1)" && $(LN) -s "$(LINKCONTENTS)" "$(1)" 27} 28 29rule RelSymLink 30{ 31 # RelSymLink <link> : <link target> : <makeDefaultDependencies> ; 32 # Creates a relative symbolic link from <link> to <link target>. 33 # <link> and <link target> can be usual targets. They may have a grist 34 # and don't need to have any dirname. Their LOCATE variables are used to 35 # find their locations. 36 # <makeDefaultDependencies> If true (which is the default), <link> will be 37 # made a dependency of the `files' pseudo target, i.e. it will be made by 38 # default, and removed on `jam clean'. 39 40 local target = $(1) ; 41 local source = $(2) ; 42 local makeDefaultDependencies = $(3) ; 43 local targetDir = [ on $(target) FDirName $(LOCATE[1]) $(target:D) ] ; 44 local sourceDir = [ on $(source) FDirName $(LOCATE[1]) $(source:D) ] ; 45 local sourcePath = $(source:G=) ; 46 sourcePath = $(sourcePath:D=$(sourceDir)) ; 47 local targetDirComponents = [ FSplitPath $(targetDir) ] ; 48 local sourceComponents = [ FSplitPath $(sourcePath) ] ; 49 50 SymLink $(target) 51 : [ FRelPath $(targetDirComponents) : $(sourceComponents) ] 52 : $(makeDefaultDependencies) ; 53 NOUPDATE $(target) ; 54 Depends $(target) : $(source) ; 55} 56 57rule AbsSymLink 58{ 59 # AbsSymLink <link> : <link target> : <link dir> 60 # : <makeDefaultDependencies> ; 61 # Creates an absolute symbolic link from <link> to <link target>. 62 # <link> and <link target> must be usual targets. If <link dir> is 63 # given, then it is set as LOCATE directory on <link>. 64 # <makeDefaultDependencies> If true (which is the default), <link> will be 65 # made a dependency of the `files' pseudo target, i.e. it will be made by 66 # default, and removed on `jam clean'. 67 68 local makeDefaultDependencies = $(4) ; 69 if ! $(makeDefaultDependencies) { 70 makeDefaultDependencies = true ; 71 } 72 73 Depends $(1) : $(2) ; 74 if $(3) { 75 MakeLocate $(1) : $(3) ; 76 } 77 SEARCH on $(2) += $(SEARCH_SOURCE) ; 78 if $(makeDefaultDependencies) = true { 79 LocalDepends files : $(1) ; 80 LocalClean clean : $(1) ; 81 } 82} 83 84actions AbsSymLink 85{ 86 target="$(2)" 87 case "$target" in 88 /*) ;; 89 *) target=`pwd`/"$target";; 90 esac 91 $(RM) "$(1)" && $(LN) -s "$target" "$(1)" 92} 93 94rule HaikuInstall 95{ 96 # Usage: HaikuInstall <[ install [ and uninstall ] pseudotarget ]> 97 # : <directory> : <sources to install> 98 # : [ <installgrist> ] : [ <install rule> ] ; 99 local install = $(1[1]) ; 100 install ?= install ; 101 local uninstall = $(1[2]) ; 102 uninstall ?= un$(install) ; 103 local dir = $(2) ; 104 local sources = $(3) ; 105 local installgrist = $(4) ; 106 installgrist ?= $(INSTALLGRIST) ; 107 local installRule = $(5) ; 108 installRule ?= Install ; 109 local targets = $(sources:G=$(installgrist)) ; 110 111 NotFile $(install) ; 112 NotFile $(uninstall) ; 113 Depends $(install) : $(targets) ; 114 Clean $(uninstall) : $(targets) ; 115 116 SEARCH on $(sources) += $(SEARCH_SOURCE) ; 117 MakeLocate $(targets) : $(dir) ; 118 119 local source ; 120 for source in $(sources) { 121 local target = $(source:G=$(installgrist)) ; 122 123 Depends $(target) : $(source) ; 124 $(installRule) $(target) : $(source) ; 125 126 if [ on $(target) return $(MODE) ] { 127 Chmod $(target) ; 128 } 129 130 if $(OWNER) && $(CHOWN) { 131 Chown $(target) ; 132 OWNER on $(target) = $(OWNER) ; 133 } 134 135 if $(GROUP) && $(CHGRP) { 136 Chgrp $(target) ; 137 GROUP on $(target) = $(GROUP) ; 138 } 139 } 140} 141 142rule InstallAbsSymLinkAdapter 143{ 144 # InstallAbsSymLinkAdapter <link> : <link target> 145 if ! [ on $(2) return $(TARGET) ] { 146 TARGET on $(2) = [ on $(2) return $(SEARCH) ] ; 147 } 148 AbsSymLink $(1) : $(2) : : false ; 149} 150 151rule HaikuInstallAbsSymLink 152{ 153 # Usage: HaikuInstallAbsSymLink <[ install [ and uninstall ] pseudotarget ]> 154 # : <directory> : <sources to install> 155 # : [ <installgrist> ] ; 156 HaikuInstall $(1) : $(2) : $(3) : $(4) : InstallAbsSymLinkAdapter ; 157} 158 159rule InstallRelSymLinkAdapter 160{ 161 # InstallRelSymLinkAdapter <link> : <link target> 162 if ! [ on $(2) return $(TARGET) ] { 163 TARGET on $(2) = [ on $(2) return $(SEARCH) ] ; 164 } 165 RelSymLink $(1) : $(2) : false ; 166} 167 168rule HaikuInstallRelSymLink 169{ 170 # Usage: HaikuInstallRelSymLink <[ install [ and uninstall ] pseudotarget ]> 171 # : <directory> : <sources to install> 172 # : [ <installgrist> ] ; 173 HaikuInstall $(1) : $(2) : $(3) : $(4) : InstallRelSymLinkAdapter ; 174} 175 176 177rule UnarchiveObjects 178{ 179 # UnarchiveObjects <target objects> : <static object> 180 181 MakeLocateArch $(1) ; 182 Depends $(1) : $(2) ; 183 SEARCH on $(2) = $(SEARCH_SOURCE) ; 184} 185 186actions UnarchiveObjects 187{ 188 ( cd $(1[1]:D) && $(TARGET_AR) $(TARGET_UNARFLAGS) "$(2)" $(1:BS) ) 189} 190 191 192rule ObjectReference 193{ 194 # ObjectReference <reference object> : <source object> 195 # Makes <reference object> refer to the same file as <source object>. 196 # The filenames must of course be identical. 197 # <source object> must have already been LOCATEd. 198 199 local ref = $(1) ; 200 local source = $(2) ; 201 if $(ref) != $(source) { 202 Depends $(ref) : $(source) ; 203 LOCATE on $(ref) = [ on $(source) return $(LOCATE) ] ; 204 } 205} 206 207rule ObjectReferences 208{ 209 # ObjectReferences <source objects> 210 # Creates local references to <source objects>, i.e. identifiers with the 211 # current grist referring to the same files. <source objects> must have 212 # already been LOCATEd. 213 214 local source ; 215 for source in $(1) { 216 ObjectReference [ FGristFiles $(source) ] : $(source) ; 217 } 218} 219 220