SConstruct 5.28 KB
Newer Older
Jan Gerber's avatar
Jan Gerber committed
1
2
3
4
5
6
7
# SCons build specification
from glob import glob
import os

import SCons


8
pkg_version="0.24+svn"
Jan Gerber's avatar
Jan Gerber committed
9
10
pkg_name="ffmpeg2theora"

11
12
13
14
scons_version=(0,97,0)
#this is needed to make scons -h work, so not checking for it right now
#(i.e. ubuntu hardy only ships with 0.97..)
#scons_version=(0,98,0)
15
16
17
18
19
20
21

try:
    EnsureSConsVersion(*scons_version)
except TypeError:
    print 'SCons %d.%d.%d or greater is required, but you have an older version' % scons_version
    Exit(2)

22
23
24
opts = Options()
opts.AddOptions(
  BoolOption('static', 'Set to 1 for static linking', 0),
Jan Gerber's avatar
Jan Gerber committed
25
  BoolOption('debug', 'Set to 1 to enable debugging', 0),
Jan Gerber's avatar
Jan Gerber committed
26
  ('prefix', 'install files in', '/usr/local'),
27
28
29
30
  ('bindir', 'user executables', 'PREFIX/bin'),
  ('mandir', 'man documentation', 'PREFIX/man'),
  ('destdir', 'extra install time prefix', ''),
  ('APPEND_CCFLAGS', 'Additional C/C++ compiler flags'),
31
  ('APPEND_LINKFLAGS', 'Additional linker flags'),
32
  BoolOption('libkate', 'enable libkate support', 1),
33
  BoolOption('crossmingw', 'Set to 1 for crosscompile with mingw', 0)
34
35
36
)
env = Environment(options = opts)
Help(opts.GenerateHelpText(env))
Jan Gerber's avatar
Jan Gerber committed
37
38

pkg_flags="--cflags --libs"
39
if env['static']:
Jan Gerber's avatar
Jan Gerber committed
40
41
42
  pkg_flags+=" --static"
  env.Append(LINKFLAGS=["-static"])

43
44
45
if env['crossmingw']:
    env.Tool('crossmingw', toolpath = ['scons-tools'])

46
47
48
49
50
51
52
prefix = env['prefix']
if env['destdir']:
  if prefix.startswith('/'): prefix = prefix[1:]
  prefix = os.path.join(env['destdir'], prefix)
man_dir = env['mandir'].replace('PREFIX', prefix)
bin_dir = env['bindir'].replace('PREFIX', prefix)

Jan Gerber's avatar
Jan Gerber committed
53
54
env.Append(CPPPATH=['.'])
env.Append(CCFLAGS=[
55
56
  '-DPACKAGE_VERSION=\\"%s\\"' % pkg_version,
  '-DPACKAGE_STRING=\\"%s-%s\\"' % (pkg_name, pkg_version),
Jan Gerber's avatar
Jan Gerber committed
57
  '-DPACKAGE=\\"%s\\"' % pkg_name,
58
  '-D_FILE_OFFSET_BITS=64'
Jan Gerber's avatar
Jan Gerber committed
59
])
60

61
62
63
env.Append(CCFLAGS = Split('$APPEND_CCFLAGS'))
env.Append(LINKFLAGS = Split('$APPEND_LINKFLAGS'))

Jan Gerber's avatar
Jan Gerber committed
64
65
if env['debug'] and env['CC'] == 'gcc':
  env.Append(CCFLAGS=["-g", "-O2", "-Wall"])
Jan Gerber's avatar
Jan Gerber committed
66

67
68
69
if GetOption("help"):
    Return()

70
71
72
73
74
75
76
def ParsePKGConfig(env, name): 
  if os.environ.get('PKG_CONFIG_PATH', ''):
    action = 'PKG_CONFIG_PATH=%s pkg-config %s "%s"' % (os.environ['PKG_CONFIG_PATH'], pkg_flags, name)
  else:
    action = 'pkg-config %s "%s"' % (pkg_flags, name)
  return env.ParseConfig(action)

77
78
79
80
81
82
83
def TryAction(action):
    import os
    ret = os.system(action)
    if ret == 0:
        return (1, '')
    return (0, '')

Jan Gerber's avatar
Jan Gerber committed
84
85
def CheckPKGConfig(context, version): 
  context.Message( 'Checking for pkg-config... ' ) 
86
  ret = TryAction('pkg-config --atleast-pkgconfig-version=%s' % version)[0] 
Jan Gerber's avatar
Jan Gerber committed
87
88
89
90
91
92
93
94
95
  context.Result( ret ) 
  return ret 

def CheckPKG(context, name): 
  context.Message( 'Checking for %s... ' % name )
  if os.environ.get('PKG_CONFIG_PATH', ''):
    action = 'PKG_CONFIG_PATH=%s pkg-config --exists "%s"' % (os.environ['PKG_CONFIG_PATH'], name)
  else:
    action = 'pkg-config --exists "%s"' % name
