1 | #! /bin/bash |
---|
2 | # |
---|
3 | # Temporary hack of a script to get FreeBSD user space header |
---|
4 | # files and network libc source code into this tree. |
---|
5 | # |
---|
6 | # NOTE: libc and include are NOT in the FreeBSD checkout used for the |
---|
7 | # USB and TCP/IP stacks. This has to be addressed. |
---|
8 | # |
---|
9 | # This probably could be integrated into the main Python script. |
---|
10 | # But so far, there are no real transformations needed and the |
---|
11 | # script just performs two tasks: |
---|
12 | # |
---|
13 | # + copies source files from FreeBSD libc and include files into this tree |
---|
14 | # + generates "wrapper" header files for the public network .h files |
---|
15 | # |
---|
16 | src=/home/joel/newbsd/git/freebsd-8.2 |
---|
17 | dest=/home/joel/newbsd/git/rtems-libbsd/freebsd-userspace |
---|
18 | |
---|
19 | progname=${0##*/} # fast basename hack for ksh, bash |
---|
20 | |
---|
21 | USAGE=\ |
---|
22 | "usage: $progname [ -opts ] |
---|
23 | -v -- verbose |
---|
24 | -f DIR -- FreeBSD directory |
---|
25 | -r DIR -- rtems-libbsd top directory |
---|
26 | " |
---|
27 | |
---|
28 | check_status() |
---|
29 | { |
---|
30 | if [ $1 -ne 0 ] ; then |
---|
31 | shift |
---|
32 | echo "$USAGE" >&2 |
---|
33 | echo >&2 |
---|
34 | echo "FAILED: " "$*" >&2 |
---|
35 | exit 1 |
---|
36 | fi |
---|
37 | } |
---|
38 | |
---|
39 | usage() |
---|
40 | { |
---|
41 | echo "$USAGE" >&2 |
---|
42 | exit 1 |
---|
43 | } |
---|
44 | |
---|
45 | # |
---|
46 | # process the options |
---|
47 | # |
---|
48 | # defaults for getopt vars |
---|
49 | # |
---|
50 | |
---|
51 | src=NOTSET |
---|
52 | dest=NOTSET |
---|
53 | verbose="no" |
---|
54 | |
---|
55 | while getopts "vf:r:" OPT |
---|
56 | do |
---|
57 | case "$OPT" in |
---|
58 | v) verbose="yes";; |
---|
59 | f) src="$OPTARG";; |
---|
60 | r) dest="$OPTARG";; |
---|
61 | *) usage;; |
---|
62 | esac |
---|
63 | done |
---|
64 | |
---|
65 | # Check arguments specified |
---|
66 | test ${src} != "NOTSET" |
---|
67 | check_status $? "FreeBSD source directory not specified" |
---|
68 | |
---|
69 | test ${dest} != "NOTSET" |
---|
70 | check_status $? "rtems-libbsd source directory not specified" |
---|
71 | |
---|
72 | # Check that they are directories |
---|
73 | test -d ${src} |
---|
74 | check_status $? "FreeBSD source directory is not a directory" |
---|
75 | |
---|
76 | test -d ${dest} |
---|
77 | check_status $? "rtems-libbsd source directory is not a directory" |
---|
78 | |
---|
79 | # Check that they appear to be the right directories |
---|
80 | test -d ${src}/include |
---|
81 | check_status $? "FreeBSD source directory does not have include directory" |
---|
82 | |
---|
83 | test -d ${src}/lib/libc |
---|
84 | check_status $? "FreeBSD source directory does not have libc directory" |
---|
85 | |
---|
86 | test -d ${dest}/freebsd-userspace |
---|
87 | check_status $? "rtems-libbsd source directory does not have freebsd-userspace directory" |
---|
88 | |
---|
89 | dest=${dest}/freebsd-userspace |
---|
90 | |
---|
91 | # source files to simply copy |
---|
92 | while read f |
---|
93 | do |
---|
94 | d=`dirname $f` |
---|
95 | test -d ${dest}/${d} || mkdir -p ${dest}/${d} |
---|
96 | test -r ${src}/${f} |
---|
97 | check_status $? "${src}/${f} is not present" |
---|
98 | |
---|
99 | test ${verbose} = "yes" && echo "Simple copy $f" |
---|
100 | cp ${src}/${f} ${dest}/${d} |
---|
101 | done <<EOF |
---|
102 | include/db.h |
---|
103 | include/ifaddrs.h |
---|
104 | include/netdb.h |
---|
105 | include/nsswitch.h |
---|
106 | include/resolv.h |
---|
107 | include/arpa/nameser_compat.h |
---|
108 | include/arpa/inet.h |
---|
109 | sys/net/ethernet.h |
---|
110 | sys/sys/syslog.h |
---|
111 | lib/libc/include/libc_private.h |
---|
112 | lib/libc/include/namespace.h |
---|
113 | lib/libc/include/nss_tls.h |
---|
114 | lib/libc/include/reentrant.h |
---|
115 | lib/libc/include/resolv_mt.h |
---|
116 | lib/libc/include/un-namespace.h |
---|
117 | lib/libc/inet/inet_addr.c |
---|
118 | lib/libc/inet/inet_cidr_ntop.c |
---|
119 | lib/libc/inet/inet_cidr_pton.c |
---|
120 | lib/libc/inet/inet_lnaof.c |
---|
121 | lib/libc/inet/inet_makeaddr.c |
---|
122 | lib/libc/inet/inet_neta.c |
---|
123 | lib/libc/inet/inet_net_ntop.c |
---|
124 | lib/libc/inet/inet_netof.c |
---|
125 | lib/libc/inet/inet_net_pton.c |
---|
126 | lib/libc/inet/inet_network.c |
---|
127 | lib/libc/inet/inet_ntoa.c |
---|
128 | lib/libc/inet/inet_ntop.c |
---|
129 | lib/libc/inet/inet_pton.c |
---|
130 | lib/libc/inet/nsap_addr.c |
---|
131 | lib/libc/net/netdb_private.h |
---|
132 | lib/libc/net/res_config.h |
---|
133 | EOF |
---|
134 | |
---|
135 | # disable BIND_4_COMPAT since it trips a weird endian issue in nameser_compat.h |
---|
136 | sed -e 's/#define BIND_4_COMPAT/\/* #define BIND_4_COMPAT *\//' \ |
---|
137 | <${src}/include/arpa/nameser.h \ |
---|
138 | >${dest}/include/arpa/nameser.h |
---|
139 | |
---|
140 | # source files to prepend "include of local/port_before.h" |
---|
141 | while read f |
---|
142 | do |
---|
143 | d=`dirname $f` |
---|
144 | test -d ${dest}/${d} || mkdir -p ${dest}/${d} |
---|
145 | test -r ${src}/${f} |
---|
146 | check_status $? "${src}/${f} is not present" |
---|
147 | |
---|
148 | test ${verbose} = "yes" && echo "Copy with prepend $f" |
---|
149 | |
---|
150 | ( echo "#include \"port_before.h\""; echo ; cat ${src}/${f} ) >${dest}/${f} |
---|
151 | done <<EOF |
---|
152 | lib/libc/net/base64.c |
---|
153 | lib/libc/net/ether_addr.c |
---|
154 | lib/libc/net/gethostbydns.c |
---|
155 | lib/libc/net/gethostbyht.c |
---|
156 | lib/libc/net/gethostbynis.c |
---|
157 | lib/libc/net/gethostnamadr.c |
---|
158 | lib/libc/net/getifaddrs.c |
---|
159 | lib/libc/net/getifmaddrs.c |
---|
160 | lib/libc/net/getnameinfo.c |
---|
161 | lib/libc/net/getnetbydns.c |
---|
162 | lib/libc/net/getnetbyht.c |
---|
163 | lib/libc/net/getnetbynis.c |
---|
164 | lib/libc/net/getnetnamadr.c |
---|
165 | lib/libc/net/getproto.c |
---|
166 | lib/libc/net/getprotoent.c |
---|
167 | lib/libc/net/getprotoname.c |
---|
168 | lib/libc/net/getservent.c |
---|
169 | EOF |
---|
170 | |
---|
171 | |
---|
172 | # files to "include with freebsd" |
---|
173 | while read f |
---|
174 | do |
---|
175 | d=`dirname $f` |
---|
176 | test -d include/${d}/${d} || mkdir -p include/${d}/${d} |
---|
177 | |
---|
178 | test ${verbose} = "yes" && echo "Generate wrapper $f" |
---|
179 | echo "#include <freebsd/${f}>" > include/${f} |
---|
180 | done <<EOF |
---|
181 | net/if.h |
---|
182 | net/if_dl.h |
---|
183 | net/if_types.h |
---|
184 | net/in.h |
---|
185 | net/route.h |
---|
186 | netinet/in.h |
---|
187 | sys/socket.h |
---|
188 | sys/sysctl.h |
---|
189 | EOF |
---|
190 | |
---|
191 | |
---|
192 | # empty files |
---|
193 | while read f |
---|
194 | do |
---|
195 | test ${verbose} = "yes" && echo "Generate empty file $f" |
---|
196 | echo "/* empty file */" > ${f} |
---|
197 | done <<EOF |
---|
198 | local/pthread_np.h |
---|
199 | local/sys/_pthreadtypes.h |
---|
200 | EOF |
---|
201 | |
---|
202 | |
---|
203 | # Fix syslog.h issues... |
---|
204 | echo "#include <sys/syslog.h>" > local/syslog.h |
---|
205 | |
---|