|
| 1 | +# Copyright (c) 2025 Mohammad Nejati |
| 2 | +# |
| 3 | +# Use, modification and distribution is subject to the Boost Software |
| 4 | +# License Version 1.0. (See accompanying file LICENSE.txt or |
| 5 | +# https://www.bfgroup.xyz/b2/LICENSE.txt) |
| 6 | + |
| 7 | +# Supports the brotli library |
| 8 | +# |
| 9 | +# After 'using brotli', the following targets are available: |
| 10 | +# |
| 11 | +# /brotli//brotlicommon -- The brotli common library |
| 12 | +# /brotli//brotlidec -- The brotli decoder library |
| 13 | +# /brotli//brotlienc -- The brotli encoder library |
| 14 | + |
| 15 | +import project ; |
| 16 | +import ac ; |
| 17 | +import errors ; |
| 18 | +import feature ; |
| 19 | +import "class" : new ; |
| 20 | +import targets ; |
| 21 | +import path ; |
| 22 | +import modules ; |
| 23 | +import indirect ; |
| 24 | +import property ; |
| 25 | +import property-set ; |
| 26 | +import args ; |
| 27 | + |
| 28 | +header = brotli/decode.h ; |
| 29 | +brotlicommon_names = brotlicommon libbrotlicommon ; |
| 30 | +brotlidec_names = brotlidec libbrotlidec ; |
| 31 | +brotlienc_names = brotlienc libbrotlienc ; |
| 32 | + |
| 33 | +library-id = 0 ; |
| 34 | + |
| 35 | +.debug = [ args.get-arg debug-configuration ] ; |
| 36 | + |
| 37 | +# Initializes the brotli library. |
| 38 | +# |
| 39 | +# Options for configuring brotli:: |
| 40 | +# |
| 41 | +# <search> |
| 42 | +# The directory containing the brotli binaries. |
| 43 | +# <brotlicommon-name> |
| 44 | +# Overrides the default name of brotlicommon library. |
| 45 | +# <brotlidec-name> |
| 46 | +# Overrides the default name of brotlidec library. |
| 47 | +# <brotlienc-name> |
| 48 | +# Overrides the default name of brotlienc library. |
| 49 | +# <include> |
| 50 | +# The directory containing the brotli headers. |
| 51 | +# <dll-path> |
| 52 | +# Extra directories to add to library search paths of consumers during |
| 53 | +# runtime (multiple instances are allowed). |
| 54 | +# |
| 55 | +# If none of these options is specified, then the environmental |
| 56 | +# variables BROTLI_LIBRARY_PATH, BROTLI_NAME, and BROTLI_INCLUDE will |
| 57 | +# be used instead. |
| 58 | +# |
| 59 | +# Examples:: |
| 60 | +# |
| 61 | +# # Find brotli in the default system location |
| 62 | +# using brotli ; |
| 63 | +# # Find brotli in /usr/local |
| 64 | +# using brotli : 1.1.0 |
| 65 | +# : <include>/usr/local/include <search>/usr/local/lib ; |
| 66 | +# |
| 67 | +rule init ( |
| 68 | + version ? |
| 69 | + # (currently ignored) |
| 70 | + |
| 71 | + : options * |
| 72 | + # A list of the options to use |
| 73 | + |
| 74 | + : requirements * |
| 75 | + # The requirements for the target |
| 76 | + |
| 77 | + : is-default ? |
| 78 | + ) |
| 79 | +{ |
| 80 | + local caller = [ project.current ] ; |
| 81 | + |
| 82 | + if ! $(.initialized) |
| 83 | + { |
| 84 | + .initialized = true ; |
| 85 | + |
| 86 | + project.initialize $(__name__) ; |
| 87 | + .project = [ project.current ] ; |
| 88 | + project brotli ; |
| 89 | + } |
| 90 | + |
| 91 | + local library-path = [ feature.get-values <search> : $(options) ] ; |
| 92 | + local include-path = [ feature.get-values <include> : $(options) ] ; |
| 93 | + local brotlicommon-name = [ feature.get-values <brotlicommon-name> : $(options) ] ; |
| 94 | + local brotlidec-name = [ feature.get-values <brotlidec-name> : $(options) ] ; |
| 95 | + local brotlienc-name = [ feature.get-values <brotlienc-name> : $(options) ] ; |
| 96 | + local dll-paths = [ property.select <dll-path> : $(options) ] ; |
| 97 | + |
| 98 | + if ! $(options) |
| 99 | + { |
| 100 | + is-default = true ; |
| 101 | + } |
| 102 | + |
| 103 | + condition = [ property-set.create $(requirements) ] ; |
| 104 | + condition = [ property-set.create [ $(condition).base ] ] ; |
| 105 | + |
| 106 | + if $(.configured.$(condition)) |
| 107 | + { |
| 108 | + if $(is-default) |
| 109 | + { |
| 110 | + if $(.debug) |
| 111 | + { |
| 112 | + ECHO "notice: [brotli] brotli is already configured" ; |
| 113 | + } |
| 114 | + } |
| 115 | + else |
| 116 | + { |
| 117 | + errors.user-error "brotli is already configured" ; |
| 118 | + } |
| 119 | + return ; |
| 120 | + } |
| 121 | + else |
| 122 | + { |
| 123 | + if $(.debug) |
| 124 | + { |
| 125 | + ECHO "notice: [brotli] Using pre-installed library" ; |
| 126 | + if $(condition) |
| 127 | + { |
| 128 | + ECHO "notice: [brotli] Condition" [ $(condition).raw ] ; |
| 129 | + } |
| 130 | + } |
| 131 | + |
| 132 | + local brotlicommon = [ new ac-library brotlicommon : $(.project) : $(condition) : |
| 133 | + $(include-path) : $(library-path) : $(brotlicommon-name) ] ; |
| 134 | + $(brotlicommon).set-header $(header) ; |
| 135 | + $(brotlicommon).set-default-names $(brotlicommon_names) ; |
| 136 | + $(brotlicommon).add-usage-requirements $(dll-paths) ; |
| 137 | + |
| 138 | + local brotlidec = [ new ac-library brotlidec : $(.project) : $(condition) : |
| 139 | + $(include-path) : $(library-path) : $(brotlidec-name) ] ; |
| 140 | + $(brotlidec).set-header $(header) ; |
| 141 | + $(brotlidec).set-default-names $(brotlidec_names) ; |
| 142 | + $(brotlidec).add-usage-requirements $(dll-paths) ; |
| 143 | + |
| 144 | + local brotlienc = [ new ac-library brotlienc : $(.project) : $(condition) : |
| 145 | + $(include-path) : $(library-path) : $(brotlienc-name) ] ; |
| 146 | + $(brotlienc).set-header $(header) ; |
| 147 | + $(brotlienc).set-default-names $(brotlienc_names) ; |
| 148 | + $(brotlienc).add-usage-requirements $(dll-paths) ; |
| 149 | + |
| 150 | + targets.main-target-alternative $(brotlicommon) ; |
| 151 | + targets.main-target-alternative $(brotlidec) ; |
| 152 | + targets.main-target-alternative $(brotlienc) ; |
| 153 | + } |
| 154 | + .configured.$(condition) = true ; |
| 155 | +} |
0 commit comments