aboutsummaryrefslogtreecommitdiffstats
path: root/src/native/build.xml
blob: fe5d08d9ffe445e91fc1956fe42f0ee5b66f7598 (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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
<project name="sip-communicator-native" default="help-native">
  <import file="../../build.xml"/>

  <!-- additionnal property -->
  <property name="obj" value="${src}/native/native_obj" />

  <!-- load cpptasks jar to have <cc /> tag -->
  <taskdef resource="cpptasks.tasks">
    <!-- load cpptasks jar -->
    <classpath>
      <pathelement location="${sc.basedir}/lib/installer-exclude/cpptasks.jar"/>
    </classpath>
  </taskdef>

  <!-- Cross compilation, this is mainly used for Linux (cross-compile 32-bit binaries
       from 64-bit host. It is also used to compile ffmpeg for Mac OS X for each 
       architecture before create universal binary with lupo tool. 
  -->
  <condition property="cross_32" value="y" >
    <equals arg1="${arch}" arg2="32" />
  </condition>

  <condition property="cross_64" value="y" >
    <equals arg1="${arch}" arg2="64" />
  </condition>
  
  <!-- Mac OS X only -->
  <condition property="cross_ppc" value="y" >
    <equals arg1="${arch}" arg2="ppc" />
  </condition>

  <!-- initialize destination directory -->
  <condition property="native_install_dir" value="${native.libs}/windows">
    <and>
      <isset property="is.running.windows"/>
      <or>
        <os arch="x86" />
        <os arch="i386" />
        <equals arg1="${arch}" arg2="32" />
      </or>
    </and>
  </condition>

  <condition property="native_install_dir" value="${native.libs}/windows-64">
    <and>
      <isset property="is.running.windows"/>
      <or>   
        <os arch="amd64" />
        <equals arg1="${arch}" arg2="64" />
      </or>
    </and>                                    
  </condition>

  <condition property="native_install_dir" value="${native.libs}/linux">
    <and>   
      <isset property="is.running.linux"/>
      <or>
        <os arch="x86" />
        <os arch="i386" />
        <equals arg1="${arch}" arg2="32" />
      </or>
    </and>                                    
  </condition>

  <condition property="native_install_dir" value="${native.libs}/linux-64">
    <and>
      <isset property="is.running.linux"/>
      <or>   
        <os arch="amd64" />
        <equals arg1="${arch}" arg2="64" />
      </or>
    </and>                                    
  </condition>

  <condition property="native_install_dir" value="${native.libs}/mac">
    <isset property="is.running.macos"/>
  </condition>

  <condition property="native_install_dir" value="${native.libs}/mac">
    <isset property="is.running.macos"/>
  </condition>

  <!--
  <echo message="ffmpeg library: ${ffmpeg}" />
  <echo message="x264 library: ${x264}" />
  <echo message="lame library: ${lame}" />
  <echo message="portaudio library: ${portaudio}" />
  <echo message="speex library: ${speex}" />
  <echo message="Install directory ${native_install_dir}" />
  <echo message="arch: ${arch}" />
  -->

  <target name="init-native" description="Initialize native stuff">
    <mkdir dir="${obj}" />
  </target>

  <!-- compile screencapture library -->
  <target name="screencapture" description="Build screencapture shared library"
    depends="init-native">
    <cc outtype="shared" name="gcc" outfile="${native_install_dir}/screencapture" objdir="${obj}">
      <!-- common compiler flags -->
      <compilerarg value="-std=c99" />
      <compilerarg value="-D_XOPEN_SOURCE=0x600" />
      <compilerarg value="-Wall" />
      <compilerarg value="-Wextra" />
      <compilerarg value="-O3" />

      <!-- Linux specific flags -->
      <compilerarg value="-m32" if="cross_32" unless="is.running.macos" />
      <compilerarg value="-m64" if="cross_64" unless="is.running.macos" />
      <compilerarg value="-I${system.JAVA_HOME}/include" if="is.running.linux" />
      <compilerarg value="-I${system.JAVA_HOME}/include/linux" if="is.running.linux" />

      <linkerarg value="-m32" if="cross_32" unless="is.running.macos" />
      <linkerarg value="-m64" if="cross_64" unless="is.running.macos" />
      <linkerarg value="-lX11" location="end" if="is.running.linux" />

      <!-- Mac OS X specific flags -->
      <compilerarg value="-arch" if="is.running.macos" />
      <compilerarg value="x86_64" if="is.running.macos" />
      <compilerarg value="-arch" if="is.running.macos" />
      <compilerarg value="i386" if="is.running.macos" />
      <compilerarg value="-arch" if="is.running.macos" />
      <compilerarg value="ppc" if="is.running.macos" />
      <compilerarg value="-I/System/Library/Frameworks/ApplicationServices.framework/Headers" if="is.running.macos" />
      <compilerarg value="-I/System/Library/Frameworks/JavaVM.framework/Headers" if="is.running.macos" />
      
      <linkerarg value="-o" location="end" if="is.running.macos" />
      <linkerarg value="libscreencapture.jnilib" location="end" if="is.running.macos" />
      <linkerarg value="-arch" if="is.running.macos" />
      <linkerarg value="x86_64" if="is.running.macos" />
      <linkerarg value="-arch" if="is.running.macos" />
      <linkerarg value="i386" if="is.running.macos" />
      <linkerarg value="-arch" if="is.running.macos" />
      <linkerarg value="ppc" if="is.running.macos" />
      <linkerarg value="-framework" if="is.running.macos" />
      <linkerarg value="ApplicationServices" if="is.running.macos" />
      
      <!-- Windows specific flags -->
      <compilerarg value="-I${system.JAVA_HOME}/include" if="is.running.windows" />
      <compilerarg value="-I${system.JAVA_HOME}/include/win32" if="is.running.windows" />

      <linkerarg value="-lgdi32" location="end" if="is.running.windows" />
      <linkerarg value="-oscreencapture.dll" if="is.running.windows" />
      <linkerarg value="-Wl,--kill-at" if="is.running.windows" />

      <fileset dir="${src}/native/screencapture" includes="*.c"/>
    </cc>
  </target>

  <!-- compile jawtrenderer library -->
  <target name="jawtrenderer" description="Build jawtrenderer shared library" depends="init-native,jawtrenderer-windows"
    unless="is.running.windows">
    <cc outtype="shared" name="gcc" outfile="${native_install_dir}/jawtrenderer" objdir="${obj}">
      <!-- common compiler flags -->
      <compilerarg value="-std=c99" />
      <compilerarg value="-Wall" />
      <compilerarg value="-O2" />
      
      <linkerarg value="-L${system.JAVA_HOME}/jre/lib/amd64" />
      <linkerarg value="-L${system.JAVA_HOME}/jre/lib/x86" />
      <linkerarg value="-ljawt" location="end" />
      
      <!-- Linux specific flags -->
      <compilerarg value="-m32" if="cross_32" unless="is.running.macos" />
      <compilerarg value="-m64" if="cross_64" unless="is.running.macos" />
      <compilerarg value="-I${system.JAVA_HOME}/include" if="is.running.linux" />
      <compilerarg value="-I${system.JAVA_HOME}/include/linux" if="is.running.linux" />

      <linkerarg value="-m32" if="cross_32" unless="is.running.macos" />
      <linkerarg value="-m64" if="cross_64" unless="is.running.macos" />
      <linkerarg value="-lXv" location="end" if="is.running.linux" />
      <linkerarg value="-lX11" location="end" if="is.running.linux" />
      
      <fileset dir="${src}/native/jawtrenderer" includes="net*.c JAWTRenderer_Linux.c" if="is.running.linux"/>
      
      <!-- Mac OS X specific flags -->
      <compilerarg value="-arch" if="is.running.macos" />
      <compilerarg value="x86_64" if="is.running.macos" />
      <compilerarg value="-arch" if="is.running.macos" />
      <compilerarg value="i386" if="is.running.macos" />
      <compilerarg value="-arch" if="is.running.macos" />
      <compilerarg value="ppc" if="is.running.macos" />
      <compilerarg value="-I/System/Library/Frameworks/JavaVM.framework/Headers" if="is.running.macos" />

      <linkerarg value="-o" location="end" if="is.running.macos" />
      <linkerarg value="libjawtrenderer.jnilib" location="end" if="is.running.macos" />
      <linkerarg value="-arch" if="is.running.macos" />
      <linkerarg value="x86_64" if="is.running.macos" />
      <linkerarg value="-arch" if="is.running.macos" />
      <linkerarg value="i386" if="is.running.macos" />
      <linkerarg value="-arch" if="is.running.macos" />
      <linkerarg value="ppc" if="is.running.macos" />
      <linkerarg value="-framework" if="is.running.macos" />
      <linkerarg value="OpenGL" if="is.running.macos" />
      <linkerarg value="-framework" if="is.running.macos" />
      <linkerarg value="Foundation" if="is.running.macos" />
      <linkerarg value="-framework" if="is.running.macos" />
      <linkerarg value="AppKit" if="is.running.macos" />
      <linkerarg value="-L/System/Library/Frameworks/JavaVM.framework/Libraries/" if="is.running.macos" />
      
      <fileset dir="${src}/native/jawtrenderer" includes="net*.c JAWTRenderer_MacOSX.m" if="is.running.macos" />

    </cc>
  </target>

  <!-- compile jawtrenderer library for Windows -->
  <target name="jawtrenderer-windows" description="Build jawtrenderer shared library for Windows" depends="init-native"
    if="is.running.windows">
    <cc outtype="shared" name="msvc" outfile="${native_install_dir}/jawtrenderer" objdir="${obj}">
      <compilerarg value="/O2" />
      <compilerarg value="/MT" location="end" />
      <compilerarg value="/IC:\Program Files\Microsoft DirectX SDK (February 2010)\Include" />
      <compilerarg value="/IC:\Program Files (x86)\Microsoft DirectX SDK (February 2010)\Include" />
      <compilerarg value="-I${system.JAVA_HOME}/include" />
      <compilerarg value="-I${system.JAVA_HOME}/include/win32" />

      <!-- <linkerarg value="/LD" /> -->
      <linkerarg value="/LIBPATH:C:\Program Files\Microsoft DirectX SDK (February 2010)\lib\x86" />
      <linkerarg value="/LIBPATH:C:\Program Files (x86)\Microsoft DirectX SDK (February 2010)\lib\x64" />
      <linkerarg value="/LIBPATH:${system.JAVA_HOME}\\lib" />
      <linkerarg value="d3d9.lib" location="end" />
      <linkerarg value="user32.lib" location="end" />
      <linkerarg value="jawt.lib" location="end" />

      <fileset dir="${src}/native/jawtrenderer" includes="net*.c JAWTRenderer_Windows.cpp windows/*.cpp windows/*.c"/>
    </cc>
  </target>

  <!-- compile ffmpeg library -->
  <target name="ffmpeg" description="Build ffmpeg shared library" depends="init-native">

    <fail message="ffmpeg repository not set!" unless="ffmpeg" />
    <fail message="x264 repository not set!" unless="x264" />
    <fail message="lame repository not set!" unless="lame" />

    <cc outtype="shared" name="gcc" outfile="${native_install_dir}/ffmpeg" objdir="${obj}">
      <!-- common compiler flags -->
      <compilerarg value="-std=c99" />
      <compilerarg value="-Wall" />
      <compilerarg value="-O2" />
      <compilerarg value="-I${ffmpeg}" />
      <compilerarg value="-DJNI_IMPLEMENTATION" />

      <linkerarg value="-L${ffmpeg}/libavformat" />
      <linkerarg value="-L${ffmpeg}/libavcodec" />
      <linkerarg value="-L${ffmpeg}/libavutil" />
      <linkerarg value="-L${ffmpeg}/libswscale" />
      <linkerarg value="-L${x264}" />
      <linkerarg value="-L${lame}/libmp3lame/.libs" />
      <!-- static libraries MUST be at the end otherwise
      they will not be added to shared library
      -->
      <linkerarg value="-lavformat" location="end" /> 
      <linkerarg value="-lavcodec" location="end" />
      <linkerarg value="-lavutil" location="end" />
      <linkerarg value="-lswscale" location="end" />
      <linkerarg value="-lx264" location="end" />
      <linkerarg value="-lmp3lame" location="end" />

      <!-- Linux specific flags -->
      <compilerarg value="-m32" if="cross_32" unless="is.running.macos" />
      <compilerarg value="-m64" if="cross_64" unless="is.running.macos" />
      <compilerarg value="-I${system.JAVA_HOME}/include" if="is.running.linux" />
      <compilerarg value="-I${system.JAVA_HOME}/include/linux" if="is.running.linux" />

      <linkerarg value="-m32" if="cross_32" unless="is.running.macos" />
      <linkerarg value="-m64" if="cross_64" unless="is.running.macos" />
      <linkerarg value="-Wl,-Bsymbolic" if="is.running.linux" />

      <!-- Mac OS X specific flags -->
      <compilerarg value="-arch" if="is.running.macos" />
      <compilerarg value="x86_64" if="is.running.macos" />
      <compilerarg value="-arch" if="is.running.macos" />
      <compilerarg value="i386" if="is.running.macos" />
      <compilerarg value="-arch" if="is.running.macos" />
      <compilerarg value="ppc" if="is.running.macos" />
      <compilerarg value="-I/System/Library/Frameworks/JavaVM.framework/Headers" if="is.running.macos" />

      <!-- ffmpeg/x264 libraries cannot be built as universal binaries
           so you have to setup and compile ffmpeg/x264 for each architecture separately.
           Run this ant script with:
           -Darch=32 (rename libffmpeg.dyld to libffmpeg.dyld.32)
           -Darch=64 (rename libffmpeg.dyld to libffmpeg.dyld.64)
           -Darch=ppc (rename libffmpeg.dyld to libffmpeg.dyld.ppc)

           Finally create the universal binary with:
           lipo -create libffmpeg.dyld.32 libffmpeg.dyld.64 libffmpeg.dyld.ppc -output libffmpeg.jnilib
      -->
      <linkerarg value="-o" location="end" if="is.running.macos" />
      <linkerarg value="libffmpeg.jnilib" location="end" if="is.running.macos" />
      <linkerarg value="-arch" if="cross_32" unless="is.running.linux" />
      <linkerarg value="-i386" if="cross_32" unless="is.running.linux" />
      <linkerarg value="-arch" if="cross_64" unless="is.running.linux" />
      <linkerarg value="x86_64" if="cross_64" unless="is.running.linux" />
      <linkerarg value="-arch" if="cross_ppc" unless="is.running.linux" />
      <linkerarg value="ppc" if="cross_ppc" unless="is.running.linux" />
      <linkerarg value="-dynamiclib" if="is.running.macos" />
      <linkerarg value="-Wl,-read_only_relocs,suppress" if="is.running.macos" />
      
      <!-- Windows specific flags -->
      <compilerarg value="-I${system.JAVA_HOME}/include" if="is.running.windows" />
      <compilerarg value="-I${system.JAVA_HOME}/include/win32" if="is.running.windows" />
      
      <linkerarg value="-offmpeg.dll" if="is.running.windows" />
      <linkerarg value="-Wl,--kill-at" if="is.running.windows" />

      <fileset dir="${src}/native/ffmpeg" includes="*.c"/>
    </cc>
  </target>

  <!-- compile jportaudio library -->
  <target name="portaudio" description="Build jportaudio shared library" depends="init-native">

    <fail message="portaudio repository not set!" unless="portaudio" />
    <fail message="speex repository not set!" unless="speex" />

    <cc outtype="shared" name="gcc" outfile="${native_install_dir}/jportaudio" objdir="${obj}">
      <!-- common compiler flags -->
      <compilerarg value="-std=c99" />
      <compilerarg value="-Wall" />
      <compilerarg value="-O2" />
      <compilerarg value="-I${portaudio}/include" />
      <compilerarg value="-I${speex}/include" />
      <compilerarg value="-DJNI_IMPLEMENTATION" />

      <linkerarg value="-L${speex}/libspeex/.libs" />
      <linkerarg value="-L${portaudio}/lib/.libs" />

      <!-- Linux specific flags -->
      <compilerarg value="-m32" if="cross_32" unless="is.running.macos" />
      <compilerarg value="-m64" if="cross_64" unless="is.running.macos" />
      <compilerarg value="-I${system.JAVA_HOME}/include" if="is.running.linux" />
      <compilerarg value="-I${system.JAVA_HOME}/include/linux" if="is.running.linux" />

      <linkerarg value="-m32" if="cross_32" unless="is.running.macos" />
      <linkerarg value="-m64" if="cross_64" unless="is.running.macos" />
      
      <!-- static libraries MUST be at the end otherwise
      they will not be added to shared library
      -->
      <linkerarg value="-Wl,-Bstatic" location="end" if="is.running.linux" />
      <linkerarg value="-lportaudio" location="end" if="is.running.linux" />
      <linkerarg value="-lspeexdsp" location="end" if="is.running.linux" />
      <linkerarg value="-Wl,-Bdynamic" location="end" if="is.running.linux" />
      <linkerarg value="-lasound" location="end" if="is.running.linux" />
      <linkerarg value="-lm" location="end" if="is.running.linux" />
      <linkerarg value="-lpthread" location="end" if="is.running.linux" />

      <!-- Mac OS X specific flags -->
      <compilerarg value="-arch"  if="is.running.macos" />
      <compilerarg value="x86_64" if="is.running.macos" />
      <compilerarg value="-arch" if="is.running.macos" />
      <compilerarg value="i386" if="is.running.macos" />
      <compilerarg value="-arch" if="is.running.macos" />
      <compilerarg value="ppc" if="is.running.macos" />
      <compilerarg value="-I/System/Library/Frameworks/JavaVM.framework/Headers" if="is.running.macos" />
      
      <linkerarg value="-o" location="end" if="is.running.macos" />
      <linkerarg value="libjportaudio.jnilib" location="end" if="is.running.macos" />
      <linkerarg value="-dynamiclib" if="is.running.macos" />
      <linkerarg value="-arch" if="is.running.macos" />
      <linkerarg value="x86_64" if="is.running.macos" />
      <linkerarg value="-arch" if="is.running.macos" />
      <linkerarg value="i386" if="is.running.macos" />
      <linkerarg value="-arch" if="is.running.macos" />
      <linkerarg value="ppc" if="is.running.macos" />
      <linkerarg value="-framework" location="end" if="is.running.macos" />
      <linkerarg value="AudioToolbox" location="end" if="is.running.macos" />
      <linkerarg value="-framework" location="end" if="is.running.macos" />
      <linkerarg value="AudioUnit" location="end" if="is.running.macos" />
      <linkerarg value="-framework" location="end" if="is.running.macos" />
      <linkerarg value="CoreAudio" location="end" if="is.running.macos" />
      <linkerarg value="-framework" location="end" if="is.running.macos" />
      <linkerarg value="Carbon" location="end" if="is.running.macos" />
      <linkerarg value="-lportaudio" location="end" if="is.running.macos" />
      <linkerarg value="-lspeexdsp" location="end" if="is.running.macos" />
      <linkerarg value="-dynamic" location="end" if="is.running.macos" />
      <linkerarg value="-lpthread" location="end" if="is.running.macos" />
      
      <!-- Windows specific flags -->
      <compilerarg value="-I${system.JAVA_HOME}/include" if="is.running.windows" />
      <compilerarg value="-I${system.JAVA_HOME}/include/win32" if="is.running.windows" />

      <linkerarg value="-L${pthread}" if="is.running.windows" />
      <linkerarg value="-ojportaudio.dll" if="is.running.windows" />
      <linkerarg value="-Wl,--kill-at" if="is.running.windows" />
      <linkerarg value="-Wl,-Bstatic" location="end" if="is.running.windows" />
      <linkerarg value="-lportaudio" location="end" if="is.running.windows" />
      <linkerarg value="-lspeexdsp" location="end" if="is.running.windows" />
      <linkerarg value="-lwinmm" location="end" if="is.running.windows" />
      <linkerarg value="-lm" location="end" if="is.running.windows" />
      <linkerarg value="-lstdc++" location="end" if="is.running.windows" />
      <linkerarg value="-lole32" location="end" if="is.running.windows" />
      <linkerarg value="-luuid" location="end" if="is.running.windows" />

      <fileset dir="${src}/native/portaudio" includes="*.c"/>
    </cc>
  </target>

  <!-- compile jspeex library -->
  <target name="speex" description="Build jspeex shared library" depends="init-native">

    <fail message="speex repository not set!" unless="speex" />

    <cc outtype="shared" name="gcc" outfile="${native_install_dir}/jspeex" objdir="${obj}">
      <!-- common compiler flags -->
      <compilerarg value="-std=c99" />
      <compilerarg value="-Wall" />
      <compilerarg value="-O2" />
      <compilerarg value="-I${speex}/include" />
      <compilerarg value="-DJNI_IMPLEMENTATION" />

      <linkerarg value="-L${speex}/libspeex/.libs" />

      <!-- Linux specific flags -->
      <compilerarg value="-m32" if="cross_32" unless="is.running.macos" />
      <compilerarg value="-m64" if="cross_64" unless="is.running.macos" />
      <compilerarg value="-I${system.JAVA_HOME}/include" if="is.running.linux" />
      <compilerarg value="-I${system.JAVA_HOME}/include/linux" if="is.running.linux" />

      <linkerarg value="-m32" if="cross_32" unless="is.running.macos" />
      <linkerarg value="-m64" if="cross_64" unless="is.running.macos" />

      <!-- static libraries MUST be at the end otherwise
      they will not be added to shared library
      -->
      <linkerarg value="-Wl,-Bstatic" location="end" if="is.running.linux" />
      <linkerarg value="-lspeex" location="end" if="is.running.linux" />
      <linkerarg value="-lspeexdsp" location="end" if="is.running.linux" />
      <linkerarg value="-Wl,-Bdynamic" location="end" if="is.running.linux" />
      <linkerarg value="-lm" location="end" if="is.running.linux" />

      <!-- Mac OS X specific flags -->
      <compilerarg value="-arch"  if="is.running.macos" />
      <compilerarg value="x86_64" if="is.running.macos" />
      <compilerarg value="-arch" if="is.running.macos" />
      <compilerarg value="i386" if="is.running.macos" />
      <compilerarg value="-arch" if="is.running.macos" />
      <compilerarg value="ppc" if="is.running.macos" />
      <compilerarg value="-I/System/Library/Frameworks/JavaVM.framework/Headers" if="is.running.macos" />

      <linkerarg value="-o" location="end" if="is.running.macos" />
      <linkerarg value="libjspeex.jnilib" location="end" if="is.running.macos" />
      <linkerarg value="-dynamiclib" if="is.running.macos" />
      <linkerarg value="-arch" if="is.running.macos" />
      <linkerarg value="x86_64" if="is.running.macos" />
      <linkerarg value="-arch" if="is.running.macos" />
      <linkerarg value="i386" if="is.running.macos" />
      <linkerarg value="-arch" if="is.running.macos" />
      <linkerarg value="ppc" if="is.running.macos" />
      <linkerarg value="-lspeex" location="end" if="is.running.macos" />
      <linkerarg value="-lspeexdsp" location="end" if="is.running.macos" />

      <!-- Windows specific flags -->
      <compilerarg value="-I${system.JAVA_HOME}/include" if="is.running.windows" />
      <compilerarg value="-I${system.JAVA_HOME}/include/win32" if="is.running.windows" />

      <linkerarg value="-ojspeex.dll" if="is.running.windows" />
      <linkerarg value="-Wl,--kill-at" if="is.running.windows" />
      <linkerarg value="-Wl,-Bstatic" location="end" if="is.running.windows" />
      <linkerarg value="-lspeex" location="end" if="is.running.windows" />
      <linkerarg value="-lspeexdsp" location="end" if="is.running.windows" />
      <linkerarg value="-Wl,-Bdynamic" location="end" if="is.running.windows" />
      <linkerarg value="-lm" location="end" if="is.running.windows" />

      <fileset dir="${src}/native/speex" includes="*.c"/>
    </cc>
  </target>

  <!-- compile hwaddressretriever library -->
  <target name="hwaddressretriever" description="Build hwaddressretriever shared library" depends="init-native,hwaddressretriever-windows"
    unless="is.running.windows">
    <cc outtype="shared" name="gcc" outfile="${native_install_dir}/hwaddressretriever" objdir="${obj}">
      <!-- common compiler flags -->
      <compilerarg value="-Wall" />
      <compilerarg value="-O2" />

      <fileset dir="${src}/native/hwaddressretriever" includes="net*.c HardwareAddressRetriever_unix.c" />

      <!-- Linux specific flags -->
      <compilerarg value="-m32" if="cross_32" unless="is.running.macos" />
      <compilerarg value="-m64" if="cross_64" unless="is.running.macos" />
      <compilerarg value="-I${system.JAVA_HOME}/include" if="is.running.linux" />
      <compilerarg value="-I${system.JAVA_HOME}/include/linux" if="is.running.linux" />

      <linkerarg value="-m32" if="cross_32" unless="is.running.macos" />
      <linkerarg value="-m64" if="cross_64" unless="is.running.macos" />

      <!-- Mac OS X specific flags -->
      <compilerarg value="-arch" if="is.running.macos" />
      <compilerarg value="x86_64" if="is.running.macos" />
      <compilerarg value="-arch" if="is.running.macos" />
      <compilerarg value="i386" if="is.running.macos" />
      <compilerarg value="-arch" if="is.running.macos" />
      <compilerarg value="ppc" if="is.running.macos" />
      <compilerarg value="-I/System/Library/Frameworks/JavaVM.framework/Headers" if="is.running.macos" />

      <linkerarg value="-o" location="end" if="is.running.macos" />
      <linkerarg value="libhwaddressretriever.jnilib" location="end" if="is.running.macos" />
      <linkerarg value="-arch" if="is.running.macos" />
      <linkerarg value="x86_64" if="is.running.macos" />
      <linkerarg value="-arch" if="is.running.macos" />
      <linkerarg value="i386" if="is.running.macos" />
      <linkerarg value="-arch" if="is.running.macos" />
      <linkerarg value="ppc" if="is.running.macos" />
    </cc>
  </target>

  <!-- compile hwaddressretrieverr library for Windows-->
  <target name="hwaddressretriever-windows" description="Build hwaddressretriever shared library for Windows" if="is.running.windows"
    depends="init-native">
    <cc outtype="shared" name="msvc" outfile="${native_install_dir}/hwaddressretriever" objdir="${obj}">
      <compilerarg value="/O2" />
      <compilerarg value="/MT" location="end" />
      <compilerarg value="-I${system.JAVA_HOME}/include" />
      <compilerarg value="-I${system.JAVA_HOME}/include/win32" />

      <linkerarg value="iphlpapi.lib" location="end" />

      <fileset dir="${src}/native/hwaddressretriever" includes="net*.c HardwareAddressRetriever_win.c" />
    </cc>
  </target>

  <!-- compile jvideo4linux2 library -->
  <target name="video4linux2" description="Build jvideo4linux2 shared library" if="is.running.linux"
    depends="init-native">
    <cc outtype="shared" name="gcc" outfile="${native_install_dir}/jvideo4linux2" objdir="${obj}">
      <compilerarg value="-std=c99" />
      <compilerarg value="-Wall" />
      <compilerarg value="-O2" />
      <compilerarg value="-I${system.JAVA_HOME}/include" />
      <compilerarg value="-I${system.JAVA_HOME}/include/linux" />
      <compilerarg value="-m32" if="cross_32" />
      <compilerarg value="-m64" if="cross_64" />

      <linkerarg value="-m32" if="cross_32" />
      <linkerarg value="-m64" if="cross_64" />

      <fileset dir="${src}/native/linux/video4linux2" includes="*.c"/>
    </cc>
  </target>

  <!-- compile galagonotification library -->
  <target name="galagonotification" description="Build galagonotification shared library" if="is.running.linux"
    depends="init-native">
    <cc outtype="shared" name="gcc" outfile="${native_install_dir}/galagonotification" objdir="${obj}">
      <compilerarg value="-std=c99" />
      <compilerarg value="-Wall" />
      <compilerarg value="-O2" />
      <compilerarg value="-I/usr/include/dbus-1.0" />
      <compilerarg value="-I/usr/lib/dbus-1.0/include" />
      <compilerarg value="-m32" if="cross_32" />
      <compilerarg value="-m64" if="cross_64" />
      <compilerarg value="-I${system.JAVA_HOME}/include" />
      <compilerarg value="-I${system.JAVA_HOME}/include/linux" />

      <linkerarg value="-m32" if="cross_32" />
      <linkerarg value="-m64" if="cross_64" />
      <linkerarg value="-ldbus-1" location="end" />

      <fileset dir="${src}/native/linux/galagonotification" includes="*.c"/>
    </cc>
  </target>

  <!-- compile LocalhostRetriever library -->
  <target name="localhostretriever" description="Build LocalhostRetriever shared library" if="is.running.windows"
    depends="init-native">
    <cc outtype="shared" name="msvc" outfile="${native_install_dir}/LocalhostRetriever" objdir="${obj}">
      <compilerarg value="/O2" />
      <compilerarg value="/MT" location="end" />
      <compilerarg value="-I${system.JAVA_HOME}/include" />
      <compilerarg value="-I${system.JAVA_HOME}/include/win32" />

      <linkerarg value="iphlpapi.lib" location="end" />

      <fileset dir="${src}/native/windows/LocalhostRetriever" includes="*.c"/>
    </cc>
  </target>

  <!-- compile jdirectshow library -->
  <target name="directshow" description="Build jdirectshow shared library" if="is.running.windows"
    depends="init-native">
    <cc outtype="shared" name="msvc" outfile="${native_install_dir}/jdirectshow" objdir="${obj}">
      <compilerarg value="/O2" />
      <compilerarg value="/W4" />
      <compilerarg value="/wd4996" />
      <compilerarg value="/EHsc" />
      <compilerarg value="/MT" location="end" />
      <compilerarg value="-I${system.JAVA_HOME}/include" />
      <compilerarg value="-I${system.JAVA_HOME}/include/win32" />

      <linkerarg value="ole32.lib" location="end" />
      <linkerarg value="oleaut32.lib" location="end" />
      <linkerarg value="user32.lib" location="end" />

      <fileset dir="${src}/native/windows/directshow" includes="*.cpp"/>
    </cc>
  </target>

  <!-- compile AEGetURLEventHandler library for Mac OS X (32-bit/64-bit/ppc) -->
  <target name="aegeturleventhandler" description="Build AEGetURLEventHandler shared library for Mac OS X" if="is.running.macos"
    depends="init-native">
    <cc outtype="shared" name="gcc" outfile="${native_install_dir}/AEGetURLEventHandler" objdir="${obj}">
      <compilerarg value="-Wall" />
      <compilerarg value="-O2" />
      <compilerarg value="-arch" />
      <compilerarg value="x86_64" />
      <compilerarg value="-arch" />
      <compilerarg value="i386" />
      <compilerarg value="-arch" />
      <compilerarg value="ppc" />
      <compilerarg value="-I/System/Library/Frameworks/JavaVM.framework/Headers" />

      <linkerarg value="-o" location="end" />
      <linkerarg value="libAEGetURLEventHandlerAgent.jnilib" location="end" />
      <linkerarg value="-arch" />
      <linkerarg value="x86_64" />
      <linkerarg value="-arch" />
      <linkerarg value="i386" />
      <linkerarg value="-arch" />
      <linkerarg value="ppc" />
      <linkerarg value="-framework" />
      <linkerarg value="Foundation" />

      <fileset dir="${src}/native/macosx/launcharghandler" includes="*.m"/>
    </cc>
  </target>

  <!-- compile sparkle library for Mac OS X (32-bit/64-bit/ppc) -->
  <target name="sparkle" description="Build sparkle shared library for Mac OS X" if="is.running.macos"
    depends="init-native">
    <cc outtype="shared" name="gcc" outfile="${native_install_dir}/sparkle_init" objdir="${obj}">
      <compilerarg value="-Wall" />
      <compilerarg value="-O2" />
      <compilerarg value="-arch" />
      <compilerarg value="x86_64" />
      <compilerarg value="-arch" />
      <compilerarg value="i386" />
      <compilerarg value="-arch" />
      <compilerarg value="ppc" />
      <compilerarg value="-I/System/Library/Frameworks/JavaVM.framework/Headers" />

      <linkerarg value="-arch" />
      <linkerarg value="x86_64" />
      <linkerarg value="-arch" />
      <linkerarg value="i386" />
      <linkerarg value="-arch" />
      <linkerarg value="ppc" />
      <linkerarg value="-framework" />
      <linkerarg value="AppKit" />
      <linkerarg value="-framework" />
      <linkerarg value="Foundation" />
      <linkerarg value="-framework" />
      <linkerarg value="Sparkle" />

      <fileset dir="${src}/native/macosx/sparkle" includes="*.m"/>
    </cc>
  </target>

  <!-- compile jquicktime library for Mac OS X (32-bit/64-bit/ppc) -->
  <target name="quicktime" description="Build jquicktime shared library for Mac OS X" if="is.running.macos"
    depends="init-native">
    <cc outtype="shared" name="gcc" outfile="${native_install_dir}/jquicktime" objdir="${obj}">
      <compilerarg value="-Wall" />
      <compilerarg value="-O2" />
      <compilerarg value="-arch" />
      <compilerarg value="x86_64" />
      <compilerarg value="-arch" />
      <compilerarg value="i386" />
      <compilerarg value="-arch" />
      <compilerarg value="ppc" />
      <compilerarg value="-I/System/Library/Frameworks/JavaVM.framework/Headers" />

      <linkerarg value="-o" location="end" />
      <linkerarg value="libjquicktime.jnilib" location="end" />
      <linkerarg value="-arch" />
      <linkerarg value="x86_64" />
      <linkerarg value="-arch" />
      <linkerarg value="i386" />
      <linkerarg value="-arch" />
      <linkerarg value="ppc" />
      <linkerarg value="-framework" />
      <linkerarg value="QTKit" />
      <linkerarg value="-framework" />
      <linkerarg value="Quartz" />
      <linkerarg value="-framework" />
      <linkerarg value="Foundation" />

      <fileset dir="${src}/native/macosx/quicktime" includes="*.c *.m"/>
    </cc>
  </target>

  <!-- Cleanup object file and shared libraries -->
  <target name="clean-native" description="Clean all object file and libraries.">
    <delete failonerror="false" includeemptydirs="true">
        <fileset dir="${obj}" />
        <fileset dir="${src}/native/" includes="*.dll *.so *.dyld *.jnilib *.manifest *.o *.obj *.lib *.exp history.xml" />
        <fileset dir="${sc.basedir}" includes="**.dll *.so *.dyld *.jnilib *.manifest *.o *.obj *.lib *.exp history.xml" />
    </delete>
  </target>

  <!-- Help, print useful targets -->
  <target name="help-native">
    <echo message="Targets available:" />
    <echo message="'ant screencapture' to compile screencapture shared library" />
    <echo message="'ant jawtrenderer' to compile jawtrenderer shared library" />
    <echo message="'ant ffmpeg' to compile ffmpeg shared library" />
    <echo message="'ant portaudio' to compile jportaudio shared library" />
    <echo message="'ant speex' to compile jspeex shared library" />
    <echo message="'ant hwaddressretriever' to compile hwaddressretriever shared library" />
    <echo message="'ant video4linux2 (Linux only)' to compile jvideo4linux2 shared library" />
    <echo message="'ant galagonotification (Linux only)' to compile galagonotification shared library" />
    <echo message="'ant localhostretriever (Windows only)' to compile LocalhostRetriever shared library" />
    <echo message="'ant directshow (Windows only)' to compile jdirectshow shared library" />
    <echo message="'ant aegeturleventhandler (Mac OS X only)' to compile AEGetURLEventHandler shared library" />
    <echo message="'ant sparkle (Mac OS X only)' to compile sparkle shared library" />
    <echo message="'ant quicktime (Mac OS X only)' to compile jquicktime shared library" />
    <echo message="" />
    <echo message="Options:" />
    <echo message="-Darch: cross-compile for 32-bit (-Darch=32), 64-bit (-Darch=64) or ppc (-Darch=ppc, Mac OS X only) targets. Windows users have to use gcc >= 4.5." />
    <echo message="-Dx264: path to x264 directory (ffmpeg JNI compilation)." />
    <echo message="-Dlame: path to lame directory (ffmpeg JNI compilation)." />
    <echo message="-Dffmpeg: path to ffmpeg directory (ffmpeg JNI compilation)." />
    <echo message="-Dportaudio path to portaudio directory (jportaudio JNI compilation)." />
    <echo message="-Dspeex: path to speex directory (jportaudio/jspeex JNI compilation)." />
    <echo message="" />
    <echo message="Please note that external libraries such as ffmpeg, x264, lame, portaudio and speex have to be compiled" />
    <echo message="(follow READMEs in relevant directory) before trying to compile libffmpeg and libjportaudio"  />
    <echo message="When compiling libffmpeg you have to tell ant script the directory of ffmpeg and x264 with"  />
    <echo message="-Dffmpeg=/path/to/ffmpeg and -Dx264=/path/to/x264 -Dlame=/path/to/lame"  />
    <echo message="When compiling libjportaudio you have to tell ant script the directory of portaudio and speex with"  />
    <echo message="-Dportaudio=/path/to/portaudio and -Dspeex=/path/to/speex"  />
  </target>
</project>