-
Notifications
You must be signed in to change notification settings - Fork 7
/
make_functable.sh
executable file
·133 lines (123 loc) · 3.6 KB
/
make_functable.sh
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash
# Explicitly include headers
declare -a include_headers=(
"drivers/usb_ethernet.h"
"include/lwip/etharp.h"
"include/lwip/ethip6.h"
"include/lwip/igmp.h"
"include/lwip/snmp.h"
"include/lwip/stats.h"
"include/lwip/ip4.h"
"include/lwip/ip4_addr.h"
"include/lwip/ip4_frag.h"
"include/lwip/ip6.h"
"include/lwip/ip6_addr.h"
"include/lwip/ip6_frag.h"
"include/lwip/ip6_zone.h"
"include/lwip/ip.h"
"include/lwip/ip_addr.h"
"include/lwip/autoip.h"
"include/lwip/pbuf.h"
"include/lwip/mem.h"
"include/lwip/memp.h"
"include/lwip/init.h"
"include/lwip/netif.h"
"include/lwip/dhcp.h"
"include/lwip/dns.h"
"include/lwip/nd6.h"
"include/lwip/raw.h"
"include/lwip/tcp.h"
"include/lwip/altcp.h"
"include/lwip/altcp_tcp.h"
"include/lwip/tcpbase.h"
"include/lwip/udp.h"
)
# Remove any prototypes disabled by macros to avoid errors
declare -a excluded_functions=(
"etharp_add_static_entry"
"etharp_remove_static_entry"
"mib2_add_arp_entry"
"mib2_add_ip4"
"mib2_add_route_ip4"
"mib2_netif_added"
"mib2_netif_removed"
"mib2_remove_arp_entry"
"mib2_remove_ip4"
"mib2_remove_route_ip4"
"mib2_udp_bind"
"mib2_udp_unbind"
"ip4_debug_print"
"ip4_output_hinted"
"ip4_route_src"
"ip6_debug_print"
"ip6_output_hinted"
"pbuf_fill_chksum"
"pbuf_split_64k"
"memp_malloc_fn"
"netif_get_loopif"
"dhcp_set_ntp_servers"
"dns_local_addhost"
"dns_local_iterate"
"dns_local_lookup"
"dns_local_removehost"
"TCP_PCB_COMMON"
"lwip_tcp_event"
"tcp_ext_arg_alloc_id"
"tcp_ext_arg_get"
"tcp_ext_arg_set"
"tcp_ext_arg_set_callbacks"
"altcp_keepalive_disable"
"altcp_keepalive_enable"
"udp_debug_print"
"udp_send_chksum"
"udp_sendto_chksum"
"udp_sendto_if_chksum"
"udp_sendto_if_src_chksum"
"ip_reass_init" # for whatever reason this prototype doesn't have a C func
)
# output_functable keeps a running list of functions we have already put into the table
# the order of functions of the functable order cannot change for forward compatibility.
output_functable=src/functable.dat
# functable_c is the C code used to reserve the functiontable in the application
output_c=src/functable.asm
[[ ! -f $output_functable ]] && touch $output_functable
# Function to process files
process_file() {
local file="src/$1" # access needs relative to this dir
echo "Processing file: $file"
/usr/local/bin/ctags -f- --kinds-C=p $file | awk '{ print $1; }' | while read -r line; do
skip=0
if ! grep -Fxq "$line" "$output_functable"; then
for exclude in "${excluded_functions[@]}"; do
if [[ "$exclude" == $line ]]; then
echo "found $line in excluded_headers, skipping"
skip=1
break
fi
done
if [ $skip -eq 0 ]; then
echo "appending function: $line"
echo "$line" >> "$output_functable"
fi
fi
done
}
# Logic
rm $output_c
echo "section .rodata" >> $output_c
echo "public _app_library_table" >> $output_c
echo "" >> $output_c
echo "_app_library_table:" >> $output_c
for file in "${include_headers[@]}"; do
# Find all C header files specified
process_file "$file"
# echo "#include \"$file\"" >> $output_c
done
while read line; do
echo " dl _$line" >> $output_c
done < $output_functable
echo "" >> $output_c
echo "" >> $output_c
while read line; do
echo "extern _$line" >> $output_c
done < $output_functable