| 1 | # Copyright (c) 2006 Klaus Nowikow.
|
|---|
| 2 | # Large portions of the code taken from midl.jam, Copyright (c) 2005 Alexey Pakhunov.
|
|---|
| 3 | #
|
|---|
| 4 | # Use, modification and distribution is subject to the Boost Software
|
|---|
| 5 | # License Version 1.0. (See accompanying file LICENSE_1_0.txt or
|
|---|
| 6 | # http://www.boost.org/LICENSE_1_0.txt)
|
|---|
| 7 |
|
|---|
| 8 | # Mozilla Cross-Platform Interface Definition Language (XPIDL) related routines,
|
|---|
| 9 | # using code from midl.jam
|
|---|
| 10 |
|
|---|
| 11 | import common ;
|
|---|
| 12 | import generators ;
|
|---|
| 13 | import feature : feature get-values ;
|
|---|
| 14 | import os ;
|
|---|
| 15 | import scanner ;
|
|---|
| 16 | import toolset : flags ;
|
|---|
| 17 | import type ;
|
|---|
| 18 | import types/idl ;
|
|---|
| 19 |
|
|---|
| 20 | rule init ( )
|
|---|
| 21 | {
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 | type.register XPTYPELIB : xpt : H ;
|
|---|
| 25 | type.register JAVA : java ;
|
|---|
| 26 |
|
|---|
| 27 | # Register scanner for XPIDL files
|
|---|
| 28 | class xpidl-scanner : scanner
|
|---|
| 29 | {
|
|---|
| 30 | import path property-set regex scanner type virtual-target ;
|
|---|
| 31 |
|
|---|
| 32 | rule __init__ ( includes * )
|
|---|
| 33 | {
|
|---|
| 34 | scanner.__init__ ;
|
|---|
| 35 |
|
|---|
| 36 | self.includes = $(includes) ;
|
|---|
| 37 |
|
|---|
| 38 | # List of quoted strings
|
|---|
| 39 | self.re-strings = "[ \t]*\"([^\"]*)\"([ \t]*,[ \t]*\"([^\"]*)\")*[ \t]*" ;
|
|---|
| 40 |
|
|---|
| 41 | # 'import' and 'importlib' directives
|
|---|
| 42 | self.re-import = "import"$(self.re-strings)"[ \t]*;" ;
|
|---|
| 43 | self.re-importlib = "importlib[ \t]*[(]"$(self.re-strings)"[)][ \t]*;" ;
|
|---|
| 44 |
|
|---|
| 45 | # C preprocessor 'include' directive
|
|---|
| 46 | self.re-include-angle = "#[ \t]*include[ \t]*<(.*)>" ;
|
|---|
| 47 | self.re-include-quoted = "#[ \t]*include[ \t]*\"(.*)\"" ;
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | rule pattern ( )
|
|---|
| 51 | {
|
|---|
| 52 | # Match '#include', 'import' and 'importlib' directives
|
|---|
| 53 | return "((#[ \t]*include|import(lib)?).+(<(.*)>|\"(.*)\").+)" ;
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | rule process ( target : matches * : binding )
|
|---|
| 57 | {
|
|---|
| 58 | local included-angle = [ regex.transform $(matches) : $(self.re-include-angle) : 1 ] ;
|
|---|
| 59 | local included-quoted = [ regex.transform $(matches) : $(self.re-include-quoted) : 1 ] ;
|
|---|
| 60 | local imported = [ regex.transform $(matches) : $(self.re-import) : 1 3 ] ;
|
|---|
| 61 | local imported_tlbs = [ regex.transform $(matches) : $(self.re-importlib) : 1 3 ] ;
|
|---|
| 62 |
|
|---|
| 63 | # CONSIDER: the new scoping rule seem to defeat "on target" variables.
|
|---|
| 64 | local g = [ on $(target) return $(HDRGRIST) ] ;
|
|---|
| 65 | local b = [ NORMALIZE_PATH $(binding:D) ] ;
|
|---|
| 66 |
|
|---|
| 67 | # Attach binding of including file to included targets.
|
|---|
| 68 | # When target is directly created from virtual target
|
|---|
| 69 | # this extra information is unnecessary. But in other
|
|---|
| 70 | # cases, it allows to distinguish between two headers of the
|
|---|
| 71 | # same name included from different places.
|
|---|
| 72 | local g2 = $(g)"#"$(b) ;
|
|---|
| 73 |
|
|---|
| 74 | included-angle = $(included-angle:G=$(g)) ;
|
|---|
| 75 | included-quoted = $(included-quoted:G=$(g2)) ;
|
|---|
| 76 | imported = $(imported:G=$(g2)) ;
|
|---|
| 77 | imported_tlbs = $(imported_tlbs:G=$(g2)) ;
|
|---|
| 78 |
|
|---|
| 79 | local all = $(included-angle) $(included-quoted) $(imported) ;
|
|---|
| 80 |
|
|---|
| 81 | INCLUDES $(target) : $(all) ;
|
|---|
| 82 | DEPENDS $(target) : $(imported_tlbs) ;
|
|---|
| 83 | NOCARE $(all) $(imported_tlbs) ;
|
|---|
| 84 | SEARCH on $(included-angle) = $(self.includes:G=) ;
|
|---|
| 85 | SEARCH on $(included-quoted) = $(b) $(self.includes:G=) ;
|
|---|
| 86 | SEARCH on $(imported) = $(b) $(self.includes:G=) ;
|
|---|
| 87 | SEARCH on $(imported_tlbs) = $(b) $(self.includes:G=) ;
|
|---|
| 88 |
|
|---|
| 89 | scanner.propagate
|
|---|
| 90 | [ type.get-scanner CPP : [ property-set.create $(self.includes) ] ] :
|
|---|
| 91 | $(included-angle) $(included-quoted) : $(target) ;
|
|---|
| 92 |
|
|---|
| 93 | scanner.propagate $(__name__) : $(imported) : $(target) ;
|
|---|
| 94 | }
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | scanner.register xpidl-scanner : include ;
|
|---|
| 98 | type.set-scanner IDL : xpidl-scanner ;
|
|---|
| 99 |
|
|---|
| 100 | flags xpidl.compile.idl INCLUDES <include> ;
|
|---|
| 101 |
|
|---|
| 102 | generators.register-c-compiler xpidl.compile.idl : IDL : XPTYPELIB H JAVA C ;
|
|---|
| 103 |
|
|---|
| 104 | TOUCH_FILE = [ common.file-touch-command ] ;
|
|---|
| 105 |
|
|---|
| 106 | actions compile.idl
|
|---|
| 107 | {
|
|---|
| 108 | xpidl -m typelib -I$(INCLUDES) -w -e $(<[1]:W) $(>:W)
|
|---|
| 109 | xpidl -m header -I$(INCLUDES) -w -e $(<[2]:W) $(>:W)
|
|---|
| 110 | xpidl -m java -I$(INCLUDES) -w -e $(<[3]:W) $(>:W)
|
|---|
| 111 | $(TOUCH_FILE) $(<[4]:W)
|
|---|
| 112 | }
|
|---|