aboutsummaryrefslogtreecommitdiff
path: root/binary/static-gcc
diff options
context:
space:
mode:
Diffstat (limited to 'binary/static-gcc')
-rwxr-xr-xbinary/static-gcc158
1 files changed, 158 insertions, 0 deletions
diff --git a/binary/static-gcc b/binary/static-gcc
new file mode 100755
index 00000000..a4d865d5
--- /dev/null
+++ b/binary/static-gcc
@@ -0,0 +1,158 @@
1#!/usr/bin/env bash
2
3DIR="$( cd "$( dirname "$0" )" && pwd )"
4
5function log() { echo -- "$@" >> $DIR/log.txt; }
6
7function runlog() { log "$@"; "$@"; }
8
9log "---------------------------"
10log INP "$@"
11
12allargs=()
13sources=()
14objects=()
15etc=()
16libdirs=("/usr/lib")
17incdirs=()
18
19linking=0
20
21while [ "$1" ]
22do
23 allargs+=("$1")
24 if [ "$next_libdir" = "1" ]
25 then
26 libdirs+=("$1")
27 next_libdir=0
28 elif [ "$next_incdir" = "1" ]
29 then
30 incdirs+=("-I$1")
31 next_incdir=0
32 elif [ "$next_lib" = "1" ]
33 then
34 libs+=("$1")
35 next_lib=0
36 elif [ "$next_output" = "1" ]
37 then
38 output="$1"
39 next_output=0
40 else
41 case "$1" in
42 -*)
43 case "$1" in
44 -shared)
45 linking=1
46 ;;
47 -static)
48 linking=1
49 ;;
50 -o)
51 next_output=1
52 ;;
53 -c)
54 object=1
55 etc+=("$1")
56 ;;
57 -L)
58 next_libdir=1
59 ;;
60 -L*)
61 libdirs+=("${1:2}")
62 ;;
63 -I)
64 next_incdir=1
65 ;;
66 -I*)
67 incdirs+=("$1")
68 ;;
69 -l)
70 next_lib=1
71 ;;
72 -l*)
73 libs+=("${1:2}")
74 ;;
75 *)
76 etc+=("$1")
77 ;;
78 esac
79 ;;
80 *.c)
81 sources+=("$1")
82 ;;
83 *.o)
84 objects+=("$1")
85 ;;
86 *)
87 etc+=("$1")
88 ;;
89 esac
90 fi
91 shift
92done
93
94staticlibs=()
95for lib in "${libs[@]}"
96do
97 for libdir in "${libdirs[@]}"
98 do
99 staticlib="$libdir/lib$lib.a"
100 if [ -e "$staticlib" ]
101 then
102 staticlibs+=("$staticlib")
103 break
104 fi
105 done
106done
107
108oflag=()
109if [ "$output" != "" ]
110then
111 oflag=("-o" "$output")
112fi
113
114if [ "$linking" = "1" ]
115then
116 log LINK
117 if [ "${#sources[@]}" -gt 0 ]
118 then
119 for source in "${sources[@]}"
120 do
121 object="${source%.c}.o"
122 runlog gcc "${incdirs[@]}" "${etc[@]}" -c -o "$object" "$source"
123 [ "$?" = 0 ] || runlog exit $?
124 objects+=("$object")
125 done
126 fi
127
128 # runlog ar rcu "${oflag[@]}" "${objects[@]}" "${staticlibs[@]}"
129 echo "CREATE $output" > ar.script
130 for o in "${objects[@]}"
131 do
132 echo "ADDMOD $o" >> ar.script
133 done
134 for o in "${staticlibs[@]}"
135 do
136 echo "ADDLIB $o" >> ar.script
137 done
138 echo "SAVE" >> ar.script
139 echo "END" >> ar.script
140 cat ar.script | ar -M
141 [ "$?" = 0 ] || runlog exit $?
142
143 [ -e "$output" ] || {
144 exit 1
145 }
146
147 runlog ranlib "$output"
148 runlog exit $?
149elif [ "$object" = 1 ]
150then
151 log OBJECT
152 runlog gcc "${oflag[@]}" "${incdirs[@]}" "${etc[@]}" "${sources[@]}"
153 runlog exit $?
154else
155 log EXECUTABLE
156 runlog gcc "${allargs[@]}"
157 runlog exit $?
158fi