added jam build system, please try it out - the advantage would be that it already...
[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)/out/$(target) ;
7 LOCATE_TARGETS ?= $(top_builddir) ;
8 LOCATE_DOCS ?= $(top_builddir)/out ;
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
21 # fix bug in Jambase where SubInclude in the middle of a jam file made it break
22 rule SubInclude
23 {
24     if ! $($(<[1]))
25     {
26         Exit SubInclude $(<[1]) without prior SubDir $(<[1]) ;
27     }
28
29     local save_SUBDIR_TOKENS = $(SUBDIR_TOKENS) ;
30
31     SubDir $(<) ;
32
33     include $(JAMFILE:D=$(SUBDIR)) ;
34
35     SubDir $(<[1]) $(save_SUBDIR_TOKENS) ;
36 }
37
38 # this MakeLocate rule differs from the Jambase one in that it also works with
39 # files being in subdirectories
40 rule MakeLocate
41 {
42     # MakeLocate targets : directory ;
43                                                                            
44     # Sets special variable LOCATE on targets, and arranges
45     # with MkDir to create target directory.
46                                                                                     
47     # Note we grist the directory name with 'dir',
48     # so that directory path components and other
49     # targets don't conflict.
50     
51     if $(>) && $(>) != "" && $(>) != "."
52     {
53         local i ;
54         for i in $(<) {
55             LOCATE on $(i) = $(>) ;
56
57             local targetfile = $(i:R=$(>)) ;
58             Depends $(i) : $(targetfile:DG=dir) ;
59             MkDir $(targetfile:DG=dir) ;
60         }
61     }
62 }
63
64 # The default MkDir rule in Jambase has problems when paths contains a sequence
65 # of multiple slashes (ie. bla////fup). We solve these problems and greatly
66 # simply this rule by using the "mkdir -p" or mkdirs command.
67 rule MkDir
68 {
69     # MkDir directory ;
70
71     # Make a directory and all its parent directories.
72
73     # Ignore timestamps on directories: we only care if they 
74     # exist.
75
76     NoUpdate $(<) ;
77
78     # don't create the dir multiple times
79     if ! $($(<)-mkdir)
80     {
81         $(<)-mkdir = true ;
82         MkDir1 $(<) ;
83     }
84 }
85
86 actions MkDir1
87 {
88         $(MKDIRS) "$(<)"
89 }
90