1#!/usr/bin/perl -w
2# Copyright © 2012-2019 Jamie Zawinski <jwz@jwz.org>
3#
4# Permission to use, copy, modify, distribute, and sell this software and its
5# documentation for any purpose is hereby granted without fee, provided that
6# the above copyright notice appear in all copies and that both that
7# copyright notice and this permission notice appear in supporting
8# documentation.  No representations are made about the suitability of this
9# software for any purpose.  It is provided "as is" without express or
10# implied warranty.
11#
12# Created: 20-Jun-2012.
13
14require 5;
15#use diagnostics;	# Fails on some MacOS 10.5 - 10.7 systems
16use strict;
17
18my $progname = $0; $progname =~ s@.*/@@g;
19my ($version) = ('$Revision: 1.5 $' =~ m/\s(\d[.\d]+)\s/s);
20
21my $verbose = 0;
22
23sub sanity_check() {
24
25  my $fail = '';
26  my $d1 = $ENV{SDK_DIR} || '';
27  my $d2 = '/usr/include/netinet/';
28  my $d3 = $d2;
29
30  if (! $d1) {
31    print STDERR "ERROR: SDK_DIR unset\n";
32    exit 1;
33  }
34
35  if (! -d $d3) {
36    my @dirs = glob ("/Applications/Xcode.app/Contents/Developer/" .
37                     "Platforms/MacOSX.platform/Developer/SDKs/" .
38                     "MacOSX*sdk/usr/include/netinet");
39    @dirs = sort @dirs;
40    $d3 = $dirs[$#dirs] . "/" if @dirs;
41  }
42
43  if (! -d $d3) {
44    print STDERR "ERROR: There is no $d3 on this system!\n";
45    exit 1;
46  }
47
48  foreach my $f ('ip.h', 'in_systm.h', 'ip_icmp.h', 'ip_var.h', 'udp.h') {
49    $fail .= "\tsudo ln -sf $d3$f $d1$d2\n"
50      unless (-f "$d1$d2$f");
51  }
52
53  exit (0) unless $fail;
54
55  print STDERR "ERROR:\t" . join(' ',  # "\n\t",
56     'The "Sonar" module won\'t build properly unless you repair your',
57     'SDK first.  The ICMP header files are missing from the SDK.',
58     'Fix it by doing this:') .
59       "\n\n$fail\n";
60  exit (1);
61}
62
63if ($#ARGV >= 0) {
64  print STDERR "usage: $progname\n";
65  exit 1;
66}
67
68sanity_check();
69