xref: /dpdk/devtools/check-dup-includes.sh (revision 5c451eb543fab68bb40ea6d0ed4090b14f0973e4)
1#! /bin/sh -e
2
3# Copyright 2017 Mellanox Technologies, Ltd. All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions
7# are met:
8#
9#   * Redistributions of source code must retain the above copyright
10#     notice, this list of conditions and the following disclaimer.
11#   * Redistributions in binary form must reproduce the above copyright
12#     notice, this list of conditions and the following disclaimer in
13#     the documentation and/or other materials provided with the
14#     distribution.
15#
16# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE  SOFTWARE.
23
24# Check C files in git repository for duplicated includes.
25# Usage: devtools/check-dup-includes.sh [directory]
26
27dir=${1:-$(dirname $(readlink -m $0))/..}
28cd $dir
29
30# speed up by ignoring Unicode details
31export LC_ALL=C
32
33for file in $(git ls-files '*.[ch]') ; do
34	sed -rn 's,^[[:space:]]*#include[[:space:]]*[<"](.*)[>"].*,\1,p' $file |
35	sort | uniq -d |
36	sed "s,^,$file: duplicated include: ,"
37done
38