2 # special package-management rules
4 # check that the package root directory is set
5 # otherwise, set it to $HOME/packages by default
8 # $(1) : list variable identifier
12 local result = $($(1)) ;
16 if ! $(i) in $(result) { result += $(i) ; }
22 # $(1) : list variable identifier
26 local result = $($(1)) ;
30 if ! $(i) in $(result) { result = $(i) $(result) ; }
37 # $(2) : optional top-level installation directory
41 Echo "nested package declarations are not allowed. please use"
42 Exit "PkgEnd to finish" $(_PKG_NAME)"'s declaration" ;
45 if ! $(PACKAGE_ROOT) {
46 PACKAGE_ROOT = [ FDirName $(HOME) packages ] ;
47 Echo "PACKAGE_ROOT variable not set, using" $(PACKAGE_ROOT) "directory" ;
51 _PKG_DESC = [ FDirName $(PACKAGE_ROOT) $(_PKG_NAME).pc ] ;
54 _PKG_TOP = [ FDirName $(PACKAGE_ROOT) $(_PKG_NAME) ] ;
57 _PKG_ORG_HDRS = $(HDRS) ;
58 _PKG_ORG_DEFINES = $(DEFINES) ;
59 _PKG_ORG_LINKLIBS = $(LINKLIBS) ;
60 _PKG_ORG_SUBDIRHDRS = $(SUBDIRHDRS) ;
62 pkg-$(_PKG_NAME)-top = $(_PKG_TOP) ;
77 if $(_PKG_DO_INSTALL) {
78 _PkgGeneratePc $(_PKG_DESC) ;
79 PKG on $(_PKG_DESC) = $(_PKG_NAME) ;
82 HDRS = $(_PKG_ORG_HDRS) ;
83 DEFINES = $(_PKG_ORG_DEFINES) ;
84 LINKLIBS = $(_PKG_ORG_LINKLIBS) ;
86 SUBDIRHDRS = $(_PKG_ORG_SUBDIRHDRS) ;
99 for p in $(1[2-]) { result = $(p) $(result) ; }
104 # $(1) : package descriptor file path
106 rule _PkgGeneratePc {
107 MkDir $(PACKAGE_ROOT) ;
108 Depends $(1) : $(PACKAGE_ROOT) ;
109 Depends install : $(1) ;
110 Clean uninstall : $(1) ;
111 Always $(1) ; # always re-install, overwrite old version
116 actions _PkgGeneratePc {
117 echo "# this file was generated automatically - do not edit" > $(1)
118 echo "pkg-$(PKG)-uses = $(pkg-$(PKG)-uses) ;" >> $(1)
119 echo "pkg-$(PKG)-libs = $(pkg-$(PKG)-libs:Q) ;" >> $(1)
120 echo "pkg-$(PKG)-defines = $(pkg-$(PKG)-defines) ;" >> $(1)
121 echo "pkg-$(PKG)-includes = $(pkg-$(PKG)-includes:Q) ;" >> $(1)
122 echo "pkg-$(PKG)-ok = 1 ;" >> $(1)
125 actions _PkgGeneratePc {
126 echo # this file was generated automatically - do not edit > $(1)
127 echo pkg-$(PKG)-uses = $(pkg-$(PKG)-uses) ; >> $(1)
128 echo pkg-$(PKG)-libs = $(pkg-$(PKG)-libs:Q) ; >> $(1)
129 echo pkg-$(PKG)-defines = $(pkg-$(PKG)-defines) ; >> $(1)
130 echo pkg-$(PKG)-includes = $(pkg-$(PKG)-includes:Q) ; >> $(1)
131 echo pkg-$(PKG)-ok = 1 ; >> $(1)
137 # nothing, this is now handled automatically by PkgEnd
141 # recomputes current package's settings whenever needed
149 _PKG_ALL_INCLUDES = ;
153 for p in $(_PKG_ALL_USES)
155 _PkgAppend _PKG_ALL_DEFINES : $(pkg-$(p)-defines) ;
156 _PkgAppend _PKG_ALL_INCLUDES : $(pkg-$(p)-includes) ;
159 for p in [ _PkgReverse $(_PKG_ALL_USES) ]
161 local thelibs = $(pkg-$(p)-libs) ;
163 _PKG_ALL_LIBS += $(thelibs) ;
164 _PKG_USE_LIBS += $(thelibs[1]) ;
167 _PkgAppend _PKG_ALL_DEFINES : $(_PKG_DEFINES) ;
168 _PkgAppend _PKG_ALL_INCLUDES : $(_PKG_INCLUDES) ;
170 HDRS = $(_PKG_ORG_HDRS) $(_PKG_ALL_INCLUDES) ;
171 DEFINES = $(_PKG_ORG_DEFINES) $(_PKG_ALL_DEFINES) ;
172 LINKLIBS = $(_PKG_ORG_LINKLIBS) $(_PKG_ALL_LIBS) ;
174 pkg-$(_PKG_NAME)-includes = $(_PKG_INCLUDES) ;
175 pkg-$(_PKG_NAME)-defines = $(_PKG_DEFINES) ;
176 pkg-$(_PKG_NAME)-uses = $(_PKG_USES) ;
177 pkg-$(_PKG_NAME)-libs = $(_PKG_LIBS) ;
181 # $(1) : list of packages to use
182 # $(2) : name of missing packages variable
189 if ! $(p) in $(_PKG_ALL_USES)
191 local pcfile = [ FDirName $(PACKAGE_ROOT) $(p).pc ] ;
200 else if $(pkg-$(p)-uses)
202 _PkgUses $(pkg-$(p)-uses) ;
204 _PKG_ALL_USES += $(p) ;
210 # $(1) : Package name list
213 local pkg-missing = ;
215 _PkgUses $(1) : pkg-missing ;
219 Exit "Please install the following required packages:" $(pkg-missing) ;
222 _PkgPrepend _PKG_USES : $(1) ;
228 # $(1) : target directory
229 # $(2) : list of sources relative to $(3)
230 # $(3) : top source directory
232 rule _PkgMakeLocate {
233 local top = $(3:E=$(DOT)) ;
239 file = [ FDirName $(top) $(ss:G="") ] ;
244 dir = [ FDirName $(dir) $(ss:D) ] ;
247 LOCATE on $(ss) = $(1) ;
248 Depends $(ss) : $(dir) ;
250 if ! $(dir) in $(dirs)
259 # $(1) : target directory
260 # $(2) : list of source files relative to $(3)
261 # $(3) : top source directory
263 rule _PkgInstallInto {
264 # InstallInto dir : sources ;
265 local sources = $(2) ;
266 local targets = $(sources:G=$(INSTALLGRIST)) ;
268 # Arrange for jam install
269 # Arrange for jam uninstall
270 # sources are in SEARCH_SOURCE
273 Depends install : $(targets) ;
274 Clean uninstall : $(targets) ;
276 _PkgMakeLocate $(1) : $(targets) : $(3) ;
278 # For each source, make gristed target name
279 # and Install, Chmod, Chown, and Chgrp
283 local t = $(s:G=$(INSTALLGRIST)) ;
285 Depends $(t) : $(s) ;
287 SEARCH on $(s) = $(3) ;
289 Install $(t) : $(s) ;
292 if $(OWNER) && $(CHOWN)
295 OWNER on $(t) = $(OWNER) ;
298 if $(GROUP) && $(CHGRP)
301 GROUP on $(t) = $(GROUP) ;
306 # $(1) : target directory
307 # $(2) : list of source binaries
308 # $(3) : top source directory
310 rule _PkgInstallBin {
311 local _t = [ FAppendSuffix $(>) : $(SUFEXE) ] ;
313 _PkgInstallInto $(<) : $(_t) : $(3) ;
314 MODE on $(_t:G=$(INSTALLGRIST)) = $(EXEMODE) ;
318 # $(1) : target directory
319 # $(2) : list of source shells
320 # $(3) : top source directory
322 rule _PkgInstallShell {
323 _PkgInstallInto $(1) : $(2) : $(3) ;
324 MODE on $(2:G=$(INSTALLGRIST)) = $(SHELLMODE) ;
328 # $(1) : target directory
329 # $(2) : list of source files
330 # $(3) : top source directory
332 rule _PkgInstallFile {
333 _PkgInstallInto $(1) : $(2) : $(3) ;
334 MODE on $(2:G=$(INSTALLGRIST)) = $(FILEMODE) ;
337 # $(1) : list of include paths
340 _PKG_INCLUDES += $(1) ;
345 _PKG_DEFINES += $(1) ;
349 # $(1) : list of header files
350 # $(2) : top-level source directory
351 # $(3) : optional directory suffix
353 rule PkgInstallHeader {
354 local dir = [ FDirName $(_PKG_TOP) include ] ;
356 _PKG_DO_INSTALL = 1 ;
358 _PkgInstallFile [ FDirName $(dir) $(3) ] : $(1) : $(2) ;
359 _PkgAppend _PKG_INCLUDES : $(dir) ;
363 # $(1) : library name
366 local lib = $(1:S=$(SUFLIB)) ;
367 local dir = [ FDirName $(_PKG_TOP) lib ] ;
369 _PKG_DO_INSTALL = 1 ;
371 _PkgInstallFile $(dir) : $(lib) : $(DOT) ;
372 _PkgPrepend _PKG_LIBS : [ FDirName $(dir) $(lib) ] ;
377 # $(1) : required library names or link flags
380 _PkgAppend _PKG_LIBS : $(1) ;
386 MainFromObjects $(<) : $(>:S=$(SUFOBJ)) ;
388 LINKLIBS on $(<:S=$(SUFEXE)) += $(LINKLIBS) ;
389 Depends $(<:S=$(SUFEXE)) : $(_PKG_USE_LIBS) ;
393 # $(1) : list of directories relative to $(2)
394 # $(2) : top search directory
399 files = [ GLOB [ FDirName $(2) $(1) ] : $(3) ] ;
400 dir = [ FDirName $(1) ] ;
402 return $(files:D=$(dir)) ;