Setup Opencv3.0/Opencv2.4.11 on windows x86_64 with MinGW64

1. download cmake-3.3.0-rc3 (http://www.cmake.org/files/v3.2/cmake-3.2.3-win32-x86.exe)
2. download eclipse-cpp-mars-R-win32-x86_64.zip
   (http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/mars/R/eclipse-cpp-mars-R-win32-x86_64.zip)
3. download java runtime environment for win86_64.
   http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html
4. download MinGW (http://www.mingw.org/download/installer) (mingw-get-setup.exe) This is for 32bit installation.
   download MinGW64.
   http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/5.1.0/threads-posix/seh/
5. download OpenCV 3.0
   (http://sourceforge.net/projects/opencvlibrary/files/opencv-win/3.0.0/opencv-3.0.0.exe/download)

6. Install JRE
7. Unzip eclipse to a directory, say(d:\tools\eclipse).
8. run mingw-get-setup.exe. accept default and install to c:\MinGW. Add c:\MinGW to your windows PATH variable.
9. Unzip Mingw64 and copy it to c:\Mingw64. Add c:\Mingw64 to your windows PATH variable (better before c:\MinGW).
10. unzip opencv3.0 to a directory, say(d:\tools\opencv).
11. run cmake-3.2.3-win32-x86.exe
12. from windows start button, run CMake(cmake-gui).
   In Where is the source code input text, select d:/tools/opencv/sources
   specify where to build the binaries, say C:/opencv
   N.B. for MinGW bug. Opencv3.0, check Grouped, Advanced checkbox, and uncheck WITH_IPP.
        for MinGW bug. Opencv2.4.11, check Grouped, Advanced checkbox, and uncheck BUILD_PERF_TESTS.
   click Configure button. Select MinGW Makefiles from Specify the generator for this project. Select Specify native compilers.
   select c:/MinGW/bin/gcc.exe for C compiler, c:/MinGW/bin/g++.exe for C++.
   Click Generate button and wait it finishes.
   N.B. Change CMAKE_BUILD_TYPE to Debug or Release to build Debug version and Release version respectively.

10.N.B for Opencv3.0
   open c:\opencv\sources\cmake\OpenCVCompilerOptions.cmake search non-virtual-dtor and comment out this line(67) as follows,
   #add_extra_compiler_option(-Werror=non-virtual-dtor)
   N.B for Opencv2.4.11 Delete two macros when complain not defined.

   launch a command prompt and cd to c:\opencv. execute following commands.
   mingw32-make all
   mingw32-make install
   if everything runs ok, you will get the generate header files and libraries under C:\opencv\install\include; C:\opencv\install\x64\mingw\lib

11.launch eclipse.
   File->New->Project->C++ Project. Input testcv
   from Project Explorer, right-click testcv project->Properties.
   C/C++ Build/Settings, GCC C++ Compiler/Includes, add one directory, “c:\opencv\install\include”
                         GCC C   Compiler/Includes, add one directory, “C:\opencv\install\include”
   MinGW C++ Linker/Libraries/Libraries(-l), add opencv_core300 opencv_highgui300 opencv_imgproc300 etc for Release version.
                                             add opencv_core300d opencv_highgui300d opencv_imgproc300d et for Debug version.
   MinGW C++ Linker/Libraries/Libraries search path (-L), add “C:\opencv\install\x64\mingw\lib”
   click ok.
   Add one new file, you can select one from samples. compile and run.

Have fun    
  
  

Posted in Uncategorized | Leave a comment

Hello world!

Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!

Posted in Uncategorized | 1 Comment

Fix checksum error during windbg trace dll

  When we compile some user mode components using visual studio 2005, like .dll, .exe files, to work with kernel mode driver, windbg will complains like following during debugging,

*** WARNING: Unable to verify checksum for AthIhvWlanExt.dll

This can be fixed by modifying visual studio configurations.

1. Right click the project name from Solution Explorer, click Properties context menu.

2. From Configuration Properties —> Linker —> Advanced —> Set Checksum, Change No to Yes(/RELEASE)

3. Rebuild your solutions, windbg can trace your dll as trace your driver.

Technorati 标签:

Posted in Windows | Leave a comment

Locate the code causing DPC Latency Checker red spikes

Technorati 标签: ,
Conclusion

When driver operates hardware, such as read/write eeprom, hw reset, hw set power mode etc, driver needs to wait some time for hw to finish. Such hardware operations should not be called at DISPATCH_LEVEL if wait too long otherwise CPU will be hogged and can not switch to other thread (Windows) or task (Linux).

Hardware registers read/write operation are time-consuming operations, especially a big loop to read/write hardware registers. Such operations can also hog CPU if called at high IRQL.

So we need postpone such time-consuming operations to lowered IRQL, such as work item or a separate thread which runs at PASSIVE_LEVEL, if they run at high IRQL, such as in timer DPC routine or ISR DPC routine which runs at DISPATCH_LEVEL.

Besides, if such operations run with spinlock held, we need to drop the spinlock or use other synchronization mechanism, like semaphore, mutex, to avoid hogging CPU at raised IRQL.

DPC Latency checker will show red spikes if CPU is hogged more than one millisecond at DISPATCH_LEVEL.

Steps to locate red spike culprit

One.

In order to root cause the high DPC latency, the windows performance tool kit from Microsoft is a good start point.

1. Install Win7 symbols to C:\SymCache. The same symbol package as what Windbg uses.

2. Install Windows Performance Tool Kit from Platform SDK. After Platform SDK installed, choose menu from Start->All Programs->Microsoft Windows SDK v7.0->Tools->Install Windows Performance Tool Kit

3. Launch a command prompt. Set the symbol path, set _NT_SYMBOL_PATH=c:\symcache. Also copy driver’s symbol file to c:\symcache.

4. Run xperf.exe –on latency –stackwalk profile from the above command prompt

5. Exercise actions to trigger the red spike.

6. Run xperf.exe –d report.etl

7. Run xperf.exe report.etl. Select Load Symbols menu from Trace menu, select view in DPC CPU Usage graph. Right click this graph and click Summary Table.

8. Since our driver is NDIS miniport driver, expand ndis.sys from DPC CPU Usage Summary Table, we can see that ndisMTimerObjectDpc duration is almost 6.99ms. We can deduce that the red spike may be caused by driver’s timer dpc routine.

Add the following code snippet to measure the time elapsed,

{

LARGE_INTEGER FirstTime, LastTime, Freq;

ULONG time;

FirstTime = KeQueryPerformanceCounter(&Freq);

/* Code to be measured */

LastTime = KeQueryPerformanceCounter(&Freq);

time = (ULONG)(((LastTime.QuadPart – FirstTime.QuadPart)* 1000000)/Freq.QuadPart);

if((time > 500) && (KeGetCurrentIrql() > 1))

{

printk("\nrhinorhino %s: %duS\n",__func__, time);

}

}————————————(1)

Run the checked driver on target machine, and run DbgView to retrieve the driver output instead of windbg which will cause too much overhead. We can get the place where CPU spends too much time at high IRQL.

Two

In order to catch time-consuming operations with spinlock held, we can use following spinlock implementation. Since xperf.exe can not give information about such high latency scenarios.

typedef struct _tagspinlock_t{

NDIS_SPIN_LOCK spinlock;

LARGE_INTEGER firsttime, lasttime, freq;

ULONG time;

}spinlock_t;

static INLINE void spin_lock_init(spinlock_t * _k)

{

NdisZeroMemory((_k), sizeof(spinlock_t));

NdisAllocateSpinLock( &(_k)->spinlock );

}

static INLINE void spin_lock_destroy(spinlock_t * _k)

{

NdisFreeSpinLock( &(_k)->spinlock );

}

static INLINE void spin_lock(spinlock_t * _k)

{

NdisAcquireSpinLock( &(_k)->spinlock );

(_k)->firsttime = KeQueryPerformanceCounter(NULL);

}

static INLINE void spin_unlock_routine(spinlock_t * _k, PCHAR filename, INT lineno, PCHAR funcname)

{

(_k)->lasttime = KeQueryPerformanceCounter(&(_k)->freq);

NdisReleaseSpinLock( &(_k)->spinlock );

(_k)->time = (ULONG)((((_k)->lasttime.QuadPart – (_k)->firsttime.QuadPart)* 1000000)/(_k)->freq.QuadPart);

if((_k)->time > 800) {

DbgPrintEx(0x50,0, "\nrhinorhino %s: %d, %s, %duS\n",filename,lineno, funcname, (_k)->time); }

}

#define spin_unlock(_k) spin_unlock_routine((_k), __FILE__, __LINE__, __FUNCTION__)

And we can find the culprit code.

Posted in NDIS | Leave a comment

Data structures used in Ndis 620 send receive data path.

In NDIS620, protocol, filter, intermediate driver, which will be called overlying driver later in this note, send data to miniport driver by NET_BUFFER_LIST(Nbl). And miniport driver indicates data to overlying driver by the same data structure, Nbl. While in NDIS5.X, NET_PACKET was the counterpart data structure. Nbl structures contain information that describes all the Nb structures that are attached to this list. Multiple Nbl structures can form a NULL terminated singly linked list. In this note, I summarize the NetBufferListPool, Nbl, Nbl context, NetBufferPool, NET_BUFFER(Nb), MDL relations and corresponding functions on how to use them.

1. NetBufferListPool

As its name implies, NetBufferListPool is a pool where Nbl can be allocated from and freed to. NdisAllocateNetBufferListPool function can be called to allocate a Nbl pool. When the fAllocateNetBuffer value is set to TRUE in this function call, an Nb structure is pre-allocated with each Nbl structure that the caller allocates from the pool. In our driver receive engine, one Nbl pool is allocated with pre-allocated Nb for indication to overlying drivers. We should call NdisFreeNetBufferListPool to free this Nbl pool after use.

2. NET_BUFFER_LIST

Overlying driver and miniport driver send and receive data in Nbl. In send data direction, NDIS calls the MiniportSendNetBufferLists function to transmit network data in a linked Nbl list. Nbl data structure layout can be viewed in Windbg as follows:

0: kd> dt _NET_BUFFER_LIST

ndis!_NET_BUFFER_LIST

+0x000 Next : Ptr32 _NET_BUFFER_LIST

+0x004 FirstNetBuffer : Ptr32 _NET_BUFFER

+0x000 Link : _SLIST_HEADER

+0x008 Context : Ptr32 _NET_BUFFER_LIST_CONTEXT

+0x00c ParentNetBufferList : Ptr32 _NET_BUFFER_LIST

+0x010 NdisPoolHandle : Ptr32 Void

+0x018 NdisReserved : [2] Ptr32 Void

+0x020 ProtocolReserved : [4] Ptr32 Void

+0x030 MiniportReserved : [2] Ptr32 Void

+0x038 Scratch : Ptr32 Void

+0x03c SourceHandle : Ptr32 Void

+0x040 NblFlags : Uint4B

+0x044 ChildRefCount : Int4B

+0x048 Flags : Uint4B

+0x04c Status : Int4B

+0x050 NetBufferListInfo : [19] Ptr32 Void

We can use the NET_BUFFER_LIST_NEXT_NBL to loop through each Nbl element in the passed in parameter NetBufferLists.

And use NET_BUFFER_LIST_FIRST_NB macro to get the first Nb from a Nbl element.

And use NET_BUFFER_LIST_FLAGS, NET_BUFFER_LIST_INFO, NET_BUFFER_LIST_STATUS macros to access the Nbl flags, info and status fields.

And use NET_BUFFER_LIST_MINIPORT_RESERVED, NET_BUFFER_LIST_PROTOCOL_RESERVED macros to access the Nbl reserve fields.

Miniport driver must call the NdisMSendNetBufferListsComplete function to complete the send requests for all Nbl structures. Miniport driver can concatenate multiple Nbl from multiple send requests to complete once or split one send request into several Nbl to complete multiple times.

In receive data direction, miniport driver calls the NdisMIndicateReceiveNetBufferLists to indicate the received data from hardware in a linked Nbl up the stack to overlying drivers. If the Status parameter is NDIS_STATUS_SUCCESS, NDIS returns the indicated Nbl structures to the miniport driver’s MiniportReturnNetBufferLists function. If the Status parameter is NDIS_STATUS_RESOURCES, MiniportReturnNetBufferLists function will not be invoked. The miniport driver regains ownership immediately after the indication function returns.

NdisAllocateNetBufferAndNetBufferList function or the NdisAllocateNetBufferList function can be called to allocate Nbl structures from Nbl pool. The former function can be called only if fAllocateNetBuffer is TRUE and DataSize is zero when allocate the Nbl pool.

NdisFreeNetBufferList function can be called to free an Nbl structure after use. The Nb structure which was not pre-allocated can be reused, or be freed separately.

The miniport driver must not modify the list of Nb structures that are associated with an Nbl structure.

If Nblc space for an Nbl structure was allocated, Nblc space should be freed before Nbl free.

3. NET_BUFFER_LIST_CONTEXT

If a driver requires additional space for context information, the driver can store such information in the NET_BUFFER_LIST_CONTEXT(Nblc) structures. NDIS provides functions to allocate, free and access the data in the Nblc structures. Our miniport driver does not use Nblc.

NdisAllocateNetBufferListContext

NdisFreeNetBufferListContext

NET_BUFFER_LIST_CONTEXT_DATA_START

NET_BUFFER_LIST_CONTEXT_DATA_SIZE

NDIS drivers typically use the MiniportReserved or ProtocolReserved members of the NET_BUFFER structure to maintain NET_BUFFER structure context information. Which is what our driver doing.

4. NetBufferPool

As its name implies, NetBufferPool is a pool where Nb can be allocated from and freed to. We can call the NdisAllocateNetBufferPool function to allocate an Nbl pool. If the DataSize value is set to nonzero, MDL and data are pre-allocated with each Nb structure, which can be allocated by NdisAllocateNetBufferMdlAndData. In this case, MDL and data buffers should not be freed separate from the Nb.

Call the NdisFreeNetBufferPool function to free Nb pool after use.

5. NET_BUFFER

Nb is the basic building block for packaging network data. Each Nb structure has an MDL chain. The MDLs describe the addresses of data that Nb specifies. Nb data structure layout can be viewed by Windbg as follows:

0: kd> dt _NET_BUFFER

ndis!_NET_BUFFER

+0x000 Next : Ptr32 _NET_BUFFER

+0x004 CurrentMdl : Ptr32 _MDL

+0x008 CurrentMdlOffset : Uint4B

+0x00c DataLength : Uint4B

+0x00c stDataLength : Uint4B

+0x010 MdlChain : Ptr32 _MDL

+0x014 DataOffset : Uint4B

+0x000 Link : _SLIST_HEADER

+0x018 ChecksumBias : Uint2B

+0x01a Reserved : Uint2B

+0x01c NdisPoolHandle : Ptr32 Void

+0x020 NdisReserved : [2] Ptr32 Void

+0x028 ProtocolReserved : [6] Ptr32 Void

+0x040 MiniportReserved : [4] Ptr32 Void

+0x050 DataPhysicalAddress : _LARGE_INTEGER

+0x058 SharedMemoryInfo : Ptr32 _NET_BUFFER_SHARED_MEMORY

+0x058 ScatterGatherList : Ptr32 _SCATTER_GATHER_LIST

Some of the important Nb fields meaning are as following picture depicts:

We can use NET_BUFFER_NEXT_NB macro to loop each element in the chained Nb. And use NET_BUFFER_FIRST_MDL, NET_BUFFER_CURRENT_MDL, NET_BUFFER_CURRENT_MDL_OFFSET, NET_BUFFER_FIRST_MDL, NDIS_MDL_LINKAGE macros to get each of the chained MDL, whose functionalities can be easily deduced from their names. And use NET_BUFFER_DATA_OFFSET, NET_BUFFER_DATA_LENGTH to get data offset and length as the above picture depicts. And use NET_BUFFER_PROTOCOL_RESERVED, NET_BUFFER_MINIPORT_RESERVED to access the reserved fields for protocol and miniport.

Besides previously described NdisAllocateNetBufferAndNetBufferList to allocate an Nbl with a pre-allocated Nb, we can use NdisAllocateNetBuffer to allocate an Nb from Nb pool. And use NdisFreeNetBuffer to free after use.

6. MDL

A memory descriptor list (MDL) describes a list of pages in physical memory. We can view the MDL data structure layout using Windbg command as follows:

0: kd> dt nt!_MDL

+0x000 Next : Ptr32 _MDL

+0x004 Size : Int2B

+0x006 MdlFlags : Int2B

+0x008 Process : Ptr32 _EPROCESS

+0x00c MappedSystemVa : Ptr32 Void

+0x010 StartVa : Ptr32 Void

+0x014 ByteCount : Uint4B

+0x018 ByteOffset : Uint4B

To access the buffer described by an MDL, we can call MmGetSystemAddressForMdlSafe to map the buffer into system space. MmGetMdlByteCount macro returns the length in bytes of the buffer described by a given MDL. The following table summarizes the routines to manipulate MDL.

Summary of MDL Routines

Name

Description

MmAllocateMappingAddress

Reserves a range of virtual addresses for mapping, but does not actually map them to physical memory.

To map the virtual addresses in the reserved range to physical addresses, the driver later calls IoAllocateMdl, MmProbeAndLockPages, and MmMapLockedPagesWithReservedMapping. This technique is less efficient than calling MmGetSystemAddressForMdlSafe or MmMapLockedPagesXxx, but is useful because it allows driver execution to continue in situations when calling these latter functions fails.

IoAllocateMdl

Allocates an MDL for a buffer, given the starting virtual address of the buffer and its length.

This routine does not associate the physical pages in the buffer with the allocated MDL. To do so, the driver must call MmBuildMdlForNonPagedPool, IoBuildPartialMdl, or MmProbeAndLockPages.

MmProbeAndLockPages

Confirms that the pages described by an MDL permit the requested type of access and, if so, locks those pages into memory.

MmBuildMdlForNonPagedPool

Fills in an MDL to describe a buffer that is allocated in system-space memory from the nonpaged pool. The MDL must have been allocated by IoAllocateMdl.

A driver can also use this function on I/O space, typically by mapping the space with MmMapIoSpace and then passing the returned virtual address to MmBuildMdlForNonPagedPool.

MmAllocatePagesForMdl

Allocates nonpaged, noncontiguous pages from physical memory, specifically for an MDL. A driver calls this function to allocate physical memory from a particular address range. Do not use this function to allocate memory for DMA; use the system’s DMA routines instead.

This function might return fewer pages than the caller requested. Therefore, the driver must call MmGetMdlByteCount to verify the number of bytes allocated.

MmGetSystemAddressForMdlSafe

Maps the physical pages described by an MDL into system space and returns a virtual address for the MDL.

The returned virtual address can be used at any IRQL and in any process context.

IoBuildPartialMdl

Maps part of a buffer described by an existing MDL into a new MDL that the driver previously allocated by calling IoAllocateMdl.

MmAdvanceMdl

Increases the starting address of an MDL.

A driver calls this function to update the MDL to describe a partial buffer when I/O operations are not (or cannot be) completed, either because not enough memory is available or because the device can write only part of the buffer at a time.

MmGetMdlVirtualAddress

Returns the starting virtual address of an MDL.

IoFreeMdl

Frees an MDL that was previously allocated by IoAllocateMdl.

MmFreePagesFromMdl

Frees the pages described by an MDL that was previously created by MmAllocatePagesForMdl.

Although the data structures can be viewed by Windbg, we should use MS published API or macros to access the fields instead of access directly.

Posted in NDIS | 2 Comments

Recover Ubuntu10.04 after installing Win7

   I installed Win7 and Ubuntu10.04 as dual-boot systems. After win7 expires I reinstall win7 but grub in MBR is overwritten. I use following steps to recover grub2.

1. Boot up the system using Ubunt10.04 installation USB.

2. Open a terminal and run following commands to locate where ubuntu10.04 partition is,

    $ sudo fdisk –l   #my system shows my ubunut10.04 locates at the 3rd partition

3. Mount the partition

    $ sudo mount –v /dev/sda3 /mnt

4. Run grub-install

    $ sudo grub-install –root-directory=/mnt   /dev/sda

5. Reboot machine and the familiar grub menu should appear.

Posted in Linux | Leave a comment

readdir return value and file test

I wrote a small perl script sample tonight and tried to modify something but did not display what I want.

#!/usr/bin/perl -w

opendir(DIR, ".") or die "Can’t open the current directory\n";
#here I try to open the parent directory, change "." to ".."
@names =readdir(DIR) or die "cannot read the current directory.\n";

foreach $name (@names) {
   next if ($name eq ".");
   next if ($name eq "..");

   # the file test needs to be given the correct path.
   # if ( -d "../".$name )
   if ( -d $name) {
     print "found a directory: $name\n";
     next;
   }

}

closedir(DIR);
 
So readdir will return an array of file names under its directory. And file test need the correct path otherwise it will not return the true story.

Posted in Perl | Leave a comment

Get the latest Directory on the windows ftp server.

Technorati 标签:

  We have put some images on a windows server which can be accessed through ftp service. We need get the latest updated directory from a certain path. Since rsh is not available, we can not run find ./ –type d –name ‘XXX.*’ –print etc on server. Perl ftp module can return some fields on date and time, so I wrote the following script to get the latest directory, stupid but works. However, since the $ftp->dir can not return the year field, it has the shortcoming mistaking years. But currently, we can make different directories storing each year to avoid this.

#!/usr/bin/perl
use Net::FTP;

sub getlatest
{
   my $latest = @_[0];

   my %MON = (
              "Jan"=>1, "Feb"=>2, "Mar"=>3,"Apr"=>4,"May"=>5,"Jun"=>6,
              "Jul"=>7, "Aug"=>8, "Sep"=>9,"Oct"=>10,"Nov"=>11,"Dec"=>12
             );

   foreach $dir (@_){
    my $monlatest = substr($latest,43,3);
    my $daylatest = substr($latest,47,2);
    my $hourlatest = substr($latest,50,2);
    my $minlatest = substr($latest,53,2);

    my $mon= substr($dir,43,3);
    my $day= substr($dir,47,2);
    my $hour= substr($dir,50,2);
    my $min= substr($dir,53,2);

    if( ($MON{$monlatest} != $MON{$mon} ) )
    {
         if ($MON{$monlatest} < $MON{$mon} )
         {
             $latest = $dir;
         }
         next;
    }    
    # here mon should be same;
    if( $daylatest != $day )
    {
        if( $daylatest < $day )
         {
             $latest = $dir;
         }
         next;
    }
    # here mon, day should be same;
    if( $hourlatest != $hour )
    {
        if( $hourlatest < $hour )
         {
             $latest = $dir;
         }
         next;
    }
    # here mon, day,hour should be same;
    if( $minlatest != $min )
    {
        if( $minlatest < $min )
         {
             $latest = $dir;
         }
         next;
    }
    # here mon, day, hour, min should be same;
    # let the first lucky entry be the latest;
   }
   return $latest;
}

$ftp = Net::FTP->new("HOSTNAME") or die "Cannot connect to HOSTNAME";

$ftp->login("anonymous",’-anonymous@’) or die "Cannot login ", $ftp->message;

$ftp->cwd("PATHYOUNEEDTOLOCATE")
     or die "Cannot change working direcotry ", $ftp->message;

my $PATH=$ftp->pwd();

my @dirs=$ftp->dir();
  $latest= &getlatest(@dirs);

  $PATH .= "/".substr($latest,56,)."/";
  print $PATH;

$ftp->quit;

Posted in Perl | Leave a comment

OID_XXX lookup gadget

During NDIS Windows driver tracing, I found the enormous amount of OID_ are hard to know their value and from value to name. I create a small application to look up a value to OID_XXX name and name to value.I use Perl script to filter out 1047 OIDs from WDK include files and our private header files.  The executive file can be downloaded from http://bbs.driverdevelop.com/read.php?tid-120192.html since MSN live does not support upload file.

The following the perl script.

#########################################################

#!/bin/perl
open OIDHEADER, ">./oids.h" || die "Can not create ./oids.h";
print OIDHEADER "
/*++

Module Name:

    OIDS.H

Abstract:

    This module contains the OID_ macro definition retrieved from WDK header files.

Author:
    Xijin Luo(luorhino\@hotmail.com)
–*/
\n";
foreach $item (@ARGV)
{
   print OIDHEADER "// OID from $item. \n";
   open OIDFILE, $item || die "Can not open $item \n";
   while(<OIDFILE>)
   {
     if( $_ =~ /#define NWF_EXTAP_OID/ ) {
        chomp();
        print OIDHEADER "$_\n";
     }

     if( $_ =~ /#define NWF_DEFINE_OID/ ) {
        chomp();
        print OIDHEADER "$_\n";
     }

     if( $_ =~ /#define NWF_VWIFI_OID/ ) {
        chomp();
        print OIDHEADER "$_\n";
     }

     if( $_ =~ /#define\sOID_/ ) {
        chomp();
        print OIDHEADER "$_\n";
     }
   }
   close OIDFILE;
}
close OIDHEADER;
open OIDARRAY, ">./oidarray.h" || die "Can not create ./oidarray.h";
open OIDHEADER, "./oids.h" || die "Can not open ./oids.h";

print OIDARRAY "
/*++

Module Name:

    OIDARRAY.H

Abstract:

    This module contains the OID_ macro lookup table retrieved from WDK header files.

Author:
    Xijin Luo(luorhino\@hotmail.com)
–*/
\n";

print OIDARRAY "
struct   OidEntries {
        ULONG       ulOidValue;
        TCHAR*      pOidName;
}OidEntries[] = {\n";

while(<OIDHEADER>)
{
   if ( $_ =~ /#define\s+(OID_\w+)/ )
   {
    print OIDARRAY "
   { $1 , TEXT(\"$1\") },\n";
   }
  }
  close OIDHEADER;

  print OIDARRAY "\n};";
  close OIDARRAY;

###############################################

Create a dialog based application by VS wizard. Add two buttons and editboxes. The following code is the main handle functions.

void COidParserDlg::OnBnClickedButton1()
{
    // TODO: Add your control notification handler code here
    CLookup lookup;

    TCHAR      ValueBuf[256] = {0};

    ULONG      ulValue;

    GetDlgItem(IDC_EDIT_VALUE)->GetWindowText(ValueBuf, sizeof(ValueBuf)/sizeof(TCHAR));

    ulValue = lookup.MyStringToUlong(ValueBuf);

    if( 0 == ulValue )
    {
        CString  temp = TEXT("0x");
        GetDlgItem(IDC_EDIT_VALUE)->SetWindowText(temp);
        return;
    }

    if( lookup.LookupName(ulValue, ValueBuf) )
    {
        CString strName = ValueBuf;
        GetDlgItem(IDC_EDIT_NAME)->SetWindowText(strName);       
    }
    else
    {
        AfxMessageBox(TEXT("Oid Value Not Found"), MB_OKCANCEL, 0);
        CString  temp = TEXT("0x");
        GetDlgItem(IDC_EDIT_VALUE)->SetWindowText(temp);
    }
}

void COidParserDlg::OnBnClickedButton2()
{
    // TODO: Add your control notification handler code here
     // TODO: Add your control notification handler code here
    CLookup    lookup;

    CString    strName;

    ULONG      ulValue;

    GetDlgItem(IDC_EDIT_NAME)->GetWindowText(strName);

    if( lookup.LookupValue(&ulValue, strName) )
    {
        CString   strValue;
        strValue.Format(TEXT("0x%08X"), ulValue);
        GetDlgItem(IDC_EDIT_VALUE)->SetWindowText(strValue);       
    }
    else
    {
        AfxMessageBox(TEXT("Oid Value Not Found"), MB_OKCANCEL, 0);
        CString  temp = TEXT("");
        GetDlgItem(IDC_EDIT_VALUE)->SetWindowText(temp);
    }
}

Add a class to provide facility functions.

BOOL CLookup::LookupName(ULONG  ulOidValue, PTCHAR pChar)
{
    ULONG     index;
    BOOL      found = FALSE;

    if( NULL == pChar)
    {
        return 0;
    }

    ULONG ulTableLength = sizeof(OidEntries)/sizeof(OidEntries[0]);

    for( index = 0; index <= ulTableLength; index++)
    {
        if( ulOidValue == OidEntries[index].ulOidValue )
        {
            if(found)
            {
                _tcscpy(pChar,TEXT(" Or ")); pChar += sizeof(TEXT(" Or "))/sizeof(TCHAR) – 1;
            }
            _tcscpy(pChar, OidEntries[index].pOidName); pChar += _tcslen(OidEntries[index].pOidName) ;

            found = TRUE;
        }
    }

    return found;
}

ULONG CLookup::MyStringToUlong(TCHAR *lpStr)
{
    ULONG   ulResult = 0;
    ULONG   ulRadix  = 10;
    TCHAR   *lpTemp = lpStr;

    if( NULL == lpStr )
        return 0;

    while( *lpTemp != ”)
    {
        if( *lpTemp >= ‘a’ && *lpTemp <= ‘f’ )
        {
            ulRadix = 16;
            break;
        }
        if( *lpTemp >= ‘A’ && *lpTemp <= ‘F’ )
        {
            ulRadix = 16;
            break;
        }

        lpTemp++;
    }

    lpTemp = lpStr;

    if( lpStr[0] == ‘0’ &&
        (lpStr[1] == ‘x’ || lpStr[1] == ‘X’)
       )
    {
        lpTemp = lpStr + 2;
        ulRadix = 16;

    }

    while( *lpTemp != ”)
    {
        if( *lpTemp >=’0′ &&
            *lpTemp <=’9′
            )
        {
           ulResult = ulResult * ulRadix + *lpTemp – ‘0’;
        }
        else if( *lpTemp >= ‘a’ &&
                 *lpTemp <= ‘f’
                 )
        {
            ulResult = ulResult * ulRadix + *lpTemp – ‘a’ + 10;
        }
        else if( *lpTemp >= ‘A’ &&
                 *lpTemp <= ‘F’
                 )
        {
            ulResult = ulResult * ulRadix + *lpTemp – ‘A’ + 10;
        }
        else
        {
            AfxMessageBox(TEXT("Invalid Digits"), MB_ICONSTOP, 0);
            return 0;
        };

        lpTemp ++;
    }

    return ulResult;
}

BOOL CLookup::LookupValue(PULONG pulValue, CString strName)

    ULONG     index;

    ULONG     ulTableLength = sizeof(OidEntries)/sizeof(OidEntries[0]);

    for( index = 0; index <= ulTableLength; index++)
    {
        CString  strOid = OidEntries[index].pOidName;
        if( !strOid.CompareNoCase( strName ) )
        {
            *pulValue = OidEntries[index].ulOidValue;
            return TRUE;
        }
    }

    return FALSE;
}

Posted in NDIS | Leave a comment

Build Linux from scratch

  Maybe too many softwares running concurrently during stepping through kernel source code will make thing complex, I just want build a clean linux system following the LFS projects.
  1. download lfslivecd-x86-6.2-3 livecd from http://ftp.osuosl.org/pub/lfs-livecd/lfslivcd-x86-6.2-3.iso or other url from what lfs website lists, and burn it to a cdrom. Why I choose x86-6.2-3 is because this version matches my linux-2.6.15.5-kgdb close.
  2. boot your machine with the lfs livecd. Press enter key whenever it stops asking for settings during booting up until the # prompts. Run startx command to enter graphics UI, that is Xfce. In the Xfce panel in the bottom of the desktop, launch a Terminal and SeaMonkey Web Browser. The SeamMonkey Web Browser will display the LFS book as its default home page, from which we can copy the commands and paste(shift + Insert) to the Terminal and run.
  3. Create a new partition or use an old partition for LFS use, say, /dev/hda2. Format this partition and mount it.
     #export LFS=/mnt/lfs
     # mke2fs -jv /dev/hda2
     # mkdir -pv $LFS
     # mount -v -t ext3 /dev/hda2 $LFS
  4. Copy the lfs souces to $LFS/sources. Make it writable and sticky.
     # mkdir -pv $LFS/sources
     # cp -R /lfs-sources/* $LFS/sources
     # chmod -v a+wt $LFS/sources
     make a directory to accommodate the temporary build tools and make a link to /
     # mkdir -pv $LFS/tools
     # ln -sv $LFS/tools /
     Add a lfs user and group and build the temporary tools as lfs user without messing host environments up. Change the
     previously created two directories ownership to lfs user
     # groupadd lfs
     # useradd -s /bin/bash -g lfs -m -k /dev/null lfs
     # chown -v lfs $LFS/tools
     # chown -v lfs $LFS/sources
     Login as user lfs and setting up the environment.
     # su – lfs
     # cat >~/.bash_profile <<"EOF"
       exec env -i HOME=$HOME TERM=$TERM PS1=’\u:\w\$ ‘ /bin/bash
       EOF
     # cat >~/.bashrc <<"EOF"
       set +h
       umask 022
       LFS=/mnt/lfs
       LC_ALL=POSIX
       PATH=/tools/bin:/bin:/usr/bin
       export LFS LC_ALL PATH
       EOF
     # source ~/.bash_profile
  5. Now we can start building LFS now. In order to save so many key strokes, I just made a shell scripts to build the time consuming packags building procedure. Run the scripts to build the temporary tools.
     # chmod +x 5chapt.sh
     # ./5chapt.sh
    Some notes I feel needs to point out for the above building procedure.
    A. First, binutils, gcc and glibc is build and installed under /tools. where ld-new is built with LIB_PATH=/tools/lib but now used during gcc and glibc build. During toolchain adjusting, the ld-new which will link /tools/lib library will be the default linker. Gcc will use /tools/lib/ld-linux.so.2 by amend its /usr/lib/gcc/i486-pc-linux-gnu/4.0.3/specs file.
    B. Then build the test tools, tcl, expect, dejagnu. Rebuild the gcc and binutils. The ld in binutils is built with LIB_PATH=/usr/lib:/lib for chapter 6 usage.
    C. Sed is extensively used during the build where it is used used mostly to replace a pattern in file. eg,
       sed -i ‘s@^/lib/ld-linux.so.2@/tools&@g’ $SPECFILE > tempspecfile
      search string /lib/ld-linux.so.2 at line beginning and append /tools to this pattern in aspecfile, -i means modify on the file directly.

   6. Install basic system software. We use the toolchain built in chapter 5 to build the basic system software.
      Prepare virtual kernel file system and change root by running the following script.
    # chmod +x 6chroot.sh
    # ./6chroot.sh
      Under the chroot’ed environment, run the following script to build the basic system software.
    # chmod +x 6chapt.sh
    # ./6chapt.sh

   7. Now we can setup system bootscripts. First chroot to the new built system.
    # chroot $LFS /usr/bin/env -i HOME=/root TERM="$TERM" PS1=’\u:\w\$ ‘ PATH=/bin:/usr/bin:/sbin:/usr/sbin /bin/bash –login
      Under the chroot’ed environment, run the following script to setup system script. Be care to modify /etc/fstab to match partition layout.
    # ./7chapt.sh

   8. Build the linux kernel. Just follow the LFS book. Copy the built kernel and System.map files to /boot directory. Of course, we can build kgdb versioned kernel here. Just follow kgdb guide. Modify our boot loader to start the new built LFS kernel.

   9. reboot the machine and choose our boot entry.
   # logout
   # umount -v $LFS/dev/pts
   # umount -v $LFS/dev/shm
   # umount -v $LFS/dev
   # umount -v $LFS/proc
   # umount -v $LFS/sys
   # umount -v $LFS
   # reboot

#############################################################
5chap.sh
#!/bin/bash

export LFS=/mnt/lfs

cd $LFS/sources
#Binutils-2.16.1 – Pass 1
tar xvf binutils-2.16.1.tar.bz2
cd binutils-2.16.1
mkdir -v ../binutils-build
cd ../binutils-build
../binutils-2.16.1/configure –prefix=/tools –disable-nls
make
make install
make -C ld clean
make -C ld LIB_PATH=/tools/lib
cp -v ld/ld-new /tools/bin
cd $LFS/sources
rm -rf binutils-2.16.1
rm -rf binutils-build

#GCC-4.0.3 – Pass 1
cd $LFS/sources
tar xvf gcc-4.0.3.tar.bz2
cd gcc-4.0.3
mkdir -v ../gcc-build
cd ../gcc-build
../gcc-4.0.3/configure –prefix=/tools \
    –with-local-prefix=/tools –disable-nls –enable-shared \
    –enable-languages=c
make bootstrap
make install
ln -vs gcc /tools/bin/cc

cd $LFS/sources
rm -rf gcc-4.0.3
rm -rf gcc-build

#Linux-Libc-Headers-2.6.12.0
tar xvf linux-libc-headers-2.6.12.0.tar.bz2
cp -Rv linux-libc-headers-2.6.12.0/include/asm-i386 /tools/include/asm
cp -Rv linux-libc-headers-2.6.12.0/include/linux /tools/include
rm -rf linux-libc-headers-2.6.12.0

cd $LFS/sources
#Glibc-2.3.6
tar xvf glibc-2.3.6.tar.bz2
mkdir -v glibc-build
cd glibc-build
../glibc-2.3.6/configure –prefix=/tools \
    –disable-profile –enable-add-ons \
    –enable-kernel=2.6.0 –with-binutils=/tools/bin \
    –without-gd –with-headers=/tools/include \
    –without-selinux
make

mkdir -v /tools/etc
touch /tools/etc/ld.so.conf

make install
cd $LFS/sources
rm -rf glibc-build
rm -rf glibc-2.3.6

#Adjusting the Toolchain
cd $LFS/sources
mv -v /tools/bin/{ld,ld-old}
mv -v /tools/$(gcc -dumpmachine)/bin/{ld,ld-old}
mv -v /tools/bin/{ld-new,ld}
ln -sv /tools/bin/ld /tools/$(gcc -dumpmachine)/bin/ld

SPECFILE=`dirname $(gcc -print-libgcc-file-name)`/specs &&
gcc -dumpspecs > $SPECFILE &&
sed ‘s@^/lib/ld-linux.so.2@/tools&@g’ $SPECFILE > tempspecfile &&
mv -vf tempspecfile $SPECFILE &&
unset SPECFILE

GCC_INCLUDEDIR=`dirname $(gcc -print-libgcc-file-name)`/include &&
find ${GCC_INCLUDEDIR}/* -maxdepth 0 -xtype d -exec rm -rvf ‘{}’ \; &&
rm -vf `grep -l "DO NOT EDIT THIS FILE" ${GCC_INCLUDEDIR}/*` &&
unset GCC_INCLUDEDIR

#Tcl-8.4.13
cd $LFS/sources
tar xvf tcl8.4.13-src.tar.gz
cd tcl8.4.13
cd unix
./configure –prefix=/tools
make
make install
make install-private-headers
ln -sv tclsh8.4 /tools/bin/tclsh
cd $LFS/sources
rm -rf tcl8.4.13

#Expect-5.43.0
cd $LFS/sources
tar xvf expect-5.43.0.tar.gz
cd expect-5.43
patch -Np1 -i ../expect-5.43.0-spawn-1.patch
./configure –prefix=/tools –with-tcl=/tools/lib \
  –with-tclinclude=/tools/include –with-x=no
make
make SCRIPTS="" install
cd $LFS/sources
rm -rf expect-5.43

#DejaGNU-1.4.4
cd $LFS/sources
tar xvf dejagnu-1.4.4.tar.gz
cd dejagnu-1.4.4
./configure –prefix=/tools
make install
cd $LFS/sources
rm -rf dejagnu-1.4.4

#GCC-4.0.3 – Pass 2
cd $LFS/sources
tar xvf gcc-4.0.3.tar.bz2
cd gcc-4.0.3

cp -v gcc/Makefile.in{,.orig} &&
sed ‘s@\./fixinc\.sh@-c true@’ gcc/Makefile.in.orig > gcc/Makefile.in

cp -v gcc/Makefile.in{,.tmp} &&
sed ‘s/^XCFLAGS =$/& -fomit-frame-pointer/’ gcc/Makefile.in.tmp \
  > gcc/Makefile.in

patch -Np1 -i ../gcc-4.0.3-specs-1.patch

mkdir -v ../gcc-build
cd ../gcc-build

../gcc-4.0.3/configure –prefix=/tools \
    –with-local-prefix=/tools –enable-clocale=gnu \
    –enable-shared –enable-threads=posix \
    –enable-__cxa_atexit –enable-languages=c,c++ \
    –disable-libstdcxx-pch

make
make -k check
make install
cd $LFS/sources
rm -rf gcc-4.0.3
rm -rf gcc-build

#Binutils-2.16.1 – Pass 2
tar xvf binutils-2.16.1.tar.bz2
cd binutils-2.16.1
mkdir -v ../binutils-build
cd ../binutils-build
../binutils-2.16.1/configure –prefix=/tools \
    –disable-nls –with-lib-path=/tools/lib

make
make check
make install
make -C ld clean
make -C ld LIB_PATH=/usr/lib:/lib
cp -v ld/ld-new /tools/bin

cd $LFS/sources
rm -rf binutils-2.16.1
rm -rf binutils-build

#Ncurses-5.5
tar xvf ncurses-5.5.tar.gz
cd ncurses-5.5
./configure –prefix=/tools –with-shared \
    –without-debug –without-ada –enable-overwrite
make
make install

cd $LFS/sources
rm -rf ncurses-5.5

#Bash-3.1
tar xvf bash-3.1.tar.gz
cd bash-3.1
patch -Np1 -i ../bash-3.1-fixes-8.patch
./configure –prefix=/tools –without-bash-malloc
make
make install
ln -vs bash /tools/bin/sh

cd $LFS/sources
rm -rf  bash-3.1

#Bzip2-1.0.3
tar xvf bzip2-1.0.3.tar.gz
cd bzip2-1.0.3
make
make PREFIX=/tools install

cd $LFS/sources
rm -rf bzip2-1.0.3

#Coreutils-5.96
tar xvf coreutils-5.96.tar.bz2
cd coreutils-5.96
./configure –prefix=/tools
make
make install
cd $LFS/sources
rm -rf coreutils-5.96

#Diffutils-2.8.1
tar xvf diffutils-2.8.1.tar.gz
cd diffutils-2.8.1
./configure –prefix=/tools
make
make install

cd $LFS/sources
rm -rf diffutils-2.8.1

#Findutils-4.2.27
tar xvf findutils-4.2.27.tar.gz
cd findutils-4.2.27
./configure –prefix=/tools
make
make install

cd $LFS/sources
rm -rf findutils-4.2.27

#Gawk-3.1.5
tar xvf gawk-3.1.5.tar.bz2
cd gawk-3.1.5
./configure –prefix=/tools
cat >>config.h <<"EOF"
#define HAVE_LANGINFO_CODESET 1
#define HAVE_LC_MESSAGES 1
EOF
make
make install

cd $LFS/sources
rm -rf gawk-3.1.5

#Gettext-0.14.5
tar xvf gettext-0.14.5.tar.gz
cd gettext-0.14.5
cd gettext-tools
./configure –prefix=/tools –disable-shared
make -C lib
make -C src msgfmt
cp -v src/msgfmt /tools/bin

cd $LFS/sources
rm -rf gettext-0.14.5

#Grep-2.5.1a
tar xvf grep-2.5.1a.tar.bz2
cd grep-2.5.1a
./configure –prefix=/tools \
    –disable-perl-regexp
make
make install

cd $LFS/sources
rm -rf grep-2.5.1a

#Gzip-1.3.5
tar xvf gzip-1.3.5.tar.gz
cd gzip-1.3.5
./configure –prefix=/tools
make
make install

cd $LFS/sources
rm -rf gzip-1.3.5

#M4-1.4.4
tar xvf m4-1.4.4.tar.gz
cd m4-1.4.4
./configure –prefix=/tools
make
make install

cd $LFS/sources
rm -rf m4-1.4.4

#Make-3.80
tar xvf make-3.80.tar.bz2
cd make-3.80
./configure –prefix=/tools
make
make install

cd $LFS/sources
rm -rf make-3.80

#Patch-2.5.4
tar xvf patch-2.5.4.tar.gz
cd patch-2.5.4
./configure –prefix=/tools
make
make install

cd $LFS/sources
rm -rf patch-2.5.4

#Perl-5.8.8
tar xvf perl-5.8.8.tar.bz2
cd perl-5.8.8
patch -Np1 -i ../perl-5.8.8-libc-2.patch
./configure.gnu –prefix=/tools -Dstatic_ext=’Data/Dumper Fcntl IO POSIX’
make perl utilities
cp -v perl pod/pod2man /tools/bin
mkdir -pv /tools/lib/perl5/5.8.8
cp -Rv lib/* /tools/lib/perl5/5.8.8

cd $LFS/sources
rm -rf perl-5.8.8

#Sed-4.1.5
tar xvf sed-4.1.5.tar.gz
cd sed-4.1.5
./configure –prefix=/tools
make
make install

cd $LFS/sources
rm -rf sed-4.1.5

#Tar-1.15.1
tar xvf tar-1.15.1.tar.bz2
cd tar-1.15.1
patch -Np1 -i ../tar-1.15.1-gcc4_fix_tests-1.patch

./configure –prefix=/tools
make
make install

cd $LFS/sources
rm -rf tar-1.15.1

#Texinfo-4.8
tar xvf texinfo-4.8.tar.bz2
cd texinfo-4.8
./configure –prefix=/tools
make
make install

cd $LFS/sources
rm -rf texinfo-4.8

#Util-linux-2.12r
tar xvf util-linux-2.12r.tar.bz2
cd util-linux-2.12r
sed -i ‘s@/usr/include@/tools/include@g’ configure
./configure
make -C lib
make -C mount mount umount
make -C text-utils more
cp mount/{,u}mount text-utils/more /tools/bin

cd $LFS/sources
rm -rf util-linux-2.12r

#End
# Go to  5.32. Changing Ownership continue
echo
echo "Please run exit and continue with 6chroot.sh"

#############################################################
6chap.sh
#!/tools/bin/bash

#Creating Directories FHS
mkdir -pv /{bin,boot,etc/opt,home,lib,mnt,opt}
mkdir -pv /{media/{floppy,cdrom},sbin,srv,var}
install -dv -m 0750 /root
install -dv -m 1777 /tmp /var/tmp
mkdir -pv /usr/{,local/}{bin,include,lib,sbin,src}
mkdir -pv /usr/{,local/}share/{doc,info,locale,man}
mkdir -v  /usr/{,local/}share/{misc,terminfo,zoneinfo}
mkdir -pv /usr/{,local/}share/man/man{1..8}
for dir in /usr /usr/local; do
  ln -sv share/{man,doc,info} $dir
done
mkdir -v /var/{lock,log,mail,run,spool}
mkdir -pv /var/{opt,cache,lib/{misc,locate},local}

#Creating Essential Files and Symlinks
ln -sv /tools/bin/{bash,cat,grep,pwd,stty} /bin
ln -sv /tools/bin/perl /usr/bin
ln -sv /tools/lib/libgcc_s.so{,.1} /usr/lib
ln -sv bash /bin/sh

touch /etc/mtab

cat > /etc/passwd << "EOF"
root:x:0:0:root:/root:/bin/bash
EOF

cat > /etc/group << "EOF"
root:x:0:
bin:x:1:
sys:x:2:
kmem:x:3:
tty:x:4:
tape:x:5:
daemon:x:6:
floppy:x:7:
disk:x:8:
lp:x:9:
dialout:x:10:
audio:x:11:
video:x:12:
utmp:x:13:
usb:x:14:
cdrom:x:15:
EOF

#exec /tools/bin/bash –login +h

touch /var/run/utmp /var/log/{btmp,lastlog,wtmp}
chgrp -v utmp /var/run/utmp /var/log/lastlog
chmod -v 664 /var/run/utmp /var/log/lastlog

cd /sources/
#Linux-Libc-Headers-2.6.12.0
tar xvf linux-libc-headers-2.6.12.0.tar.bz2
cd linux-libc-headers-2.6.12.0
patch -Np1 -i ../linux-libc-headers-2.6.12.0-inotify-3.patch
install -dv /usr/include/asm
cp -Rv include/asm-i386/* /usr/include/asm
cp -Rv include/linux /usr/include
chown -Rv root:root /usr/include/{asm,linux}
find /usr/include/{asm,linux} -type d -exec chmod -v 755 {} \;
find /usr/include/{asm,linux} -type f -exec chmod -v 644 {} \;

cd /sources/
rm -rf linux-libc-headers-2.6.12.0

#Man-pages-2.34
tar xvf man-pages-2.34.tar.bz2
cd man-pages-2.34
make install

cd /sources/
rm -rf man-pages-2.34

#Glibc-2.3.6
tar xvf glibc-2.3.6.tar.bz2
cd glibc-2.3.6
tar -xf ../glibc-libidn-2.3.6.tar.bz2
patch -Np1 -i ../glibc-2.3.6-linux_types-1.patch
patch -Np1 -i ../glibc-2.3.6-inotify-1.patch
sed -i ‘/vi_VN.TCVN/d’ localedata/SUPPORTED
sed -i \
‘s|libs -o|libs -L/usr/lib -Wl,-dynamic-linker=/lib/ld-linux.so.2 -o|’ \
        scripts/test-installation.pl
mkdir -v ../glibc-build
cd ../glibc-build
../glibc-2.3.6/configure –prefix=/usr \
    –disable-profile –enable-add-ons \
    –enable-kernel=2.6.0 –libexecdir=/usr/lib/glibc
make
make -k check 2>&1 | tee glibc-check-log
grep Error glibc-check-log
touch /etc/ld.so.conf
make install
cp -v ../glibc-2.3.6/sysdeps/unix/sysv/linux/inotify.h \
    /usr/include/sys
mkdir -pv /usr/lib/locale
localedef -i de_DE -f ISO-8859-1 de_DE
localedef -i de_DE@euro -f ISO-8859-15 de_DE@euro
localedef -i en_HK -f ISO-8859-1 en_HK
localedef -i en_PH -f ISO-8859-1 en_PH
localedef -i en_US -f ISO-8859-1 en_US
localedef -i en_US -f UTF-8 en_US.UTF-8
localedef -i es_MX -f ISO-8859-1 es_MX
localedef -i fa_IR -f UTF-8 fa_IR
localedef -i fr_FR -f ISO-8859-1 fr_FR
localedef -i fr_FR@euro -f ISO-8859-15 fr_FR@euro
localedef -i fr_FR -f UTF-8 fr_FR.UTF-8
localedef -i it_IT -f ISO-8859-1 it_IT
localedef -i ja_JP -f EUC-JP ja_JP

cat > /etc/nsswitch.conf << "EOF"
# Begin /etc/nsswitch.conf

passwd: files
group: files
shadow: files

hosts: files dns
networks: files

protocols: files
services: files
ethers: files
rpc: files

# End /etc/nsswitch.conf
EOF

cp -v –remove-destination /usr/share/zoneinfo/Asia/Shanghai \
    /etc/localtime

cat > /etc/ld.so.conf << "EOF"
# Begin /etc/ld.so.conf

/usr/local/lib
/opt/lib

# End /etc/ld.so.conf
EOF

cd /sources/
rm -rf glibc-2.3.6
rm -rf glibc-build

#Re-adjusting the toolchain
mv -v /tools/bin/{ld,ld-old}
mv -v /tools/$(gcc -dumpmachine)/bin/{ld,ld-old}
mv -v /tools/bin/{ld-new,ld}
ln -sv /tools/bin/ld /tools/$(gcc -dumpmachine)/bin/ld

gcc -dumpspecs | \
perl -p -e ‘s@/tools/lib/ld-linux.so.2@/lib/ld-linux.so.2@g;’ \
    -e ‘s@\*startfile_prefix_spec:\n@$_/usr/lib/ @g;’ > \
    `dirname $(gcc –print-libgcc-file-name)`/specs

#Binutils-2.16.1
tar xvf binutils-2.16.1.tar.bz2
cd binutils-2.16.1
mkdir -v ../binutils-build
cd ../binutils-build
../binutils-2.16.1/configure –prefix=/usr \
    –enable-shared
make tooldir=/usr
make check
make tooldir=/usr install
cp -v ../binutils-2.16.1/include/libiberty.h /usr/include

cd /sources/
rm -rf binutils-2.16.1
rm -rf binutils-build

#GCC-4.0.3
tar xvf gcc-4.0.3.tar.bz2
cd gcc-4.0.3
sed -i ‘s/install_to_$(INSTALL_DEST) //’ libiberty/Makefile.in
sed -i ‘s/^XCFLAGS =$/& -fomit-frame-pointer/’ gcc/Makefile.in
sed -i ‘s@\./fixinc\.sh@-c true@’ gcc/Makefile.in
sed -i ‘s/@have_mktemp_command@/yes/’ gcc/gccbug.in
mkdir -v ../gcc-build
cd ../gcc-build
../gcc-4.0.3/configure –prefix=/usr \
    –libexecdir=/usr/lib –enable-shared \
    –enable-threads=posix –enable-__cxa_atexit \
    –enable-clocale=gnu –enable-languages=c,c++

make
make -k check
../gcc-4.0.3/contrib/test_summary
make install
ln -sv ../usr/bin/cpp /lib
ln -sv gcc /usr/bin/cc

cd /sources/
rm -rf gcc-4.0.3
rm -rf gcc-build

#Berkeley DB-4.4.20
tar xvf db-4.4.20.tar.gz
cd db-4.4.20
patch -Np1 -i ../db-4.4.20-fixes-1.patch
cd build_unix &&
../dist/configure –prefix=/usr –enable-compat185 –enable-cxx

make
make docdir=/usr/share/doc/db-4.4.20 install
chown -v root:root /usr/bin/db_* \
    /usr/lib/libdb* /usr/include/db* &&
chown -Rv root:root /usr/share/doc/db-4.4.20

cd /sources/
rm -rf db-4.4.20

#Coreutils-5.96
tar xvf coreutils-5.96.tar.bz2
cd coreutils-5.96
patch -Np1 -i ../coreutils-5.96-uname-1.patch
patch -Np1 -i ../coreutils-5.96-suppress_uptime_kill_su-1.patch
patch -Np1 -i ../coreutils-5.96-i18n-1.patch
chmod +x tests/sort/sort-mb-tests
sed -i ‘s/_LEN 6/_LEN 20/’ src/who.c
./configure –prefix=/usr
make
echo "dummy1:x:1000:" >> /etc/group
echo "dummy2:x:1001:dummy" >> /etc/group
echo "dummy:x:1000:1000::/root:/bin/bash" >> /etc/passwd
make NON_ROOT_USERNAME=dummy check-root
src/su dummy -c "make RUN_EXPENSIVE_TESTS=yes check"
sed -i ‘/dummy/d’ /etc/passwd /etc/group
make install

mv -v /usr/bin/{cat,chgrp,chmod,chown,cp,date,dd,df,echo} /bin
mv -v /usr/bin/{false,hostname,ln,ls,mkdir,mknod,mv,pwd,rm} /bin
mv -v /usr/bin/{rmdir,stty,sync,true,uname} /bin
mv -v /usr/bin/chroot /usr/sbin

mv -v /usr/bin/{head,sleep,nice} /bin

cd /sources/
rm -rf coreutils-5.96

#Iana-Etc-2.10
tar -xvf iana-etc-2.10.tar.bz2
cd iana-etc-2.10
make
make install

cd /sources/
rm -rf iana-etc-2.10

#M4-1.4.4
tar xvf m4-1.4.4.tar.gz
cd  m4-1.4.4
./configure –prefix=/usr
make
make install

cd /sources/
rm -rf m4-1.4.4

#Bison-2.2
tar xvf bison-2.2.tar.bz2
cd bison-2.2
./configure –prefix=/usr
echo ‘#define YYENABLE_NLS 1’ >> config.h
make
make check
make install

cd /sources/
rm -rf bison-2.2

#Ncurses-5.5
tar -xvf ncurses-5.5.tar.gz
cd ncurses-5.5
patch -Np1 -i ../ncurses-5.5-fixes-1.patch
./configure –prefix=/usr –with-shared –without-debug –enable-widec

make
make install
chmod -v 755 /usr/lib/*.5.5
chmod -v 644 /usr/lib/libncurses++w.a
mv -v /usr/lib/libncursesw.so.5* /lib
ln -sfv ../../lib/libncursesw.so.5 /usr/lib/libncursesw.so
for lib in curses ncurses form panel menu ; do \
    rm -vf /usr/lib/lib${lib}.so ; \
    echo "INPUT(-l${lib}w)" >/usr/lib/lib${lib}.so ; \
    ln -sfv lib${lib}w.a /usr/lib/lib${lib}.a ; \
done &&
ln -sfv libncurses++w.a /usr/lib/libncurses++.a
echo "INPUT(-lncursesw)" >/usr/lib/libcursesw.so &&
ln -sfv libncurses.so /usr/lib/libcurses.so &&
ln -sfv libncursesw.a /usr/lib/libcursesw.a &&
ln -sfv libncurses.a /usr/lib/libcurses.a
make distclean &&
./configure –prefix=/usr –with-shared –without-normal \
  –without-debug –without-cxx-binding &&
make sources libs &&
cp -av lib/lib*.so.5* /usr/lib

cd /sources/
rm -rf ncurses-5.5

#procps-3.2.6
tar xvf procps-3.2.6.tar.gz
cd procps-3.2.6
make
make install

cd /sources/
rm -rf procps-3.2.6

#Sed-4.1.5
tar xvf sed-4.1.5.tar.gz
cd sed-4.1.5
./configure –prefix=/usr –bindir=/bin –enable-html
make
make install

cd /sources/
rm -rf sed-4.1.5

#libtool-1.5.22
tar xvf libtool-1.5.22.tar.gz
cd  libtool-1.5.22
./configure –prefix=/usr

make
make install

cd /sources/
rm -rf libtool-1.5.22

#perl-5.8.8.tar.bz2
tar xvf perl-5.8.8.tar.bz2
cd  perl-5.8.8
echo "127.0.0.1 localhost $(hostname)" > /etc/hosts
./configure.gnu –prefix=/usr \
    -Dman1dir=/usr/share/man/man1 \
    -Dman3dir=/usr/share/man/man3 \
    -Dpager="/usr/bin/less -isR"
make
make install

cd /sources/
rm -rf  perl-5.8.8

#Readline-5.1
tar xvf readline-5.1.tar.gz
cd readline-5.1
patch -Np1 -i ../readline-5.1-fixes-3.patch
sed -i ‘/MV.*old/d’ Makefile.in
sed -i ‘/{OLDSUFF}/c:’ support/shlib-install
./configure –prefix=/usr –libdir=/lib
make SHLIB_LIBS=-lncurses
make install
chmod -v 755 /lib/lib{readline,history}.so*
mv -v /lib/lib{readline,history}.a /usr/lib
rm -v /lib/lib{readline,history}.so
ln -sfv ../../lib/libreadline.so.5 /usr/lib/libreadline.so
ln -sfv ../../lib/libhistory.so.5 /usr/lib/libhistory.so

cd /sources/
rm -rf readline-5.1

#Zlib-1.2.3
tar xvf zlib-1.2.3.tar.gz
cd zlib-1.2.3
./configure –prefix=/usr –shared –libdir=/lib
make
make install
rm -v /lib/libz.so
ln -sfv ../../lib/libz.so.1.2.3 /usr/lib/libz.so
make clean
./configure –prefix=/usr
make
make install
chmod -v 644 /usr/lib/libz.a

cd /sources/
rm -rf zlib-1.2.3

#Autoconf-2.59
tar xvf autoconf-2.59.tar.bz2
cd  autoconf-2.59
./configure –prefix=/usr
make
make install

cd /sources/
rm -rf autoconf-2.59

#Automake-1.9.6
tar xvf automake-1.9.6.tar.bz2
cd automake-1.9.6
./configure –prefix=/usr
make
make install

cd /sources/
rm -rf automake-1.9.6

#Bash-3.1
tar xvf bash-3.1.tar.gz
cd bash-3.1
tar -xvf ../bash-doc-3.1.tar.gz &&
sed -i "s|htmldir = @htmldir@|htmldir = /usr/share/doc/bash-3.1|" \
    Makefile.in
patch -Np1 -i ../bash-3.1-fixes-8.patch
./configure –prefix=/usr –bindir=/bin \
    –without-bash-malloc –with-installed-readline
make
make tests
make install

cd /sources/
rm -rf bash-3.1

#Bzip2-1.0.3
tar xvf bzip2-1.0.3.tar.gz
cd bzip2-1.0.3
patch -Np1 -i ../bzip2-1.0.3-install_docs-1.patch
patch -Np1 -i ../bzip2-1.0.3-bzgrep_security-1.patch
sed -i ‘s@tempfile -d /tmp -p bz@mktemp -p /tmp@’ bzdiff
make -f Makefile-libbz2_so
make clean

make
make install
cp -v bzip2-shared /bin/bzip2
cp -av libbz2.so* /lib
ln -sv ../../lib/libbz2.so.1.0 /usr/lib/libbz2.so
rm -v /usr/bin/{bunzip2,bzcat,bzip2}
ln -sv bzip2 /bin/bunzip2
ln -sv bzip2 /bin/bzcat

cd /sources/
rm -rf bzip2-1.0.3

#Diffutils-2.8.1
tar xvf diffutils-2.8.1.tar.gz
cd diffutils-2.8.1
patch -Np1 -i ../diffutils-2.8.1-i18n-1.patch
touch man/diff.1
./configure –prefix=/usr
make
make install

cd /sources/
rm -rf diffutils-2.8.1

#E2fsprogs-1.39
tar xvf e2fsprogs-1.39.tar.gz
cd e2fsprogs-1.39
mkdir -v build
cd build
../configure –prefix=/usr –with-root-prefix="" \
    –enable-elf-shlibs –disable-evms
make
make install
make install-libs

cd /sources/
rm -rf e2fsprogs-1.39

#File-4.17
tar xvf file-4.17.tar.gz
cd file-4.17
./configure –prefix=/usr
make
make install

cd /sources/
rm -rf file-4.17

#Findutils-4.2.27
tar xvf findutils-4.2.27.tar.gz
cd findutils-4.2.27
./configure –prefix=/usr –libexecdir=/usr/lib/findutils \
    –localstatedir=/var/lib/locate
make
make install
mv -v /usr/bin/find /bin
sed -i -e ‘s/find:=${BINDIR}/find:=\/bin/’ /usr/bin/updatedb

cd /sources/
rm -rf findutils-4.2.27

#Flex-2.5.33
tar xvf flex-2.5.33.tar.bz2
cd flex-2.5.33
./configure –prefix=/usr
make
make install
ln -sv libfl.a /usr/lib/libl.a
cat > /usr/bin/lex << "EOF"
#!/bin/sh
# Begin /usr/bin/lex

exec /usr/bin/flex -l "$@"

# End /usr/bin/lex
EOF
chmod -v 755 /usr/bin/lex

cd /sources/
rm -rf flex-2.5.33

#GRUB-0.97
tar xvf grub-0.97.tar.gz
cd grub-0.97
patch -Np1 -i ../grub-0.97-disk_geometry-1.patch
./configure –prefix=/usr
make
make install
mkdir -v /boot/grub
cp -v /usr/lib/grub/i386-pc/stage{1,2} /boot/grub

cd /sources/
rm -rf grub-0.97

#gawk-3.1.5
tar xvf gawk-3.1.5.tar.bz2
cd gawk-3.1.5
patch -Np1 -i ../gawk-3.1.5-segfault_fix-1.patch
./configure –prefix=/usr –libexecdir=/usr/lib
cat >>config.h <<"EOF"
#define HAVE_LANGINFO_CODESET 1
#define HAVE_LC_MESSAGES 1
EOF
make
make install

cd /sources/
rm -rf gawk-3.1.5

#Gettext-0.14.5
tar xvf gettext-0.14.5.tar.gz
cd gettext-0.14.5
./configure –prefix=/usr
make
make install

cd /sources/
rm -rf  gettext-0.14.5

#Grep-2.5.1a
tar xvf grep-2.5.1a.tar.bz2
cd grep-2.5.1a
patch -Np1 -i ../grep-2.5.1a-redhat_fixes-2.patch
chmod +x tests/fmbtest.sh
./configure –prefix=/usr –bindir=/bin
make
make install

cd /sources/
rm -rf grep-2.5.1a

#Groff-1.18.1.1
tar xvf groff-1.18.1.1.tar.gz
cd groff-1.18.1.1
patch -Np1 -i ../groff-1.18.1.1-debian_fixes-1.patch
sed -i -e ‘s/2010/002D/’ -e ‘s/2212/002D/’ \
    -e ‘s/2018/0060/’ -e ‘s/2019/0027/’ font/devutf8/R.proto
PAGE=A4 ./configure –prefix=/usr –enable-multibyte
make
make install
ln -sv eqn /usr/bin/geqn
ln -sv tbl /usr/bin/gtbl

cd /sources/
rm -rf groff-1.18.1.1

#Gzip-1.3.5
tar xvf gzip-1.3.5.tar.gz
cd gzip-1.3.5
patch -Np1 -i ../gzip-1.3.5-security_fixes-1.patch
./configure –prefix=/usr
sed -i ‘s@"BINDIR"@/bin@g’ gzexe.in
make
make install
mv -v /usr/bin/gzip /bin
rm -v /usr/bin/{gunzip,zcat}
ln -sv gzip /bin/gunzip
ln -sv gzip /bin/zcat
ln -sv gzip /bin/compress
ln -sv gunzip /bin/uncompress

cd /sources/
rm -rf gzip-1.3.5

#Inetutils-1.4.2
tar xvf inetutils-1.4.2.tar.gz
cd inetutils-1.4.2
patch -Np1 -i ../inetutils-1.4.2-gcc4_fixes-3.patch
patch -Np1 -i ../inetutils-1.4.2-no_server_man_pages-1.patch
./configure –prefix=/usr –libexecdir=/usr/sbin \
    –sysconfdir=/etc –localstatedir=/var \
    –disable-logger –disable-syslogd \
    –disable-whois –disable-servers
make
make install
mv -v /usr/bin/ping /bin

cd /sources/
rm -rf inetutils-1.4.2

#IPRoute2-2.6.16-060323
tar xvf iproute2-2.6.16-060323.tar.gz
cd iproute2-2.6.16-060323
make SBINDIR=/sbin
make SBINDIR=/sbin install
mv -v /sbin/arpd /usr/sbin

cd /sources/
rm -rf iproute2-2.6.16-060323

#Kbd-1.12
tar xvf kbd-1.12.tar.bz2
cd kbd-1.12
patch -Np1 -i ../kbd-1.12-backspace-1.patch
patch -Np1 -i ../kbd-1.12-gcc4_fixes-1.patch
./configure –datadir=/lib/kbd
make
make install
mv -v /usr/bin/{kbd_mode,openvt,setfont} /bin

cd /sources/
rm -rf kbd-1.12

#Less-394
tar xvf less-394.tar.gz
cd less-394
./configure –prefix=/usr –sysconfdir=/etc
make
make install

cd /sources/
rm -rf less-394

#make-3.80
tar xvf make-3.80.tar.bz2
cd make-3.80
./configure –prefix=/usr
make
make install

cd /sources/
rm -rf make-3.80

#Man-DB-2.4.3
tar xvf man-db-2.4.3.tar.gz
cd man-db-2.4.3
mv man/de{_DE.88591,} &&
mv man/es{_ES.88591,} &&
mv man/it{_IT.88591,} &&
mv man/ja{_JP.eucJP,} &&
sed -i ‘s,\*_\*,??,’ man/Makefile.in

sed -i ‘/\t\/usr\/man/d’ src/man_db.conf.in
cat >>include/manconfig.h.in <<"EOF"
#define WEB_BROWSER "exec /usr/bin/lynx"
#define COL "/usr/bin/col"
#define VGRIND "/usr/bin/vgrind"
#define GRAP "/usr/bin/grap"
EOF

./configure –prefix=/usr –enable-mb-groff –disable-setuid
make
make install
cat >>convert-mans <<"EOF"
#!/bin/sh -e
FROM="$1"
TO="$2"
shift ; shift
while [ $# -gt 0 ]
do
        FILE="$1"
        shift
        iconv -f "$FROM" -t "$TO" "$FILE" >.tmp.iconv
        mv .tmp.iconv "$FILE"
done
EOF
install -m755 convert-mans  /usr/bin
cat >>convert-mans <<"EOF"
#!/bin/sh -e
FROM="$1"
TO="$2"
shift ; shift
while [ $# -gt 0 ]
do
        FILE="$1"
        shift
        iconv -f "$FROM" -t "$TO" "$FILE" >.tmp.iconv
        mv .tmp.iconv "$FILE"
done
EOF
install -m755 convert-mans  /usr/bin

cd /sources/
rm -rf man-db-2.4.3

#Mktemp-1.5
tar xvf mktemp-1.5.tar.gz
cd mktemp-1.5
patch -Np1 -i ../mktemp-1.5-add_tempfile-3.patch
./configure –prefix=/usr –with-libc
make
make install
make install-tempfile

cd /sources/
rm -rf mktemp-1.5

#Module-Init-Tools-3.2.2
tar xvf module-init-tools-3.2.2.tar.bz2
cd module-init-tools-3.2.2
patch -Np1 -i ../module-init-tools-3.2.2-modprobe-1.patch
./configure &&
make check &&
make distclean
./configure –prefix=/ –enable-zlib
make
make INSTALL=install install

cd /sources/
rm -rf module-init-tools-3.2.2

#Patch-2.5.4
tar xvf patch-2.5.4.tar.gz
cd patch-2.5.4
./configure –prefix=/usr
make
make install

cd /sources/
rm -rf patch-2.5.4

#Psmisc-22.2
tar xvf psmisc-22.2.tar.gz
cd psmisc-22.2
./configure –prefix=/usr –exec-prefix=""
make
make install
mv -v /bin/pstree* /usr/bin
ln -sv killall /bin/pidof

cd /sources/
rm -rf psmisc-22.2

#Shadow-4.0.15
tar xvf shadow-4.0.15.tar.bz2
cd shadow-4.0.15
./configure –libdir=/lib –enable-shared –without-selinux
sed -i ‘s/groups$(EXEEXT) //’ src/Makefile
find man -name Makefile -exec sed -i ‘/groups/d’ {} \;
sed -i -e ‘s/ ko//’ -e ‘s/ zh_CN zh_TW//’ man/Makefile
 for i in de es fi fr id it pt_BR; do
    convert-mans UTF-8 ISO-8859-1 man/${i}/*.?
done

for i in cs hu pl; do
    convert-mans UTF-8 ISO-8859-2 man/${i}/*.?
done

convert-mans UTF-8 EUC-JP man/ja/*.?
convert-mans UTF-8 KOI8-R man/ru/*.?
convert-mans UTF-8 ISO-8859-9 man/tr/*.?

make
make install
cp -v etc/{limits,login.access} /etc
sed -e’s@#MD5_CRYPT_ENAB.no@MD5_CRYPT_ENAB yes@’ \
    -e ‘s@/var/spool/mail@/var/mail@’ \
    etc/login.defs > /etc/login.defs
mv -v /usr/bin/passwd /bin
mv -v /lib/libshadow.*a /usr/lib
rm -v /lib/libshadow.so
ln -sfv ../../lib/libshadow.so.0 /usr/lib/libshadow.so
mkdir -v /etc/default

cd /sources/
rm -rf shadow-4.0.15

#Sysklogd-1.4.1
tar xvf sysklogd-1.4.1.tar.gz
cd sysklogd-1.4.1
patch -Np1 -i ../sysklogd-1.4.1-fixes-1.patch
patch -Np1 -i ../sysklogd-1.4.1-8bit-1.patch
make
make install
cat > /etc/syslog.conf << "EOF"
# Begin /etc/syslog.conf

auth,authpriv.* -/var/log/auth.log
*.*;auth,authpriv.none -/var/log/sys.log
daemon.* -/var/log/daemon.log
kern.* -/var/log/kern.log
mail.* -/var/log/mail.log
user.* -/var/log/user.log
*.emerg *

# End /etc/syslog.conf
EOF

cd /sources/
rm -rf sysklogd-1.4.1

#sysvinit-2.86
tar xvf sysvinit-2.86.tar.gz
cd sysvinit-2.86
sed -i ‘s@Sending processes@& started by init@g’ \
    src/init.c
make -C src
make -C src install
cat > /etc/inittab << "EOF"
# Begin /etc/inittab

id:3:initdefault:

si::sysinit:/etc/rc.d/init.d/rc sysinit

l0:0:wait:/etc/rc.d/init.d/rc 0
l1:S1:wait:/etc/rc.d/init.d/rc 1
l2:2:wait:/etc/rc.d/init.d/rc 2
l3:3:wait:/etc/rc.d/init.d/rc 3
l4:4:wait:/etc/rc.d/init.d/rc 4
l5:5:wait:/etc/rc.d/init.d/rc 5
l6:6:wait:/etc/rc.d/init.d/rc 6

ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now

su:S016:once:/sbin/sulogin

1:2345:respawn:/sbin/agetty tty1 9600
2:2345:respawn:/sbin/agetty tty2 9600
3:2345:respawn:/sbin/agetty tty3 9600
4:2345:respawn:/sbin/agetty tty4 9600
5:2345:respawn:/sbin/agetty tty5 9600
6:2345:respawn:/sbin/agetty tty6 9600

# End /etc/inittab
EOF

cd /sources/
rm -rf sysvinit-2.86

#Tar-1.15.1
tar xvf tar-1.15.1.tar.bz2
cd tar-1.15.1
patch -Np1 -i ../tar-1.15.1-gcc4_fix_tests-1.patch
patch -Np1 -i ../tar-1.15.1-sparse_fix-1.patch
patch -Np1 -i ../tar-1.15.1-security_fixes-1.patch
./configure –prefix=/usr –bindir=/bin –libexecdir=/usr/sbin
make
make install

cd /sources/
rm -rf tar-1.15.1

#Texinfo-4.8
tar xvf texinfo-4.8.tar.bz2
cd texinfo-4.8
patch -Np1 -i ../texinfo-4.8-multibyte-1.patch
patch -Np1 -i ../texinfo-4.8-tempfile_fix-2.patch
./configure –prefix=/usr
make
make install
make TEXMF=/usr/share/texmf install-tex

cd /usr/share/info
rm dir
for f in *
do install-info $f dir 2>/dev/null
done

cd /sources/
rm -rf texinfo-4.8

#Udev-096
tar xvf udev-096.tar.bz2
cd udev-096
tar xf ../udev-config-6.2.tar.bz2
install -dv /lib/{firmware,udev/devices/{pts,shm}}
mknod -m0666 /lib/udev/devices/null c 1 3
ln -sv /proc/self/fd /lib/udev/devices/fd
ln -sv /proc/self/fd/0 /lib/udev/devices/stdin
ln -sv /proc/self/fd/1 /lib/udev/devices/stdout
ln -sv /proc/self/fd/2 /lib/udev/devices/stderr
ln -sv /proc/kcore /lib/udev/devices/core
make EXTRAS="extras/ata_id extras/cdrom_id extras/edd_id \
            extras/firmware extras/floppy extras/path_id \
            extras/scsi_id extras/usb_id extras/volume_id"
make test

make DESTDIR=/ \
    EXTRAS="extras/ata_id extras/cdrom_id extras/edd_id \
            extras/firmware extras/floppy extras/path_id \
            extras/scsi_id extras/usb_id extras/volume_id" install
cp -v udev-config-6.2/[0-9]* /etc/udev/rules.d/
install -m644 -D -v docs/writing_udev_rules/index.html \
    /usr/share/doc/udev-096/index.html

cd /sources/
rm -rf udev-096

#Util-linux-2.12r
tar xvf util-linux-2.12r.tar.bz2
cd util-linux-2.12r
sed -i ‘s@etc/adjtime@var/lib/hwclock/adjtime@g’ \
    hwclock/hwclock.c
mkdir -p /var/lib/hwclock
patch -Np1 -i ../util-linux-2.12r-cramfs-1.patch
./configure
make HAVE_KILL=yes HAVE_SLN=yes
make HAVE_KILL=yes HAVE_SLN=yes install

cd /sources/
rm -rf util-linux-2.12r

#Vim-7.0
tar xvf vim-7.0.tar.bz2
cd vim70
patch -Np1 -i ../vim-7.0-fixes-7.patch
patch -Np1 -i ../vim-7.0-mandir-1.patch
patch -Np1 -i ../vim-7.0-spellfile-1.patch
echo ‘#define SYS_VIMRC_FILE "/etc/vimrc"’ >> src/feature.h
./configure –prefix=/usr –enable-multibyte
make
make install
rm -f /usr/share/vim/vim70/tutor/tutor.{gr,pl,ru,sk}
rm -f /usr/share/vim/vim70/tutor/tutor.??.*
ln -sv vim /usr/bin/vi
for L in "" fr it pl ru; do
    ln -sv vim.1 /usr/share/man/$L/man1/vi.1
done
ln -sv ../vim/vim70/doc /usr/share/doc/vim-7.0
cat > /etc/vimrc << "EOF"
" Begin /etc/vimrc

set nocompatible
set backspace=2
syntax on
if (&term == "iterm") || (&term == "putty")
  set background=dark
endif

" End /etc/vimrc
EOF

cd /sources/
rm -rf vim70

#End

echo " Chroot into the new environments with the following,
chroot \"\$LFS\" /usr/bin/env -i \
    HOME=/root TERM=\"$TERM\" PS1=’\u:\w\$ ‘ \
    PATH=/bin:/usr/bin:/sbin:/usr/sbin \
    /bin/bash –login
"

echo "
and continue with 7chapt.sh
"

#############################################################
6chroot.sh
#!/bin/bash

export LFS=/mnt/lfs

chown -R root:root $LFS/tools
mkdir -pv $LFS/{dev,proc,sys}
mknod -m 600 $LFS/dev/console c 5 1
mknod -m 666 $LFS/dev/null c 1 3

mount –bind /dev $LFS/dev

mount -vt devpts devpts $LFS/dev/pts
mount -vt tmpfs shm $LFS/dev/shm
mount -vt proc proc $LFS/proc
mount -vt sysfs sysfs $LFS/sys

echo
echo "Now we will chroot. Please continue with 6chapt.sh"
echo

chroot "$LFS" /tools/bin/env -i \
    HOME=/root TERM="$TERM" PS1=’\u:\w\$ ‘ \
    PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
    /tools/bin/bash –login +h

#############################################################
7chapt.sh
#!/bin/bash

cd /sources/

#LFS-Bootscripts-6.2
tar xvf lfs-bootscripts-6.2.tar.bz2
cd lfs-bootscripts-6.2
make install

cd /sources/
rm -rf lfs-bootscripts-6.2

cat > /etc/sysconfig/clock << "EOF"
# Begin /etc/sysconfig/clock

UTC=1

# End /etc/sysconfig/clock
EOF

cat > /etc/sysconfig/console << "EOF"
# Begin /etc/sysconfig/console
KEYMAP="defkeymap"
FONT="default8x16"
# End /etc/sysconfig/console
EOF

cat > /etc/inputrc << "EOF"
# Begin /etc/inputrc
# Modified by Chris Lynn <roryo@roryo.dynup.net>

# Allow the command prompt to wrap to the next line
set horizontal-scroll-mode Off

# Enable 8bit input
set meta-flag On
set input-meta On

# Turns off 8th bit stripping
set convert-meta Off

# Keep the 8th bit for display
set output-meta On

# none, visible or audible
set bell-style none

# All of the following map the escape sequence of the
# value contained inside the 1st argument to the
# readline specific functions

"\eOd": backward-word
"\eOc": forward-word

# for linux console
"\e[1~": beginning-of-line
"\e[4~": end-of-line
"\e[5~": beginning-of-history
"\e[6~": end-of-history
"\e[3~": delete-char
"\e[2~": quoted-insert

# for xterm
"\eOH": beginning-of-line
"\eOF": end-of-line

# for Konsole
"\e[H": beginning-of-line
"\e[F": end-of-line

# End /etc/inputrc
EOF

cat > /etc/profile << "EOF"
# Begin /etc/profile

LANG="C" ; export LANG
export INPUTRC=/etc/inputrc

# End /etc/profile
EOF

echo "HOSTNAME=<lfs>" > /etc/sysconfig/network

cat > /etc/fstab << "EOF"
# Begin /etc/fstab

# file system  mount-point  type   options         dump  fsck
#                                                        order

/dev/hda2      /            ext3  defaults        1     1
/dev/hda3     swap         swap   pri=1           0     0
proc           /proc        proc   defaults        0     0
sysfs          /sys         sysfs  defaults        0     0
devpts         /dev/pts     devpts gid=4,mode=620  0     0
shm            /dev/shm     tmpfs  defaults        0     0
# End /etc/fstab
EOF

echo "
Continue with 8.3. Linux-2.6.16.27
"
#############################################################

Posted in Linux | Leave a comment