fa613095a9a2830b61061acdbe090a21be05a869
[supertux.git] / mk / jam / subdir.jam
1 #============================================================================
2 # Work around problems the SubDir rule of Jambase 
3 #       (until jampeople accept my patches :-/ )
4 #============================================================================
5
6 LOCATE_OBJECTS ?= $(top_builddir)/build/$(target) ;
7 LOCATE_TARGETS ?= $(top_builddir) ;
8 LOCATE_DOCS ?= $(top_builddir)/build ;
9
10 SUBDIRRULES += FixSubDirPath ;
11
12 MKDIR ?= mkdir ;
13 MKDIRS ?= "$(MKDIR) -p" ;
14
15 rule FixSubDirPath
16 {
17     LOCATE_SOURCE = [ ConcatDirs $(LOCATE_OBJECTS) $(SUBDIR_TOKENS) ] ;
18     LOCATE_TARGET = [ ConcatDirs $(LOCATE_OBJECTS) $(SUBDIR_TOKENS) ] ;
19
20     # We need to package the Jamfile (a bit hacky here...)
21     Package Jamfile ;
22 }
23
24 # fix bug in Jambase where SubInclude in the middle of a jam file made it break
25 rule SubInclude
26 {
27     if ! $($(<[1]))
28     {
29         Exit SubInclude $(<[1]) without prior SubDir $(<[1]) ;
30     }
31
32     local save_SUBDIR_TOKENS = $(SUBDIR_TOKENS) ;
33
34     SubDir $(<) ;
35
36     include $(JAMFILE:D=$(SUBDIR)) ;
37
38     SubDir $(<[1]) $(save_SUBDIR_TOKENS) ;
39 }
40
41 # this MakeLocate rule differs from the Jambase one in that it also works with
42 # files being in subdirectories
43 rule MakeLocate
44 {
45     # MakeLocate targets : directory ;
46                                                                            
47     # Sets special variable LOCATE on targets, and arranges
48     # with MkDir to create target directory.
49                                                                                     
50     # Note we grist the directory name with 'dir',
51     # so that directory path components and other
52     # targets don't conflict.
53     
54     if $(>) && $(>) != "" && $(>) != "."
55     {
56         local i ;
57         for i in $(<) {
58             LOCATE on $(i) = $(>) ;
59
60             local targetfile = $(i:R=$(>)) ;
61             Depends $(i) : $(targetfile:DG=dir) ;
62             MkDir $(targetfile:DG=dir) ;
63         }
64     }
65 }
66
67 # The default MkDir rule in Jambase has problems when paths contains a sequence
68 # of multiple slashes (ie. bla////fup). We solve these problems and greatly
69 # simply this rule by using the "mkdir -p" or mkdirs command.
70 rule MkDir
71 {
72     # MkDir directory ;
73
74     # Make a directory and all its parent directories.
75
76     # Ignore timestamps on directories: we only care if they 
77     # exist.
78
79     NoUpdate $(<) ;
80
81     # don't create the dir multiple times
82     if ! $($(<)-mkdir)
83     {
84         $(<)-mkdir = true ;
85         MkDir1 $(<) ;
86     }
87 }
88
89 actions MkDir1
90 {
91         $(MKDIRS) "$(<)"
92 }
93