summaryrefslogtreecommitdiffstats
path: root/SConstruct
blob: a699008d19d36cdf621e9193a4418bf2ead56108 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#! /usr/bin/env python
## The kde detection is located in kde.py (have a look!)
## Delete the comments following as you see it fit

"""
scons files are python scripts, comments begin by a "#" symbol
or are enclosed between sequences of triple quotes, so 
this is a comment :)

There is a lot of documentation and comments, but you can
remove them when you convert your program
"""

"""
----------------------------------
How to enjoy bksys full and plenty
(and forget about the autohell ? :)
-----------------------------------

The program scons is usually launched as "scons"
When it is not intalled globally, one can run
"python scons.py" instead (ie : to use the local scons 
that comes with bksys - try ./unpack_local_scons.sh)

To compile the project, you will then only need to launch
scons on the top-level directory, the scripts find and
cache the proper environment automatically :
-> scons
(or python scons.py)

To clean the project
-> scons -c
(or python scons.py -c)

To install the project
-> scons install
(or python scons.py scons install)

To uninstall the project
-> scons -c install

To compile while being in a subdirectory
-> cd src; scons -u

To (re)configure the project and give particular arguments, use ie :
-> scons configure debug=1
-> scons configure prefix=/tmp/ita debug=full extraincludes=/usr/local/include:/tmp/include prefix=/usr/local
or -> python scons.py configure debug=1
etc ..
The variables are saved automatically after the first run
(look at kde.cache.py, ..)

Here is a quick list of options used (look at generic.py and kde.py) :
prefix
exec_prefix
datadir
libdir
kdeincludes
qtincludes
tdelibs
qtlibs
extraincludes (a list of paths separated by ':')

"""

###########################################
## Common section, for loading the tools

## Load the builders in config
env = Environment(TARGS=COMMAND_LINE_TARGETS, ARGS=ARGUMENTS, tools=['default', 'generic', 'kde'], toolpath=['./', './admin'])
#env = Environment(TARGS=COMMAND_LINE_TARGETS, ARGS=ARGUMENTS, tools=['default', 'generic', 'kde', 'cg'], toolpath=['./'])
#env = Environment(TARGS=COMMAND_LINE_TARGETS, ARGS=ARGUMENTS, tools=['default', 'generic', 'kde', 'sound'], toolpath=['./'])
#env = Environment(TARGS=COMMAND_LINE_TARGETS, ARGS=ARGUMENTS, tools=['default', 'generic', 'kde', 'libxml'], toolpath=['./'])

## the configuration should be done by now, quit
if 'configure' in COMMAND_LINE_TARGETS:
	env.Exit(0)

"""
Overview of the module system :

Each module (kde.py, generic.py, sound.py..) tries to load a stored 
configuration when run. If the stored configuration does not exist
or if 'configure' is given on the command line (scons configure), 
the module launches the verifications and detectioins and stores 
the results. Modules also call exit when the detection fail.

For example, kde.py stores its config into kde.cache.py

This has several advantages for both developers and users :
  - Users do not have to run ./configure to compile
  - The build is insensitive to environment changes
  - The cache maintains the objects so the config can be changed often
  - Each module adds its own help via env.Help("message")
"""

## Use the variables available in the environment - unsafe, but moc, meinproc need it :-/
import os
env.AppendUnique( ENV = os.environ )

## The target make dist requires the python module shutil which is in 2.3
env.EnsurePythonVersion(2, 3)

## Bksys requires scons 0.96
env.EnsureSConsVersion(0, 96)

"""
Explanation of the 'env = Environment...' line :
* the command line arguments and targets are stored in env['TARGS'] and env['ARGS'] for use by the tools
* the part 'tools=['default', 'generic ..' detect and load the necessary functions for doing the things
* the part "toolpath=['./']" tells that the tools can be found in the current directory (generic.py, kde.py ..)
"""

"""
To load more configuration modules one should only have to add the appropriate tool
ie: to detect alsa and add the proper cflags, ldflags .. 
    a file alsa.py file will be needed, and one should then use :
    env = Environment(TARGS=COMMAND_LINE_TARGETS, ARGS=ARGUMENTS, tools=['default', 'generic', 'kde', 'alsa'], toolpath=['./'])

You can also load environments that are targetted to different platforms
ie: if os.sys.platform = "darwin":
	env = Environment(...
    elsif os.sys.platform = "linux":
	env = Environment(...

"""

