1#---------------------------------------------------------------------------- 2# Project: Horizon 3# File: utildefs.om 4# 5# Copyright (C)2009-2011 Nintendo Co., Ltd. All rights reserved. 6# 7# These coded instructions, statements, and computer programs contain 8# proprietary information of Nintendo of America Inc. and/or Nintendo 9# Company Ltd., and are protected by Federal copyright law. They may 10# not be disclosed to third parties or copied or duplicated in any form, 11# in whole or in part, without the prior written consent of Nintendo. 12# 13# $Rev: 35508 $ 14#---------------------------------------------------------------------------- 15 16# ���̃t�@�C���͊���`�݂̂ł� 17# ����`�ȊO��lj����Ȃ��ł������� 18 19#---------------------------------------------------------------------------- 20# ����` 21#---------------------------------------------------------------------------- 22 23#------------------------------------------------------- 24# gsub 25# 26# �T�v 27# | 28# 29# �Q�Ƃ��Ă���O���[�o���ϐ� 30# FS, RS, stdout 31#------------------------------------------------------- 32public.gsub(str1, pattern, str2) = 33 FS=__XYZ 34 RS=__XYZ 35 stdout = $(open-out-string) 36 fsubst($(open-in-string $(str1))) 37 case $(pattern) g 38 value $(str2) 39 private.result = $(out-contents $(stdout)) 40 close($(stdout)) 41 return $(result) 42 43#------------------------------------------------------- 44# findstring 45# 46# �T�v 47# | 48# 49# �Q�Ƃ��Ă���O���[�o���ϐ� 50# �Ȃ� 51#------------------------------------------------------- 52public.findstring(str1, pattern) = 53 return $(grep q, $(pattern), $(open-in-string $(str1))) 54 55#------------------------------------------------------- 56# compileToRegex 57# 58# �T�v 59# | 60# 61# �Q�Ƃ��Ă���O���[�o���ϐ� 62# stdout 63#------------------------------------------------------- 64public.compileToRegex(filterstrings) = 65 private.regex_result = 66 foreach(fs, $(filterstrings)) 67 stdout = $(open-out-string) 68 fsubst($(open-in-string $(fs))) 69 case $'\*(\.\*)+' g 70 value $'*' 71 case $'\.' g 72 value $'\.' 73 case $'\*' g 74 value $'.*' 75 case $'[()]' g 76 value $'\'$1 # ' 77 78 private.regex = $(out-contents $(stdout)) 79 close($(stdout)) 80 value $"\($(regex)\)" 81 return $(concat $'|', $(regex_result)) 82 83#------------------------------------------------------- 84# isFilterMatch 85# 86# �T�v 87# | 88# 89# �Q�Ƃ��Ă���O���[�o���ϐ� 90# �Ȃ� 91#------------------------------------------------------- 92public.isFilterMatch(regex, fullname) = 93 match $(fullname) 94 case $(regex) 95 return true 96 default 97 return false 98 99#------------------------------------------------------- 100# exist-dirs 101# 102# �T�v 103# | 104# 105# �Q�Ƃ��Ă���O���[�o���ϐ� 106# �Ȃ� 107#------------------------------------------------------- 108public.exist-dirs(dirs) = 109 return $(filter $(dirs),$(glob D,*)) 110 111#------------------------------------------------------- 112# ls_ 113# 114# �T�v 115# | 116# 117# �Q�Ƃ��Ă���O���[�o���ϐ� 118# �Ȃ� 119#------------------------------------------------------- 120public.ls_(options, path) = 121 private.files = $(EMPTY) 122 .SUBDIRS: $(path) 123 files = $(ls $(options), .) 124 export files 125 return $(files) 126 127#------------------------------------------------------- 128# subdirs_ 129# 130# �T�v 131# | 132# 133# �Q�Ƃ��Ă���O���[�o���ϐ� 134# �Ȃ� 135#------------------------------------------------------- 136public.subdirs_(options, path) = 137 private.dirs = $(EMPTY) 138 .SUBDIRS: $(path) 139 dirs = $(subdirs $(options), .) 140 export dirs 141 return $(dirs) 142 143#------------------------------------------------------- 144# ls_relative 145# 146# �T�v 147# | 148# 149# �Q�Ƃ��Ă���O���[�o���ϐ� 150# �Ȃ� 151#------------------------------------------------------- 152public.ls_relative(options, rdir) = 153 private.adir = $(absname $(rdir)) 154 return $(removeprefix $(adir)$(DIRSEP), $(filter-out $(adir), $(ls_ $(options), $(adir)))) 155 156#------------------------------------------------------- 157# files 158# 159# �T�v 160# | 161# 162# �Q�Ƃ��Ă���O���[�o���ϐ� 163# GLOBAL_TEMP_RESULT 164#------------------------------------------------------- 165public.files(options, path) = 166 section 167 GLOBAL_TEMP_RESULT = $(EMPTY) 168 export GLOBAL_TEMP_RESULT 169 .SUBDIRS: $(path) 170 foreach(filename, $(ls $(options), .)) 171 if $(test -f $(filename)) 172 GLOBAL_TEMP_RESULT += $(string $(filename)) 173 return $(GLOBAL_TEMP_RESULT) 174 175#------------------------------------------------------- 176# filter-dirs 177# 178# �T�v 179# | 180# 181# �Q�Ƃ��Ă���O���[�o���ϐ� 182# �Ȃ� 183#------------------------------------------------------- 184public.filter-dirs(filenames) = 185 private.result = $(EMPTY) 186 section 187 export result 188 foreach(filename, $(filenames)) 189 if $(test -d $(filename)) 190 result += $(filename) 191 return $(result) 192 193#------------------------------------------------------- 194# filter-files 195# 196# �T�v 197# | 198# 199# �Q�Ƃ��Ă���O���[�o���ϐ� 200# �Ȃ� 201#------------------------------------------------------- 202public.filter-files(filenames) = 203 private.result = $(EMPTY) 204 section 205 export result 206 foreach(filename, $(filenames)) 207 if $(test -f $(filename)) 208 result += $(filename) 209 return $(result) 210 211#------------------------------------------------------- 212# CheckProg_ 213# 214# �T�v 215# | 216# 217# �Q�Ƃ��Ă���O���[�o���ϐ� 218# �Ȃ� 219#------------------------------------------------------- 220public.CheckProg_(prog) = 221 private.where = $(where $(prog)) 222 if $(where) 223 return true 224 else 225 return false 226 227#------------------------------------------------------- 228# readfile 229# 230# �T�v 231# | 232# 233# �Q�Ƃ��Ă���O���[�o���ϐ� 234# �Ȃ� 235#------------------------------------------------------- 236public.readfile(filename) = 237 private.result = $(EMPTY) 238 try 239 channel = $(fopen $(filename), r) 240 result += $(input-line $(channel)) 241 close($(channel)) 242 export result 243 catch RuntimeException(e) 244 return 245 return $(result) 246 247#------------------------------------------------------- 248# makeDirectory 249# 250# �T�v 251# | 252# 253# �Q�Ƃ��Ă���O���[�o���ϐ� 254# �Ȃ� 255#------------------------------------------------------- 256public.makeDirectory(path) = 257 $(path): 258 mkdir -p $@ 259 return $(dir $(path)) 260 261#------------------------------------------------------- 262# getMtimeIfLarge 263# 264# �T�v 265# | 266# 267# �Q�Ƃ��Ă���O���[�o���ϐ� 268# �Ȃ� 269#------------------------------------------------------- 270public.getMtimeIfLarge(path_list) = 271 private.result = 272 foreach (path, $(path_list)) 273 if $(file-exists $(path)) 274 private.file_stat = $(stat $(path)) 275 value $(if $(ge $(file_stat.size), 8000000),$(file_stat.mtime),1) 276 else 277 value 0 278 return $(result) 279 280#------------------------------------------------------- 281# makePath 282# 283# �T�v 284# | 285# 286# �Q�Ƃ��Ă���O���[�o���ϐ� 287# �Ȃ� 288#------------------------------------------------------- 289public.makePath(a) = 290 return $(concat $(DIRSEP),$(a)) 291 292#------------------------------------------------------- 293# stripEmpty 294# 295# �T�v 296# | 297# 298# �Q�Ƃ��Ă���O���[�o���ϐ� 299# GLOBAL_TEMP_B 300#------------------------------------------------------- 301public.stripEmpty(a) = 302 section 303 GLOBAL_TEMP_B = $(EMPTY) 304 export GLOBAL_TEMP_B 305 foreach (e, $(a)) 306 GLOBAL_TEMP_B += $(e) 307 return $(GLOBAL_TEMP_B) 308 309#------------------------------------------------------- 310# isEmpty 311# 312# �T�v 313# | 314# 315# �Q�Ƃ��Ă���O���[�o���ϐ� 316# �Ȃ� 317#------------------------------------------------------- 318public.isEmpty(seq) = 319 return $(eq 0, $(length $(seq))) 320 321#------------------------------------------------------- 322# digest-in-path-optional_internal 323# 324# �T�v 325# digest-in-path-optional �p�̓����� 326# 327# �Q�Ƃ��Ă���O���[�o���ϐ� 328# �Ȃ� 329#------------------------------------------------------- 330digest-in-path-optional_internal(path, file) = 331 # ��p�X�ł���� path �̒T���͕s�v 332 if $(equal $(fullname $(file)), $(absname $(file))) 333 private.path_digest = $(digest-optional $(file)) 334 if $(not $(equal $(path_digest), false)) 335 return $(file) $(path_digest) 336 return 337 338 # ���p�X 339 foreach(dir, $(path)) 340 private.filepath = $(dir)$(DIRSEP)$(file) 341 export filepath 342 if $(equal ., $(dirof $(filepath))) 343 filepath = $(basename $(file)) 344 else 345 filepath = $(dirof $(filepath))$(DIRSEP)$(basename $(filepath)) 346 347 private.path_digest = $(digest-optional $(filepath)) 348 if $(not $(equal $(path_digest), false)) 349 return $(filepath) $(path_digest) 350 return 351 352#------------------------------------------------------- 353# digest-in-path-optional_ 354# 355# �T�v 356# digest-in-path-optional �̃L���b�V�����Q�Ƃ��Ȃ��� 357# 358# �Q�Ƃ��Ă���O���[�o���ϐ� 359# GLOBAL_TEMP_RESULT 360#------------------------------------------------------- 361public.digest-in-path-optional_(path, files) = 362 # �ŏ��ɃJ�����g�p�X���e�X�g�����悤�� 363 path = . $(path) 364 365 GLOBAL_TEMP_RESULT = 366 foreach(filename, $(files)) 367 GLOBAL_TEMP_RESULT += $(digest-in-path-optional_internal $(path), $(filename)) 368 export GLOBAL_TEMP_RESULT 369 370 return $(GLOBAL_TEMP_RESULT) 371 372 373 374 375 376public.mapToArray(m, f) = 377 GLOBAL_TEMP_RESULT = $(EMPTY_ARRAY) 378 section 379 export GLOBAL_TEMP_RESULT 380 m.foreach(k,v) 381 GLOBAL_TEMP_RESULT += $(apply $(f),$(k),$(v)) 382 return $(GLOBAL_TEMP_RESULT) 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404