SConstruct 6.32 KB
Newer Older
Jan Gerber's avatar
Jan Gerber committed
1
# SCons build specification
2
# vi:si:et:sw=2:sts=2:ts=2
Jan Gerber's avatar
Jan Gerber committed
3
4
5
6
7
from glob import glob
import os

import SCons

8
def version():
Jan Gerber's avatar
Jan Gerber committed
9
    f = os.popen("./version.sh")
Jan Gerber's avatar
Jan Gerber committed
10
11
12
    version = f.read().strip()
    f.close()
    return version
Jan Gerber's avatar
Jan Gerber committed
13

Jan Gerber's avatar
Jan Gerber committed
14
pkg_version="0.29"
Jan Gerber's avatar
Jan Gerber committed
15

Jan Gerber's avatar
Jan Gerber committed
16
17
pkg_name="ffmpeg2theora"

Jan Gerber's avatar
Jan Gerber committed
18
scons_version=(1,2,0)
19
20
21
22
23
24
25

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)

Jan Gerber's avatar
Jan Gerber committed
26
27
28
29
opts = Variables()
opts.AddVariables(
  BoolVariable('static', 'Set to 1 for static linking', 0),
  BoolVariable('debug', 'Set to 1 to enable debugging', 0),
30
  BoolVariable('build_ffmpeg', 'Set to 1 to build local copy of ffmpeg', 0),
Jan Gerber's avatar
Jan Gerber committed
31
  ('prefix', 'install files in', '/usr/local'),
32
33
34
35
  ('bindir', 'user executables', 'PREFIX/bin'),
  ('mandir', 'man documentation', 'PREFIX/man'),
  ('destdir', 'extra install time prefix', ''),
  ('APPEND_CCFLAGS', 'Additional C/C++ compiler flags'),
36
  ('APPEND_LINKFLAGS', 'Additional linker flags'),
Jan Gerber's avatar
Jan Gerber committed
37
38
  BoolVariable('libkate', 'enable libkate support', 1),
  BoolVariable('crossmingw', 'Set to 1 for crosscompile with mingw', 0)
39
40
41
)
env = Environment(options = opts)
Help(opts.GenerateHelpText(env))
Jan Gerber's avatar
Jan Gerber committed
42
43

pkg_flags="--cflags --libs"
44
if env['static']:
Jan Gerber's avatar
Jan Gerber committed
45
46
47
  pkg_flags+=" --static"
  env.Append(LINKFLAGS=["-static"])

48
49
50
if env['crossmingw']:
    env.Tool('crossmingw', toolpath = ['scons-tools'])

51
52
53
54
55
56
57
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
58
59
env.Append(CPPPATH=['.'])
env.Append(CCFLAGS=[
60
61
  '-DPACKAGE_VERSION=\\"%s\\"' % pkg_version,
  '-DPACKAGE_STRING=\\"%s-%s\\"' % (pkg_name, pkg_version),
Jan Gerber's avatar
Jan Gerber committed
62
  '-DPACKAGE=\\"%s\\"' % pkg_name,
63
  '-D_FILE_OFFSET_BITS=64'
Jan Gerber's avatar
Jan Gerber committed
64
])
65

66
67
68
env.Append(CCFLAGS = Split('$APPEND_CCFLAGS'))
env.Append(LINKFLAGS = Split('$APPEND_LINKFLAGS'))

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

72
73
74
if GetOption("help"):
    Return()

75
76
77
78
79
80
81
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)

82
83
84
85
86
87
88
def TryAction(action):
    import os
    ret = os.system(action)
    if ret == 0:
        return (1, '')
    return (0, '')

Jan Gerber's avatar
Jan Gerber committed
89
90
def CheckPKGConfig(context, version): 
  context.Message( 'Checking for pkg-config... ' ) 
91
  ret = TryAction('pkg-config --atleast-pkgconfig-version=%s' % version)[0] 
Jan Gerber's avatar
Jan Gerber committed
92
93
94
95
96
97
98
99
100
  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
101
  ret = TryAction(action)[0]
Jan Gerber's avatar
Jan Gerber committed
102
103
104
  context.Result( ret ) 
  return ret

105
106
env.PrependENVPath ('PATH', os.environ['PATH'])

Jan Gerber's avatar
Jan Gerber committed
107
108
109
conf = Configure(env, custom_tests = {
  'CheckPKGConfig' : CheckPKGConfig,
  'CheckPKG' : CheckPKG,
110
111
})

112
113
114
115
116
117
if env["build_ffmpeg"]:
  if env.GetOption('clean'):
    TryAction("cd ffmpeg;make distclean")
  else:
    TryAction("./build_ffmpeg.sh")

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
if not env.GetOption('clean'):
  pkgconfig_version='0.15.0'
  if not conf.CheckPKGConfig(pkgconfig_version): 
     print 'pkg-config >= %s not found.' % pkgconfig_version 
     Exit(1)

  if not conf.CheckPKG("ogg >= 1.1"): 
    print 'ogg >= 1.1 missing'
    Exit(1) 

  if not conf.CheckPKG("vorbis"): 
    print 'vorbis missing'
    Exit(1) 

  if not conf.CheckPKG("vorbisenc"): 
    print 'vorbisenc missing'
    Exit(1) 

  if not conf.CheckPKG("theoraenc >= 1.1.0"): 
    print 'theoraenc >= 1.1.0 missing'
    Exit(1) 

  XIPH_LIBS="ogg >= 1.1 vorbis vorbisenc theoraenc >= 1.1.0"

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

  FFMPEG_LIBS=[
      "libavdevice",
      "libavformat",
Jan Gerber's avatar
Jan Gerber committed
150
      "libavfilter",
151
152
153
      "libavcodec >= 52.30.0",
      "libpostproc",
      "libswscale",
Jan Gerber's avatar
Jan Gerber committed
154
      "libswresample",
155
156
157
158
159
160
      "libavutil",
  ]
  if os.path.exists("./ffmpeg"):
    pkg_path = list(set(map(os.path.dirname, glob('./ffmpeg/*/*.pc'))))
    pkg_path.append(os.environ.get('PKG_CONFIG_PATH', ''))
    os.environ['PKG_CONFIG_PATH'] = ':'.join(pkg_path)
161
    env.Append(CCFLAGS=[
162
      '-Iffmpeg'
163
    ])
164

165
  if not conf.CheckPKG(' '.join(FFMPEG_LIBS)): 
166
    print """
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
        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.sh (for more information see INSTALL)
    """ %(" ".join(FFMPEG_LIBS), " ".join(["%s-dev"%l.split()[0] for l in FFMPEG_LIBS]))
    Exit(1) 

  for lib in FFMPEG_LIBS:
      ParsePKGConfig(env, lib)

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

  KATE_LIBS="oggkate"
  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
      """

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

  if env['crossmingw']:
      env.Append(CCFLAGS=['-Wl,-subsystem,windows'])
      env.Append(LIBS=['m'])
  elif env['static']:
      env.Append(LIBS=['m', 'dl'])
211
212


Jan Gerber's avatar
Jan Gerber committed
213
214
215
env = conf.Finish()

# ffmpeg2theora 
216
ffmpeg2theora = env.Clone()
Jan Gerber's avatar
Jan Gerber committed
217
ffmpeg2theora_sources = glob('src/*.c')
Jan Gerber's avatar
Jan Gerber committed
218
ffmpeg2theora.Program('ffmpeg2theora', ffmpeg2theora_sources)
219
220
221
222

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