## Setup the cache directory - this avoids recompiling the same files over and over again
## this is very handy when working with cvs
env.CacheDir('cache')

## Avoid spreading .sconsign files everywhere - keep this line
env.SConsignFile('scons_signatures')

## If you need more libs and they rely on pkg-config
## ie: add support for GTK (source: the scons wiki on www.scons.org)
# env.ParseConfig('pkg-config --cflags --libs gtk+-2.0')

"""
This tell scons that there are no rcs or sccs files - this trick 
can speed up things a bit when having lots of #include
in the source code and for network file systems
"""
env.SourceCode(".", None)

dirs = [ '.', 'src', 'po', 'doc']

for dir in dirs:
	env.SourceCode(dir, None)

## If we had only one program (named kvigor) to build, 
## we could add before exporting the env (some kde 
## helpers in kde.py need it) :
# env['APPNAME'] = 'kvigor'

## Use this define if you are using the kde translation scheme (.po files)
env.Append( CPPFLAGS = ['-DQT_NO_TRANSLATION'] )

## Add this define if you want to use qthreads
#env.Append( CPPFLAGS = ['-DQT_THREAD_SUPPORT', '-D_REENTRANT'] )

## To use kdDebug(intvalue)<<"some trace"<<endl; you need to define -DDEBUG - it is done
## in generic.py automatically when you do scons configure debug=1

## There are also many other defines :
### -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -DQT_CLEAN_NAMESPACE -DQT_NO_ASCII_CAST -DQT_NO_STL -DQT_NO_COMPAT -DQT_NO_TRANSLATION
# where are they documented ? if you know, mail tnagyemail-mail@yahoo@fr please

## Important : export the environment so that SConscript files can the 
## configuration and builders in it
Export("env")


####################################################
## Process the SConscript files to build the targets
## the sconscript files are comparable to Makefile.am_s
## except that no makefile is generated here :)

env.SConscript("src/SConscript")
env.SConscript("doc/SConscript")
env.SConscript("po/SConscript")

####################################################
## Quick helper to distribute the program

"""
'scons dist' creates a tarball named bksys-version.tar.bz2 
containing the source code - this is handy
do not forget to remove the object files by scons -c
"""

### To make a tarball of your sctest
if 'dist' in COMMAND_LINE_TARGETS:

        APPNAME = 'sctest'
        VERSION = os.popen("cat VERSION").read().rstrip()
        FOLDER  = APPNAME+'-'+VERSION
        ARCHIVE = FOLDER+'.tar.bz2'

        GREEN  ="\033[92m"
        NORMAL ="\033[0m"

        import shutil
        import glob

        ## check if the temporary directory already exists
        if os.path.isdir(FOLDER):
                shutil.rmtree(FOLDER)

        ## create a temporary directory
        startdir = os.getcwd()
        shutil.copytree(startdir, FOLDER)

        ## remove the unnecessary files
        os.popen("find "+FOLDER+" -name \"{arch}\" | xargs rm -rf")
        os.popen("find "+FOLDER+" -name \".arch-ids\" | xargs rm -rf")
        os.popen("find "+FOLDER+" -name \".arch-inventory\" | xargs rm -f")
        os.popen("find "+FOLDER+" -name \"sconsign*\" | xargs rm -f")
        os.popen("find "+FOLDER+" -name \"*cache*\" | xargs rm -rf")
        os.popen("find "+FOLDER+" -name \"kdiss*-data\" | xargs rm -rf")
        os.popen("find "+FOLDER+" -name \"*.pyc\" | xargs rm -f")
        os.popen("rm -f "+FOLDER+"/config.py*")

        ## make the tarball
        print(GREEN+"Writing archive "+ARCHIVE+NORMAL)
        os.popen("tar cjf "+ARCHIVE+" "+FOLDER)

        ## remove the temporary directory
        if os.path.isdir(FOLDER):
                shutil.rmtree(FOLDER)

        env.Default(None)
        env.Exit(0)