]> git.sven.stormbind.net Git - sven/exfat-utils.git/blob - SConstruct
* New upstream release.
[sven/exfat-utils.git] / SConstruct
1 #
2 #       SConstruct (10.09.09)
3 #       SConscript for all components.
4 #
5 #       Copyright (C) 2010-2012  Andrew Nayenko
6 #
7 #       This program is free software: you can redistribute it and/or modify
8 #       it under the terms of the GNU General Public License as published by
9 #       the Free Software Foundation, either version 3 of the License, or
10 #       (at your option) any later version.
11 #
12 #       This program is distributed in the hope that it will be useful,
13 #       but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #       GNU General Public License for more details.
16 #
17 #       You should have received a copy of the GNU General Public License
18 #       along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20
21 import os
22 import platform
23 import SCons
24
25 env = Environment(**ARGUMENTS)
26 conf = Configure(env)
27
28 destdir = env.get('DESTDIR', '/sbin');
29 targets = []
30 libs = ['exfat']
31
32 if 'CC' in os.environ:
33         conf.env.Replace(CC = os.environ['CC'])
34 if 'CCFLAGS' in os.environ:
35         conf.env.Replace(CCFLAGS = os.environ['CCFLAGS'])
36 # Set default CCFLAGS for known compilers
37 if not conf.env['CCFLAGS']:
38         if conf.env['CC'] == 'gcc':
39                 conf.env.Replace(CCFLAGS = '-Wall -O2 -ggdb -std=c99')
40         elif conf.env['CC'] == 'clang':
41                 conf.env.Replace(CCFLAGS = '-Wall -O2 -g -std=c99')
42 if 'CPPFLAGS' in os.environ:
43         conf.env.Replace(CPPFLAGS = os.environ['CPPFLAGS'])
44 conf.env.Append(CPPDEFINES = {'_FILE_OFFSET_BITS' : 64})
45 conf.env.Append(CPPPATH = ['libexfat'])
46 if 'LDFLAGS' in os.environ:
47         conf.env.Append(LINKFLAGS = os.environ['LDFLAGS'])
48 conf.env.Append(LIBPATH = ['libexfat'])
49
50 # GNU/Linux requires _BSD_SOURCE define for vsyslog(), _XOPEN_SOURCE >= 500 for
51 # pread(), pwrite(), snprintf(), strdup(), etc. Everything needed is enabled by
52 # _GNU_SOURCE.
53 if platform.system() == 'Linux':
54         conf.env.Append(CPPDEFINES = '_GNU_SOURCE');
55
56 # __DARWIN_64_BIT_INO_T=0 define is needed because since Snow Leopard inode
57 # numbers are 64-bit by default, but libfuse operates 32-bit ones. This define
58 # forces 32-bit inode declaration in system headers, but it's also possible to
59 # link against libfuse_ino64 instead.
60 if platform.system() == 'Darwin':
61         conf.env.Append(CPPDEFINES = {'__DARWIN_64_BIT_INO_T' : 0})
62         conf.env.Append(CPPDEFINES = {'__DARWIN_UNIX03' : 1})
63
64 # FreeBSD does not support block devices, only raw devices. Ublio is required
65 # for unaligned I/O and caching.
66 if platform.system() == 'FreeBSD':
67         conf.env.Append(CPPDEFINES = 'USE_UBLIO')
68         libs.append('ublio')
69         conf.env.Append(CPPPATH = ['/usr/local/include'])
70         conf.env.Append(LIBPATH = ['/usr/local/lib'])
71
72 env = conf.Finish()
73
74 def make_symlink(dir, target, link_name):
75         workdir = os.getcwd()
76         os.chdir(dir)
77         try:
78                 os.remove(link_name)
79         except OSError:
80                 pass
81         os.symlink(target, link_name)
82         os.chdir(workdir)
83
84 symlink = SCons.Action.ActionFactory(make_symlink,
85                 lambda dir, target, link_name:
86                                 'make_symlink("%s", "%s", "%s")' % (dir, target, link_name))
87
88 def program(pattern, output, alias, libs):
89         sources = Glob(pattern)
90         if not sources:
91                 return
92         target = env.Program(output, sources, LIBS = libs)
93         if alias:
94                 Alias('install', Install(destdir, target),
95                                 symlink(destdir, os.path.basename(output), alias))
96         else:
97                 Alias('install', Install(destdir, target))
98         targets.append(target)
99
100 env.Library('libexfat/exfat', Glob('libexfat/*.c'))
101
102 program('fuse/*.c', 'fuse/mount.exfat-fuse', 'mount.exfat', [libs + ['fuse']])
103 program('dump/*.c', 'dump/dumpexfat', None, libs)
104 program('fsck/*.c', 'fsck/exfatfsck', 'fsck.exfat', libs)
105 program('mkfs/*.c', 'mkfs/mkexfatfs', 'mkfs.exfat', libs)
106 program('label/*.c', 'label/exfatlabel', None, libs)
107
108 Default(targets)