ad85e41c29935d88de334337af45432a9d6c9974
[supertux.git] / mk / jam / install.jam
1 #============================================================================
2 # Rules for installation
3 #============================================================================
4
5 COPYDIRS ?= "cp -R" ;
6
7 INSTALL ?= "install" ;
8 INSTALL_PROGRAM ?= $(INSTALL) ;
9 INSTALL_SCRIPT ?= $(INSTALL) ;
10 INSTALL_DATA ?= "$(INSTALL) -m644" ;
11
12 # set some paths
13 appdatadir ?= [ ConcatDirs $(datadir) $(PACKAGE_NAME) ] ;
14 appdocdir ?= [ ConcatDirs $(datadir) doc $(PACKAGE_NAME)-$(PACKAGE_VERSION) ] ;
15 appconfdir ?= [ ConcatDirs $(sysconfdir) $(PACKAGE_NAME) ] ;
16 plugindir ?= [ ConcatDirs $(libdir) $(PACKAGE_NAME) ] ;
17
18 ##  InstallHeader headername [ : subdir ]
19 ##    DoInstall a headerfile into the includedir directory. A subdirectory
20 ##    relative to the includedir can be specified.
21 rule InstallHeader
22 {
23     SEARCH on $(<:G=installheader) = $(SUBDIR) ;
24     Depends install_include : [ DoInstall $(<:G=installheader) : $(includedir) $(2) ] ;
25 }
26
27 ##  InstallShellScript scriptname [ : subdir ]
28 ##    Installs a shell script into the bindir directory. A subdirectory
29 ##    relative to the bindir can be specified.
30 rule InstallShellScript
31 {
32     SEARCH on $(<:G=installscript) = $(SUBDIR) ;
33     Depends install_shellscript 
34         : [ DoInstall $(<:G=installscript) : $(bindir) $(2) : $(INSTALL_SCRIPT) ]
35     ;
36 }
37
38 ##  InstallData files [ : subdir ]
39 ##    Installs data files
40 rule InstallData
41 {
42     SEARCH on $(<:G=installdata) = $(SUBDIR) ;
43     Depends install_data : [ DoInstall $(<:G=installdata) : $(appdatadir) $(2) ] ;
44 }
45
46 ##  InstallConfig files [ : subdir ]
47 ##    Installs configuration files
48 rule InstallConfig
49 {
50     SEARCH on $(<:G=installconfig) = $(SUBDIR) ;
51     Depends install_config : [ DoInstall $(<:G=installconfig) : $(appconfdir) $(2) ] ;
52 }
53
54 ##  InstallDoc files [ : subdir ]
55 ##    Installs documentation files
56 rule InstallDoc
57 {
58     SEARCH on $(<:G=installdoc) = $(SUBDIR) ;
59     Depends install_doc : [ DoInstall $(<:G=installdoc) : $(appdocdir) $(2) ] ;
60 }
61
62 ##  InstallMan files
63 ##    DoInstall man files
64 rule InstallMan
65 {
66     local dir i ;
67     
68     SEARCH on $(<:G=installman) = $(SUBDIR) ;
69     for i in $(<:G=installman) {
70         dir = $(mandir) ;
71         switch $(i:S) {
72             case .1 : dir += man1 ;
73             case .2 : dir += man2 ;
74             case .3 : dir += man3 ;
75             case .4 : dir += man4 ;
76             case .5 : dir += man5 ;
77             case .6 : dir += man6 ;
78             case .7 : dir += man7 ;
79             case .8 : dir += man8 ;
80             case .9 : dir += man9 ;
81             case * :
82                 echo "WARNING: manfile has no *.[0-9] ending." ;
83         }
84         Depends install_man : [ DoInstall $(i) : $(dir) ] ;
85     }
86 }
87
88 ##  DoInstall sourcename : directories [ : installapp ] [ : options ]
89 ##    Creates a new installtarget for the given sources. The target(s) are
90 ##    returned as function result.
91 rule DoInstall
92 {
93     local targets target i dir gdir ;
94     dir = [ ConcatDirs $(DESTDIR) $(2) ] ;
95
96     gdir = $(dir:G=dir) ;
97     MkDir $(gdir) ;
98   
99     for i in $(<) {
100         target = $(i:BSR=$(dir):G=install) ;
101         targets += $(target) ;
102         Depends $(target) : $(gdir) $(i) ;
103         Install1 $(target) : $(i) ;
104
105         if $(3) {
106             INSTALL on $(target) = $(3) ;
107         } else {
108             INSTALL on $(target) = $(INSTALL_DATA) ;
109         }
110     }
111
112     # We want to package all files we install
113     if ! [ IsElem nopackage : $(4) ] {
114         Package $(<) ;
115     }
116
117     Always $(targets) ;
118     return $(targets) ;
119 }
120
121 #----------------------------------------------------------------------------
122
123 INSTALLTARGETS = install_bin install_plugin install_lib install_header
124                  install_shellscript install_data install_config
125                  install_doc ;
126
127 Always install $(INSTALLTARGETS) ;
128 NotFile install $(INSTALLTARGETS) ;
129 Depends install : $(INSTALLTARGETS) ;
130
131 Help install : "Install $(PACKAGE_NAME)" ;
132
133 actions Install1
134 {
135   $(INSTALL) "$(>)" "$(<:D)" $(INSTALLFLAGS) ;
136 }
137
138 actions CopyDirs
139 {
140   $(COPYDIRS) "$(>)" "$(<)"
141 }
142