source: headers @ 157

Revision 157, 42.7 KB checked in by jim, 7 years ago (diff)

Updates for 2.6.23 kernel

  • Property svn:executable set to *
Line 
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
90usage() {
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
104make_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
253check_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}
263check_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
274clean_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
283create_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
296create_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
371multilib_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
402EOF
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
414EOF
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
421EOF
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
430EOF
431                fi
432                cat >> $NEWDIR/asm-${STUBARCH1}-biarch/${hdr} << EOF
433
434#endif /* __STUB__${name}__ */
435EOF
436        done
437}
438
439change_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#
450if [ "$1" = "" ]; then
451        usage
452fi
453
454while [ $# -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
493done
494
495# Checking for all the tools we need
496TEST=`whereis awk | cut -f2 -d:`
497if [ "$TEST" = "" ]; then
498        echo "Missing awk"
499        exit 254
500fi
501TEST=`whereis cp | cut -f2 -d:`
502if [ "$TEST" = "" ]; then
503        echo "Missing cp."
504        exit 253
505fi
506TEST=`whereis install | cut -f2 -d:`
507if [ "$TEST" = "" ]; then
508        echo "Missing install."
509        exit 252
510fi
511TEST=`whereis mv | cut -f2 -d:`
512if [ "$TEST" = "" ]; then
513        echo "Missing mv."
514        exit 251
515fi
516TEST=`whereis pwd | cut -f2 -d:`
517if [ "$TEST" = "" ]; then
518        echo "Missing pwd."
519        exit 250
520fi
521TEST=`whereis sed | cut -f2 -d:`
522if [ "$TEST" = "" ]; then
523        echo "Missing sed."
524        exit 249
525fi
526TEST=`whereis rm | cut -f2 -d:`
527if [ "$TEST" = "" ]; then
528        echo "Missing rm."
529        exit 248
530fi
531TEST=`whereis rmdir | cut -f2 -d:`
532if [ "$TEST" = "" ]; then
533        echo "Missing rmdir."
534        exit 247
535fi
536TEST=`whereis tar | cut -f2 -d:`
537if [ "$TEST" = "" ]; then
538        echo "Missing tar."
539        exit 246
540fi
541TEST=`whereis unifdef | cut -f2 -d:`
542if [ "$TEST" = "" ]; then
543        echo "Missing unifdef."
544        exit 245
545fi
546TEST=`whereis wget | cut -f2 -d:`
547if [ "$TEST" = "" ]; then
548        echo "Missing wget."
549        exit 244
550fi
551
552# Set Linux Version
553P1=`echo $VERSION | cut -f1 -d.`
554P2=`echo $VERSION | cut -f2 -d.`
555P3=`echo $VERSION | cut -f3 -d.`
556LINUXVERSION="$P1.$P2"
557
558# Our Working Directories
559CURRENT_DIR=`pwd -P`
560ORIGDIR=$CURRENT_DIR/linux-headers-$VERSION.orig/include
561NEWDIR=$CURRENT_DIR/linux-headers-$VERSION/include
562
563# Headers to Sanitize
564ASM_HEADERS=$(cat $CURRENT_DIR/lists/asm-headers)
565ASM_ARCH_HEADERS=$(cat $CURRENT_DIR/lists/asm-arch-headers)
566ASM_SYS_HEADERS=$(cat $CURRENT_DIR/lists/asm-sys-headers)
567
568LINUX_HEADERS=$(cat $CURRENT_DIR/lists/linux-headers)
569
570NOSANTIZE_ASM_HEADERS=$(cat $CURRENT_DIR/lists/no_santize-asm-headers)
571NOSANTIZE_LINUX_HEADERS=$(cat $CURRENT_DIR/lists/no_santize-linux-headers)
572
573BLANK_HEADERS=$(cat $CURRENT_DIR/lists/blank-headers)
574
575ROOT_HEADERS=$(cat $CURRENT_DIR/lists/root-headers)
576SYS_HEADERS=$(cat $CURRENT_DIR/lists/sys-headers)
577
578GLIBC_HEADERS=$(cat $CURRENT_DIR/lists/glibc-headers)
579
580COPY_HEADERS=$(cat $CURRENT_DIR/lists/copy-headers)
581
582REMOVE_HEADERS=$(cat $CURRENT_DIR/lists/remove-headers)
583
584if [ "$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
594fi
595
596if [ "$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
631fi
632
633if ! [ -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
640fi
641
642echo "Decompressing Kernel Headers only..."
643rm -rf linux-$VERSION linux-headers-$VERSION linux-headers-$VERSION.orig
644tar --wildcards -jxf linux-$VERSION.tar.bz2 linux-$VERSION/include/*
645if [ -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
651fi
652if [ -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
658fi
659for 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
666done
667
668if [ "$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
685fi     
686
687echo "Renaming directory to linux-headers-$VERSION..."
688mv linux-$VERSION linux-headers-$VERSION.orig
689
690echo "Creating directory Structure..."
691install -d linux-headers-$VERSION
692cd $ORIGDIR
693DIRS=`find * -type d`
694cd $CURRENT_DIR
695for dir in $DIRS; do
696        install -d $NEWDIR/$dir
697done
698
699DONT_CHANGE=no
700TYPE=asm
701HEADERS="$ASM_HEADERS"
702if [ "$HEADERS" != "" ]; then
703        make_headers
704fi
705
706TYPE=asm
707HEADERS=$ASM_ARCH_HEADERS
708if [ "$HEADERS" != "" ]; then
709        make_headers
710fi
711
712TYPE=linux
713HEADERS=$LINUX_HEADERS
714if [ "$HEADERS" != "" ]; then
715        make_headers
716fi
717
718SETTYPE="byteorder dvb isdn lockd mtd netfilter netfilter_arp netfilter_bridge netfilter_ipv4 netfilter_ipv6
719         nfsd raid sunrpc tc_act tc_ematch"
720for 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
729done
730
731SETTYPE="acpi mtd scsi sound"
732for 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
741done
742
743DONT_CHANGE=yes
744TYPE=linux
745HEADERS=$NOSANTIZE_LINUX_HEADERS
746if [ "$HEADERS" != "" ]; then
747        make_headers
748fi
749
750TYPE=asm
751HEADERS=$NOSANTIZE_ASM_HEADERS
752if [ "$HEADERS" != "" ]; then
753        make_headers
754fi
755
756for 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
766done
767
768for 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
773done
774
775for 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
780done
781
782cd $NEWDIR
783PLATFORM=`ls -1 asm-* -d | sed -e 's/asm-generic//g'`
784for 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
857done
858
859cp $ORIGDIR/asm-ia64/page.h $NEWDIR/asm-ia64/page.h
860PAGE_H=$NEWDIR/asm-ia64/page.h
861echo "Processing include/asm-ia64/page.h..."
862unifdef -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
864cp $PAGE_H.new $PAGE_H
865sed -e 's/# error Unsupported page size./#define PAGE_SIZE\tsysconf (_SC_PAGE_SIZE)\nNeXtLiNe/' $PAGE_H > $PAGE_H.new
866cp $PAGE_H.new $PAGE_H
867sed -e 's/NeXtLiNe/\n#define PAGE_SHIFT\t(getpageshift())/' $PAGE_H > $PAGE_H.new
868mv $PAGE_H.new $PAGE_H
869clean_header $PAGE_H
870       
871cd $NEWDIR
872PLATFORM=`ls -1 asm-* -d | sed -e 's/asm-generic//g' -e 's/asm-ia64//g'`
873for 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
968done
969
970PLATFORM="asm-m68k asm-sparc asm-sparc64"
971for 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
1016done
1017
1018CACHE_H=$NEWDIR/asm-i386/cache.h
1019echo "Fixing include/asm-i386/cache.h..."
1020sed -e 's@CONFIG_X86_L1_CACHE_SHIFT@7@' $CACHE_H > $CACHE_H.new
1021mv $CACHE_H.new $CACHE_H
1022clean_header $CACHE_H
1023
1024CACHE_H=$NEWDIR/asm-x86_64/cache.h
1025echo "Fixing include/asm-x86_64/cache.h..."
1026sed -e 's@CONFIG_X86_L1_CACHE_SHIFT@7@' $CACHE_H > $CACHE_H.new
1027mv $CACHE_H.new $CACHE_H
1028clean_header $CACHE_H
1029
1030PARAM_H=$NEWDIR/asm-i386/param.h
1031echo "Fixing include/asm-i386/param.h..."
1032sed -e 's@#define HZ 100@#define HZ\t\t100\n#endif\n\nNeXtLiNe\n@' $PARAM_H > $PARAM_H.new
1033cp $PARAM_H.new $PARAM_H
1034sed -e 's@NeXtLiNe@#ifndef USER_HZ\n#define USER_HZ\t\t100@' $PARAM_H > $PARAM_H.new
1035mv $PARAM_H.new $PARAM_H
1036clean_header $PARAM_H
1037
1038PROCESSOR_H=$NEWDIR/asm-i386/processor.h
1039echo "Fixing include/asm-i386/processor.h..."
1040sed -e 's@#include <asm/segment.h>@#include <asm/segment.h>\n#include <asm/page.h>@' $PROCESSOR_H > $PROCESSOR_H.new
1041mv $PROCESSOR_H.new $PROCESSOR_H
1042clean_header $PROCESSOR_H
1043
1044PROCESSOR_H=$NEWDIR/asm-x86_64/processor.h
1045echo "Fixing include/asm-x86_64/processor.h..."
1046sed -e 's@#include <asm/segment.h>@#include <asm/segment.h>\n#include <asm/page.h>@' $PROCESSOR_H > $PROCESSOR_H.new
1047mv $PROCESSOR_H.new $PROCESSOR_H
1048clean_header $PROCESSOR_H
1049
1050TERMIOS_H=$NEWDIR/asm-sparc/termios.h
1051echo "Fixing include/asm-sparc/termios.h..."
1052sed -e 's@struct sunos_ttysize@#endif\n\nstruct sunos_ttysize@' $TERMIOS_H > $TERMIOS_H.new
1053mv $TERMIOS_H.new $TERMIOS_H
1054clean_header $TERMIOS_H
1055
1056TERMIOS_H=$NEWDIR/asm-sparc64/termios.h
1057echo "Fixing include/asm-sparc64/termios.h..."
1058sed -e 's@struct sunos_ttysize@#endif\n\nstruct sunos_ttysize@' $TERMIOS_H > $TERMIOS_H.new
1059mv $TERMIOS_H.new $TERMIOS_H
1060clean_header $TERMIOS_H
1061
1062cd $NEWDIR
1063for 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
1068done
1069
1070for 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
1075done
1076
1077VERSION_H=$NEWDIR/linux/version.h
1078echo "Creating include/linux/version.h..."
1079let LINUXCODE="($P1<<16)+($P2<<8)+$P3"
1080echo "#ifndef _LINUX_VERSION_H" > $VERSION_H
1081echo "#define _LINUX_VERSION_H" >> $VERSION_H
1082echo "" >> $VERSION_H
1083echo "#define UTS_RELEASE \"$P1.$P2.$P3\"" >> $VERSION_H
1084echo "#define LINUX_VERSION_CODE $LINUXCODE" >> $VERSION_H
1085echo "#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))" >> $VERSION_H
1086echo "" >> $VERSION_H
1087echo "#endif /* _LINUX_VERSION_H */" >> $VERSION_H
1088clean_header $VERSION_H
1089
1090BIG_ENDIAN_H=include/linux/byteorder/big_endian.h
1091LITTLE_ENDIAN_H=include/linux/byteorder/little_endian.h
1092HEADERS="$BIG_ENDIAN_H $LITTLE_ENDIAN_H"
1093for 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
1105done
1106
1107ATOMIC_H=$NEWDIR/asm-mips/atomic.h
1108echo "Creating include/asm-mips/atomic.h..."
1109echo "#ifndef _ASM_ATOMIC_H" > $ATOMIC_H
1110echo "#define _ASM_ATOMIC_H" >> $ATOMIC_H
1111echo "" >> $ATOMIC_H
1112echo "typedef struct { volatile int counter; } atomic_t;" >> $ATOMIC_H
1113echo "" >> $ATOMIC_H
1114echo "#ifdef __mips64" >> $ATOMIC_H
1115echo "typedef struct { volatile long counter; } atomic64_t;" >> $ATOMIC_H
1116echo "#endif" >> $ATOMIC_H
1117echo "" >> $ATOMIC_H
1118echo "#endif /* _ASM_ATOMIC_H */" >> $ATOMIC_H
1119clean_header $ATOMIC_H
1120
1121ATOMIC_H=$NEWDIR/asm-i386/atomic.h
1122echo "Fixing include/asm-i386/atomic.h"
1123if [ -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
1125else
1126        sed -e '/#include <asm.processor.h>/d' $ATOMIC_H > $ATOMIC_H.new
1127fi
1128mv $ATOMIC_H.new $ATOMIC_H
1129clean_header $ATOMIC_H
1130
1131HEADER_FILE="agpgart.h"
1132HEADER_NAME="_AGP_H 1"
1133HEADER_UPDATE="#include <asm/types.h>"
1134change_header
1135
1136HEADER_FILE="atmarp.h"
1137HEADER_NAME="_LINUX_ATMARP_H"
1138HEADER_UPDATE="#include <linux/types.h>"
1139change_header
1140
1141ATM_H=$NEWDIR/linux/atm.h
1142echo "Fixing include/linux/atm.h..."
1143sed -e 's@#include <linux/atmapi.h>@#include <linux/types.h>\n#include <linux/atmapi.h>@' $ATM_H > $ATM_H.new
1144cp $ATM_H.new $ATM_H
1145sed -e 's@#include <linux/atmioc.h>@#include <linux/atmioc.h>\n#include <stdint.h>@' $ATM_H > $ATM_H.new
1146mv $ATM_H.new $ATM_H
1147clean_header $ATM_H
1148
1149ATM_TCP_H=$NEWDIR/linux/atm_tcp.h
1150echo "Fixing include/linux/atm_tcp.h..."
1151sed -e 's@#include <linux/atmapi.h>@#include <linux/types.h>\n#include <linux/atmapi.h>@' $ATM_TCP_H > $ATM_TCP_H.new
1152cp $ATM_TCP_H.new $ATM_TCP_H
1153clean_header $ATM_TCP_H
1154
1155echo "Creating include/linux/ax25.h..."
1156echo "#include <netax25/ax25.h>" > $NEWDIR/linux/ax25.h
1157
1158ELF_H=$NEWDIR/linux/elf.h
1159echo "Fixing include/linux/elf.h..."
1160sed -e 's@#include <elf.h>@#include <elf.h>\n#include <asm/elf.h>@' $ELF_H > $ELF_H.new
1161mv $ELF_H.new $ELF_H
1162clean_header $ELF_H
1163
1164HEADER_FILE="ethtool.h"
1165HEADER_NAME="_LINUX_ETHTOOL_H"
1166HEADER_UPDATE="#include <asm/types.h>"
1167change_header
1168
1169FS_H=$NEWDIR/linux/fs.h
1170echo "Fixing include/linux/fs.h..."
1171sed -e 's@#include <linux/limits.h>@#include <linux/types.h>\n#include <linux/limits.h>@' $FS_H > $FS_H.new
1172mv $FS_H.new $FS_H
1173clean_header $FS_H
1174
1175HEADER_FILE="if_fc.h"
1176HEADER_NAME="_LINUX_IF_FC_H"
1177HEADER_UPDATE="#include <asm/types.h>"
1178change_header
1179
1180IF_HIPPI_H=$NEWDIR/linux/if_hippi.h
1181echo "Fixing include/linux/if_hippi.h..."
1182sed -e 's@#include <asm/byteorder.h>@#include <endian.h>\n#include <byteswap.h>\nNeXtLiNe@' $IF_HIPPI_H > $IF_HIPPI_H.new
1183cp $IF_HIPPI_H.new $IF_HIPPI_H
1184sed -e 's@NeXtLiNe@#include <asm/types.h>@' $IF_HIPPI_H > $IF_HIPPI_H.new
1185mv $IF_HIPPI_H.new $IF_HIPPI_H
1186clean_header $IF_HIPPI_H
1187
1188IF_PPPOX_H=$NEWDIR/linux/if_pppox.h
1189echo "Fixing include/linux/if_pppox.h..."
1190sed -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
1191cp $IF_PPPOX_H.new $IF_PPPOX_H
1192sed -e 's@NeXtLiNe@#include <linux/if_ether.h>@' $IF_PPPOX_H > $IF_PPPOX_H.new
1193cp $IF_PPPOX_H.new $IF_PPPOX_H
1194sed -e 's@#include <asm/byteorder.h>@#include <endian.h>\n#include <byteswap.h>\nNeXtLiNe@' $IF_PPPOX_H > $IF_PPPOX_H.new
1195cp $IF_PPPOX_H.new $IF_PPPOX_H
1196sed -e 's@NeXtLiNe@#include <asm/byteorder.h>@' $IF_PPPOX_H > $IF_PPPOX_H.new
1197mv $IF_PPPOX_H.new $IF_PPPOX_H
1198clean_header $IF_PPPOX_H
1199
1200HEADER_FILE="if_strip.h"
1201HEADER_NAME="__LINUX_STRIP_H"
1202HEADER_UPDATE="#include <asm/types.h>"
1203change_header
1204
1205IF_TUNNEL_H=$NEWDIR/linux/if_tunnel.h
1206echo "Fixing include/linux/if_tunnel.h..."
1207sed -e 's/#define _IF_TUNNEL_H_/#define _IF_TUNNEL_H_\n\nNeXtLiNe/' $IF_TUNNEL_H > $IF_TUNNEL_H.new
1208cp $IF_TUNNEL_H.new $IF_TUNNEL_H
1209sed -e 's@NeXtLiNe@#include <linux/if.h>\nNeXtLiNe@' $IF_TUNNEL_H > $IF_TUNNEL_H.new
1210cp $IF_TUNNEL_H.new $IF_TUNNEL_H
1211sed -e 's@NeXtLiNe@#include <linux/ip.h>\nNeXtLiNe@' $IF_TUNNEL_H > $IF_TUNNEL_H.new
1212cp $IF_TUNNEL_H.new $IF_TUNNEL_H
1213sed -e 's@NeXtLiNe@#include <asm/types.h>\nNeXtLiNe@' $IF_TUNNEL_H > $IF_TUNNEL_H.new
1214cp $IF_TUNNEL_H.new $IF_TUNNEL_H
1215sed -e 's@NeXtLiNe@#include <asm/byteorder.h>@' $IF_TUNNEL_H > $IF_TUNNEL_H.new
1216mv $IF_TUNNEL_H.new $IF_TUNNEL_H
1217clean_header $IF_TUNNEL_H
1218
1219HEADER_FILE="if_tr.h"
1220HEADER_NAME="_LINUX_IF_TR_H"
1221HEADER_UPDATE="#include <asm/types.h>"
1222change_header
1223
1224if [ "$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
1230fi
1231
1232JOYSTICK_H=$NEWDIR/linux/joystick.h
1233echo "Fixing include/linux/joystick.h..."
1234sed -e 's@int32_t@__s32@' $JOYSTICK_H > $JOYSTICK_H.new
1235cp $JOYSTICK_H.new $JOYSTICK_H
1236sed -e 's@int64_t@__s64@' $JOYSTICK_H > $JOYSTICK_H.new
1237mv $JOYSTICK_H.new $JOYSTICK_H
1238clean_header $JOYSTICK_H
1239
1240PCI_H=$NEWDIR/linux/pci.h
1241echo "Fixing include/linux/pci.h..."
1242sed -e '/#include <linux.mod_devicetable.h>/d' $PCI_H > $PCI_H.new
1243mv $PCI_H.new $PCI_H
1244clean_header $PCI_H
1245
1246echo "Creating include/linux/netrom.h..."
1247echo "#include <netrom/netrom.h>" > $NEWDIR/linux/netrom.h
1248
1249NFS3_H=$NEWDIR/linux/nfs3.h
1250echo "Fixing include/linux/nfs3.h..."
1251sed -e 's@#endif /. _LINUX_NFS3_H ./@@' $NFS3_H > $NFS3_H.new
1252cp $NFS3_H.new $NFS3_H
1253echo "#endif /* NFS_NEED_KERNEL_TYPES */" >> $NFS3_H
1254echo "#endif /* _LINUX_NFS3_H */" >> $NFS3_H
1255clean_header $NFS3_H
1256
1257RTNETLINK_H=$NEWDIR/linux/rtnetlink.h
1258echo "Fixing include/linux/rtnetlink.h..."
1259sed -e 's@#define RTPROT_XORP   14      .* XORP *..@#define RTPROT_XORP\t14\t/* XORP */\nNeXtLiNe@' $RTNETLINK_H > $RTNETLINK_H.new
1260cp $RTNETLINK_H.new $RTNETLINK_H
1261sed -e 's@NeXtLiNe@#define RTPROT_NTK\t15\t/* Netsukuku */@' $RTNETLINK_H > $RTNETLINK_H.new
1262mv $RTNETLINK_H.new $RTNETLINK_H
1263clean_header $RTNETLINK_H
1264
1265SWAB_H=$NEWDIR/linux/byteorder/swab.h
1266HEADER_FILE="byteorder/swab.h"
1267HEADER_NAME="_LINUX_BYTEORDER_SWAB_H"
1268HEADER_UPDATE="#include <byteswap.h>"
1269change_header
1270sed -e '/#ifndef __arch__swab16/,/#endif .* _LINUX_BYTEORDER_SWAB_H *./d' $SWAB_H > $SWAB_H.new
1271cp $SWAB_H.new $SWAB_H
1272sed -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
1273mv $SWAB_H.new $SWAB_H
1274if [ "$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
1292fi
1293echo "#endif /* _LINUX_BYTEORDER_SWAB_H */" >> $SWAB_H
1294clean_header $SWAB_H
1295
1296TIME_H=$NEWDIR/linux/time.h
1297echo "Creating include/linux/time.h..."
1298echo "#ifndef LINUX_TIME_H" > $TIME_H
1299echo "" >> $TIME_H
1300echo "#define MSEC_PER_SEC      1000L" >> $TIME_H
1301echo "#define USEC_PER_SEC      1000000L" >> $TIME_H
1302echo "#define NSEC_PER_SEC      1000000000L" >> $TIME_H
1303echo "#define NSEC_PER_USEC     1000L" >> $TIME_H
1304echo "" >> $TIME_H
1305echo "#include <sys/time.h>" >> $TIME_H
1306echo "" >> $TIME_H
1307echo "#endif" >> $TIME_H
1308
1309TYPES_H=$NEWDIR/linux/types.h
1310echo "Fixing include/linux/types.h..."
1311sed -e 's@#include <linux/posix_types.h>@#include <sys/types.h>\n#include <linux/posix_types.h>@' $TYPES_H > $TYPES_H.new
1312cp $TYPES_H.new $TYPES_H
1313sed -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
1314cp $TYPES_H.new $TYPES_H
1315sed -e 's@#endif /. __KERNEL_STRICT_NAMES ./@\n#endif\n#endif\n\n@' $TYPES_H > $TYPES_H.new
1316cp $TYPES_H.new $TYPES_H
1317clean_header $TYPES_H
1318
1319for 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        }
1325done
1326
1327for file in $REMOVE_HEADERS; do
1328        echo "Removing unused header $file..."
1329        rm -f $NEWDIR/$file
1330done
1331
1332echo "Removing Headers that are replaced by glibc headers..."
1333for file in $GLIBC_HEADERS; do
1334        rm $NEWDIR/$file
1335done
1336
1337if [ "$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
1346fi
1347
1348echo "Removing any Kbuild files..."
1349cd $CURRENT_DIR/linux-headers-$VERSION
1350FILES=`find * -name Kbuild`
1351for file in $FILES; do
1352        rm -f $file
1353done
1354
1355echo "Cleaning up linux-headers-$VERSION directories..."
1356PASS=1
1357while [ "$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))
1370done
1371
1372echo "Creating multilib headers for x86_64..."
1373multilib_stubs x86_64 i386 __x86_64__
1374echo "Creating multilib headers for Sparc64..."
1375multilib_stubs sparc64 sparc __arch64__
1376
1377count=`find $CURRENT_DIR/linux-headers-$VERSION -type f | wc -l`
1378echo "Processed $count headers..."
1379
1380creation="$CURRENT_DIR/linux-headers-$VERSION/creation"
1381echo "Processed $count headers on `date +%m-%d-%Y` at `date +%r`" > $creation
1382echo "based on $VERSION kernel." >> $creation
1383if [ -e "$CURRENT_DIR/patches/$PATCHFILE" ]; then
1384        echo "Utilized patch - $PATCHFILE" >> $creation
1385fi
1386
1387bugreport="$CURRENT_DIR/linux-headers-$VERSION/bug-report"
1388echo "Report bugs at http://headers.cross-lfs.org" > $bugreport
1389echo "" >> $bugreport
1390echo "Include the following information:" >> $bugreport
1391echo "          Program Name" >> $bugreport
1392echo "          Program Version" >> $bugreport
1393echo "          URL to Download Program" >> $bugreport
1394echo "          Name of Missing Header" >> $bugreport
1395echo "" >> $bugreport
1396echo "or"  >> $bugreport
1397echo "Use the headers_list script from" >> $bugreport
1398echo "http://ftp.jg555.com/headers/headers_list" >> $bugreport
1399echo "" >> $bugreport
1400echo "Thank you for you support of Linux-Headers." >> $bugreport
1401
1402install -d $CURRENT_DIR/linux-headers-$VERSION/script
1403cp $0 $CURRENT_DIR/linux-headers-$VERSION/script
1404install -d $CURRENT_DIR/linux-headers-$VERSION/lists
1405cp $CURRENT_DIR/lists/* $CURRENT_DIR/linux-headers-$VERSION/lists
1406install -d $CURRENT_DIR/linux-headers-$VERSION/script/patches
1407if [ -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
1409fi
1410if [ -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
1412fi
1413for 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
1417done
1418
1419cp license $CURRENT_DIR/linux-headers-$VERSION/license
1420
1421echo "Creating linux-headers-$VERSION.tar.bz2..."
1422cd $CURRENT_DIR
1423tar -jcf linux-headers-$VERSION.tar.bz2 linux-headers-$VERSION
Note: See TracBrowser for help on using the repository browser.