aboutsummaryrefslogtreecommitdiff
path: root/bin/mftl.awk
blob: 916348b20c4d18cc235eea2ee27229a9d8c69e78 (plain) (blame)
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
# Try to find the targets in a Makefile that look like they're targets the user
# could be reasonably expected to call directly

# Separators are space, tab, or colon
BEGIN { FS = "[ \t:]" }

# Skip comments
/^#/ { next }

# Join backslash-broken lines
/\\$/ {
    sub(/\\$/, "")
    line = line $0
    next
}
{
    $0 = line $0
    line = ""
}

# Check lines matching expected "targets:dependencies" format
/^[a-zA-Z0-9][a-zA-Z0-9./ \t_-]+:([^=]|$)/ {

    # Iterate through the targets that don't look like substitutions or
    # inference rules and stack them up into an array's keys to keep them
    # unique; this probably needs refinement
    for (i = 1; i < NF; i++)
        if ($i ~ /^[a-zA-Z0-9][a-zA-Z0-9.\/_-]*$/)
            ats[$i]++
}

# Print unique determined targets, sorted
END {
    sort = ""
    for (t in ats) {
        if (!sort)
            sort = "sort"
        print t | sort
    }
    if (sort)
        close(sort)
}