freebsd-sources.pl revision 255577
1255577Sdes#!/usr/bin/perl -w
2255577Sdes#-
3255577Sdes# Copyright (c) 2013 Dag-Erling Sm��rgrav
4255577Sdes# All rights reserved.
5255577Sdes#
6255577Sdes# Redistribution and use in source and binary forms, with or without
7255577Sdes# modification, are permitted provided that the following conditions
8255577Sdes# are met:
9255577Sdes# 1. Redistributions of source code must retain the above copyright
10255577Sdes#    notice, this list of conditions and the following disclaimer.
11255577Sdes# 2. Redistributions in binary form must reproduce the above copyright
12255577Sdes#    notice, this list of conditions and the following disclaimer in the
13255577Sdes#    documentation and/or other materials provided with the distribution.
14255577Sdes#
15255577Sdes# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16255577Sdes# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17255577Sdes# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18255577Sdes# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19255577Sdes# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20255577Sdes# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21255577Sdes# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22255577Sdes# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23255577Sdes# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24255577Sdes# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25255577Sdes# SUCH DAMAGE.
26255577Sdes#
27255577Sdes# $Id$
28255577Sdes#
29255577Sdes
30255577Sdesuse strict;
31255577Sdesuse warnings;
32255577Sdesuse Text::Wrap;
33255577Sdes
34255577Sdesour @targets = qw(LIBUNBOUND DAEMON UBANCHOR CHECKCONF);
35255577Sdes
36255577Sdesour %target_names = (
37255577Sdes    LIBUNBOUND => "libunbound",
38255577Sdes    DAEMON => "unbound",
39255577Sdes    UBANCHOR => "unbound-anchor",
40255577Sdes    CHECKCONF => "unbound-checkconf",
41255577Sdes);
42255577Sdes
43255577Sdessub get_sources($) {
44255577Sdes    my ($target) = @_;
45255577Sdes    local $/;
46255577Sdes
47255577Sdes    open(MAKE, "-|", "make", "-V${target}_OBJ_LINK")
48255577Sdes	or die("failed to exec make: $!\n");
49255577Sdes    my $objs = <MAKE>;
50255577Sdes    close(MAKE);
51255577Sdes    chomp($objs);
52255577Sdes    $objs =~ s/\.l?o\b/.c/g;
53255577Sdes    return (split(/\s+/, $objs));
54255577Sdes}
55255577Sdes
56255577SdesMAIN:{
57255577Sdes    my %sources;
58255577Sdes    foreach my $target (@targets) {
59255577Sdes	$sources{$target} = {
60255577Sdes	    map({ $_ => 1 }
61255577Sdes		grep({ !exists($sources{LIBUNBOUND}->{$_}) }
62255577Sdes		     get_sources($target)))
63255577Sdes	};
64255577Sdes	print("# $target_names{$target}\n");
65255577Sdes	my $SRCS = fill("SRCS=\t", "\t", sort keys %{$sources{$target}});
66255577Sdes	$SRCS =~ s/\n/ \\\n/gm;
67255577Sdes	print("$SRCS\n");
68255577Sdes    }
69255577Sdes}
70255577Sdes
71255577Sdes1;
72255577Sdes
73