#!/bin/bash
echo "Generate modules.cgz for Marvell PCI-X to Serial ATA adapters."
if [ -z "$1" ] ; then
echo "parameter missing"
exit 1
fi
BOOT_FLAGS="-D__BOOT_KERNEL_BOOT=1 -D__BOOT_KERNEL_UP=1 -D__BOOT_KERNEL_SMP=0"
SMP_FLAGS="-D__SMP__=1 -D__BOOT_KERNEL_SMP=1 -D__BOOT_KERNEL_UP=0"
UP_FLAGS="-D__BOOT_KERNEL_SMP=0 -D__BOOT_KERNEL_UP=1"
HUGEMEM_FLAGS="-D__BOOT_KERNEL_HUGEMEM=1"
BIGMEM_FLAGS="-D__BOOT_KERNEL_BIGMEM=1"
i386_FLAGS="-D__MODULE_KERNEL_i686=0 -D__MODULE_KERNEL_i586=0 -D__MODULE_KERNEL_athlon=0 -march=i386"
i686_FLAGS="-D__MODULE_KERNEL_i686=1 -D__MODULE_KERNEL_athlon=0 -D__MODULE_KERNEL_i586=0 -march=i686"
athlon_FLAGS="-D__MODULE_KERNEL_athlon=1 -D__MODULE_KERNEL_i686=0 -D__MODULE_KERNEL_i586=0 -march=athlon"
external_flags=""
get_flags()
{
local flags=""
local build=$1
local cpu=$2
local build_flags=""
#echo get flags: build = $build cpu = $cpu
external_flags=""
case "$build" in
"UP" ) build_flags=$UP_FLAGS;;
"BOOT" ) build_flags=${BOOT_FLAGS};;
"SMP" ) build_flags=${SMP_FLAGS};;
"HUGEMEM" ) build_flags=${HUGEMEM_FLAGS};;
"BIGMEM" ) build_flags=${BIGMEM_FLAGS};;
esac
case "$cpu" in
"i386" ) build_flags="${build_flags} ${i386_FLAGS}";;
"i686" ) build_flags="${build_flags} ${i686_FLAGS}";;
"athlon" ) build_flags="${build_flags} ${athlon_FLAGS}";;
esac
flags="${flags}${build_flags} "
external_flags="$external_flags $flags"
}
dir=`pwd`
rm -rf temp
mkdir -p temp
mkdir -p files
for inc in $(ls -1 ${1}) ; do
target=${inc}
echo "target = ${target}"
isEL=`echo $target| grep -c ".EL"`
if [ ${isEL} != 0 ] ; then
largemem="HUGEMEM"
else
largemem="BIGMEM"
fi
for build in 'UP' 'BOOT' 'SMP' ${largemem}; do
if [ "$build" == "UP" ]; then
build1=""
else
build1=${build}
fi
echo "Creating ${target}${build1}..."
rm -rf temp/${target}${build1}
cd ..
make clean
if [ "$build" == "BOOT" ] ; then
mkdir -p ${dir}/temp/${target}${build1}
cpu="i386"
get_flags $build $cpu $external_flags
echo $external_flags
echo "Compiling $target $build for ${cpu} cpu..."
make -s "KERNEL_SRC=${1}/${inc}" "EXTERNAL_CFLAGS=${external_flags}"
if [ ! -f mv_sata.o ] ; then
echo "failed to make mv_sata.o from ${inc}${build11}"
exit 1
fi
cp -f mv_sata.o ${dir}/temp/${target}${build1}
if [ $? -ne 0 ]; then
echo "failed to copy mv_sata.o to ${target}${build1}"
exit 1
fi
else
if [ ${isEL} != 0 ] ; then
for cpu in 'i686' 'athlon'; do
mkdir -p ${dir}/temp/${target}${build1}/${cpu}
get_flags $build $cpu
echo $external_flags
make clean
echo "Compiling $target $build for ${cpu} cpu..."
make -s "KERNEL_SRC=${1}/${inc}" "EXTERNAL_CFLAGS=${external_flags}"
if [ ! -f mv_sata.o ] ; then
echo "failed to make mv_sata.o from ${inc}${build1}"
exit 1
fi
cp -f mv_sata.o ${dir}/temp/${target}${build1}/${cpu}
if [ $? -ne 0 ]; then
echo "failed to copy mv_sata.o to ${target}${build1}"
exit 1
fi
done
else
cpu=`uname -p`
mkdir -p ${dir}/temp/${target}${build1}
get_flags $build $cpu
echo $external_flags
make clean
echo "Compiling $target $build for ${cpu} cpu..."
make -s "KERNEL_SRC=${1}/${inc}" "EXTERNAL_CFLAGS=${external_flags}"
if [ ! -f mv_sata.o ] ; then
echo "failed to make mv_sata.o from ${inc}${build1}"
exit 1
fi
cp -f mv_sata.o ${dir}/temp/${target}${build1}
if [ $? -ne 0 ]; then
echo "failed to copy mv_sata.o to ${target}${build1}"
exit 1
fi
fi
fi
cd ${dir}
done
done
cd ${dir}/temp
echo "Modules list:"
ls -1 -R */*.o
find .
# Remove old modules.cgz (if exists)
rm -f modules.cgz
# create modules.cgz
find .|cpio -o -Hcrc|gzip -9> modules.cgz
if [ $? -ne 0 ]; then
echo "failed to create modules.cgz"
exit 1
fi
mv modules.cgz ${dir}/files
cd ..
rm -rf temp
echo "modules.cgz created successfully."