96
  ret = TryAction(action)[0]
Jan Gerber's avatar
Jan Gerber committed
97
98
99
100
101
102
103
  context.Result( ret ) 
  return ret

conf = Configure(env, custom_tests = {
  'CheckPKGConfig' : CheckPKGConfig,
  'CheckPKG' : CheckPKG,
  })
104

105
106
107
pkgconfig_version='0.15.0'
if not conf.CheckPKGConfig(pkgconfig_version): 
   print 'pkg-config >= %s not found.' % pkgconfig_version 
Jan Gerber's avatar
Jan Gerber committed
108
109
   Exit(1)

Jan Gerber's avatar
Jan Gerber committed
110
XIPH_LIBS="ogg >= 1.1 vorbis vorbisenc theoraenc >= 1.1beta3"
Jan Gerber's avatar
Jan Gerber committed
111
112
113
114

if not conf.CheckPKG(XIPH_LIBS): 
  print 'some xiph libs are missing, ffmpeg2theora depends on %s' % XIPH_LIBS
  Exit(1) 
115
ParsePKGConfig(env, XIPH_LIBS)
Jan Gerber's avatar
Jan Gerber committed
116

117
FFMPEG_LIBS="libavcodec libavformat libavdevice libpostproc libswscale"
Jan Gerber's avatar
Jan Gerber committed
118
if os.path.exists("./ffmpeg"):
119
  os.environ['PKG_CONFIG_PATH'] = "./ffmpeg/libavutil:./ffmpeg/libavformat:./ffmpeg/libavcodec:./ffmpeg/libavdevice:./ffmpeg/libswscale:./ffmpeg/libpostproc:" + os.environ.get('PKG_CONFIG_PATH', '')
Jan Gerber's avatar
Jan Gerber committed
120
121
122
123
124
125
126
127
128
if not conf.CheckPKG(FFMPEG_LIBS): 
  print """
      Could not find %s.
      You can install it via
       sudo apt-get install %s
      or update PKG_CONFIG_PATH to point to ffmpeg's source folder
      or run ./get_ffmpeg_svn.sh (for more information see INSTALL)
  """ %(FFMPEG_LIBS, " ".join(["%s-dev"%l for l in FFMPEG_LIBS.split()]))
  Exit(1) 
129
for lib in FFMPEG_LIBS.split():
130
    ParsePKGConfig(env, lib)
Jan Gerber's avatar
Jan Gerber committed
131

132
133
134
135
if conf.CheckCHeader('libavformat/framehook.h'):
    env.Append(CCFLAGS=[
      '-DHAVE_FRAMEHOOK'
    ])
136

Jan Gerber's avatar
Jan Gerber committed
137
KATE_LIBS="oggkate"
138
139
140
141
142
143
144
145
146
147
148
149
150
151
if env['libkate']:
  if os.path.exists("./libkate/misc/pkgconfig"):
    os.environ['PKG_CONFIG_PATH'] = "./libkate/misc/pkgconfig:" + os.environ.get('PKG_CONFIG_PATH', '')
  if os.path.exists("./libkate/pkg/pkgconfig"):
    os.environ['PKG_CONFIG_PATH'] = "./libkate/pkg/pkgconfig:" + os.environ.get('PKG_CONFIG_PATH', '')
  if conf.CheckPKG(KATE_LIBS):
    ParsePKGConfig(env, KATE_LIBS)
    env.Append(CCFLAGS=['-DHAVE_KATE', '-DHAVE_OGGKATE'])
  else:
    print """
        Could not find libkate. Subtitles support will be disabled.
        You can also run ./get_libkate.sh (for more information see INSTALL)
        or update PKG_CONFIG_PATH to point to libkate's source folder
    """
152
153
154
155
156

if conf.CheckCHeader('iconv.h'):
    env.Append(CCFLAGS=[
      '-DHAVE_ICONV'
    ])
157
158
159
    if conf.CheckLib('iconv'):
        env.Append(LIBS=['iconv'])

160

Jan Gerber's avatar
Jan Gerber committed
161
162
163
env = conf.Finish()

# ffmpeg2theora 
164
ffmpeg2theora = env.Clone()
Jan Gerber's avatar
Jan Gerber committed
165
ffmpeg2theora_sources = glob('src/*.c')
Jan Gerber's avatar
Jan Gerber committed
166
ffmpeg2theora.Program('ffmpeg2theora', ffmpeg2theora_sources)
167
168
169
170
171

ffmpeg2theora.Install(bin_dir, 'ffmpeg2theora')
ffmpeg2theora.Install(man_dir + "/man1", 'ffmpeg2theora.1')
ffmpeg2theora.Alias('install', prefix)