-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSConstruct
1609 lines (1391 loc) · 60.3 KB
/
SConstruct
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
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
### SCons build recipe for the GPSD project
# Important targets:
#
# build - build the software (default)
# dist - make distribution tarball
# install - install programs, libraries, and manual pages
# uninstall - undo an install
#
# check - run regression and unit tests.
# audit - run code-auditing tools
# testbuild - test-build the code from a tarball
# release - ship a release
#
# Setting the DESTDIR environment variable will prefix the install destinations
# without changing the --prefix prefix.
# Unfinished items:
# * Out-of-directory builds: see http://www.scons.org/wiki/UsingBuildDir
# Release identification begins here
gpsd_version = "3.4~dev"
# library version
libgps_version_current = 20
libgps_version_revision = 0
libgps_version_age = 0
# Release identification ends here
# Hosting information (mainly used for templating web pages) begins here
# Each variable foo has a corresponding @FOO@ expanded in .in files.
# There are no project-dependent URLs or references to the hosting site
# anywhere else in the distribution; preserve this property!
sitename = "Savannah"
sitesearch = "catb.org"
website = "http://catb.org/gpsd"
mainpage = "https://savannah.nongnu.org/projects/gpsd/"
webupload = "login.ibiblio.org:/public/html/catb/gpsd"
scpupload = "dl.sv.nongnu.org:/releases/gpsd/"
mailman = "http://lists.nongnu.org/mailman/listinfo/"
admin = "https://savannah.nongnu.org/project/admin/?group=gpsd"
download = "http://download-mirror.savannah.gnu.org/releases/gpsd/"
bugtracker = "https://savannah.nongnu.org/bugs/?group=gpsd"
browserepo = "http://git.savannah.gnu.org/cgit/gpsd.git"
clonerepo = "https://savannah.nongnu.org/git/?group=gpsd"
gitrepo = "git://git.savannah.nongnu.org/gpsd.git"
webform = "https://www.mainframe.cx/cgi-bin/gps_report.cgi"
formserver = "[email protected]"
devmail = "[email protected]"
# Hosting information ends here
EnsureSConsVersion(2,0,1)
import copy, os, sys, glob, re, platform, time
from distutils import sysconfig
from distutils.util import get_platform
import SCons
# replacement for functions from the commands module, which is deprecated.
from subprocess import PIPE, STDOUT, Popen
def _getstatusoutput(cmd, input=None, cwd=None, env=None):
pipe = Popen(cmd, shell=True, cwd=cwd, env=env, stdout=PIPE, stderr=STDOUT)
(output, errout) = pipe.communicate(input=input)
status = pipe.returncode
return (status, output)
def _getoutput(cmd, input=None, cwd=None, env=None):
return _getstatusoutput(cmd, input, cwd, env)[1]
#
# Build-control options
#
# Start by reading configuration variables from the cache
opts = Variables('.scons-option-cache')
systemd = os.path.exists("/usr/share/systemd/system")
# Set distribution-specific defaults here
imloads = True
if sys.platform.startswith('linux'):
(distro, version, cutename) = platform.linux_distribution()
if distro == 'Fedora':
if int(version) >= 13:
# See https://fedoraproject.org/wiki/Features/ChangeInImplicitDSOLinking
imloads = False
elif os.path.exists("/etc/arch-release"):
imloads = False
boolopts = (
# GPS protocols
("nmea", True, "NMEA support"),
("ashtech", True, "Ashtech support"),
("earthmate", True, "DeLorme EarthMate Zodiac support"),
("evermore", True, "EverMore binary support"),
("fv18", True, "San Jose Navigation FV-18 support"),
("garmin", True, "Garmin kernel driver support"),
("garmintxt", True, "Garmin Simple Text support"),
("geostar", True, "Geostar Protocol support"),
("itrax", True, "iTrax hardware support"),
("mtk3301", True, "MTK-3301 support"),
("navcom", True, "Navcom support"),
("oncore", True, "Motorola OnCore chipset support"),
("sirf", True, "SiRF chipset support"),
("superstar2", True, "Novatel SuperStarII chipset support"),
("tnt", True, "True North Technologies support"),
("tripmate", True, "DeLorme TripMate support"),
("tsip", True, "Trimble TSIP support"),
("ubx", True, "UBX Protocol support"),
("fury", True, "Jackson Labs Fury and Firefly support"),
# Non-GPS protocols
("aivdm", True, "AIVDM support"),
("gpsclock", True, "GPSClock support"),
("ntrip", True, "NTRIP support"),
("oceanserver", True, "OceanServer support"),
("rtcm104v2", True, "rtcm104v2 support"),
("rtcm104v3", True, "rtcm104v3 support"),
# Time service
("ntpshm", True, "NTP time hinting support"),
("pps", True, "PPS time syncing support"),
# Export methods
("socket_export", True, "data export over sockets"),
("dbus_export", False, "enable DBUS export support"),
("shm_export", True, "export via shared memory"),
# Communication
('usb', True, "libusb support for USB devices"),
("bluez", True, "BlueZ support for Bluetooth devices"),
("ipv6", True, "build IPv6 support"),
("netfeed", True, "build support for handling TCP/IP data sources"),
("passthrough", True, "build support for passing through JSON"),
# Other daemon options
("force_global", False, "force daemon to listen on all addressses"),
("timing", False, "latency timing support"),
("control_socket",True, "control socket for hotplug notifications"),
("systemd", systemd, "systemd socket activation"),
# Client-side options
("clientdebug", True, "client debugging support"),
("oldstyle", True, "oldstyle (pre-JSON) protocol support"),
("libgpsmm", True, "build C++ bindings"),
("libQgpsmm", True, "build QT bindings"),
("reconfigure", True, "allow gpsd to change device settings"),
("controlsend", True, "allow gpsctl/gpsmon to change device settings"),
("cheapfloats", True, "float ops are cheap, compute error estimates"),
("squelch", False, "squelch gpsd_report/gpsd_hexdump to save cpu"),
("ncurses", True, "build with ncurses"),
# Build control
("shared", True, "build shared libraries, not static"),
("implicit_link", imloads,"implicit linkage is supported in shared libs"),
("python", True, "build Python support and modules."),
("debug", False, "include debug information in build"),
("profiling", False, "build with profiling enabled"),
("strip", True, "build with stripping of binaries enabled"),
)
for (name, default, help) in boolopts:
opts.Add(BoolVariable(name, help, default))
nonboolopts = (
("gpsd_user", "nobody", "privilege revocation user",),
("gpsd_group", "(undefined)", "privilege revocation group"),
("prefix", "/usr/local", "installation directory prefix"),
("limited_max_clients", 0, "maximum allowed clients"),
("limited_max_devices", 0, "maximum allowed devices"),
("fixed_port_speed", 0, "fixed serial port speed"),
("fixed_stop_bits", 0, "fixed serial port stop bits"),
("pps_pin", "DCD", "pin to expect PPS pulses on"),
("target", "", "cross-development target"),
("sysroot", "", "cross-development system root"),
)
for (name, default, help) in nonboolopts:
opts.Add(name, help, default)
pathopts = (
("sysconfdir", "etc", "system configuration directory"),
("bindir", "bin", "application binaries directory"),
("includedir", "include", "header file directory"),
("libdir", "lib", "system libraries"),
("sbindir", "sbin", "system binaries directory"),
("mandir", "share/man", "manual pages directory"),
("docdir", "share/doc", "documents directory"),
("pkgconfig", "$libdir/pkgconfig", "pkgconfig file directory"),
)
for (name, default, help) in pathopts:
opts.Add(PathVariable(name, help, default, PathVariable.PathAccept))
#
# Environment creation
#
import_env = (
"DISPLAY", # Required for dia to run under scons
"GROUPS", # Required by gpg
"HOME", # Required by gpg
"LOGNAME", # LOGNAME is required for the flocktest production.
'PATH', # Required for ccache and Coverity scan-build
'PKG_CONFIG_PATH', # Set .pc file directory in a crossbuild
'STAGING_PREFIX', # Required by the OpenWRT build.
)
envs = {}
for var in import_env:
if var in os.environ:
envs[var] = os.environ[var]
env = Environment(tools=["default", "tar", "textfile"], options=opts, ENV=envs)
opts.Save('.scons-option-cache', env)
env.SConsignFile(".sconsign.dblite")
for (name, default, help) in pathopts:
env[name] = env.subst(env[name])
env['VERSION'] = gpsd_version
env['PYTHON'] = sys.executable
# Set defaults from environment. Note that scons doesn't cope well
# with multi-word CPPFLAGS/LDFLAGS/SHLINKFLAGS values; you'll have to
# explicitly quote them or (better yet) use the "=" form of GNU option
# settings.
env['STRIP'] = "strip"
env['PKG_CONFIG'] = "pkg-config"
env['CHRPATH'] = 'chrpath'
for i in ["AR", "ARFLAGS", "CCFLAGS", "CFLAGS", "CC", "CXX", "CXXFLAGS", "STRIP", "PKG_CONFIG", "CHRPATH", "LD", "TAR"]:
if os.environ.has_key(i):
j = i
if i == "LD":
i = "SHLINK"
if i == "CFLAGS" or i == "CCFLAGS":
env.Replace(**{j: Split(os.getenv(i))})
else:
env.Replace(**{j: os.getenv(i)})
for flags in ["LDFLAGS", "LINKFLAGS", "SHLINKFLAGS", "CPPFLAGS"]:
if os.environ.has_key(flags):
env.MergeFlags({flags : [os.getenv(flags)]})
# Placeholder so we can kluge together something like VPATH builds.
# $SRCDIR replaces occurrences for $(srcdir) in the autotools build.
env['SRCDIR'] = '.'
def announce(msg):
if not env.GetOption("silent"):
print msg
# GCC isn't always named gcc, alas.
if env['CC'] == 'gcc' or (sys.platform.startswith('freebsd') and env['CC'] == 'cc'):
# Enable all GCC warnings except uninitialized and
# missing-field-initializers, which we can't help triggering because
# of the way some of the JSON-parsing code is generated.
# Also not including -Wcast-qual and -Wimplicit-function-declaration,
# because we can't seem to keep scons from passing it to g++.
env.Append(CFLAGS=Split('''-Wextra -Wall -Wno-uninitialized
-Wno-missing-field-initializers -Wcast-align
-Wmissing-declarations -Wmissing-prototypes
-Wstrict-prototypes -Wpointer-arith -Wreturn-type
-D_GNU_SOURCE'''))
# DESTDIR environment variable means user wants to prefix the installation root.
DESTDIR = os.environ.get('DESTDIR', '')
def installdir(dir, add_destdir=True):
# use os.path.join to handle absolute paths properly.
wrapped = os.path.join(env['prefix'], env[dir])
if add_destdir:
wrapped = os.path.normpath(DESTDIR + os.path.sep + wrapped)
wrapped.replace("/usr/etc", "/etc")
return wrapped
# Honor the specified installation prefix in link paths.
env.Prepend(LIBPATH=[installdir('libdir')])
if env["shared"]:
env.Prepend(RPATH=[installdir('libdir')])
# Give deheader a way to set compiler flags
if 'MORECFLAGS' in os.environ:
env.Append(CFLAGS=Split(os.environ['MORECFLAGS']))
# Don't change CCFLAGS if already set by environment.
if not 'CCFLAGS' in os.environ:
# Should we build with profiling?
if env['profiling']:
env.Append(CCFLAGS=['-pg'])
env.Append(LDFLAGS=['-pg'])
# Should we build with debug symbols?
if env['debug']:
env.Append(CCFLAGS=['-g'])
env.Append(CCFLAGS=['-O0'])
else:
env.Append(CCFLAGS=['-O2'])
# Get a slight speedup by not doing automatic RCS and SCCS fetches.
env.SourceCode('.', None)
## Cross-development
devenv = (("ADDR2LINE", "addr2line"),
("AR","ar"),
("AS","as"),
("CHRPATH", "chrpath"),
("CXX","c++"),
("CXXFILT","c++filt"),
("CPP","cpp"),
("GXX","g++"),
("CC","gcc"),
("GCCBUG","gccbug"),
("GCOV","gcov"),
("GPROF","gprof"),
("LD", "ld"),
("NM", "nm"),
("OBJCOPY","objcopy"),
("OBJDUMP","objdump"),
("RANLIB", "ranlib"),
("READELF","readelf"),
("SIZE", "size"),
("STRINGS", "strings"),
("STRIP", "strip"))
if env['target']:
for (name, toolname) in devenv:
env[name] = env['target'] + '-' + toolname
if env['sysroot']:
env.MergeFlags({"CFLAGS": ["--sysroot=%s" % env['sysroot']]})
env.MergeFlags({"LINKFLAGS": ["--sysroot=%s" % env['sysroot']]})
## Build help
Help("""Arguments may be a mixture of switches and targets in any order.
Switches apply to the entire build regardless of where they are in the order.
Important switches include:
prefix=/usr probably what you want for production tools
Options are cached in a file named .scons-option-cache and persist to later
invocations. The file is editable. Delete it to start fresh. Current option
values can be listed with 'scons -h'.
""" + opts.GenerateHelpText(env, sort=cmp))
if "help" in ARGLIST:
Return()
## Configuration
def CheckPKG(context, name):
context.Message( 'Checking for %s... ' % name )
ret = context.TryAction('%s --exists \'%s\'' % (env['PKG_CONFIG'], name))[0]
context.Result( ret )
return ret
def CheckExecutable(context, testprogram, check_for):
context.Message( 'Checking for %s... ' %(check_for,))
ret = context.TryAction(testprogram)[0]
context.Result( ret )
return ret
# Stylesheet URLs for making HTML and man pages from DocBook XML.
docbook_url_stem = 'http://docbook.sourceforge.net/release/xsl/current/'
docbook_man_uri = docbook_url_stem + 'manpages/docbook.xsl'
docbook_html_uri = docbook_url_stem + 'html/docbook.xsl'
def CheckXsltproc(context):
context.Message('Checking that xsltproc can make man pages... ')
with open("xmltest.xml", "w") as ofp:
ofp.write('''
<refentry id="foo.1">
<refmeta>
<refentrytitle>foo</refentrytitle>
<manvolnum>1</manvolnum>
<refmiscinfo class='date'>9 Aug 2004</refmiscinfo>
</refmeta>
<refnamediv id='name'>
<refname>foo</refname>
<refpurpose>check man page generation from docbook source</refpurpose>
</refnamediv>
</refentry>
''')
probe = "xsltproc --nonet --noout '%s' xmltest.xml" % (docbook_man_uri,)
ret = context.TryAction(probe)[0]
os.remove("xmltest.xml")
if os.path.exists("foo.1"):
os.remove("foo.1")
context.Result( ret )
return ret
config = Configure(env, custom_tests = { 'CheckPKG' : CheckPKG,
'CheckExecutable' : CheckExecutable,
'CheckXsltproc' : CheckXsltproc})
env.Prepend(LIBPATH=[os.path.realpath(os.curdir)])
if config.CheckExecutable('$CHRPATH -v', 'chrpath'):
# Tell generated binaries to look in the current directory for
# shared libraries so we can run tests without hassle. Should be
# handled sanely by scons on all systems. Not good to use '.' or
# a relative path here; it's a security risk. At install time we
# use chrpath to edit this out of RPATH.
if env["shared"]:
env.Prepend(RPATH=[os.path.realpath(os.curdir)])
else:
print "chrpath is not available, forcing static linking."
env["shared"] = False
confdefs = ["/* gpsd_config.h. Generated by scons, do not hand-hack. */\n"]
confdefs.append('#define VERSION "%s"\n' % gpsd_version)
confdefs.append('#define GPSD_URL "%s"\n' % website)
cxx = config.CheckCXX()
# define a helper function for pkg-config - we need to pass
# --static for static linking, too.
if env["shared"]:
pkg_config = lambda pkg: ['!%s --cflags --libs %s' %(env['PKG_CONFIG'], pkg, )]
else:
pkg_config = lambda pkg: ['!%s --cflags --libs --static %s' %(env['PKG_CONFIG'], pkg, )]
# The actual distinction here is whether the platform has ncurses in the
# base system or not. If it does, pkg-config is not likely to tell us
# anything useful. FreeBSD does, Linux doesn't. Most likely other BSDs
# are like FreeBSD.
ncurseslibs= []
if env['ncurses']:
if config.CheckPKG('ncurses'):
ncurseslibs = pkg_config('ncurses')
elif config.CheckExecutable('ncurses5-config --version', 'ncurses5-config'):
ncurseslibs = ['!ncurses5-config --libs --cflags']
elif sys.platform.startswith('freebsd'):
ncurseslibs= [ '-lncurses' ]
elif sys.platform.startswith('openbsd'):
ncurseslibs= [ '-lcurses' ]
if env['usb']:
# In FreeBSD except version 7, USB libraries are in the base system
if config.CheckPKG('libusb-1.0'):
confdefs.append("#define HAVE_LIBUSB 1\n")
try:
usblibs = pkg_config('libusb-1.0')
except OSError:
announce("pkg_config is confused about the state of libusb-1.0.")
usblibs = []
elif sys.platform.startswith("freebsd"):
confdefs.append("#define HAVE_LIBUSB 1\n")
usblibs = [ "-lusb"]
else:
confdefs.append("/* #undef HAVE_LIBUSB */\n")
usblibs = []
else:
confdefs.append("/* #undef HAVE_LIBUSB */\n")
usblibs = []
if config.CheckLib('librt'):
confdefs.append("#define HAVE_LIBRT 1\n")
# System library - no special flags
rtlibs = ["-lrt"]
else:
confdefs.append("/* #undef HAVE_LIBRT */\n")
rtlibs = []
if env['dbus_export'] and config.CheckPKG('dbus-1'):
confdefs.append("#define HAVE_DBUS 1\n")
dbus_libs = pkg_config('dbus-1')
else:
confdefs.append("/* #undef HAVE_DBUS */\n")
dbus_libs = []
if env['bluez'] and config.CheckPKG('bluez'):
confdefs.append("#define HAVE_BLUEZ 1\n")
bluezlibs = pkg_config('bluez')
else:
confdefs.append("/* #undef HAVE_BLUEZ */\n")
bluezlibs = []
if config.CheckHeader("sys/timepps.h"):
confdefs.append("#define HAVE_SYS_TIMEPPS_H 1\n")
announce("You have kernel PPS available.")
else:
confdefs.append("/* #undef HAVE_SYS_TIMEPPS_H */\n")
announce("You do not have kernel PPS available.")
# check function after libraries, because some function require library
# for example clock_gettime() require librt on Linux
for f in ("daemon", "strlcpy", "strlcat", "clock_gettime"):
if config.CheckFunc(f):
confdefs.append("#define HAVE_%s 1\n" % f.upper())
else:
confdefs.append("/* #undef HAVE_%s */\n" % f.upper())
# Map options to libraries required to support them that might be absent.
optionrequires = {
"bluez": ["libbluetooth"],
"dbus_export" : ["libdbus-1"],
}
keys = map(lambda x: (x[0],x[2]), boolopts) + map(lambda x: (x[0],x[2]), nonboolopts) + map(lambda x: (x[0],x[2]), pathopts)
keys.sort()
for (key,help) in keys:
value = env[key]
if value and key in optionrequires:
for required in optionrequires[key]:
if not config.CheckLib(required):
announce("%s not found, %s cannot be enabled." % (required,key))
value = False
break
confdefs.append("/* %s */" % help)
if type(value) == type(True):
if value:
confdefs.append("#define %s_ENABLE 1\n" % key.upper())
else:
confdefs.append("/* #undef %s_ENABLE */\n" % key.upper())
elif value in (0, "", "(undefined)"):
confdefs.append("/* #undef %s */\n" % key.upper())
else:
if value.isdigit():
confdefs.append("#define %s %s\n" % (key.upper(), value))
else:
confdefs.append("#define %s \"%s\"\n" % (key.upper(), value))
confdefs.append('''
/* will not handle pre-Intel Apples that can run big-endian */
#if defined __BIG_ENDIAN__
#define WORDS_BIGENDIAN 1
#else
#undef WORDS_BIGENDIAN
#endif
/* Some libcs do not have strlcat/strlcpy. Local copies are provided */
#ifndef HAVE_STRLCAT
# ifdef __cplusplus
extern "C" {
# endif
size_t strlcat(/*@out@*/char *dst, /*@in@*/const char *src, size_t size);
# ifdef __cplusplus
}
# endif
#endif
#ifndef HAVE_STRLCPY
# ifdef __cplusplus
extern "C" {
# endif
size_t strlcpy(/*@out@*/char *dst, /*@in@*/const char *src, size_t size);
# ifdef __cplusplus
}
# endif
#endif
#define GPSD_CONFIG_H
''')
manbuilder = mangenerator = htmlbuilder = None
if config.CheckXsltproc():
mangenerator = 'xsltproc'
build = "xsltproc --nonet %s $SOURCE >$TARGET"
htmlbuilder = build % docbook_html_uri
manbuilder = build % docbook_man_uri
elif WhereIs("xmlto"):
mangenerator = 'xmlto'
htmlbuilder = "xmlto html-nochunks $SOURCE; mv `basename $TARGET` $TARGET"
manbuilder = "xmlto man $SOURCE; mv `basename $TARGET` $TARGET"
else:
announce("Neither xsltproc nor xmlto found, documentation cannot be built.")
if manbuilder:
env['BUILDERS']["Man"] = Builder(action=manbuilder)
env['BUILDERS']["HTML"] = Builder(action=htmlbuilder,
src_suffix=".xml", suffix=".html")
qt_network = env['libQgpsmm'] and config.CheckPKG('QtNetwork')
env = config.Finish()
# Be explicit about what we're doing.
changelatch = False
for (name, default, help) in boolopts + nonboolopts + pathopts:
if env[name] != env.subst(default):
if not changelatch:
announce("Altered configuration variables:")
changelatch = True
announce("%s = %s (default %s): %s" % (name, env[name], env.subst(default), help))
if not changelatch:
announce("All configuration flags are defaulted.")
# Gentoo systems can have a problem with the Python path
if os.path.exists("/etc/gentoo-release"):
announce("This is a Gentoo system.")
announce("Adjust your PYTHONPATH to see library directories under /usr/local/lib")
# Should we build the Qt binding?
if cxx and qt_network:
qt_env = env.Clone()
qt_env.MergeFlags('-DUSE_QT')
if qt_network:
try:
qt_env.MergeFlags(pkg_config('QtNetwork'))
except OSError:
announce("pkg_config is confused about the state of QtNetwork.")
qt_env = None
else:
qt_env = None
## Two shared libraries provide most of the code for the C programs
libgps_version_soname = libgps_version_current - libgps_version_age
libgps_version = "%d.%d.%d" %(libgps_version_soname, libgps_version_age, libgps_version_revision)
libgps_sources = [
"ais_json.c",
"daemon.c",
"gpsutils.c",
"gpsdclient.c",
"gps_maskdump.c",
"hex.c",
"json.c",
"libgps_core.c",
"libgps_dbus.c",
"libgps_json.c",
"libgps_shm.c",
"libgps_sock.c",
"netlib.c",
"rtcm2_json.c",
"shared_json.c",
"strl.c",
]
if cxx and env['libgpsmm']:
libgps_sources.append("libgpsmm.cpp")
libgpsd_sources = [
"bits.c",
"bsd_base64.c",
"crc24q.c",
"gpsd_json.c",
"geoid.c",
"isgps.c",
"libgpsd_core.c",
"net_dgpsip.c",
"net_gnss_dispatch.c",
"net_ntrip.c",
"packet.c",
"pseudonmea.c",
"serial.c",
#"srecord.c",
"subframe.c",
"timebase.c",
"drivers.c",
"driver_aivdm.c",
"driver_evermore.c",
"driver_garmin.c",
"driver_garmin_txt.c",
"driver_geostar.c",
"driver_italk.c",
"driver_navcom.c",
"driver_nmea.c",
"driver_oncore.c",
"driver_rtcm2.c",
"driver_rtcm3.c",
"driver_sirf.c",
"driver_superstar2.c",
"driver_tsip.c",
"driver_ubx.c",
"driver_zodiac.c",
]
# Cope with scons's failure to set SONAME in its builtins.
# Inspired by Richard Levitte's (slightly buggy) code at
# http://markmail.org/message/spttz3o4xrsftofr
def VersionedSharedLibrary(env, libname, libgps_version, lib_objs=[], parse_flags=[]):
platform = env.subst('$PLATFORM')
shlib_pre_action = None
shlib_suffix = env.subst('$SHLIBSUFFIX')
shlib_post_action = None
shlink_flags = SCons.Util.CLVar(env.subst('$SHLINKFLAGS'))
if platform == 'posix':
ilib_suffix = shlib_suffix + '.' + libgps_version
(major, age, revision) = libgps_version.split(".")
soname = "lib" + libname + shlib_suffix + "." + major
shlink_flags += [ '-Wl,-Bsymbolic', '-Wl,-soname=%s' % soname ]
elif platform == 'cygwin':
ilib_suffix = shlib_suffix
shlink_flags += [ '-Wl,-Bsymbolic',
'-Wl,--out-implib,${TARGET.base}.a' ]
elif platform == 'darwin':
ilib_suffix = '.' + libgps_version + shlib_suffix
shlink_flags += [ '-current_version', '%s' % libgps_version,
'-compatibility_version', '%s' % libgps_version,
'-undefined', 'dynamic_lookup' ]
ilib = env.SharedLibrary(libname,lib_objs,
SHLIBSUFFIX=ilib_suffix,
SHLINKFLAGS=shlink_flags, parse_flags=parse_flags)
if platform == 'darwin':
if libgps_version.count(".") != 2:
# We need a library name in libfoo.x.y.z.dylib form to proceed
raise ValueError
lib = 'lib' + libname + '.' + libgps_version + '.dylib'
lib_no_ver = 'lib' + libname + '.dylib'
# Link libfoo.x.y.z.dylib to libfoo.dylib
env.AddPostAction(ilib, 'rm -f %s; ln -s %s %s' % (
lib_no_ver, lib, lib_no_ver))
env.Clean(lib, lib_no_ver)
elif platform == 'posix':
if libgps_version.count(".") != 2:
# We need a library name in libfoo.so.x.y.z form to proceed
raise ValueError
lib = "lib" + libname + ".so." + libgps_version
suffix_re = '%s\\.[0-9\\.]*$' % re.escape(shlib_suffix)
# For libfoo.so.x.y.z, links libfoo.so libfoo.so.x.y libfoo.so.x
major_name = shlib_suffix + "." + lib.split(".")[2]
minor_name = major_name + "." + lib.split(".")[3]
for linksuffix in [shlib_suffix, major_name, minor_name]:
linkname = re.sub(suffix_re, linksuffix, lib)
env.AddPostAction(ilib, 'rm -f %s; ln -s %s %s' % (
linkname, lib, linkname))
env.Clean(lib, linkname)
return ilib
def VersionedSharedLibraryInstall(env, destination, libs):
platform = env.subst('$PLATFORM')
shlib_suffix = env.subst('$SHLIBSUFFIX')
ilibs = env.Install(destination, libs)
if platform == 'posix':
suffix_re = '%s\\.[0-9\\.]*$' % re.escape(shlib_suffix)
for lib in map(str, libs):
if lib.count(".") != 4:
# We need a library name in libfoo.so.x.y.z form to proceed
raise ValueError
# For libfoo.so.x.y.z, links libfoo.so libfoo.so.x.y libfoo.so.x
major_name = shlib_suffix + "." + lib.split(".")[2]
minor_name = major_name + "." + lib.split(".")[3]
for linksuffix in [shlib_suffix, major_name, minor_name]:
linkname = re.sub(suffix_re, linksuffix, lib)
env.AddPostAction(ilibs, 'cd %s; rm -f %s; ln -s %s %s' % (destination, linkname, lib, linkname))
env.Clean(lib, linkname)
return ilibs
if not env["shared"]:
def Library(env, target, sources, version, parse_flags=[]):
return env.StaticLibrary(target, sources, parse_flags=parse_flags)
LibraryInstall = lambda env, libdir, sources: env.Install(libdir, sources)
else:
def Library(env, target, sources, version, parse_flags=[]):
return VersionedSharedLibrary(env=env,
libname=target,
libgps_version=version,
lib_objs=sources,
parse_flags=parse_flags)
LibraryInstall = lambda env, libdir, sources: \
VersionedSharedLibraryInstall(env, libdir, sources)
# Klugery to handle sonames ends
compiled_gpslib = Library(env=env,
target="gps",
sources=libgps_sources,
version=libgps_version,
parse_flags= ["-lm"] + dbus_libs)
env.Clean(compiled_gpslib, "gps_maskdump.c")
compiled_gpsdlib = Library(env=env,
target="gpsd",
sources=libgpsd_sources,
version=libgps_version,
parse_flags=usblibs + rtlibs + bluezlibs)
libraries = [compiled_gpslib, compiled_gpsdlib]
if qt_env:
qtobjects = []
qt_flags = qt_env['CFLAGS']
for c_only in ('-Wmissing-prototypes', '-Wstrict-prototypes'):
if c_only in qt_flags:
qt_flags.remove(c_only)
# Qt binding object files have to be renamed as they're built to avoid
# name clashes with the plain non-Qt object files. This prevents the
# infamous "Two environments with different actions were specified
# for the same target" error.
for src in libgps_sources:
if src in ("gpsutils.c", "libgps_sock.c"):
compile_with = qt_env['CXX']
compile_flags = qt_flags
else:
compile_with = qt_env['CC']
compile_flags = qt_env['CFLAGS']
qtobjects.append(qt_env.SharedObject(src.split(".")[0] + '-qt', src,
CC=compile_with,
CFLAGS=compile_flags,
parse_flags=dbus_libs))
compiled_qgpsmmlib = Library(qt_env, "Qgpsmm", qtobjects, libgps_version)
libraries.append(compiled_qgpsmmlib)
# The libraries have dependencies on system libraries
gpslibs = ["-lgps"]
gpsdlibs = ["-lgpsd"] + usblibs + bluezlibs + gpslibs
# Source groups
gpsd_sources = ['gpsd.c','ntpshm.c','shmexport.c','dbusexport.c']
if env['systemd']:
gpsd_sources.append("sd_socket.c")
gpsmon_sources = [
'gpsmon.c',
'monitor_italk.c',
'monitor_nmea.c',
'monitor_oncore.c',
'monitor_sirf.c',
'monitor_superstar2.c',
'monitor_tnt.c',
'monitor_ubx.c',
'monitor_garmin.c',
]
## Production programs
# FIXME: What we really want is for libm to be linked when libgps is.
# VersionedSharedLibrary accomplishes this for its case, but we don't
# know how to force it when linking staticly.
#
# It turns out there are two cases where we need to force this. Some
# distributions don't do implicit linking by design. See the test
# code for implicit_link.
#
if not env['shared'] or not env["implicit_link"]:
env.MergeFlags("-lm")
gpsd_env = env.Clone()
gpsd_env.MergeFlags("-pthread")
gpsd = gpsd_env.Program('gpsd', gpsd_sources,
parse_flags = gpsdlibs + dbus_libs)
env.Depends(gpsd, [compiled_gpsdlib, compiled_gpslib])
gpsdecode = env.Program('gpsdecode', ['gpsdecode.c'], parse_flags=gpsdlibs)
env.Depends(gpsdecode, [compiled_gpsdlib, compiled_gpslib])
gpsctl = env.Program('gpsctl', ['gpsctl.c'], parse_flags=gpsdlibs)
env.Depends(gpsctl, [compiled_gpsdlib, compiled_gpslib])
gpsdctl = env.Program('gpsdctl', ['gpsdctl.c'], parse_flags=gpslibs)
env.Depends(gpsdctl, compiled_gpslib)
gpsmon = env.Program('gpsmon', gpsmon_sources,
parse_flags=gpsdlibs + ncurseslibs)
env.Depends(gpsmon, [compiled_gpsdlib, compiled_gpslib])
gpspipe = env.Program('gpspipe', ['gpspipe.c'], parse_flags=gpslibs)
env.Depends(gpspipe, compiled_gpslib)
gpxlogger = env.Program('gpxlogger', ['gpxlogger.c'], parse_flags=gpslibs)
env.Depends(gpxlogger, compiled_gpslib)
lcdgps = env.Program('lcdgps', ['lcdgps.c'], parse_flags=gpslibs)
env.Depends(lcdgps, compiled_gpslib)
cgps = env.Program('cgps', ['cgps.c'], parse_flags=gpslibs + ncurseslibs)
env.Depends(cgps, compiled_gpslib)
binaries = [gpsd, gpsdecode, gpsctl, gpsdctl, gpspipe, gpxlogger, lcdgps]
if ncurseslibs:
binaries += [cgps, gpsmon]
clockwatcher = env.Program('clockwatcher', ['clockwatcher.c'], parse_flags=gpslibs)
env.Depends(clockwatcher, compiled_gpslib)
# Test programs
test_float = env.Program('test_float', ['test_float.c'])
test_geoid = env.Program('test_geoid', ['test_geoid.c'], parse_flags=gpsdlibs)
env.Depends(test_geoid, compiled_gpsdlib)
test_json = env.Program('test_json', ['test_json.c'], parse_flags=gpslibs)
env.Depends(test_json, compiled_gpslib)
test_mkgmtime = env.Program('test_mkgmtime', ['test_mkgmtime.c'], parse_flags=gpslibs)
env.Depends(test_mkgmtime, compiled_gpslib)
test_trig = env.Program('test_trig', ['test_trig.c'], parse_flags=["-lm"])
test_packet = env.Program('test_packet', ['test_packet.c'], parse_flags=gpsdlibs)
env.Depends(test_packet, [compiled_gpsdlib, compiled_gpslib])
test_bits = env.Program('test_bits', ['test_bits.c'], parse_flags=gpsdlibs)
env.Depends(test_bits, [compiled_gpsdlib, compiled_gpslib])
test_gpsmm = env.Program('test_gpsmm', ['test_gpsmm.cpp'], parse_flags=gpslibs)
env.Depends(test_gpsmm, compiled_gpslib)
test_libgps = env.Program('test_libgps', ['test_libgps.c'], parse_flags=gpslibs)
env.Depends(test_libgps, compiled_gpslib)
testprogs = [test_float, test_trig, test_bits, test_packet,
test_mkgmtime, test_geoid, test_libgps]
if env['socket_export']:
testprogs.append(test_json)
if cxx and env["libgpsmm"]:
testprogs.append(test_gpsmm)
# Python programs
if not env['python']:
python_built_extensions = []
else:
python_progs = ["gpscat", "gpsfake", "gpsprof", "xgps", "xgpsspeed", "gegps"]
python_modules = Glob('gps/*.py')
# Build Python binding
#
python_extensions = {
"gps" + os.sep + "packet" : ["gpspacket.c", "packet.c", "isgps.c",
"driver_rtcm2.c", "strl.c", "hex.c", "crc24q.c"],
"gps" + os.sep + "clienthelpers" : ["gpsclient.c", "geoid.c", "gpsdclient.c", "strl.c"]
}
python_env = env.Clone()
vars = sysconfig.get_config_vars('CC', 'CXX', 'OPT', 'BASECFLAGS', 'CCSHARED', 'LDSHARED', 'SO', 'INCLUDEPY')
for i in range(len(vars)):
if vars[i] is None:
vars[i] = ""
(cc, cxx, opt, basecflags, ccshared, ldshared, so_ext, includepy) = vars
# in case CC/CXX was set to the scan-build wrapper,
# ensure that we build the python modules with scan-build, too
if env['CC'] is None or env['CC'].find('scan-build') < 0:
python_env['CC'] = cc
else:
python_env['CC'] = ' '.join([env['CC']] + cc.split()[1:])
if env['CXX'] is None or env['CXX'].find('scan-build') < 0:
python_env['CXX'] = cxx
else:
python_env['CXX'] = ' '.join([env['CXX']] + cxx.split()[1:])
python_env['SHLINKFLAGS'] = []
python_env['SHLINK'] = ldshared
python_env['SHLIBPREFIX']=""
python_env['SHLIBSUFFIX']=so_ext
python_env['CPPPATH'] =[includepy]
python_env['CPPFLAGS']=basecflags + " " + opt
python_objects={}
python_compiled_libs = {}
for ext, sources in python_extensions.iteritems():
python_objects[ext] = []
for src in sources:
python_objects[ext].append(
python_env.NoCache(
python_env.SharedObject(
src.split(".")[0] + '-py_' + '_'.join(['%s' %(x) for x in sys.version_info]) + so_ext, src
)
)
)
python_compiled_libs[ext] = python_env.SharedLibrary(ext, python_objects[ext])
python_built_extensions = python_compiled_libs.values()
python_egg_info_source = """Metadata-Version: 1.0
Name: gps
Version: %s
Summary: Python libraries for the gpsd service daemon
Home-page: %s
Author: the GPSD project
Author-email: %s
License: BSD
Description: The gpsd service daemon can monitor one or more GPS devices connected to a host computer, making all data on the location and movements of the sensors available to be queried on TCP port 2947.
Platform: UNKNOWN
""" %(gpsd_version, website, devmail)
python_egg_info = python_env.Textfile(target="gps-%s.egg-info" %(gpsd_version, ), source=python_egg_info_source)
env.Command(target = "packet_names.h", source="packet_states.h", action="""
rm -f $TARGET &&\
sed -e '/^ *\([A-Z][A-Z0-9_]*\),/s// \"\\1\",/' <$SOURCE >$TARGET &&\
chmod a-w $TARGET""")
# build timebase.h
def timebase_h(target, source, env):
from leapsecond import make_leapsecond_include
with open(target[0].abspath, 'w') as f:
f.write(make_leapsecond_include(source[0].abspath))
env.Command(target="timebase.h", source="leapseconds.cache",
action=timebase_h)
env.Textfile(target="gpsd_config.h", source=confdefs)
env.Textfile(target="gpsd.h", source=[File("gpsd.h-head"), File("gpsd_config.h"), File("gpsd.h-tail")])
env.Command(target="gps_maskdump.c", source=["maskaudit.py", "gps.h", "gpsd.h"], action='''
rm -f $TARGET &&\
$PYTHON $SOURCE -c $SRCDIR >$TARGET &&\
chmod a-w $TARGET''')
env.Command(target="ais_json.i", source="jsongen.py", action='''\
rm -f $TARGET &&\
$PYTHON $SOURCE --ais --target=parser >$TARGET &&\
chmod a-w $TARGET''')
# generate revision.h
if 'dev' in gpsd_version:
(st, rev) = _getstatusoutput('git describe')
if st != 0:
from datetime import datetime
rev = datetime.now().isoformat()[:-4]
else:
rev = gpsd_version
revision='#define REVISION "%s"\n' %(rev.strip(),)
env.Textfile(target="revision.h", source=[revision])
# generate pps_pin.h
pps_pin = env['pps_pin']
ppsh = '/* generated by scons from the pps_pin option - do not hand-hack */\n'