assembler: Some r15 fixes
[b43-tools.git] / assembler / b43-asm
1 #!/bin/bash
2 #
3 #  b43-asm preprocessing frontend
4 #
5 #  Copyright (c) 2007 Michael Buesch <mb@bu3sch.de>
6 #  Licensed under the GNU/GPL version 2.
7 #
8
9
10 # The b43-asm backend binary
11 B43_ASM="b43-asm.bin"
12 # The C preprocessor binary
13 CPP="gcc -E"
14
15
16 # This variable is changed by the installer scripts.
17 installed=0
18 if [ $installed -eq 0 ] && [ -x "./$B43_ASM" ]; then
19         B43_ASM="./$B43_ASM"
20 fi
21
22 # Probe the CPP binary
23 $CPP --help >/dev/null 2>&1
24 if [ $? -ne 0 ]; then
25         echo "ERROR: Failed to execute the C preprocessor \"$CPP\""
26         exit 1
27 fi
28 # Probe the b43-asm binary
29 $B43_ASM a b --help >/dev/null 2>&1
30 if [ $? -ne 0 ]; then
31         echo "ERROR: Failed to execute the b43-asm binary \"$B43_ASM\""
32         exit 2
33 fi
34
35 if [ $# -lt 2 ]; then
36         $B43_ASM --help
37         exit 3
38 fi
39 infile="$1"
40 shift
41 outfile="$1"
42 shift
43
44 cpp_args=
45 if [ "$1" == "--cpp-args" ]; then
46         shift
47         while [ "$1" != "--" ]; do
48                 if [ $# -eq 0 ]; then
49                         echo "ERROR: --cpp-args must be terminated by --"
50                         exit 4
51                 fi
52                 cpp_args="$cpp_args $1"
53                 shift
54         done
55         shift
56 fi
57
58 if [ "$infile" != "-" ]; then
59         if ! [ -r "$infile" ]; then
60                 echo "ERROR: Can not read input file \"$infile\""
61                 exit 5
62         fi
63 fi
64
65 $CPP -x c++ -traditional-cpp $cpp_args "$infile" | $B43_ASM "-" "$outfile" --__real_infile "$infile" $@