Magellan Linux

Contents of /trunk/linux-libc-headers/headers.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 642 - (show annotations) (download) (as text)
Tue Dec 18 00:23:39 2007 UTC (16 years, 5 months ago) by niro
File MIME type: application/x-sh
File size: 43716 byte(s)
-synced with upstream

1 #!/bin/bash
2 #
3 # Minimal Sanitized Headers - Version 01.02
4 #
5 # Submit bugreports via http://headers.cross-lfs.org
6 #
7 #
8 # By Jim Gifford (scripts@jg555.com)
9 # Ken Moffat (ken@linxufromscratch.org)
10 # Seth Klein
11 #
12 # Based on research and work by Jürg Billeter and Mariusz Mazur
13 #
14 # Community Member Acknowledgement
15 #
16 # Ryan Oliver
17 # Joe Ciccone
18 # Matt Darcy
19 # Greg Schafer
20 # Tushar Teredesai
21 # D.J. Lucas
22 # Jeremy Huntwork
23 # Andrew Benton
24 # Florian Schanda
25 # Theo Schneider
26 # Roberto Nibali
27 #
28 # LFS/CLFS Build notes
29 #
30 # You will also need to copy over asm-generic to ensure you have all the
31 # necessary headers. In LLH they asm-generic these into the asm-{architecture}
32 # so there is no asm-generic.
33 #
34 # Headers Lists
35 # As of version 01.00 we have removed the headers lists from the scripts
36 # and put them into separate text files in lists directory. The file format
37 # is one header per line.
38 #
39 # Programs Required
40 #
41 # This version requires unifdef - get it at
42 #
43 # http://ftp.debian.org/debian/pool/main/u/unifdef/
44 #
45 #
46 # Conversion Process
47 #
48 # Removal of __KERNEL__ - These tags are only during the build of the kernel
49 #
50 # Conversion u and s variables to userspace variables is the following link
51 # for more information http://www.linuxdevices.com/articles/AT5340618290.html
52 #
53 # Removal of <linux/config.h> - Not needed for userspace contains kernel build
54 # information.
55 #
56 # Conversion of linux to __linux__ - converts to a userspace usable
57 #
58 # Removal of __iomem
59 # for more information http://lwn.net/Articles/102232/
60 #
61 # version.h is created so that all the kernel versioning information
62 # is available
63 #
64 # compiler.h is removed
65 #
66 #
67 # I386 Specific
68 #
69 #
70 # MIPS Specific
71 #
72 # CONFIG_64BIT and CONFIG_32BIT are not defined in userspace so we use
73 # __mips64.
74 #
75 # Make atomic.h the same as LLH.
76 #
77 #
78 # Sparc Specific
79 #
80 # RAW Headers use variables from the configuration to get the PAGE SIZE
81 # so we use a function that exists in glibc to figure it out.
82 #
83 #
84 # Creation of biarch headers for multilib builds
85 #
86 # Links that inspired my creation
87 #
88 # http://kerneltrap.org/node/365
89
90 usage() {
91 echo "usage:"
92 echo " $0 version=kernel_version {optional}"
93 echo "example: $0"
94 echo ""
95 echo "Optional:"
96 echo " check - checks to see if the header exists in unsantized headers"
97 echo " dump - dump headers name then create headers package"
98 echo " dumponly - dump headers name then exit"
99 echo " file - creates a file list"
100 echo " patchfile={patch} - utilize this patch"
101 exit 255
102 }
103
104 make_headers() {
105 for headers in $HEADERS; do
106 cd $ORIGDIR
107 HDR_DIRS=`find * -type d | grep $TYPE | cut -f1 -d'/' | sort -u`
108 for locate in $HDR_DIRS; do
109 cd $CURRENT_DIR/linux-headers-$VERSION.orig
110 LOCATE=`find */$locate -type f | grep -F "/$headers" | sort -u`
111 for file in $LOCATE; do
112 TEST1=`echo $file | grep -c /$TYPE/`
113 TEST2=`echo $file | grep -c /$TYPE-`
114 if [ "$TEST1" = "0" -a "$TEST2" = "0" ]; then
115 break
116 fi
117 header="$CURRENT_DIR/linux-headers-$VERSION/$file"
118
119 echo "Processing $file..."
120
121 install -m 644 "$file" "$header"
122
123 if grep -c __KERNEL__ "$header" >/dev/null; then
124 unifdef -e -U__KERNEL__ $header > $header.new
125 mv $header.new $header
126 fi
127
128 if [ "$DONT_CHANGE" = "no" ]; then
129 sed -e 's/\b[us]\(8\|16\|32\|64\)\b/__&/g' \
130 -e 's/\b__\(be\|le\)\(16\|32\|64\)\b/__u\2/g' \
131 -e 's/\b__force\b//g' \
132 -e 's/\b__iomem\b//g' \
133 -e 's/\b__attribute_const__\b//g' \
134 -e 's/\b__user\b//g' \
135 -e 's/ inline / __inline__ /g' \
136 -e 's/__kernel_sockaddr_/sockaddr_/g' \
137 -e 's/^#define $//' \
138 $header > $header.new
139 mv $header.new $header
140 fi
141
142 sed -e '/#include <asm.acpi.h>/d' \
143 -e '/#include <asm.archparam.h>/d' \
144 -e '/#include <asm.asm-offsets.h>/d' \
145 -e '/#include <asm.bug.h>/d' \
146 -e '/#include <asm.compiler.h>/d' \
147 -e '/#include <asm.cpu-info.h>/d' \
148 -e '/#include <asm.current.h>/d' \
149 -e '/#include <asm.dsp.h>/d' \
150 -e '/#include <asm.hack.h>/d' \
151 -e '/#include <asm.hazards.h>/d' \
152 -e '/#include <asm.hpet.h>/d' \
153 -e '/#include <asm.ide.h>/d' \
154 -e '/#include <asm.interrupt.h>/d' \
155 -e '/#include <asm.machtypes.h>/d' \
156 -e '/#include <asm.mach-types.h>/d' \
157 -e '/#include <asm.machvec_init.h>/d' \
158 -e '/#include <asm.mtd-xip.h>/d' \
159 -e '/#include <asm.offset.h>/d' \
160 -e '/#include <asm.offsets.h>/d' \
161 -e '/#include <asm.page.h>/d' \
162 -e '/#include <asm.percpu.h>/d' \
163 -e '/#include <asm.prefetch.h>/d' \
164 -e '/#include <asm.proc-fns.h>/d' \
165 -e '/#include <asm.rwclock.h>/d' \
166 -e '/#include <asm.sections.h>/d' \
167 -e '/#include <asm.serial-bigsur.h>/d' \
168 -e '/#include <asm.serial-ec3104.h>/d' \
169 -e '/#include <asm.spinlock_types.h>/d' \
170 -e '/#include <asm.thread_info.h>/d' \
171 -e '/#include <asm.uaccess.h>/d' \
172 -e '/#include <asm.virtconvert.h>/d' \
173 -e '/#include <asm.arch.at91rm9200.h>/d' \
174 -e '/#include <asm.arch.at91rm9200_sys.h>/d' \
175 -e '/#include <asm.arch.atomic.h>/d' \
176 -e '/#include <asm.arch.cm.h>/d' \
177 -e '/#include <asm.arch.hwregs.reg_map.h>/d' \
178 -e '/#include <asm.arch.hwregs.reg_rdwr.h>/d' \
179 -e '/#include <asm.arch.hwregs.timer_defs.h>/d' \
180 -e '/#include <asm.arch.idle.h>/d' \
181 -e '/#include <asm.arch.prcm.h>/d' \
182 -e '/#include <asm.mach.ide.h>/d' \
183 -e '/#include <kmalloc.h>/d' \
184 -e '/#include <linux.autoconf.h>/d' \
185 -e '/#include <linux.bio.h>/d' \
186 -e '/#include <linux.blkdev.h>/d' \
187 -e '/#include <linux.clk.h>/d' \
188 -e '/#include <linux.compiler.h>/d' \
189 -e '/#include <linux.config.h>/d' \
190 -e '/#include <linux.completion.h>/d' \
191 -e '/#include <linux.cpumask.h>/d' \
192 -e '/#include <linux.crc-ccitt.h>/d' \
193 -e '/#include <linux.dmaengine.h>/d' \
194 -e '/#include <linux.dma-mapping.h>/d' \
195 -e '/#include <linux.genetlink.h>/d' \
196 -e '/#include <linux.hardirq.h>/d' \
197 -e '/#include <linux.kref.h>/d' \
198 -e '/#include <linux.kobject.h>/d' \
199 -e '/#include <linux.mempolicy.h>/d' \
200 -e '/#include <linux.mutex.h>/d' \
201 -e '/#include <linux.nodemask.h>/d' \
202 -e '/#include <linux.profile.h>/d' \
203 -e '/#include <linux.rcupdate.h>/d' \
204 -e '/#include <linux.rwsem.h>/d' \
205 -e '/#include <linux.seq_file.h>/d' \
206 -e '/#include <linux.smp.h>/d' \
207 -e '/#include <linux.spinlock.h>/d' \
208 -e '/#include <linux.spinlock_types.h>/d' \
209 -e '/#include <linux.stat.h>/d' \
210 -e '/#include <linux.string.h>/d' \
211 -e '/#include <linux.sunrpc.msg_prot.h>/d' \
212 -e '/#include <linux.textsearch.h>/d' \
213 -e '/#include <linux.thread_info.h>/d' \
214 -e '/#include <linux.timer.h>/d' \
215 -e '/#include <linux.topology.h>/d' \
216 -e '/#include <linux.transport_class.h>/d' \
217 -e '/#include <linux.uaccess.h>/d' \
218 -e '/#include <linux.byteorder.generic.h>/d' \
219 -e '/endif .* __KERNEL__/d' \
220 -e 's/|| !defined (__KERNEL__)//g' \
221 -e 's/|| !defined(__KERNEL__)//g' \
222 -e 's/!defined(__KERNEL__) ..//g' \
223 -e 's/|| defined(__KERNEL__)//g' \
224 -e 's/defined(__KERNEL__) ..//g' \
225 -e 's/|| defined (__KERNEL__)//g' \
226 -e 's/#ifdef linux/#ifdef __linux__/g' \
227 -e 's/#ifndef linux/#ifndef __linux__/g' \
228 $header > $header.new
229 mv $header.new $header
230
231 case $header in *mips*)
232 sed -e 's/#ifdef CONFIG_32BIT/#ifndef __mips64/g' \
233 -e 's/#ifdef CONFIG_64BIT/#ifdef __mips64/g' \
234 $header > $header.new
235 mv $header.new $header
236 esac
237
238 case $header in *byteorder.h*)
239 unifdef -e -U__GNUC__ $header > $header.new
240 mv $header.new $header
241 esac
242
243 sed -e '/^$/N;/\n$/D' \
244 $header > $header.new
245
246 install -m 644 $header.new $header
247 rm $header.new
248 done
249 done
250 done
251 }
252
253 check_headers() {
254 for file in $CHECKHEADERS; do
255 TEST="`find * -name $file`"
256 if [ "$TEST" != "" ]; then
257 echo "$file was found"
258 else
259 echo "$file was not located." >> $CURRENT_DIR/missing_headers
260 fi
261 done
262 }
263 check_headers2() {
264 for file in $CHECKHEADERS; do
265 TEST="`find * -print0 | grep -FzZ $file`"
266 if [ "$TEST" != "" ]; then
267 echo "$file was found"
268 else
269 echo "$file was not located." >> $CURRENT_DIR/missing_headers
270 fi
271 done
272 }
273
274 clean_header() {
275 header=$1
276 sed -e '/^$/N;/\n$/D' \
277 -e 's@#if defined@#if defined@g' \
278 -e 's@#if !defined@#if !defined@g' \
279 $header > $header.new
280 mv $header.new $header
281 }
282
283 create_linux_header() {
284 echo "Creating include/$header..."
285 new_header=$NEWDIR/$header
286 echo -n "#ifndef LINUX_" > $new_header
287 HEADING=`echo $header | tr '[:lower:]' '[:upper:]' | cut -f2 -d/ | cut -f1 -d.`
288 echo -n "$HEADING" >> $new_header
289 echo "_H" >> $new_header
290 echo "" >> $new_header
291 echo "$CONTENT" >> $new_header
292 echo "" >> $new_header
293 echo "#endif" >> $new_header
294 }
295
296 create_asm_header() {
297 for dir in $DIRS; do
298 echo "Creating include/$dir/$header..."
299 DEFINE3="_H"
300 if [ "$dir" = "asm-alpha" ]; then
301 DEFINE1="__ALPHA_"
302 fi
303 if [ "$dir" = "asm-arm" -o "$dir" = "asm-arm26" ]; then
304 DEFINE1="_ASM_ARM_"
305 fi
306 if [ "$dir" = "asm-cris" ]; then
307 DEFINE1="_ASM_CRIS_"
308 fi
309 if [ "$dir" = "asm-frv" -o "$dir" = "asm-i386" -o \
310 "$dir" = "asm-mips" -o "$dir" = "asm-parisc" -o \
311 "$dir" = "asm-x86_64" ]; then
312 DEFINE1="_ASM_"
313 fi
314 if [ "$dir" = "asm-h8300" ]; then
315 DEFINE1="_H8300_"
316 fi
317 if [ "$dir" = "asm-ia64" ]; then
318 DEFINE1="_ASM_IA64_"
319 fi
320 if [ "$dir" = "asm-m32r" ]; then
321 DEFINE1="_ASM_M32R_"
322 fi
323 if [ "$dir" = "asm-m68k" ]; then
324 DEFINE1="_"
325 fi
326 if [ "$dir" = "asm-m68knommu" ]; then
327 DEFINE1="_M68KNOMMU_"
328 fi
329 if [ "$dir" = "asm-powerpc" ]; then
330 DEFINE1="_ASM_POWERPC_"
331 fi
332 if [ "$dir" = "asm-ppc" ]; then
333 DEFINE1="_ASM_PPC_"
334 fi
335 if [ "$dir" = "asm-s390" ]; then
336 DEFINE1="_S390_"
337 fi
338 if [ "$dir" = "asm-sh" ]; then
339 DEFINE1="__ASM_"
340 fi
341 if [ "$dir" = "asm-sh64" ]; then
342 DEFINE1="__ASM_SH64_"
343 fi
344 if [ "$dir" = "asm-sparc" ]; then
345 DEFINE1="__SPARC_"
346 fi
347 if [ "$dir" = "asm-sparc64" ]; then
348 DEFINE1="__SPARC64_"
349 fi
350 if [ "$dir" = "asm-um" ]; then
351 DEFINE1="__UM_"
352 fi
353 if [ "$dir" = "asm-v850" ]; then
354 DEFINE1="__V850_"
355 DEFINE3="_H__"
356 fi
357 if [ "$dir" = "asm-xtensa" ]; then
358 DEFINE1="_XTENSA_"
359 fi
360 DEFINE2=`echo $header | tr '[:lower:]' '[:upper:]' | cut -f2 -d/ | cut -f1 -d.`
361 echo -n "#ifndef $DEFINE1" > $NEWDIR/$dir/$header
362 echo -n "$DEFINE2" >> $NEWDIR/$dir/$header
363 echo "$DEFINE3" >> $NEWDIR/$dir/$header
364 echo "" >> $NEWDIR/$dir/$header
365 echo "$CONTENT" >> $NEWDIR/$dir/$header
366 echo "" >> $NEWDIR/$dir/$header
367 echo "#endif" >> $NEWDIR/$dir/$header
368 done
369 }
370
371 multilib_stubs() {
372 cd $CURRENT_DIR
373 STUBARCH1=$1
374 STUBARCH2=$2
375 STUBSWITCH=$3
376 HDRS=""
377 DIRS=""
378 for arch in ${STUBARCH1} ${STUBARCH2}; do
379 cd $NEWDIR/asm-${arch}
380 dirs=`find . -type d -printf "%P\n"`
381 hdrs=`find . -type f -name \*.h -printf "%P\n"`
382 DIRS=`echo ${DIRS} ${dirs} | sort -u`
383 HDRS=`echo ${HDRS} ${hdrs} | sort -u`
384 done
385
386 cd $CURRENT_DIR
387 # Create directories (if required) under include/asm
388 install -d $NEWDIR/asm-${STUBARCH1}-biarch
389 if [ "${DIRS}" != "" ]; then
390 for dir in ${DIRS}; do
391 install -d $NEWDIR/asm-${STUBARCH1}-biarch/${dir}
392 done
393 fi
394
395 for hdr in ${HDRS}; do
396 # include barrier
397 name=`basename ${hdr} | tr [a-z]. [A-Z]_`
398 cat > $NEWDIR/asm-${STUBARCH1}-biarch/${hdr} << EOF
399 #ifndef __STUB__${name}__
400 #define __STUB__${name}__
401
402 EOF
403 # check whether we exist in arch1
404 if [ -f linux-headers-$VERSION/include/asm-${STUBARCH1}/${hdr} ]; then
405 # check if we also exist arch2
406 if [ -f linux-headers-$VERSION/include/asm-${STUBARCH2}/${hdr} ]; then
407 # we exist in both
408 cat >> $NEWDIR/asm-${STUBARCH1}-biarch/${hdr} << EOF
409 #ifdef ${STUBSWITCH}
410 #include <asm-${STUBARCH1}/${hdr}>
411 #else
412 #include <asm-${STUBARCH2}/${hdr}>
413 #endif
414 EOF
415 else
416 # we only exist in arch1
417 cat >> $NEWDIR/asm-${STUBARCH1}-biarch/${hdr} << EOF
418 #ifdef ${STUBSWITCH}
419 #include <asm-${STUBARCH1}/${hdr}>
420 #endif
421 EOF
422 fi
423 # end arch1
424 else
425 # if we get here we only exist in arch2
426 cat >> $NEWDIR/asm-${STUBARCH1}-biarch/${hdr} << EOF
427 #ifndef ${STUBSWITCH}
428 #include <asm-${STUBARCH2}/${hdr}>
429 #endif
430 EOF
431 fi
432 cat >> $NEWDIR/asm-${STUBARCH1}-biarch/${hdr} << EOF
433
434 #endif /* __STUB__${name}__ */
435 EOF
436 done
437 }
438
439 change_header() {
440 FIX_HEADER=$NEWDIR/linux/$HEADER_FILE
441 echo "Fixing include/linux/$HEADER_FILE..."
442 sed -e "s/#define $HEADER_NAME/#define $HEADER_NAME\n\nNeXtLiNe/" $FIX_HEADER > $FIX_HEADER.new
443 cp $FIX_HEADER.new $FIX_HEADER
444 sed -e "s@NeXtLiNe@$HEADER_UPDATE@" $FIX_HEADER > $FIX_HEADER.new
445 mv $FIX_HEADER.new $FIX_HEADER
446 }
447
448 # Input Check
449 #
450 if [ "$1" = "" ]; then
451 usage
452 fi
453
454 while [ $# -gt 0 ]; do
455 case $1 in
456
457 check)
458 CHECK=yes
459 ;;
460
461 file)
462 FILE=yes
463 ;;
464
465 dump)
466 DUMP=yes
467 ;;
468
469 patchfile=*)
470 TEMPPATCH=`echo $1 | awk -F= '{print $2;}'`
471 if [ "$PATCHES" = "" ]; then
472 PATCHES="$TEMPPATCH"
473 else
474 PATCHES="$PATCHES $TEMPPATCH"
475 fi
476 ;;
477
478 dumponly)
479 DUMP=yes
480 DUMPONLY=yes
481 ;;
482
483 version=*)
484 VERSION=`echo $1 | awk -F= '{print $2;}'`
485 ;;
486
487 *)
488 usage
489 ;;
490
491 esac
492 shift
493 done
494
495 # Checking for all the tools we need
496 TEST=`whereis awk | cut -f2 -d:`
497 if [ "$TEST" = "" ]; then
498 echo "Missing awk"
499 exit 254
500 fi
501 TEST=`whereis cp | cut -f2 -d:`
502 if [ "$TEST" = "" ]; then
503 echo "Missing cp."
504 exit 253
505 fi
506 TEST=`whereis install | cut -f2 -d:`
507 if [ "$TEST" = "" ]; then
508 echo "Missing install."
509 exit 252
510 fi
511 TEST=`whereis mv | cut -f2 -d:`
512 if [ "$TEST" = "" ]; then
513 echo "Missing mv."
514 exit 251
515 fi
516 TEST=`whereis pwd | cut -f2 -d:`
517 if [ "$TEST" = "" ]; then
518 echo "Missing pwd."
519 exit 250
520 fi
521 TEST=`whereis sed | cut -f2 -d:`
522 if [ "$TEST" = "" ]; then
523 echo "Missing sed."
524 exit 249
525 fi
526 TEST=`whereis rm | cut -f2 -d:`
527 if [ "$TEST" = "" ]; then
528 echo "Missing rm."
529 exit 248
530 fi
531 TEST=`whereis rmdir | cut -f2 -d:`
532 if [ "$TEST" = "" ]; then
533 echo "Missing rmdir."
534 exit 247
535 fi
536 TEST=`whereis tar | cut -f2 -d:`
537 if [ "$TEST" = "" ]; then
538 echo "Missing tar."
539 exit 246
540 fi
541 TEST=`whereis unifdef | cut -f2 -d:`
542 if [ "$TEST" = "" ]; then
543 echo "Missing unifdef."
544 exit 245
545 fi
546 TEST=`whereis wget | cut -f2 -d:`
547 if [ "$TEST" = "" ]; then
548 echo "Missing wget."
549 exit 244
550 fi
551
552 # Set Linux Version
553 P1=`echo $VERSION | cut -f1 -d.`
554 P2=`echo $VERSION | cut -f2 -d.`
555 P3=`echo $VERSION | cut -f3 -d.`
556 LINUXVERSION="$P1.$P2"
557
558 # Our Working Directories
559 CURRENT_DIR=`pwd -P`
560 ORIGDIR=$CURRENT_DIR/linux-headers-$VERSION.orig/include
561 NEWDIR=$CURRENT_DIR/linux-headers-$VERSION/include
562
563 # Headers to Sanitize
564 ASM_HEADERS=$(cat $CURRENT_DIR/lists/asm-headers)
565 ASM_ARCH_HEADERS=$(cat $CURRENT_DIR/lists/asm-arch-headers)
566 ASM_SYS_HEADERS=$(cat $CURRENT_DIR/lists/asm-sys-headers)
567
568 LINUX_HEADERS=$(cat $CURRENT_DIR/lists/linux-headers)
569
570 NOSANTIZE_ASM_HEADERS=$(cat $CURRENT_DIR/lists/no_santize-asm-headers)
571 NOSANTIZE_LINUX_HEADERS=$(cat $CURRENT_DIR/lists/no_santize-linux-headers)
572
573 BLANK_HEADERS=$(cat $CURRENT_DIR/lists/blank-headers)
574
575 ROOT_HEADERS=$(cat $CURRENT_DIR/lists/root-headers)
576 SYS_HEADERS=$(cat $CURRENT_DIR/lists/sys-headers)
577
578 GLIBC_HEADERS=$(cat $CURRENT_DIR/lists/glibc-headers)
579
580 COPY_HEADERS=$(cat $CURRENT_DIR/lists/copy-headers)
581
582 REMOVE_HEADERS=$(cat $CURRENT_DIR/lists/remove-headers)
583
584 if [ "$FILE" = "yes" ]; then
585 echo "Files List to $CURRENT_DIR/asm-list..."
586 for file in $ASM_HEADERS; do
587 echo "$file" >> $CURRENT_DIR/asm-list
588 done
589 echo "Files List to $CURRENT_DIR/linux-list..."
590 for file in $LINUX_HEADERS; do
591 echo "$file" >> $CURRENT_DIR/linux-list
592 done
593 exit
594 fi
595
596 if [ "$DUMP" = "yes" ]; then
597 echo "Dumping Files List to $CURRENT_DIR/asm-headers..."
598 echo "ASM Files Generic" > $CURRENT_DIR/asm-headers
599 echo "-----" >> $CURRENT_DIR/asm-headers
600 for file in $ASM_HEADERS; do
601 echo "$file" >> $CURRENT_DIR/asm-headers
602 done
603 echo "-----" >> $CURRENT_DIR/asm-headers
604 echo "ASM Architecture Specific Files" >> $CURRENT_DIR/asm-headers
605 echo "-----" >> $CURRENT_DIR/asm-headers
606 for file in $ASM_ARCH_HEADERS; do
607 echo "$file" >> $CURRENT_DIR/asm-headers
608 done
609 echo "-----" >> $CURRENT_DIR/asm-headers
610 echo "ASM Architecture Non Santize Files" >> $CURRENT_DIR/asm-headers
611 echo "-----" >> $CURRENT_DIR/asm-headers
612 for file in $NOSANTIZE_ASM_HEADERS; do
613 echo "$file" >> $CURRENT_DIR/asm-headers
614 done
615 echo "Dumping Files List to $CURRENT_DIR/linux-headers..."
616 echo "Linux Files" > $CURRENT_DIR/linux-headers
617 echo "-----" >> $CURRENT_DIR/linux-headers
618 for file in $LINUX_HEADERS; do
619 echo "$file" >> $CURRENT_DIR/linux-headers
620 done
621 echo "-----" >> $CURRENT_DIR/linux-headers
622 echo "Linux Non Santize Files" >> $CURRENT_DIR/linux-headers
623 echo "-----" >> $CURRENT_DIR/linux-headers
624 for file in $NOSANTIZE_LINUX_HEADERS; do
625 echo "$file" >> $CURRENT_DIR/linux-headers
626 done
627 if [ "$DUMPONLY" = "yes" ]; then
628 echo "Exiting - Dump only requested..."
629 exit 0
630 fi
631 fi
632
633 if ! [ -f linux-$VERSION.tar.bz2 ]; then
634 echo "Downloading kernel linux-$VERSION from kernel.org..."
635 wget --quiet http://www.kernel.org/pub/linux/kernel/v$P1.$P2/linux-$VERSION.tar.bz2
636 if [ "$?" != "0" ]; then
637 echo "Error during Download."
638 exit 255
639 fi
640 fi
641
642 echo "Decompressing Kernel Headers only..."
643 rm -rf linux-$VERSION linux-headers-$VERSION linux-headers-$VERSION.orig
644 tar --wildcards -jxf linux-$VERSION.tar.bz2 linux-$VERSION/include/*
645 if [ -e $CURRENT_DIR/patches/linux-$VERSION-REQUIRED-1.patch ]; then
646 if [ "$PATCHES" = "" ]; then
647 PATCHES="linux-$VERSION-REQUIRED-1.patch"
648 else
649 PATCHES="$PATCHES linux-$VERSION-REQUIRED-1.patch"
650 fi
651 fi
652 if [ -e $CURRENT_DIR/patches/linux-$VERSION-mips_headers-1.patch ]; then
653 if [ "$PATCHES" = "" ]; then
654 PATCHES="linux-$VERSION-mips_headers-1.patch"
655 else
656 PATCHES="$PATCHES linux-$VERSION-mips_headers-1.patch"
657 fi
658 fi
659 for PATCHFILE in $PATCHES; do
660 if [ -e "$CURRENT_DIR/patches/$PATCHFILE" ]; then
661 cd linux-$VERSION
662 echo "Patching Kernel Headers with $PATCHFILE..."
663 patch -Np1 -f -s -i $CURRENT_DIR/patches/$PATCHFILE
664 cd ..
665 fi
666 done
667
668 if [ "$CHECK" = "yes" ]; then
669 cd linux-headers-$VERSION
670 rm -f $CURRENT_DIR/missing_headers
671 echo "Checking ASM..."
672 CHECKHEADERS="$ASM_HEADERS $NOSANTIZE_ASM_HEADERS"
673 check_headers
674 CHECKHEADERS="$ASM_ARCH_HEADERS $NOSANTIZE_ASM_HEADERS"
675 check_headers2
676 echo "Checking Linux..."
677 CHECKHEADERS="$LINUX_HEADERS"
678 check_headers
679 CHECKHEADERS="$NOSANTIZE_LINUX_HEADERS"
680 check_headers2
681 echo "Report is located at $CURRENT_DIR/missing_headers."
682 rm -rf linux-headers-$VERSION
683 cd $CURRENT_DIR
684 exit 0
685 fi
686
687 echo "Renaming directory to linux-headers-$VERSION..."
688 mv linux-$VERSION linux-headers-$VERSION.orig
689
690 echo "Creating directory Structure..."
691 install -d linux-headers-$VERSION
692 cd $ORIGDIR
693 DIRS=`find * -type d`
694 cd $CURRENT_DIR
695 for dir in $DIRS; do
696 install -d $NEWDIR/$dir
697 done
698
699 DONT_CHANGE=no
700 TYPE=asm
701 HEADERS="$ASM_HEADERS"
702 if [ "$HEADERS" != "" ]; then
703 make_headers
704 fi
705
706 TYPE=asm
707 HEADERS=$ASM_ARCH_HEADERS
708 if [ "$HEADERS" != "" ]; then
709 make_headers
710 fi
711
712 TYPE=linux
713 HEADERS=$LINUX_HEADERS
714 if [ "$HEADERS" != "" ]; then
715 make_headers
716 fi
717
718 SETTYPE="byteorder dvb isdn lockd mtd netfilter netfilter_arp netfilter_bridge netfilter_ipv4 netfilter_ipv6
719 nfsd raid sunrpc tc_act tc_ematch"
720 for type in $SETTYPE; do
721 TYPE=linux
722 cd $ORIGDIR/linux
723 if [ -e $ORIGDIR/linux/$type ]; then
724 HEADERS=`find $type | grep .h | sed -e '/big_endian.h/d' | sed -e '/little_endian.h/d' | sort -u `
725 if [ "$HEADERS" != "" ]; then
726 make_headers
727 fi
728 fi
729 done
730
731 SETTYPE="acpi mtd scsi sound"
732 for type in $SETTYPE; do
733 TYPE="$type"
734 cd $ORIGDIR
735 if [ -e $ORIGDIR/$type ]; then
736 HEADERS=`find $type | grep .h | sort -u `
737 if [ "$HEADERS" != "" ]; then
738 make_headers
739 fi
740 fi
741 done
742
743 DONT_CHANGE=yes
744 TYPE=linux
745 HEADERS=$NOSANTIZE_LINUX_HEADERS
746 if [ "$HEADERS" != "" ]; then
747 make_headers
748 fi
749
750 TYPE=asm
751 HEADERS=$NOSANTIZE_ASM_HEADERS
752 if [ "$HEADERS" != "" ]; then
753 make_headers
754 fi
755
756 for header in $BLANK_HEADERS; do
757 CONTENT="/* Empty */"
758 TEST=`echo $header | grep -c linux/`
759 if [ "$TEST" = "1" ]; then
760 create_linux_header
761 else
762 DIRS=`echo $header | cut -f1 -d/`
763 header=`echo $header | sed -e "s@$DIRS/@@g"`
764 create_asm_header
765 fi
766 done
767
768 for header in $ROOT_HEADERS; do
769 new_header=`echo $header | cut -f2 -d/`
770 HEADING=`echo $header | tr '[:lower:]' '[:upper:]' | cut -f2 -d/ | cut -f1 -d.`
771 CONTENT="#include <$new_header>"
772 create_linux_header
773 done
774
775 for header in $SYS_HEADERS; do
776 new_header=`echo $header | cut -f2 -d/`
777 HEADING=`echo $header | tr '[:lower:]' '[:upper:]' | cut -f2 -d/ | cut -f1 -d.`
778 CONTENT="#include <sys/$new_header>"
779 create_linux_header
780 done
781
782 cd $NEWDIR
783 PLATFORM=`ls -1 asm-* -d | sed -e 's/asm-generic//g'`
784 for platform in $PLATFORM; do
785 ELF_H=$NEWDIR/$platform/elf.h
786 echo "Fixing include/$platform/elf.h..."
787 if [ -e $ELF_H ]; then
788 if [ "$platform" = "asm-alpha" ]; then
789 sed -e '/#include <asm.auxvec.h>/d' \
790 $ELF_H > $ELF_H.new
791 fi
792 if [ "$platform" = "asm-arm" -o "$platform" = "asm-cris" ]; then
793 sed -e '/#include <asm.user.h>/d' \
794 -e '/#include <asm.procinfo.h>/d' \
795 $ELF_H > $ELF_H.new
796 fi
797 if [ "$platform" = "asm-h8300" -o "$platform" = "asm-m68k" -o \
798 "$platform" = "asm-sparc" -o "$platform" = "asm-sparc64" ]; then
799 sed -e '/#include <asm.ptrace.h>/d' \
800 $ELF_H > $ELF_H.new
801 fi
802 if [ "$platform" = "asm-i386" -o "$platform" = "asm-x86_64" ]; then
803 sed -e '/#include <asm.ptrace.h>/d' \
804 -e '/#include <asm.processor.h>/d' \
805 -e '/#include <asm.system.h>/d' \
806 -e '/#include <asm.auxvec.h>/d' \
807 -e '/#include <linux.utsname.h>/d' \
808 $ELF_H > $ELF_H.new
809 fi
810 if [ "$platform" = "asm-ia64" ]; then
811 sed -e '/#include <asm.fpu.h>/d' \
812 -e '/#include <asm.auxvec.h>/d' \
813 $ELF_H > $ELF_H.new
814 fi
815 if [ "$platform" = "asm-m32r" ]; then
816 sed -e 's@#include <asm/user.h>@#include <asm/user.h>\n#include <asm/page.h>@' \
817 $ELF_H > $ELF_H.new
818 fi
819 if [ "$platform" = "asm-m68knommu" ]; then
820 sed -e '/#include <asm.ptrace.h>/d' \
821 -e '/#include <asm.user.h>/d' \
822 $ELF_H > $ELF_H.new
823 fi
824 if [ "$platform" = "asm-parisc" ]; then
825 sed -e 's@#include <asm/ptrace.h>@#include <asm/types.h>@' \
826 $ELF_H > $ELF_H.new
827 fi
828 if [ "$platform" = "asm-powerpc" ]; then
829 sed -e '/#include <asm.auxvec.h>/d' \
830 $ELF_H > $ELF_H.new
831 fi
832 if [ "$platform" = "asm-s390" ]; then
833 sed -e 's/#define __ASMS390_ELF_H/#define __ASMS390_ELF_H\n\nNeXtLiNe/' \
834 $ELF_H > $ELF_H.new
835 cp $ELF_H.new $ELF_H
836 sed -e 's@NeXtLiNe@#include <asm/ptrace.h>\n#include <asm/system.h>\n@' \
837 $ELF_H > $ELF_H.new
838 fi
839 if [ "$platform" = "asm-sparc64" ]; then
840 sed -e 's@#define __ASM_SPARC64_ELF_H@#define __ASM_SPARC64_ELF_H\n\n#include <asm/spitfire.h>\n@' \
841 $ELF_H > $ELF_H.new
842 fi
843 if [ "$platform" = "asm-sh" ]; then
844 sed -e 's@#define __ASM_SH_ELF_H@#define __ASM_SH_ELF_H\n\n#include <asm/ptrace.h>\n@' \
845 $ELF_H > $ELF_H.new
846 fi
847 if [ "$platform" = "asm-v850" ]; then
848 sed -e '/#include <asm.user.h>/d' \
849 -e '/#include <asm.byteorder.h/d' \
850 $ELF_H > $ELF_H.new
851 fi
852 if [ -e $ELF_H.new ]; then
853 cp $ELF_H.new $ELF_H
854 fi
855 clean_header $ELF_H
856 fi
857 done
858
859 cp $ORIGDIR/asm-ia64/page.h $NEWDIR/asm-ia64/page.h
860 PAGE_H=$NEWDIR/asm-ia64/page.h
861 echo "Processing include/asm-ia64/page.h..."
862 unifdef -e -UCONFIG_IA64_PAGE_SIZE_4KB -UCONFIG_IA64_PAGE_SIZE_8KB \
863 -UCONFIG_IA64_PAGE_SIZE_16KB -UCONFIG_IA64_PAGE_SIZE_64KB $PAGE_H > $PAGE_H.new
864 cp $PAGE_H.new $PAGE_H
865 sed -e 's/# error Unsupported page size./#define PAGE_SIZE\tsysconf (_SC_PAGE_SIZE)\nNeXtLiNe/' $PAGE_H > $PAGE_H.new
866 cp $PAGE_H.new $PAGE_H
867 sed -e 's/NeXtLiNe/\n#define PAGE_SHIFT\t(getpageshift())/' $PAGE_H > $PAGE_H.new
868 mv $PAGE_H.new $PAGE_H
869 clean_header $PAGE_H
870
871 cd $NEWDIR
872 PLATFORM=`ls -1 asm-* -d | sed -e 's/asm-generic//g' -e 's/asm-ia64//g'`
873 for platform in $PLATFORM; do
874 PAGE_H=$NEWDIR/$platform/page.h
875 echo "Creating include/$platform/page.h..."
876 if [ "$platform" = "asm-alpha" ]; then
877 FILEHEADER="_ALPHA_PAGE_H"
878 fi
879 if [ "$platform" = "asm-arm" -o "$platform" = "asm-arm26" ]; then
880 FILEHEADER="_ASMARM_PAGE_H"
881 fi
882 if [ "$platform" = "asm-cris" ]; then
883 FILEHEADER="_CRIS_PAGE_H"
884 fi
885 if [ "$platform" = "asm-h8300" ]; then
886 FILEHEADER="_H8300_PAGE_H"
887 fi
888 if [ "$platform" = "asm-i386" ]; then
889 FILEHEADER="_I386_PAGE_H"
890 fi
891 if [ "$platform" = "asm-m68k" ]; then
892 FILEHEADER="_M68K_PAGE_H"
893 fi
894 if [ "$platform" = "asm-m68knommu" ]; then
895 FILEHEADER="_M68KNOMMU_PAGE_H"
896 fi
897 if [ "$platform" = "asm-mips" -o "$platform" = "asm-frv" ]; then
898 FILEHEADER="_ASM_PAGE_H"
899 fi
900 if [ "$platform" = "asm-parisc" ]; then
901 FILEHEADER="_PARISC_PAGE_H"
902 fi
903 if [ "$platform" = "asm-ppc" ]; then
904 FILEHEADER="_PPC_PAGE_H"
905 fi
906 if [ "$platform" = "asm-powerpc" ]; then
907 FILEHEADER="_ASM_POWERPC_PAGE_H"
908 fi
909 if [ "$platform" = "asm-s390" ]; then
910 FILEHEADER="_S390_PAGE_H"
911 fi
912 if [ "$platform" = "asm-sh" ]; then
913 FILEHEADER="__ASM_SH_PAGE_H"
914 fi
915 if [ "$platform" = "asm-sh64" ]; then
916 FILEHEADER="__ASM_SH64_PAGE_H"
917 fi
918 if [ "$platform" = "asm-sparc" ]; then
919 FILEHEADER="_SPARC_PAGE_H"
920 fi
921 if [ "$platform" = "asm-sparc64" ]; then
922 FILEHEADER="_SPARC64_PAGE_H"
923 fi
924 if [ "$platform" = "asm-um" ]; then
925 FILEHEADER="__UM_PAGE_H"
926 fi
927 if [ "$platform" = "asm-v850" ]; then
928 FILEHEADER="__V850_PAGE_H__"
929 fi
930 if [ "$platform" = "asm-x86_64" ]; then
931 FILEHEADER="_X86_64_PAGE_H"
932 fi
933 if [ "$platform" = "asm-xtensa" ]; then
934 FILEHEADER="_XTENSA_PAGE_H"
935 fi
936 echo "#ifndef $FILEHEADER" > $PAGE_H
937 echo "#define $FILEHEADER" >> $PAGE_H
938 echo "" >> $PAGE_H
939 if [ "$platform" = "asm-alpha" ]; then
940 echo "#include <asm/pal.h>" >> $PAGE_H
941 fi
942 echo "#include <unistd.h>" >> $PAGE_H
943 if [ "$platform" = "asm-arm26" ]; then
944 echo "#define EXEC_PAGESIZE 32768" >> $PAGE_H
945 fi
946 echo "" >> $PAGE_H
947 echo "#define PAGE_SIZE sysconf (_SC_PAGE_SIZE)" >> $PAGE_H
948 echo "#define PAGE_SHIFT (getpageshift())" >> $PAGE_H
949 echo "#define PAGE_MASK (~(PAGE_SIZE-1))" >> $PAGE_H
950 echo "" >> $PAGE_H
951 if [ "$platform" = "asm-arm26" ]; then
952 echo "#define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK)">> $PAGE_H
953 fi
954 if [ "$platform" = "asm-mips" ]; then
955 echo "#ifdef CONFIG_LIMITED_DMA" >> $PAGE_H
956 echo "#define WANT_PAGE_VIRTUAL" >> $PAGE_H
957 echo "#endif" >> $PAGE_H
958 echo "" >> $PAGE_H
959 fi
960 if [ "$platform" = "asm-v850" ]; then
961 echo "#ifndef PAGE_OFFSET" >> $PAGE_H
962 echo "#define PAGE_OFFSET 0x0000000" >> $PAGE_H
963 echo "#endif" >> $PAGE_H
964 echo "" >> $PAGE_H
965 fi
966 echo "#endif /* ($FILEHEADER) */" >> $PAGE_H
967 clean_header $PAGE_H
968 done
969
970 PLATFORM="asm-m68k asm-sparc asm-sparc64"
971 for platform in $PLATFORM; do
972 KBIO_H=$NEWDIR/$platform/kbio.h
973 echo "Creating include/$platform/kbio.h..."
974 echo "#ifndef __LINUX_KBIO_H" > $KBIO_H
975 echo "#define __LINUX_KBIO_H" >> $KBIO_H
976 echo "" >> $KBIO_H
977 echo "#define KIOCTYPE _IOR('k', 9, int)" >> $KBIO_H
978 echo "" >> $KBIO_H
979 echo "#define KIOCLAYOUT _IOR('k', 20, int)" >> $KBIO_H
980 echo "" >> $KBIO_H
981 echo "enum {" >> $KBIO_H
982 echo " TR_NONE," >> $KBIO_H
983 echo " TR_ASCII," >> $KBIO_H
984 echo " TR_EVENT," >> $KBIO_H
985 echo " TR_UNTRANS_EVENT" >> $KBIO_H
986 echo "};" >> $KBIO_H
987 echo "" >> $KBIO_H
988 echo "#define KIOCGTRANS _IOR('k', 5, int)" >> $KBIO_H
989 echo "" >> $KBIO_H
990 echo "#define KIOCTRANS _IOW('k', 0, int)" >> $KBIO_H
991 echo "" >> $KBIO_H
992 echo "#define KIOCCMD _IOW('k', 8, int)" >> $KBIO_H
993 echo "" >> $KBIO_H
994 echo "#define KIOCSDIRECT _IOW('k', 10, int)" >> $KBIO_H
995 echo "" >> $KBIO_H
996 echo "#define KIOCSLED _IOW('k', 14, unsigned char)" >> $KBIO_H
997 echo "" >> $KBIO_H
998 echo "#define KIOCGLED _IOR('k', 15, unsigned char)" >> $KBIO_H
999 echo "struct kbd_rate {" >> $KBIO_H
1000 echo " unsigned char delay;" >> $KBIO_H
1001 echo " unsigned char rate; " >> $KBIO_H
1002 echo "};" >> $KBIO_H
1003 echo "" >> $KBIO_H
1004 echo "#define KIOCSRATE _IOW('k', 40, struct kbd_rate)" >> $KBIO_H
1005 echo "" >> $KBIO_H
1006 echo "#define KIOCGRATE _IOW('k', 41, struct kbd_rate)" >> $KBIO_H
1007 echo "" >> $KBIO_H
1008 echo "#define KBD_UP 0x80" >> $KBIO_H
1009 echo "" >> $KBIO_H
1010 echo "#define KBD_KEYMASK 0x7f" >> $KBIO_H
1011 echo "" >> $KBIO_H
1012 echo "#define KBD_IDLE 0x75" >> $KBIO_H
1013 echo "" >> $KBIO_H
1014 echo "#endif /* __LINUX_KBIO_H */" >> $KBIO_H
1015 clean_header $KBIO_H
1016 done
1017
1018 CACHE_H=$NEWDIR/asm-i386/cache.h
1019 echo "Fixing include/asm-i386/cache.h..."
1020 sed -e 's@CONFIG_X86_L1_CACHE_SHIFT@7@' $CACHE_H > $CACHE_H.new
1021 mv $CACHE_H.new $CACHE_H
1022 clean_header $CACHE_H
1023
1024 CACHE_H=$NEWDIR/asm-x86_64/cache.h
1025 echo "Fixing include/asm-x86_64/cache.h..."
1026 sed -e 's@CONFIG_X86_L1_CACHE_SHIFT@7@' $CACHE_H > $CACHE_H.new
1027 mv $CACHE_H.new $CACHE_H
1028 clean_header $CACHE_H
1029
1030 PARAM_H=$NEWDIR/asm-i386/param.h
1031 echo "Fixing include/asm-i386/param.h..."
1032 sed -e 's@#define HZ 100@#define HZ\t\t100\n#endif\n\nNeXtLiNe\n@' $PARAM_H > $PARAM_H.new
1033 cp $PARAM_H.new $PARAM_H
1034 sed -e 's@NeXtLiNe@#ifndef USER_HZ\n#define USER_HZ\t\t100@' $PARAM_H > $PARAM_H.new
1035 mv $PARAM_H.new $PARAM_H
1036 clean_header $PARAM_H
1037
1038 PROCESSOR_H=$NEWDIR/asm-i386/processor.h
1039 echo "Fixing include/asm-i386/processor.h..."
1040 sed -e 's@#include <asm/segment.h>@#include <asm/segment.h>\n#include <asm/page.h>@' $PROCESSOR_H > $PROCESSOR_H.new
1041 mv $PROCESSOR_H.new $PROCESSOR_H
1042 clean_header $PROCESSOR_H
1043
1044 PROCESSOR_H=$NEWDIR/asm-x86_64/processor.h
1045 echo "Fixing include/asm-x86_64/processor.h..."
1046 sed -e 's@#include <asm/segment.h>@#include <asm/segment.h>\n#include <asm/page.h>@' $PROCESSOR_H > $PROCESSOR_H.new
1047 mv $PROCESSOR_H.new $PROCESSOR_H
1048 clean_header $PROCESSOR_H
1049
1050 TERMIOS_H=$NEWDIR/asm-sparc/termios.h
1051 echo "Fixing include/asm-sparc/termios.h..."
1052 sed -e 's@struct sunos_ttysize@#endif\n\nstruct sunos_ttysize@' $TERMIOS_H > $TERMIOS_H.new
1053 mv $TERMIOS_H.new $TERMIOS_H
1054 clean_header $TERMIOS_H
1055
1056 TERMIOS_H=$NEWDIR/asm-sparc64/termios.h
1057 echo "Fixing include/asm-sparc64/termios.h..."
1058 sed -e 's@struct sunos_ttysize@#endif\n\nstruct sunos_ttysize@' $TERMIOS_H > $TERMIOS_H.new
1059 mv $TERMIOS_H.new $TERMIOS_H
1060 clean_header $TERMIOS_H
1061
1062 cd $NEWDIR
1063 for header in `find * -name types.h` ; do
1064 echo "Fixing include/$header..."
1065 sed -e 's@&& !defined(__STRICT_ANSI__)@@' $header > $header.new
1066 mv $header.new $header
1067 clean_header $header
1068 done
1069
1070 for header in $ASM_SYS_HEADERS; do
1071 cd $NEWDIR
1072 DIRS=`ls -1 asm-* -d | sed -e 's/asm-generic//g'`
1073 CONTENT="#include <sys/$header>"
1074 create_asm_header
1075 done
1076
1077 VERSION_H=$NEWDIR/linux/version.h
1078 echo "Creating include/linux/version.h..."
1079 let LINUXCODE="($P1<<16)+($P2<<8)+$P3"
1080 echo "#ifndef _LINUX_VERSION_H" > $VERSION_H
1081 echo "#define _LINUX_VERSION_H" >> $VERSION_H
1082 echo "" >> $VERSION_H
1083 echo "#define UTS_RELEASE \"$P1.$P2.$P3\"" >> $VERSION_H
1084 echo "#define LINUX_VERSION_CODE $LINUXCODE" >> $VERSION_H
1085 echo "#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))" >> $VERSION_H
1086 echo "" >> $VERSION_H
1087 echo "#endif /* _LINUX_VERSION_H */" >> $VERSION_H
1088 clean_header $VERSION_H
1089
1090 BIG_ENDIAN_H=include/linux/byteorder/big_endian.h
1091 LITTLE_ENDIAN_H=include/linux/byteorder/little_endian.h
1092 HEADERS="$BIG_ENDIAN_H $LITTLE_ENDIAN_H"
1093 for hdr in $HEADERS; do
1094 echo "Fixing $hdr..."
1095 sed -e 's/(__force __be..)//' \
1096 -e 's/(__force __u..)//' \
1097 -e 's/(__force __le..)//' \
1098 -e '/#include <linux.byteorder.generic.h>/d' \
1099 -e '/static/,/#define/d' \
1100 -e 's/\b[us]\(8\|16\|32\|64\)\b/__&/g' \
1101 -e 's/\b__\(be\|le\)\(16\|32\|64\)\b/__u\2/g' \
1102 $CURRENT_DIR/linux-headers-$VERSION/$hdr > $CURRENT_DIR/linux-headers-$VERSION/$hdr.new
1103 mv $CURRENT_DIR/linux-headers-$VERSION/$hdr.new $CURRENT_DIR/linux-headers-$VERSION/$hdr
1104 clean_header $CURRENT_DIR/linux-headers-$VERSION/$hdr
1105 done
1106
1107 ATOMIC_H=$NEWDIR/asm-mips/atomic.h
1108 echo "Creating include/asm-mips/atomic.h..."
1109 echo "#ifndef _ASM_ATOMIC_H" > $ATOMIC_H
1110 echo "#define _ASM_ATOMIC_H" >> $ATOMIC_H
1111 echo "" >> $ATOMIC_H
1112 echo "typedef struct { volatile int counter; } atomic_t;" >> $ATOMIC_H
1113 echo "" >> $ATOMIC_H
1114 echo "#ifdef __mips64" >> $ATOMIC_H
1115 echo "typedef struct { volatile long counter; } atomic64_t;" >> $ATOMIC_H
1116 echo "#endif" >> $ATOMIC_H
1117 echo "" >> $ATOMIC_H
1118 echo "#endif /* _ASM_ATOMIC_H */" >> $ATOMIC_H
1119 clean_header $ATOMIC_H
1120
1121 ATOMIC_H=$NEWDIR/asm-i386/atomic.h
1122 echo "Fixing include/asm-i386/atomic.h"
1123 if [ -e $NEWDIR/asm-i386/alternative.h ]; then
1124 sed -e 's@#include <asm.processor.h>@#include <asm/alternative.h>@g' $ATOMIC_H > $ATOMIC_H.new
1125 else
1126 sed -e '/#include <asm.processor.h>/d' $ATOMIC_H > $ATOMIC_H.new
1127 fi
1128 mv $ATOMIC_H.new $ATOMIC_H
1129 clean_header $ATOMIC_H
1130
1131 HEADER_FILE="agpgart.h"
1132 HEADER_NAME="_AGP_H 1"
1133 HEADER_UPDATE="#include <asm/types.h>"
1134 change_header
1135
1136 HEADER_FILE="atmarp.h"
1137 HEADER_NAME="_LINUX_ATMARP_H"
1138 HEADER_UPDATE="#include <linux/types.h>"
1139 change_header
1140
1141 ATM_H=$NEWDIR/linux/atm.h
1142 echo "Fixing include/linux/atm.h..."
1143 sed -e 's@#include <linux/atmapi.h>@#include <linux/types.h>\n#include <linux/atmapi.h>@' $ATM_H > $ATM_H.new
1144 cp $ATM_H.new $ATM_H
1145 sed -e 's@#include <linux/atmioc.h>@#include <linux/atmioc.h>\n#include <stdint.h>@' $ATM_H > $ATM_H.new
1146 mv $ATM_H.new $ATM_H
1147 clean_header $ATM_H
1148
1149 ATM_TCP_H=$NEWDIR/linux/atm_tcp.h
1150 echo "Fixing include/linux/atm_tcp.h..."
1151 sed -e 's@#include <linux/atmapi.h>@#include <linux/types.h>\n#include <linux/atmapi.h>@' $ATM_TCP_H > $ATM_TCP_H.new
1152 cp $ATM_TCP_H.new $ATM_TCP_H
1153 clean_header $ATM_TCP_H
1154
1155 echo "Creating include/linux/ax25.h..."
1156 echo "#include <netax25/ax25.h>" > $NEWDIR/linux/ax25.h
1157
1158 ELF_H=$NEWDIR/linux/elf.h
1159 echo "Fixing include/linux/elf.h..."
1160 sed -e 's@#include <elf.h>@#include <elf.h>\n#include <asm/elf.h>@' $ELF_H > $ELF_H.new
1161 mv $ELF_H.new $ELF_H
1162 clean_header $ELF_H
1163
1164 HEADER_FILE="ethtool.h"
1165 HEADER_NAME="_LINUX_ETHTOOL_H"
1166 HEADER_UPDATE="#include <asm/types.h>"
1167 change_header
1168
1169 FS_H=$NEWDIR/linux/fs.h
1170 echo "Fixing include/linux/fs.h..."
1171 sed -e 's@#include <linux/limits.h>@#include <linux/types.h>\n#include <linux/limits.h>@' $FS_H > $FS_H.new
1172 mv $FS_H.new $FS_H
1173 clean_header $FS_H
1174
1175 HEADER_FILE="if_fc.h"
1176 HEADER_NAME="_LINUX_IF_FC_H"
1177 HEADER_UPDATE="#include <asm/types.h>"
1178 change_header
1179
1180 IF_HIPPI_H=$NEWDIR/linux/if_hippi.h
1181 echo "Fixing include/linux/if_hippi.h..."
1182 sed -e 's@#include <asm/byteorder.h>@#include <endian.h>\n#include <byteswap.h>\nNeXtLiNe@' $IF_HIPPI_H > $IF_HIPPI_H.new
1183 cp $IF_HIPPI_H.new $IF_HIPPI_H
1184 sed -e 's@NeXtLiNe@#include <asm/types.h>@' $IF_HIPPI_H > $IF_HIPPI_H.new
1185 mv $IF_HIPPI_H.new $IF_HIPPI_H
1186 clean_header $IF_HIPPI_H
1187
1188 IF_PPPOX_H=$NEWDIR/linux/if_pppox.h
1189 echo "Fixing include/linux/if_pppox.h..."
1190 sed -e 's@#define __LINUX_IF_PPPOX_H@#define __LINUX_IF_PPPOX_H\n\n#include <linux/if.h>\nNeXtLiNe@' $IF_PPPOX_H > $IF_PPPOX_H.new
1191 cp $IF_PPPOX_H.new $IF_PPPOX_H
1192 sed -e 's@NeXtLiNe@#include <linux/if_ether.h>@' $IF_PPPOX_H > $IF_PPPOX_H.new
1193 cp $IF_PPPOX_H.new $IF_PPPOX_H
1194 sed -e 's@#include <asm/byteorder.h>@#include <endian.h>\n#include <byteswap.h>\nNeXtLiNe@' $IF_PPPOX_H > $IF_PPPOX_H.new
1195 cp $IF_PPPOX_H.new $IF_PPPOX_H
1196 sed -e 's@NeXtLiNe@#include <asm/byteorder.h>@' $IF_PPPOX_H > $IF_PPPOX_H.new
1197 mv $IF_PPPOX_H.new $IF_PPPOX_H
1198 clean_header $IF_PPPOX_H
1199
1200 HEADER_FILE="if_strip.h"
1201 HEADER_NAME="__LINUX_STRIP_H"
1202 HEADER_UPDATE="#include <asm/types.h>"
1203 change_header
1204
1205 IF_TUNNEL_H=$NEWDIR/linux/if_tunnel.h
1206 echo "Fixing include/linux/if_tunnel.h..."
1207 sed -e 's/#define _IF_TUNNEL_H_/#define _IF_TUNNEL_H_\n\nNeXtLiNe/' $IF_TUNNEL_H > $IF_TUNNEL_H.new
1208 cp $IF_TUNNEL_H.new $IF_TUNNEL_H
1209 sed -e 's@NeXtLiNe@#include <linux/if.h>\nNeXtLiNe@' $IF_TUNNEL_H > $IF_TUNNEL_H.new
1210 cp $IF_TUNNEL_H.new $IF_TUNNEL_H
1211 sed -e 's@NeXtLiNe@#include <linux/ip.h>\nNeXtLiNe@' $IF_TUNNEL_H > $IF_TUNNEL_H.new
1212 cp $IF_TUNNEL_H.new $IF_TUNNEL_H
1213 sed -e 's@NeXtLiNe@#include <asm/types.h>\nNeXtLiNe@' $IF_TUNNEL_H > $IF_TUNNEL_H.new
1214 cp $IF_TUNNEL_H.new $IF_TUNNEL_H
1215 sed -e 's@NeXtLiNe@#include <asm/byteorder.h>@' $IF_TUNNEL_H > $IF_TUNNEL_H.new
1216 mv $IF_TUNNEL_H.new $IF_TUNNEL_H
1217 clean_header $IF_TUNNEL_H
1218
1219 HEADER_FILE="if_tr.h"
1220 HEADER_NAME="_LINUX_IF_TR_H"
1221 HEADER_UPDATE="#include <asm/types.h>"
1222 change_header
1223
1224 if [ "$LINUXCODE" -lt "132625" ]; then
1225 INPUT_H=$NEWDIR/linux/input.h
1226 echo "Fixing include/linux/input.h..."
1227 sed -e '/struct input_device_id/,/INPUT_DEVICE_ID_MATCH_SWBIT/d' $INPUT_H > $INPUT_H.new
1228 mv $INPUT_H.new $INPUT_H
1229 clean_header $INPUT_H
1230 fi
1231
1232 JOYSTICK_H=$NEWDIR/linux/joystick.h
1233 echo "Fixing include/linux/joystick.h..."
1234 sed -e 's@int32_t@__s32@' $JOYSTICK_H > $JOYSTICK_H.new
1235 cp $JOYSTICK_H.new $JOYSTICK_H
1236 sed -e 's@int64_t@__s64@' $JOYSTICK_H > $JOYSTICK_H.new
1237 mv $JOYSTICK_H.new $JOYSTICK_H
1238 clean_header $JOYSTICK_H
1239
1240 PCI_H=$NEWDIR/linux/pci.h
1241 echo "Fixing include/linux/pci.h..."
1242 sed -e '/#include <linux.mod_devicetable.h>/d' $PCI_H > $PCI_H.new
1243 mv $PCI_H.new $PCI_H
1244 clean_header $PCI_H
1245
1246 echo "Creating include/linux/netrom.h..."
1247 echo "#include <netrom/netrom.h>" > $NEWDIR/linux/netrom.h
1248
1249 NFS3_H=$NEWDIR/linux/nfs3.h
1250 echo "Fixing include/linux/nfs3.h..."
1251 sed -e 's@#endif /. _LINUX_NFS3_H ./@@' $NFS3_H > $NFS3_H.new
1252 cp $NFS3_H.new $NFS3_H
1253 echo "#endif /* NFS_NEED_KERNEL_TYPES */" >> $NFS3_H
1254 echo "#endif /* _LINUX_NFS3_H */" >> $NFS3_H
1255 clean_header $NFS3_H
1256
1257 RTNETLINK_H=$NEWDIR/linux/rtnetlink.h
1258 echo "Fixing include/linux/rtnetlink.h..."
1259 sed -e 's@#define RTPROT_XORP 14 .* XORP *..@#define RTPROT_XORP\t14\t/* XORP */\nNeXtLiNe@' $RTNETLINK_H > $RTNETLINK_H.new
1260 cp $RTNETLINK_H.new $RTNETLINK_H
1261 sed -e 's@NeXtLiNe@#define RTPROT_NTK\t15\t/* Netsukuku */@' $RTNETLINK_H > $RTNETLINK_H.new
1262 mv $RTNETLINK_H.new $RTNETLINK_H
1263 clean_header $RTNETLINK_H
1264
1265 SWAB_H=$NEWDIR/linux/byteorder/swab.h
1266 HEADER_FILE="byteorder/swab.h"
1267 HEADER_NAME="_LINUX_BYTEORDER_SWAB_H"
1268 HEADER_UPDATE="#include <byteswap.h>"
1269 change_header
1270 sed -e '/#ifndef __arch__swab16/,/#endif .* _LINUX_BYTEORDER_SWAB_H *./d' $SWAB_H > $SWAB_H.new
1271 cp $SWAB_H.new $SWAB_H
1272 sed -e 's/provide defaults when no architecture-specific optimization is detected/definitions that are not in glibc but required/g' $SWAB_H > $SWAB_H.new
1273 mv $SWAB_H.new $SWAB_H
1274 if [ "$LINUXCODE" -gt "132625" ]; then
1275 echo "" >> $SWAB_H
1276 echo "#define ___constant_swab16(x) __bswap_constant_16(x)" >> $SWAB_H
1277 echo "#define ___constant_swab32(x) __bswap_constant_32(x)" >> $SWAB_H
1278 echo "#define ___constant_swab64(x) __bswap_constant_64(x)" >> $SWAB_H
1279 echo "" >> $SWAB_H
1280 echo "#define __swab16(x) bswap_16(x)" >> $SWAB_H
1281 echo "#define __swab32(x) bswap_32(x)" >> $SWAB_H
1282 echo "#define __swab64(x) bswap_64(x)" >> $SWAB_H
1283 echo "" >> $SWAB_H
1284 echo "#define __swab16p(x) __swab16(*(x))" >> $SWAB_H
1285 echo "#define __swab32p(x) __swab32(*(x))" >> $SWAB_H
1286 echo "#define __swab64p(x) __swab64(*(x))" >> $SWAB_H
1287 echo "" >> $SWAB_H
1288 echo "#define __swab16s(x) do { *(x) = __swab16p((x)); } while (0)" >> $SWAB_H
1289 echo "#define __swab32s(x) do { *(x) = __swab32p((x)); } while (0)" >> $SWAB_H
1290 echo "#define __swab64s(x) do { *(x) = __swab64p((x)); } while (0)" >> $SWAB_H
1291 echo "" >> $SWAB_H
1292 fi
1293 echo "#endif /* _LINUX_BYTEORDER_SWAB_H */" >> $SWAB_H
1294 clean_header $SWAB_H
1295
1296 TIME_H=$NEWDIR/linux/time.h
1297 echo "Creating include/linux/time.h..."
1298 echo "#ifndef LINUX_TIME_H" > $TIME_H
1299 echo "" >> $TIME_H
1300 echo "#define MSEC_PER_SEC 1000L" >> $TIME_H
1301 echo "#define USEC_PER_SEC 1000000L" >> $TIME_H
1302 echo "#define NSEC_PER_SEC 1000000000L" >> $TIME_H
1303 echo "#define NSEC_PER_USEC 1000L" >> $TIME_H
1304 echo "" >> $TIME_H
1305 echo "#include <sys/time.h>" >> $TIME_H
1306 echo "" >> $TIME_H
1307 echo "#endif" >> $TIME_H
1308
1309 TYPES_H=$NEWDIR/linux/types.h
1310 echo "Fixing include/linux/types.h..."
1311 sed -e 's@#include <linux/posix_types.h>@#include <sys/types.h>\n#include <linux/posix_types.h>@' $TYPES_H > $TYPES_H.new
1312 cp $TYPES_H.new $TYPES_H
1313 sed -e 's@typedef __u32 __kernel_dev_t;@typedef __u32 __kernel_dev_t;\n\n#if defined(WANT_KERNEL_TYPES) || !defined(__GLIBC__)@' $TYPES_H > $TYPES_H.new
1314 cp $TYPES_H.new $TYPES_H
1315 sed -e 's@#endif /. __KERNEL_STRICT_NAMES ./@\n#endif\n#endif\n\n@' $TYPES_H > $TYPES_H.new
1316 cp $TYPES_H.new $TYPES_H
1317 clean_header $TYPES_H
1318
1319 for files in $COPY_HEADERS; do
1320 echo "$files" | {
1321 IFS=':' read sfile dfile
1322 echo "Copying $sfile to $dfile..."
1323 cp $NEWDIR/$sfile $NEWDIR/$dfile
1324 }
1325 done
1326
1327 for file in $REMOVE_HEADERS; do
1328 echo "Removing unused header $file..."
1329 rm -f $NEWDIR/$file
1330 done
1331
1332 echo "Removing Headers that are replaced by glibc headers..."
1333 for file in $GLIBC_HEADERS; do
1334 rm $NEWDIR/$file
1335 done
1336
1337 if [ "$LINUXCODE" -gt "132625" ]; then
1338 HEADER_FILE="videodev.h"
1339 HEADER_NAME="__LINUX_VIDEODEV_H"
1340 HEADER_UPDATE="#include <linux/types.h>"
1341 change_header
1342 VIDEODEV_H=$NEWDIR/linux/videodev.h
1343 sed -e '/CONFIG_VIDEO_V4L1_COMPAT/d' $VIDEODEV_H > $VIDEODEV_H.new
1344 cp $VIDEODEV_H.new $VIDEODEV_H
1345 clean_header $VIDEODEV_H
1346 fi
1347
1348 echo "Removing any Kbuild files..."
1349 cd $CURRENT_DIR/linux-headers-$VERSION
1350 FILES=`find * -name Kbuild`
1351 for file in $FILES; do
1352 rm -f $file
1353 done
1354
1355 echo "Cleaning up linux-headers-$VERSION directories..."
1356 PASS=1
1357 while [ "$PASS" -lt "4" ]; do
1358 cd $CURRENT_DIR/linux-headers-$VERSION
1359 DIRS=`find * -type d`
1360 cd $CURRENT_DIR
1361 for dir in $DIRS; do
1362 if [ -e $CURRENT_DIR/linux-headers-$VERSION/$dir ]; then
1363 rmdir $CURRENT_DIR/linux-headers-$VERSION/$dir > /dev/null 2>&1
1364 if [ "$?" = "0" ]; then
1365 echo "Removing empty directory linux-headers-$VERSION/$dir..."
1366 fi
1367 fi
1368 done
1369 PASS=$(($PASS + 1))
1370 done
1371
1372 echo "Creating multilib headers for x86_64..."
1373 multilib_stubs x86_64 i386 __x86_64__
1374 echo "Creating multilib headers for Sparc64..."
1375 multilib_stubs sparc64 sparc __arch64__
1376
1377 count=`find $CURRENT_DIR/linux-headers-$VERSION -type f | wc -l`
1378 echo "Processed $count headers..."
1379
1380 creation="$CURRENT_DIR/linux-headers-$VERSION/creation"
1381 echo "Processed $count headers on `date +%m-%d-%Y` at `date +%r`" > $creation
1382 echo "based on $VERSION kernel." >> $creation
1383 if [ -e "$CURRENT_DIR/patches/$PATCHFILE" ]; then
1384 echo "Utilized patch - $PATCHFILE" >> $creation
1385 fi
1386
1387 bugreport="$CURRENT_DIR/linux-headers-$VERSION/bug-report"
1388 echo "Report bugs at http://headers.cross-lfs.org" > $bugreport
1389 echo "" >> $bugreport
1390 echo "Include the following information:" >> $bugreport
1391 echo " Program Name" >> $bugreport
1392 echo " Program Version" >> $bugreport
1393 echo " URL to Download Program" >> $bugreport
1394 echo " Name of Missing Header" >> $bugreport
1395 echo "" >> $bugreport
1396 echo "or" >> $bugreport
1397 echo "Use the headers_list script from" >> $bugreport
1398 echo "http://ftp.jg555.com/headers/headers_list" >> $bugreport
1399 echo "" >> $bugreport
1400 echo "Thank you for you support of Linux-Headers." >> $bugreport
1401
1402 install -d $CURRENT_DIR/linux-headers-$VERSION/script
1403 cp $0 $CURRENT_DIR/linux-headers-$VERSION/script
1404 install -d $CURRENT_DIR/linux-headers-$VERSION/lists
1405 cp $CURRENT_DIR/lists/* $CURRENT_DIR/linux-headers-$VERSION/lists
1406 install -d $CURRENT_DIR/linux-headers-$VERSION/script/patches
1407 if [ -e $CURRENT_DIR/patches/linux-$VERSION-REQUIRED-1.patch ]; then
1408 cp $CURRENT_DIR/patches/linux-$VERSION-REQUIRED-1.patch $CURRENT_DIR/linux-headers-$VERSION/script/patches/linux-$VERSION-REQUIRED-1.patch
1409 fi
1410 if [ -e $CURRENT_DIR/patches/linux-$VERSION-mips_headers-1.patch ]; then
1411 cp $CURRENT_DIR/patches/linux-$VERSION-mips_headers-1.patch $CURRENT_DIR/linux-headers-$VERSION/script/patches/linux-$VERSION-mips_headers-1.patch
1412 fi
1413 for PATCHFILE in $PATCHES; do
1414 if [ -e "$CURRENT_DIR/patches/$PATCHFILE" ]; then
1415 cp $CURRENT_DIR/patches/$PATCHFILE $CURRENT_DIR/linux-headers-$VERSION/script/patches/$PATCHFILE
1416 fi
1417 done
1418
1419 cp license $CURRENT_DIR/linux-headers-$VERSION/license
1420
1421 echo "Creating linux-headers-$VERSION.tar.bz2..."
1422 cd $CURRENT_DIR
1423 tar -jcf linux-headers-$VERSION.tar.bz2 linux-headers-$VERSION