1# Copyright 2008 Eduardo Gurgel
2#
3# Distributed under the Boost Software License, Version 1.0. (See
4# accompanying file LICENSE_1_0.txt or copy at
5# http://www.boost.org/LICENSE_1_0.txt)
6#
7
8# Support for creating components for the Tntnet web application
9# server (http://tntnet.org)
10#
11# Example:
12#
13#   using tntnet : /usr ;
14#   lib index : index.png index.js index.css index.ecpp otherclass.cpp
15#   /tntnnet//tntnet /tntnet//cxxtools ;
16#
17#
18
19import modules ;
20import feature ;
21import errors ;
22import "class" : new ;
23import generators ;
24import project ;
25import toolset : flags ;
26import os ;
27import virtual-target ;
28import scanner ;
29import type ;
30
31type.register ECPP : ecpp ;
32type.register JPEG : jpeg ;
33type.register JPG : jpg ;
34type.register PNG : png ;
35type.register JS : js ;
36type.register CSS : css ;
37type.register GIF : gif ;
38
39project.initialize $(__name__) ;
40project tntnet ;
41
42# Save the project so that we tolerate 'import + using' combo.
43.project = [ project.current ] ;
44# Initialized the Tntnet support module. The 'prefix' parameter
45# tells where Tntnet is installed.
46rule init ( prefix : full_bin ? : full_inc ? : full_lib ? )
47{
48    project.push-current $(.project) ;
49
50    # pre-build paths to detect reinitializations changes
51    local inc_prefix lib_prefix bin_prefix ;
52    if $(full_inc)
53    {
54        inc_prefix = $(full_inc) ;
55    }
56    else
57    {
58        inc_prefix = $(prefix)/include ;
59    }
60    if $(full_lib)
61    {
62        lib_prefix = $(full_lib) ;
63    }
64    else
65    {
66        lib_prefix = $(prefix)/lib ;
67    }
68    if $(full_bin)
69    {
70        bin_prefix = $(full_bin) ;
71    }
72    else
73    {
74        bin_prefix = $(prefix)/bin ;
75    }
76
77    if $(.initialized)
78    {
79        if $(prefix) != $(.prefix)
80        {
81            errors.error
82                "Attempt the reinitialize Tntnet with different installation prefix" ;
83        }
84        if $(inc_prefix) != $(.incprefix)
85        {
86            errors.error
87                "Attempt the reinitialize Tntnet with different include path" ;
88        }
89        if $(lib_prefix) != $(.libprefix)
90        {
91            errors.error
92                "Attempt the reinitialize Tntnet with different library path" ;
93        }
94        if $(bin_prefix) != $(.binprefix)
95        {
96            errors.error
97                "Attempt the reinitialize Tntnet with different bin path" ;
98        }
99    }
100    else
101    {
102        .initialized = true ;
103        .prefix = $(prefix) ;
104
105        # Setup prefixes for include, binaries and libs.
106        .incprefix = $(.prefix)/include ;
107        .libprefix = $(.prefix)/lib ;
108        .binprefix = $(.prefix)/bin ;
109
110        # Generates cpp files from ecpp files using "ecppc" tool
111        generators.register-standard tntnet.ecpp : ECPP : CPP ;
112        # Generates cpp files from jpeg files using "ecppc" tool
113        generators.register-standard tntnet.jpeg : JPEG : CPP ;
114        # Generates cpp files from jpg files using "ecppc" tool
115        generators.register-standard tntnet.jpg : JPG : CPP ;
116        # Generates cpp files from png files using "ecppc" tool
117        generators.register-standard tntnet.png : PNG : CPP ;
118        # Generates cpp files from js files using "ecppc" tool
119        generators.register-standard tntnet.js : JS : CPP ;
120        # Generates cpp files from gif files using "ecppc" tool
121        generators.register-standard tntnet.gif : GIF : CPP ;
122        # Generates cpp files from css files using "ecppc" tool
123        generators.register-standard tntnet.css : CSS : CPP ;
124      	# Scanner for ecpp includes
125        type.set-scanner ECPP : ecpp-scanner ;
126
127
128	local usage-requirements =
129		<include>$(.incprefix)
130		<library-path>$(.libprefix)
131		<dll-path>$(.libprefix)
132		<threading>multi
133		<allow>tntnet ;
134	lib cxxtools : $(main)
135		:
136		:
137		:
138		<include>$(.incprefix)/cxxtools
139		$(usage-requiriments)
140		;
141	lib tntnet : $(main)
142		:
143		:
144		:
145		<include>$(.incprefix)/tntnet
146		$(usage-requiriments)
147		;
148
149    }
150    project.pop-current ;
151
152}
153
154rule directory
155{
156    return $(.prefix) ;
157}
158
159rule initialized ( )
160{
161    return $(.initialized) ;
162}
163
164# Get <include> from current toolset.
165flags tntnet.ecpp INCLUDES <include> ;
166
167actions ecpp
168{
169	$(.binprefix)/ecppc -I " $(INCLUDES) " -o $(<) $(>)
170}
171
172actions jpeg
173{
174	$(.binprefix)/ecppc -b -m image/jpeg -o $(<) $(>)
175}
176
177actions jpg
178{
179	$(.binprefix)/ecppc -b -m image/jpeg -o $(<) $(>)
180}
181
182actions js
183{
184	$(.binprefix)/ecppc -b -m application/x-javascript -o $(<) $(>)
185}
186
187actions png
188{
189	$(.binprefix)/ecppc -b -m image/png -o $(<) $(>)
190}
191actions gif
192{
193	$(.binprefix)/ecppc -b -m image/gif -o $(<) $(>)
194}
195actions css
196{
197	$(.binprefix)/ecppc -b -m text/css -o $(<) $(>)
198}
199
200class ecpp-scanner : common-scanner
201{
202	rule pattern ( )
203	{
204		return  "<%include.*>(.*)</%include>" ;
205	}
206}
207
208scanner.register ecpp-scanner : include ;
209