• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash -e
2#
3# Copyright (c) 2012 The Chromium Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7# This script is used to compare vpx_config.h and vpx_config.asm to
8# verify the two files match.
9#
10# Arguments:
11#
12# -h - C Header file.
13# -a - ASM file.
14# -p - Print the options if correct.
15# -o - Output file.
16#
17# Usage:
18#
19# # Compare the two configuration files and output the final results.
20# ./lint_config.sh -h vpx_config.h -a vpx_config.asm -o libvpx.config -p
21
22export LC_ALL=C
23print_final="no"
24
25while getopts "h:a:o:p" flag
26do
27  if [ "$flag" = "h" ]; then
28    header_file=$OPTARG
29  elif [ "$flag" = "a" ]; then
30    asm_file=$OPTARG
31  elif [ "$flag" = "o" ]; then
32    out_file=$OPTARG
33  elif [ "$flag" = "p" ]; then
34    print_final="yes"
35  fi
36done
37
38if [ -z "$header_file" ]; then
39  echo "Header file not specified."
40  false
41  exit
42fi
43
44if [ -z "$asm_file" ]; then
45  echo "ASM file not specified."
46  false
47  exit
48fi
49
50# Concat header file and assembly file and select those ended with 0 or 1.
51combined_config="$(cat $header_file $asm_file | grep -E ' +[01] *$')"
52
53# Extra filtering for known exceptions.
54combined_config="$(echo "$combined_config" | grep -v DO1STROUNDING)"
55
56# Remove all spaces.
57combined_config="$(echo "$combined_config" | sed 's/[ \t]//g')"
58
59# Remove #define in the header file.
60combined_config="$(echo "$combined_config" | sed 's/.*define//')"
61
62# Remove equ in the ASM file.
63combined_config="$(echo "$combined_config" | sed 's/\.equ//')" # gas style
64combined_config="$(echo "$combined_config" | sed 's/equ//')" # rvds style
65
66# Remove %define in YASM ASM files.
67combined_config="$(echo "$combined_config" | sed 's/%define\s *//')" # yasm style
68
69# Remove useless comma in gas style assembly file.
70combined_config="$(echo "$combined_config" | sed 's/,//')"
71
72# Substitute 0 with =no.
73combined_config="$(echo "$combined_config" | sed 's/0$/=no/')"
74
75# Substitute 1 with =yes.
76combined_config="$(echo "$combined_config" | sed 's/1$/=yes/')"
77
78# Find the mismatch variables.
79odd_config="$(echo "$combined_config" | sort | uniq -u)"
80odd_vars="$(echo "$odd_config" | sed 's/=.*//' | uniq)"
81
82for var in $odd_vars; do
83  echo "Error: Configuration mismatch for $var."
84  echo "Header file: $header_file"
85  echo "$(cat -n $header_file | grep "$var[ \t]")"
86  echo "Assembly file: $asm_file"
87  echo "$(cat -n $asm_file | grep "$var[ \t]")"
88  echo ""
89done
90
91if [ -n "$odd_vars" ]; then
92  false
93  exit
94fi
95
96if [ "$print_final" = "no" ]; then
97  exit
98fi
99
100# Do some additional filter to make libvpx happy.
101combined_config="$(echo "$combined_config" | grep -v ARCH_X86=no)"
102combined_config="$(echo "$combined_config" | grep -v ARCH_X86_64=no)"
103
104# Print out the unique configurations.
105if [ -n "$out_file" ]; then
106  echo "$combined_config" | sort | uniq > $out_file
107else
108  echo "$combined_config" | sort | uniq
109fi
110