-
Notifications
You must be signed in to change notification settings - Fork 18
/
SConscript
3473 lines (3046 loc) · 127 KB
/
SConscript
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 file. Only meant to be run from SContruct.
#
# This file is Copyright 2010 by the GPSD project
# SPDX-License-Identifier: BSD-2-clause
#
# This code runs compatibly under Python 2 and 3.x for x >= 2.
# Preserve this property!
from __future__ import print_function
import ast
import atexit # for atexit.register()
import functools
import glob
import operator
import os
import pickle
import re
# replacement for functions from the commands module, which is deprecated.
import subprocess
import sys
import time
try:
# sysconfig since 2.7, still in 3.13
import sysconfig
PYTHON_SYSCONFIG_IMPORT = 'import sysconfig'
except ModuleNotFoundError:
# distutils gone in 3.13, but needed for 2.6
from distutils import sysconfig
PYTHON_SYSCONFIG_IMPORT = 'from distutils import sysconfig'
import SCons
# scons does not like targets that come and go (if cleaning, if python,
# etc). All targets are needed for proper cleaning. If a target should
# not be built (if not python), then do not include the target in the
# next layer sources.
# scons gets confused by targets that are not a real file (shmclean, etc.).
# Set them Pseudo (like in a Makefile) and use an Alias() for them.
# Note: Do not use context.TryRun() as that breaks cross-compiling
# Facilitate debugging with pdb.
# At pdb startup, the environment is such that setting breakpoints in
# SConstruct requires specifying its full absolute path, which is incovenient.
# Stopping here at an automatic breakpoint makes this easier. Note that this
# code has no effect unless pdb is loaded.
# To use this, run with pdb and continue from the initial pdb prompt.
pdb_module = sys.modules.get('pdb')
if pdb_module:
pdb_module.set_trace()
pass # Breakpoint default file is now SConscript
# gpsd needs Scons version at least 2.3
EnsureSConsVersion(2, 3, 0)
# gpsd needs Python version at least 2.6
EnsurePythonVersion(2, 6)
# By user choice, or due to system-dependent availability, the scons
# executable may be called using names other than plain "scons",
# e.g. "scons-3" on CentOS 8.
scons_executable_name = os.path.basename(sys.argv[0]) or 'scons'
# Have scons rebuild an existing target when the source(s) MD5 changes
# Do not use time to prevent rebuilding when sources, like gpsd_config.h,
# are rebuilt, but with no changes.
Decider('MD5')
# Put .sconsign*dblite and .scons-options-cache in variantdir for
# one-touch cleaning
# support building with various Python versions.
sconsign_file = '.sconsign.%d.dblite' % pickle.HIGHEST_PROTOCOL
SConsignFile(os.getcwd() + os.path.sep + sconsign_file)
# Start by reading configuration variables from the cache
opts = Variables('.scons-option-cache')
# ugly hack from http://www.catb.org/esr/faqs/practical-python-porting/
# handle python2/3 strings
def polystr(o):
if bytes is str: # Python 2
return str(o)
# python 3.
if isinstance(o, str):
return o
if isinstance(o, (bytes, bytearray)):
return str(o, encoding='latin1')
if isinstance(o, int):
return str(o)
raise ValueError
def strtobool(val):
val = val.lower()
if val in ('y', 'yes', 't', 'true', 'on', '1'):
return True
elif val in ('n', 'no', 'f', 'false', 'off', '0'):
return False
else:
raise ValueError("invalid truth value %r" % (val,))
# Helper functions for revision hackery
def GetMtime(file):
"""Get mtime of given file, or 0."""
try:
return os.stat(file).st_mtime
except OSError:
return 0
def FileList(patterns, exclusion=None):
"""Get list of files based on patterns, minus excluded path."""
files = functools.reduce(operator.add, map(glob.glob, patterns), [])
for file in files:
if file.find(exclusion):
files.remove(file)
return files
# FIXME: replace with TryAction()
def _getstatusoutput(cmd, nput=None, shell=True, cwd=None, env=None):
pipe = subprocess.Popen(cmd, shell=shell, cwd=cwd, env=env,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
(output, errout) = pipe.communicate(input=nput)
status = pipe.returncode
return (status, output)
# Workaround for old SCons bug that couldn't overwrite existing symlinks
# This was fixed in 2.3.2, but we allow 2.3.0 (e.g., on Ubuntu 14)
#
# In the troublesome versions, we monkey-patch os.symlink to bully it through
standard_os_symlink = os.symlink
def _forced_symlink(source, link_name):
try:
standard_os_symlink(source, link_name)
except OSError:
# Out of paranoia, only do this when the target is a symlink
if os.path.islink(link_name):
os.remove(link_name)
standard_os_symlink(source, link_name)
else:
raise
if SCons.__version__ in ['2.3.0', '2.3.1']:
os.symlink = _forced_symlink
# SCons 2.3.0 is also missing the Psuedo method. See the workaround after
# the initial 'env' setup.
# All man pages. Always build them all.
all_manpages = {
"man/cgps.1": "man/cgps.adoc",
"man/gegps.1": "man/gegps.adoc",
"man/gps.1": "man/gps.adoc",
"man/gps2udp.1": "man/gps2udp.adoc",
"man/gpscsv.1": "man/gpscsv.adoc",
"man/gpscat.1": "man/gpscat.adoc",
"man/gpsctl.1": "man/gpsctl.adoc",
"man/gpsd.8": "man/gpsd.adoc",
"man/gpsdebuginfo.1": "man/gpsdebuginfo.adoc",
"man/gpsdctl.8": "man/gpsdctl.adoc",
"man/gpsdecode.1": "man/gpsdecode.adoc",
"man/gpsd_json.5": "man/gpsd_json.adoc",
"man/gpsfake.1": "man/gpsfake.adoc",
"man/gpsinit.8": "man/gpsinit.adoc",
"man/gpsmon.1": "man/gpsmon.adoc",
"man/gpspipe.1": "man/gpspipe.adoc",
"man/gpsplot.1": "man/gpsplot.adoc",
"man/gpsprof.1": "man/gpsprof.adoc",
"man/gpsrinex.1": "man/gpsrinex.adoc",
"man/gpssnmp.1": "man/gpssnmp.adoc",
"man/gpssubframe.1": "man/gpssubframe.adoc",
"man/gpxlogger.1": "man/gpxlogger.adoc",
"man/lcdgps.1": "man/lcdgps.adoc",
"man/libgps.3": "man/libgps.adoc",
"man/libgpsmm.3": "man/libgpsmm.adoc",
"man/libQgpsmm.3": "man/libgpsmm.adoc",
"man/ntpshmmon.1": "man/ntpshmmon.adoc",
"man/ppscheck.8": "man/ppscheck.adoc",
"man/ubxtool.1": "man/ubxtool.adoc",
"man/xgps.1": "man/xgps.adoc",
"man/xgpsspeed.1": "man/xgpsspeed.adoc",
"man/zerk.1": "man/zerk.adoc",
}
# doc files to install in share/gpsd/doc
doc_files = [
'AUTHORS',
'build.adoc',
'COPYING',
'www/example1.c.txt',
'www/example2.py.txt',
'NEWS',
'README.adoc',
'SUPPORT.adoc',
]
# doc files to install in share/gpsd/doc/
icon_files = [
'packaging/X11/gpsd-logo.png',
]
# MIB files to install in $PREFIX/share/snmp/mibs/gpsd/
mib_files = [
'man/GPSD-MIB',
]
mib_lint = (mib_files + ['SConstruct', 'SConscript'])
# gpsd_version, and variantdir, from SConstruct
Import('*')
# Create a fixed-name symlink to the build tree, for scripts and symlinks.
# FIXME: Make this work with Execute()
vdir_parent = os.path.dirname(os.path.abspath(os.path.dirname(variantdir)))
try:
os.symlink(variantdir, os.path.join(vdir_parent, 'buildtmp'))
except OSError:
pass # May already exist
# API (JSON) version
api_version_major = 3
api_version_minor = 15
# client library version
libgps_version_current = 30
libgps_version_revision = 0
libgps_version_age = 0
libgps_version = "%d.%d.%d" % (libgps_version_current, libgps_version_age,
libgps_version_revision)
#
# 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!
annmail = "[email protected]"
bugtracker = "https://gitlab.com/gpsd/gpsd/-/issues"
cgiupload = "[email protected]:/var/www/cgi-bin/"
clonerepo = "[email protected]:gpsd/gpsd.git"
devmail = "[email protected]"
download = "http://download-mirror.savannah.gnu.org/releases/gpsd/"
formserver = "[email protected]"
gitrepo = "[email protected]:gpsd/gpsd.git"
ircchan = "irc://chat.libera.chat:6697/#gpsd"
mailman = "https://lists.nongnu.org/mailman/listinfo/"
mainpage = "https://gpsd.io"
projectpage = "https://gitlab.com/gpsd/gpsd"
scpupload = "[email protected]:/releases/gpsd/"
sitename = "GPSD"
sitesearch = "gpsd.io"
tiplink = "<a href='https://www.patreon.com/esr'>" \
"leave a remittance at Patreon</a>"
tipwidget = '<p><a href="https://www.patreon.com/esr">' \
'Donate here to support continuing development.</a></p>'
usermail = "[email protected]"
webform = "http://www.thyrsus.com/cgi-bin/gps_report.cgi"
website = "https://gpsd.io/"
# Hosting information ends here
# Utility productions
def Utility(target, source, action, **kwargs):
targ = env.Command(target=target, source=source, action=action, **kwargs)
# why always build? wasteful?
# when gpsdecode is the source this rebuilds the entire daemon!
# env.AlwaysBuild(targ)
# Why precious?
env.Precious(targ)
# Is pseudo really needed (didn't used to be)?
env.Pseudo(targ)
# Alias to make name work without variantdir prefix
env.Alias(target, targ)
return targ
def UtilityWithHerald(herald, target, source, action, **kwargs):
if not env.GetOption('silent'):
action = ['@echo "%s"' % herald] + action
return Utility(target=target, source=source, action=action, **kwargs)
# Spawn replacement that suppresses non-error stderr
def filtered_spawn(sh, escape, cmd, args, env):
proc = subprocess.Popen([sh, '-c', ' '.join(args)],
env=env, close_fds=True, stderr=subprocess.PIPE)
_, stderr = proc.communicate()
if proc.returncode:
sys.stderr.write(stderr)
return proc.returncode
#
# Build-control options
#
# guess systemd defaults
systemd_dir = '/lib/systemd/system'
systemd = os.path.exists(systemd_dir)
# Set distribution-specific defaults here
imloads = True
boolopts = (
# GPS protocols
# for back compatibility, deprecated Feb 2021
("ashtech", True, "alias for NMEA0183 support, deprecated"),
("earthmate", True, "DeLorme EarthMate Zodiac support"),
("evermore", True, "EverMore binary support"),
("fury", True, "Jackson Labs Fury and Firefly 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"),
("greis", True, "Javad GREIS support"),
("itrax", True, "iTrax hardware support"),
("navcom", True, "Navcom NCT support"),
("nmea2000", True, "NMEA2000/CAN support"),
("oncore", True, "Motorola OnCore chipset support"),
("sirf", True, "SiRF chipset support"),
("skytraq", True, "Skytraq chipset support"),
("superstar2", True, "Novatel SuperStarII chipset support"),
("tnt", True, "True North Technologies support"),
("tripmate", True, "DeLorme TripMate support"),
("tsip", True, "Trimble TSIP support"),
# Non-GPS protocols
("aivdm", True, "AIVDM support"),
("gpsclock", True, "Furuno GPSClock support"),
("isync", True, "Spectratime iSync LNRClok/GRCLOK support"),
# Time service
("oscillator", True, "Disciplined oscillator support"),
# Export methods
("dbus_export", True, "enable DBUS export support"),
("shm_export", True, "export via shared memory"),
("socket_export", True, "data export over sockets"),
# Communication
("bluez", True, "BlueZ support for Bluetooth devices"),
('usb', True, "libusb support for USB devices"),
# Other daemon options
("control_socket", True, "control socket for hotplug notifications"),
("systemd", systemd, "systemd socket activation"),
# Client-side options
("clientdebug", True, "client debugging support"),
("libgpsmm", True, "build C++ bindings"),
("ncurses", True, "build with ncurses"),
("qt", True, "build Qt bindings"),
# Daemon options
("squelch", False, "squelch gpsd_log/gpsd_hexdump to save cpu"),
# Build control
("coveraging", False, "build with code coveraging enabled"),
("debug", False, "add debug information to build, unoptimized"),
("debug_opt", False, "add debug information to build, optimized"),
("gpsdclients", True, "gspd client programs"),
("gpsd", True, "gpsd itself"),
("implicit_link", imloads, "implicit linkage is supported in shared libs"),
# FIXME: should check for Pi, not for "linux"
("magic_hat", sys.platform.startswith('linux'),
"special Linux PPS hack for Raspberry Pi et al"),
("minimal", False, "turn off every option not set on the command line"),
("nostrip", False, "don't symbol-strip binaries at link time"),
("profiling", False, "build with profiling enabled"),
("python", True, "build Python support and modules."),
("shared", True, "build shared libraries, not static"),
("timeservice", False, "time-service configuration"),
("xgps", True, "include xgps and xgpsspeed."),
# Test control
("slow", False, "run tests with realistic (slow) delays"),
)
# now step on the boolopts just read from '.scons-option-cache'
# Otherwise if no cache, then no boolopts.
for (name, default, helpd) in boolopts:
opts.Add(BoolVariable(name, helpd, default))
# See PEP 394 for why 'python' is the preferred name for Python.
# override with "target_python=XX" on scons command line if want different
# Later there are tests for OS specifics.
def_target_python = "python"
def_python_shebang = "/usr/bin/env %s" % def_target_python
# Gentoo, Fedora, openSUSE systems use dialout for ttyS*, ttyUSB*, and similar
# As of October 2024, we only know distros that use "dialout"
def_group = "dialout"
# darwin and BSDs do not have /run, maybe others.
if os.path.exists("/run"):
rundir = "/run"
else:
rundir = "/var/run"
nonboolopts = (
("gpsd_group", def_group, "privilege revocation group"),
("gpsd_user", "nobody", "privilege revocation user",),
("manbuild", "auto",
"build help in man and HTML formats. No/Auto/Yes."),
("max_clients", '64', "maximum allowed clients"),
("max_devices", '6', "maximum allowed devices"),
("prefix", "/usr/local", "installation directory prefix"),
("python_coverage", "coverage run", "coverage command for Python progs"),
("python_libdir", "", "Python module directory prefix"),
("python_shebang", def_python_shebang, "Python shebang"),
("qt_versioned", "", "version for versioned Qt"),
("release", "", "Suffix for gpsd version"),
("rundir", rundir,
"Directory for run-time variable data"),
("sysroot", "",
"Logical root directory for headers and libraries.\n"
"For cross-compiling, or building with multiple local toolchains.\n"
"See gcc and ld man pages for more details."),
("target", "",
"Prefix to the binary tools to use (gcc, ld, etc.)\n"
"For cross-compiling, or building with multiple local toolchains.\n"
),
# If build and target platform are different, then redefining target
# platform might be necessary to use better build flags
("target_platform", sys.platform,
"target platform for cross-compiling (linux, darwin, etc.)"),
("target_python", def_target_python, "target Python version as command"),
)
# now step on the non boolopts just read from '.scons-option-cache'
# why?
for (name, default, helpd) in nonboolopts:
opts.Add(name, helpd, default)
pathopts = (
("bindir", "bin", "application binaries directory"),
("docdir", "share/gpsd/doc", "documents directory"),
("icondir", "share/gpsd/icons", "icon directory"),
("includedir", "include", "header file directory"),
("libdir", "lib", "system libraries"),
("mandir", "share/man", "manual pages directory"),
# /usr/share/snmp/mibs is default for net-snmp
("mibdir", "share/snmp/mibs/gpsd", "MIB directory"),
("pkgconfig", "$libdir/pkgconfig", "pkgconfig file directory"),
("sbindir", "sbin", "system binaries directory"),
("sharedir", "share/gpsd", "share directory"),
("sysconfdir", "etc", "system configuration directory"),
("udevdir", "/lib/udev", "udev rules directory"),
("unitdir", systemd_dir, "Directory for systemd unit files"),
)
# now step on the path options just read from '.scons-option-cache'
for (name, default, helpd) in pathopts:
opts.Add(PathVariable(name, helpd, default, PathVariable.PathAccept))
#
# Environment creation
#
import_env = (
# Variables used by programs invoked during the build
"DISPLAY", # Required for dia to run under scons
"GROUPS", # Required by gpg
"HOME", # Required by gpg
"LANG", # To avoid Gtk warnings with Python >=3.7
'PATH', # Required for ccache and Coverity scan-build
'CCACHE_DIR', # Required for ccache
'CCACHE_RECACHE', # Required for ccache (probably there are more)
# pkg-config (required for crossbuilds at least, and probably pkgsrc)
'PKG_CONFIG_LIBDIR',
'PKG_CONFIG_PATH',
'PKG_CONFIG_SYSROOT_DIR',
# Variables for specific packaging/build systems
"MACOSX_DEPLOYMENT_TARGET", # MacOSX 10.4 (and probably earlier)
'STAGING_DIR', # OpenWRT and CeroWrt
'STAGING_PREFIX', # OpenWRT and CeroWrt
'CWRAPPERS_CONFIG_DIR', # pkgsrc
# Variables used in testing
'WRITE_PAD', # So we can test WRITE_PAD values on the fly.
)
envs = {}
for var in import_env:
if var in os.environ:
envs[var] = os.environ[var]
envs["GPSD_HOME"] = os.getcwd() + os.sep + 'gpsd'
env = Environment(tools=["default", "tar", "textfile"], options=opts, ENV=envs)
# Release identification begins here.
#
# Actual releases follow the normal X.Y or X.Y.Z scheme. The version
# number in git between releases has the form X.Y~dev, when it is
# expected that X.Y will be the next actual release. As an example,
# when 3.20 is the last release, and 3.20.1 is the expected next
# release, the version in git will be 3.20.1~dev. Note that ~ is used,
# because there is some precedent, ~ is an allowed version number in
# the Debian version rules, and it does not cause confusion with
# whether - separates components of the package name, separates the
# name from the version, or separates version components.
if 'dev' in gpsd_version:
(st, gpsd_revision) = _getstatusoutput('git describe --tags')
if st != 0:
# If git describe failed
# Try to use current commit hash
(st, gpsd_commit) = _getstatusoutput('git rev-parse HEAD')
if st == 0 and gpsd_commit:
# Format output similar to normal revision
gpsd_revision = '%s-g%s' % (gpsd_version, polystr(gpsd_commit[:9]))
else:
# Only if git describe and git rev-parse failed
# Use timestamp from latest relevant file,
# ignoring generated files (../$variantdir)
# from root, not from $variantdir
files = FileList(['../*.c', '../*/*.c', '../*.cpp', '../*/*.cpp',
'../include/*.h', '../*.in', '../*/*.in',
'../SConstruct', '../SConscript'],
'../%s' % variantdir)
timestamps = map(GetMtime, files)
if timestamps:
from datetime import datetime
latest = datetime.fromtimestamp(sorted(timestamps)[-1])
gpsd_revision = '%s-%s' % (gpsd_version, latest.isoformat())
else:
gpsd_revision = gpsd_version # Paranoia
else:
gpsd_revision = gpsd_version
gpsd_revision = polystr(gpsd_revision.strip())
# Distros like to add a suffix to the version. Fedora, and others,
# call it the "release". It often looks like: r1
if env['release']:
gpsd_revision += "-" + polystr(env['release'])
# SCons 2.3.0 lacks the Pseudo method. If it's missing here, make it a
# dummy and hope for the best.
try:
env.Pseudo
except AttributeError:
env.Pseudo = lambda x: None
# Minimal build turns off every option not set on the command line,
if ARGUMENTS.get('minimal'):
for (name, default, helpd) in boolopts:
# Ensure gpsd and gpsdclients are always enabled unless explicitly
# turned off.
if ((default is True and
not ARGUMENTS.get(name) and
name not in ("gpsd", "gpsdclients"))):
env[name] = False
# Time-service build = stripped-down with some diagnostic tools
if ARGUMENTS.get('timeservice'):
timerelated = ("gpsd",
"ipv6",
"magic_hat",
"ncurses",
"oscillator",
"socket_export",
)
for (name, default, helpd) in boolopts:
if ((default is True and
not ARGUMENTS.get(name) and
name not in timerelated)):
env[name] = False
opts.Save('.scons-option-cache', env)
for (name, default, helpd) in pathopts:
env[name] = env.subst(env[name])
env['VERSION'] = gpsd_version
env['SC_PYTHON'] = sys.executable # Path to SCons Python
# 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.
#
# Scons also uses different internal names than most other build-systems.
#
# scons uses gcc, or clang, to link. Thus LDFLAGS does not serve its
# traditional function of providing arguments to ln. LDFLAGS set in the
# environment before running scons get moved into CCFLAGS by scons.
# LDFLAGS set while running scons get ignored.
#
# This means all uses of LDFLAG in this file ae simply dead code. Except
# for the import from the environment passed to scons.
#
# OepnEmbedded (OE) has been hit because OE build environment adds
# -fvisibility-inlines-hidden to CXXFLAGS (correctly), but SCons as it
# is now, October 2024, (without the dictionary being passed to MergeFlags)
# propagates this option to CCFLAGS. This makes GCC output a warning about a
# C++/ObjC++-only option used for C, which makes tests (e.g. strerror_r)
# fail as the warning turns into an error, masking test result.
env['STRIP'] = "strip"
env['PKG_CONFIG'] = "pkg-config"
for i in ["AR", # linker for static libs, usually "ar"
"CC",
"CXX",
# "LD", # scons does not use LD, usually "ld"
"PKG_CONFIG",
"SHLINK", # linker for shared libs, usually "gcc" or "g++", NOT "ld"
"STRIP",
"TAR"]:
if i in os.environ:
env[i] = os.getenv(i)
for i in ["ARFLAGS",
"CCFLAGS",
"CFLAGS",
"CPPFLAGS",
"CXXFLAGS",
"LDFLAGS",
"LINKFLAGS",
"SHLINKFLAGS",
]:
if i in os.environ:
t = i
# scons uses LINKFLAGS instead of LDFLAGS
if t == "LDFLAGS":
t = "LINKFLAGS"
# If MergeFlags() didn't get the *FLAGS variable name as the key in the
# dict passed here, it would have to guess to which flags each option
# belongs. That is not reliable. Some options can be included in
# multiple flags, e.g. -spec can be included in both compiler and
# linker flags with different values.
env.MergeFlags({t: Split(os.getenv(i))})
# Keep scan-build and RPM-specific build options in the environment.
# They may be referenced by a linker script specified in LDFLAGS
# (e.g. RPM_PACKAGE_NAME). The build would fail without them.
for key, value in os.environ.items():
if ((key.startswith('CCC_') or
key.startswith('RPM_'))):
env.Append(ENV={key: value})
# Placeholder so we can kluge together something like VPATH builds.
# ${SRCDIR} replaces occurrences for $(srcdir) in the autotools build.
# scons can get confused if this is not a full path
# WARNING: ${SRCDIR} may contain spaces!
# FIXME: could get variantdir from SRCDIR
env['SRCDIR'] = os.getcwd()
# We may need to force slow regression tests to get around race
# conditions in the pty layer, especially on a loaded machine.
if env["slow"]:
env['REGRESSOPTS'] = "-S"
else:
env['REGRESSOPTS'] = ""
if env.GetOption("silent"):
env['REGRESSOPTS'] += " -Q"
def announce(msg, end=False):
if not env.GetOption("silent"):
print(msg)
if end:
# duplicate message at exit
atexit.register(lambda: print(msg))
announce("scons version: %s" % SCons.__version__)
announce("scons is running under Python version: %s" %
".".join(map(str, sys.version_info)))
announce("gpsd version: %s" % polystr(gpsd_revision))
# DESTDIR environment variable means user prefix the installation root.
DESTDIR = os.environ.get('DESTDIR', '')
def installdir(idir, add_destdir=True):
# use os.path.join to handle absolute paths properly.
wrapped = os.path.join(env['prefix'], env[idir])
if add_destdir:
wrapped = os.path.normpath(DESTDIR + os.path.sep + wrapped)
wrapped.replace("/usr/etc", "/etc")
wrapped.replace("/usr/lib/systemd", "/lib/systemd")
return wrapped
# Honor the specified installation prefix in link paths.
if env["sysroot"]:
env.Prepend(LIBPATH=[env["sysroot"] + installdir('libdir',
add_destdir=False)])
# Don't change CCFLAGS if already set by environment.
if 'CCFLAGS' in os.environ:
announce('Warning: CCFLAGS from environment overriding scons settings')
else:
# Should we build with profiling?
if env['profiling']:
env.Append(CCFLAGS=['-pg'])
# Should we build with coveraging?
if env['coveraging']:
env.Append(CFLAGS=['-coverage'])
env.Append(LINKFLAGS=['-coverage'])
# Should we build with debug symbols?
if env['debug'] or env['debug_opt']:
env.Append(CCFLAGS=['-g3'])
env.Append(LINKFLAGS=['-g3'])
# Should we build with optimisation?
if env['debug'] or env['coveraging']:
env.Append(CCFLAGS=['-O0'])
else:
env.Append(CCFLAGS=['-O2'])
# Cross-development
devenv = (("ADDR2LINE", "addr2line"),
("AR", "ar"),
("AS", "as"),
("CC", "gcc"),
("CPP", "cpp"),
("CXX", "c++"),
("CXXFILT", "c++filt"),
("GCCBUG", "gccbug"),
("GCOV", "gcov"),
("GPROF", "gprof"),
("GXX", "g++"),
# ("LD", "ld"), # scons does not use 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
def cmp(a, b):
return (a > b) - (a < b)
# FIXME: include __doc__ in 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 packagers want
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))
# Configuration
def CheckFlt_Eval_Method(context):
"""Ensure FLT_EVAL_METHOD is 0"""
context.Message('Checking FLT_EVAL_METHOD is 0... ')
ret = context.TryLink("""
#include <float.h>
#ifndef FLT_EVAL_METHOD
error
#endif
#if 0 != FLT_EVAL_METHOD
error
#endif
int main(int argc, char **argv) {
(void) argc; (void) argv;
return 0;
}
""", '.c')
context.Result(ret)
return ret
def CheckPKG(context, name):
context.Message('Checking pkg-config for %s... ' % name)
ret = context.TryAction('%s --exists \'%s\''
% (context.env['PKG_CONFIG'], name))[0]
context.Result(ret)
return ret
def CheckStrerror_r(context):
"""Return strerror_r(24,...).
Will return true if POSIX, false if gnu-like
Required because libc's are random about it.
"""
context.Message('Checking if strerror_r() returns int... ')
old_CFLAGS = context.env['CFLAGS'][:] # Get a *copy* of the old list
# Make the cast warning an error
context.env.Append(CFLAGS="-Werror")
ret = context.TryCompile("""
#define _GNU_SOURCE
#include <stddef.h>
#include <string.h>
int main(void) {
char buf[100];
int ret;
ret = strerror_r(24, buf, sizeof(buf));
return ret;
}
""", '.c')
context.Result(ret)
context.env.Replace(CFLAGS=old_CFLAGS) # restore flags
return ret
def CheckCompilerOption(context, option):
context.Message('Checking if compiler accepts %s... ' % (option,))
old_CFLAGS = context.env['CFLAGS'][:] # Get a *copy* of the old list
context.env.Append(CFLAGS=option)
new_CFLAGS = context.env['CFLAGS'][:] # Get a *copy* of the old list
# we don't want to use options that gernerate warnings.
context.env.Append(CFLAGS="-Werror")
ret = context.TryLink("""
int main(int argc, char **argv) {
(void) argc; (void) argv;
return 0;
}
""", '.c')
if ret:
# worked, remove the -Werror
context.env.Replace(CFLAGS=new_CFLAGS)
else:
context.env.Replace(CFLAGS=old_CFLAGS)
context.Result(ret)
return ret
# Check if this compiler is C11 or better
def CheckC11(context):
context.Message('Checking if compiler is C11... ')
ret = context.TryLink("""
#if (__STDC_VERSION__ < 201112L)
#error Not C11
#endif
int main(int argc, char **argv) {
(void) argc; (void) argv;
return 0;
}
""", '.c')
context.Result(ret)
return ret
def GetPythonValue(context, name, imp, expr, brief=False):
"""Get a value from the target python, not the running one."""
context.Message('Checking Python %s... ' % name)
if context.env['target_python']:
command = (context.env['target_python'] + " $SOURCE > $TARGET")
text = "%s; print(%s)" % (imp, expr)
# TryAction returns (1, outputStr), or (0, '') on fail
(status, value) = context.TryAction(command, text, '.py')
# do not disable python because this failed
# maybe testing for newer python feature
else:
# FIXME: this ignores imp
status = 1
value = str(eval(expr))
if 1 == status:
# we could convert to str(), but caching turns it into bytes anyway
value = value.strip()
if brief is True:
context.did_show_result = 1
print("ok")
context.Result(value)
# return value
return value
def GetLoadPath(context):
context.Message("Getting system load path... ")
cleaning = env.GetOption('clean')
helping = env.GetOption('help')
# Always set up LIBPATH so that cleaning works properly.
# FIXME: use ${SRCDIR}?
env.Prepend(LIBPATH=[os.path.realpath(os.curdir)])
# from scons 3.0.5, any changes to env after this, until after
# config.Finish(), will be lost. Use config.env until then.
config = Configure(env, custom_tests={
'CheckC11': CheckC11,
'CheckCompilerOption': CheckCompilerOption,
'CheckFlt_Eval_Method': CheckFlt_Eval_Method,
'CheckPKG': CheckPKG,
'CheckStrerror_r': CheckStrerror_r,
'GetPythonValue': GetPythonValue,
})
# Use print, rather than announce, so we see it in -s mode.
print("This system is: %s" % sys.platform)
libgps_flags = []
rtlibs = []
bluezflags = []
capflags = []
confdefs = []
dbusflags = []
adoc_prog = False
ncurseslibs = []
mathlibs = []
xtlibs = []
tiocmiwait = True # For cleaning, which works on any OS
usbflags = []
have_dia = False
# canplayer is part of can-utils, required for NMEA 2000 tests
have_canplayer = False
have_coverage = False
have_cppcheck = False
have_flake8 = False
have_pycodestyle = False
have_pylint = False
have_scan_build = False
have_smilint = False
have_tar = False
have_valgrind = False
# skip config part if cleaning or helping.
# per SCons 4.0.1 doc: Section 23.9. Not Configuring When Cleaning Targets
if not cleaning and not helping:
# OS X aliases gcc to clang
if (sys.platform != config.env['target_platform']):
announce("Target system is: %s" % config.env['target_platform'])
if 'CCVERSION' in env:
announce("cc is %s, version %s" % (env['CC'], env['CCVERSION']))
else:
# sometimes scons can not determine clang version
announce("cc is %s, WARNING version is unknown" % env['CC'])
# clang accepts -pthread, then warns it is unused.
if not config.CheckCC():
announce("ERROR: CC doesn't work")
if ((config.CheckCompilerOption("-pthread") and
not config.env['target_platform'].startswith('darwin'))):
config.env.MergeFlags("-pthread")
if config.env['target_platform'].startswith('openbsd7'):
# as of 5 Jan 23:
# scons 4.4.0 with clang 13.0.0 has trouble determining clang version.
# Then fails to add -fPIC. So we force it here:
config.env.Append(CCFLAGS=['-fPIC'])
confdefs = ["/* gpsd_config.h generated by scons, do not hand-hack. */\n"]
confdefs.append('#ifndef GPSD_CONFIG_H\n')
confdefs.append('#define VERSION "%s"' % gpsd_version)
confdefs.append('#define REVISION "%s"' % gpsd_revision)
confdefs.append('#define GPSD_PROTO_VERSION_MAJOR %u' % api_version_major)
confdefs.append('#define GPSD_PROTO_VERSION_MINOR %u' % api_version_minor)
confdefs.append('#define GPSD_URL "%s"\n' % website)
# TODO: Move these into an if block only on systems with glibc.
# needed for isfinite(), pselect(), etc.
# for strnlen() before glibc 2.10
# glibc 2.10+ needs 200908L (or XOPEN 700+) for strnlen()
# on newer glibc _DEFAULT_SOURCE resets _POSIX_C_SOURCE
# we set it just in case
confdefs.append('#if !defined(_POSIX_C_SOURCE)')
confdefs.append('#define _POSIX_C_SOURCE 200809L')
confdefs.append('#endif\n')
# for daemon(), cfmakeraw(), strsep() and setgroups()
# on glibc 2.19+
# may also be added by pkg_config
# on linux this eventually sets _USE_XOPEN
confdefs.append('#if !defined(_DEFAULT_SOURCE)')
confdefs.append('#define _DEFAULT_SOURCE')
confdefs.append('#endif\n')
# sys/un.h, and more, needs __USE_MISC with glibc and osX