#!/bin/bash # ------------------------------------------------------------------- # # Shell program to rebuild rpm for cross-compile. # # Copyright 2003, . # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # Description: # set +x #. script PROGNAME=$(basename $0) VERSION="0.0.1" # ----------------- # configure section # ----------------- # You can modify that list tool_ignore_reqs="/sbin/ldconfig /usr/bin/perl /bin/sh /sbin/install-info rpmlib.* pkgconfig /etc/termcap /usr/bin/env grep sed textutils mktemp fileutils initscripts words gawk sh-utils /usr/sbin/groupadd rpm cracklib-dicts pwdb /bin/ln /lib/cpp /usr/sbin/chkfontpath /usr/X11R6/bin/mkfontdir /usr/X11R6/bin/xauth XFree86-base-fonts XFree86-xfs" # You can modify that list of files ext. for Function "get_all_files" file_exts=".*\.h .*\.a .*\.la .*\.so .*\.so\..* .*\.pc .*\.hwm .*\.pwd .*\.pwi .*bitmaps/.* .*qmake\.conf" tool_replace_reqs="libc.* libutil.* libm.* libdl.* libpthread.* libnsl.* librt.* libresolv.* ld-linux.* ld\.so\..* libstdc.*" spec_build_root='%{_tmppath}/%{name}' # ----------- # Functions # ----------- # check errors function check_error { if [ "$1" != 0 ] then echo "${PROGNAME}: ${2:-'Unknown error'}" >&2 exit 1 fi } function usage { echo "Usage: ${PROGNAME} base_pack [aux_pack ... ]" echo "Optional: key -fb [file]" } # Section that see keys of programm change_lib_flag=0 has_prefix_flag=0 default_insert_place=0 TEMP=`getopt -o t:: --long fb: --long prefix:,arch: -- "$@"` if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi # Note the quotes around `$TEMP': they are essential! eval set -- "$TEMP" #set -x while true ; do case "$1" in --fb) change_lib_flag=1; file=$2 ; shift 2 ;; --prefix) has_prefix_flag=1; objprefix=$2; shift 2;; --arch) build_arch=$2; shift 2;; -t) case "$2" in "") default_insert_place="post"; shift 2;; *) default_insert_place=$2 ; shift 2;; esac ;; --) shift ; break ;; *) echo "Internal error!" ; exit 1 ;; esac done #set +x prefix=${objprefix} lib_prefix=${prefix}/${build_arch}/lib include_prefix=${prefix}/${build_arch}/include if [ ! -f $file ] then check_error 1 "No such file $file" fi if [ $change_lib_flag -eq 1 ] then file ${file} | grep ASCII > /dev/null check_error $? "Not right format of fb file: ${file}" fi # Check number of args function check_args { num="$1" shift func="$1" shift if [ $# -ne $num ] then check_error 1 "Internal error in ${func}" fi } function list2grep { for i in $@ do echo '-e ^'"$i"'$' done } function list2sed { repl="$1" shift for i in $@ do echo "s|^${build_arch}-$i$|${repl}|; " done } function xecho { echo -ne $1 } # ###### Section with functions to generate RPM specs items ###### # # -- Section with base functions to create all basic information -- # # Funcion that get require any RPM information function rpm_info { check_args 2 "$FUNCNAME" $@ what="$1" pack="$2" rpm -pq --qf '[%{'${what}'}\n]' ${pack} 2>/dev/null check_error $? "No rpm file ${pack}" } # Function get name of RPM pack function get_pack_name { rpm_info NAME $@ } # Function get version of RPM pack function get_pack_vers { rpm_info VERSION $@ } # Function get release of RPM pack function get_pack_rel { rpm_info RELEASE $@ } # Function get provides of RPM pack function get_pack_provides { rpm_info PROVIDES $@ } # Function get requires of RPM pack function get_pack_reqs { rpm_info REQUIRENAME $@ } # ------ Section that generate provides and requires ------- # # ------ of RPM for toolchain-utils -------- # # Function generate provides that needs for RPM # mips-linux (See configure section for Ignore list) function get_all_provides { base_pack="$1" grep_ignore_list=`get_pack_name ${base_pack} | sed -e "s/^.*$/^&$/"` for i in $@ do get_pack_provides $i done | sort | uniq | grep -v ${grep_ignore_list} } # Function generate requires that needs for # mips-linux RPM (See configure section for Ignore list) function get_all_requires { grep_ignore_list=`list2grep $tool_ignore_reqs` provides_list=`get_all_provides $@` grep_ignore_list="${grep_ignore_list} `list2grep $provides_list`" for i in $@ do pack_list="${pack_list} `get_pack_name $i`" done grep_ignore_list="${grep_ignore_list} `list2grep $pack_list`" for i in $@ do get_pack_reqs $i done | sort | uniq | grep -v ${grep_ignore_list} } # ------ Section that generate and output RPM specs headers ------ # # Function create Summary of mips-linux RPM packet function get_Summary { echo -n "Summary: " rpm_info SUMMARY $@ } # Function create Name of mips-linux RPM packet function get_Name { check_args 1 "$FUNCNAME" $@ echo -n "${build_arch}-" get_pack_name "$1" } # Function create Version of mips-linux RPM packet function get_Version { echo -n "Version: " get_pack_vers $@ } # Function create Release of mips-linux RPM packet function get_Release { echo -n "Release: " get_pack_rel $@ } # Function create License of mips-linux RPM packet function get_License { echo -n "License: " rpm_info LICENSE $@ } # Function create Group of mips-linux RPM packet function get_Group { echo -n "Group: " echo "Development/Libraries/MIPS" } # Function create Sources of mips-linux RPM packet function get_Sources { n=0 for i in $@ do name=`basename "$i"` echo "Source$n: ${name}" n=`expr $n + 1` done } # Function create Requires of mips-linux RPM packet function get_Requires { #set -x #sed_list=`list2sed ${build_arch}-glibc ${tool_replace_reqs}` sed_list=`list2sed toolchain-mips ${tool_replace_reqs}` echo -n "Requires: " get_all_requires $@ | sed -e "s/^.*$/${build_arch}-&/" | sed -e "${sed_list}" | sort | uniq } # Function create Provides of mips-linux RPM packet function get_Provides { provides=`get_all_provides $@` if [ ! -z "${provides}" ] then echo -n "Provides: " echo "${provides}" | sed -e "s/^.*$/${build_arch}-&/" fi } # ------ Section that generate RPM spec-file sections ------ # # ------ (like descriptions, install, etc...) ------ # # Function create list of RPM packet files function get_pack_files { check_args 1 "$FUNCNAME" $@ pack="$1" rpm -pql "${pack}" check_error $? "No rpm file ${pack_path}" } # Function generate files for mips-linux RPM packet # (See configure sections for list of files ext.) function get_all_files { grep_ext_list=`list2grep ${file_exts}` for i in $@ do get_pack_files $i done | grep ${grep_ext_list} } # Function create %Description section of mips-linux RPM packet function get_Description { echo '%description' rpm_info DESCRIPTION $@ } # Function create %Prep section of mips-linux RPM packet function get_Prep { echo '%setup -c -T' cpio="cpio -i --no-absolute-filenames --make-directories --no-preserve-owner" get_Sources ${base_pack} ${aux_packs} | sed -e 's/\(Source[0-9]*\).*$/\1/' | tr '[a-z]' '[A-Z]' | sed -e "s/^.*/rpm2cpio \%\{&\} | ${cpio}/" } # Function create %Build section of mips-linux RPM packet function get_Build { echo '[' -d usr/lib/pkgconfig ']' '&&' find usr/lib/pkgconfig -name '\*.pc' -exec sh -c '"' mv '{}' '{}.tmp' '&&' sed -e "s./usr.${prefix}/${build_arch}.g" '{}.tmp' '>' '{}"' "';'" echo find usr/ -name '\*.la' -exec sh -c '"' mv '{}' '{}.tmp' '&&' sed -e "s./usr.${prefix}/${build_arch}.g" '{}.tmp' '>' '{}"' "';'" } # Function create %Install section of mips-linux RPM packet function get_Install { get_all_files $@ | sed -e 's|^/\(.*\)$|install_file \1 /\1|' | # sed -e 's|^/\(.*\)$|mkdir -p `dirname /\1`; test ! -e /\1 -o -L /\1 \&\& rm -f /\1 \&\& cp -a \1 /\1|' | sed "s. /usr/include/asm-sparc. \$RPM_BUILD_ROOT${include_prefix}/asm.g" | sed "s. /usr/include. \$RPM_BUILD_ROOT${include_prefix}.g" | sed "s. /usr/X11R6/include. \$RPM_BUILD_ROOT${include_prefix}.g" | sed "s. /usr/include/linux. \$RPM_BUILD_ROOT${include_prefix}/linux.g" | sed "s. /usr/kerberos/include. \$RPM_BUILD_ROOT${include_prefix}.g" | #sed "s./usr/\([/a-zA-Z0-9]*\)include. \$RPM_BUILD_ROOT${include_prefix}.g" | sed "s. /lib. \$RPM_BUILD_ROOT${lib_prefix}.g" | sed "s. /usr/lib. \$RPM_BUILD_ROOT${lib_prefix}.g" | #sed "s./usr\([/a-zA-Z0-9]*\)lib. \$RPM_BUILD_ROOT${lib_prefix}.g" sed "s. /usr/X11R6/lib. \$RPM_BUILD_ROOT${lib_prefix}.g" | sed "s. /usr/share/doc/ncurses-devel-5\.2/test. \$RPM_BUILD_ROOT${include_prefix}.g" | sed "s. /usr/share/doc/db3-devel-3\.3\.11/examples_c. \$RPM_BUILD_ROOT${include_prefix}.g" | sed "s. /usr/kerberos/lib. \$RPM_BUILD_ROOT${lib_prefix}.g" | sed "s. /usr/X11R6/LessTif/Motif1\.2/lib. \$RPM_BUILD_ROOT${lib_prefix}.g" | sed "s. /usr/X11R6/LessTif/Motif1\.2/include. \$RPM_BUILD_ROOT${include_prefix}.g" | sed "/\/usr\/share\/doc/d" } # Function create %Clean section of mips-linux RPM packet function get_Clean { echo 'rm -rf $RPM_BUILD_ROOT' } #Function create %post section of mips-linux RPM package function get_Post { if [ $change_lib_flag -eq 1 ] then if [ $has_prefix_flag -eq 1 ] then cat $file | sed "s. \${lib_prefix}. $lib_prefix.g" else cat $file fi fi } # Function create %Files section of mips-linux RPM packet function get_Files { echo '%defattr(-,root,root)' echo "${prefix}/${build_arch}" } # --------------------------- # Program starts here # --------------------------- ##### Main Logic ##### if [ $# -eq 0 ] then usage exit 1 fi base_pack="$1" shift aux_packs="$@" ( get_Summary ${base_pack} check_error $? echo -n "Name: " get_Name ${base_pack} check_error $? get_Version ${base_pack} check_error $? get_Release ${base_pack} check_error $? get_License ${base_pack} check_error $? get_Group ${base_pack} check_error $? get_Sources ${base_pack} ${aux_packs} if [ $change_lib_flag -eq 1 ] then echo "Source1000: ${file}" check_error $? fi echo "BuildRoot: ${spec_build_root}" echo "AutoReqProv: no" echo `get_Requires ${base_pack} ${aux_packs}` check_error $? echo `get_Provides ${base_pack} ${aux_packs}` check_error $? echo -ne "\n" get_Description ${base_pack} echo -ne "\n" echo '%prep' get_Prep ${base_pack} echo -ne "\n" echo '%build' get_Build if [ $change_lib_flag -eq 1 ] && [ $default_insert_place == "build" ] then get_Post echo -ne "\n" fi echo -ne "\n" echo '%install' echo 'install_file()' echo '{' echo -e '\tsrc="$1"' echo -e '\tdst="$2"' echo -e '\tmkdir -p `dirname ${dst}`' echo -e '\tif [ -L ${src} ]' echo -e '\tthen' echo -e '\t\tif [ ! -e ${dst} ]' echo -e '\t\tthen' echo -ne '\t\t\tdr_src=`ls -l ${src} | ' echo "sed 's/^.*-> \(.*\)$/\1/'"'`' echo -e '\t\t\techo ${dst}' echo -e '\t\t\tif echo ${dr_src} |'"grep '^\.\./.*$'" echo -e '\t\t\tthen' echo -e '\t\t\t\tlinkto=`basename ${dr_src}`' echo -e '\t\t\t\ttest ! -e ${dst} && ln -s ${linkto} ${dst}' echo -e '\t\t\telse' echo -e '\t\t\t\tcp -a ${src} ${dst}' echo -e '\t\t\tfi' echo -e '\t\tfi' echo -e '\telse' echo -e '\t\ttest -L ${dst} && rm -f ${dst}' echo -e '\t\tcp -a ${src} ${dst}' echo -e '\tfi' echo '}' get_Install ${base_pack} ${aux_packs} if [ $change_lib_flag -eq 1 ] && [ $default_insert_place == "install" ] then get_Post echo -ne "\n" fi echo -ne "\n" echo '%clean' get_Clean echo -ne "\n" if [ $change_lib_flag -eq 1 ] && [ $default_insert_place == "post" ] then echo '%post' get_Post echo -ne "\n" fi echo '%files' get_Files ) > $(get_Name ${base_pack}).spec