home *** CD-ROM | disk | FTP | other *** search
/ linuxmafia.com 2016 / linuxmafia.com.tar / linuxmafia.com / pub / palmos / pippy-0.6beta-src.tar.gz / pippy-0.6beta-src.tar / pippy-0.6beta-src / src / Modules / makesetup < prev    next >
Text File  |  2000-12-21  |  7KB  |  271 lines

  1. #! /bin/sh
  2.  
  3. # Convert templates into Makefile and config.c, based on the module
  4. # definitions found in the file Setup.
  5. #
  6. # Usage: makesetup [-s dir] [-c file] [-m file] [Setup] ... [-n [Setup] ...]
  7. #
  8. # Options:
  9. # -s directory: alternative source directory (default derived from $0)
  10. # -c file:      alternative config.c template (default $srcdir/config.c.in)
  11. # -c -:         don't write config.c
  12. # -m file:      alternative Makefile template (default ./Makefile.pre)
  13. # -m -:         don't write Makefile
  14. #
  15. # Remaining arguments are one or more Setup files (default ./Setup).
  16. # Setup files after a -n option are used for their variables, modules
  17. # and libraries but not for their .o files.
  18. #
  19. # See Setup.in for a description of the format of the Setup file.
  20. #
  21. # The following edits are made:
  22. #
  23. # Copying config.c.in to config.c:
  24. # - insert an identifying comment at the start
  25. # - for each <module> mentioned in Setup before *noconfig*:
  26. #   + insert 'extern void init<module>();' before MARKER 1
  27. #   + insert '{"<module>", initmodule},' before MARKER 2
  28. #
  29. # Copying Makefile.pre to Makefile:
  30. # - insert an identifying comment at the start
  31. # - replace _MODOBJS_ by the list of objects from Setup (except for
  32. #   Setup files after a -n option)
  33. # - replace _MODLIBS_ by the list of libraries from Setup
  34. # - for each object file mentioned in Setup, append a rule
  35. #   '<file>.o: <file>.c; <build commands>' to the end of the Makefile
  36. # - for each module mentioned in Setup, append a rule
  37. #   which creates a shared library version to the end of the Makefile
  38. # - for each variable definition found in Setup, insert the definition
  39. #   before the comment 'Definitions added by makesetup'
  40.  
  41. # Loop over command line options
  42. usage='
  43. usage: makesetup [-s srcdir] [-c config.c.in] [-m Makefile.pre]
  44.                  [Setup] ... [-n [Setup] ...]'
  45. srcdir=''
  46. config=''
  47. makepre=''
  48. noobjects=''
  49. doconfig=yes
  50. while :
  51. do
  52.     case $1 in
  53.     -s)    shift; srcdir=$1; shift;;
  54.     -c)    shift; config=$1; shift;;
  55.     -m)    shift; makepre=$1; shift;;
  56.     --)    shift; break;;
  57.     -n)    noobjects=yes;;
  58.     -*)    echo "$usage" 1>&2; exit 2;;
  59.     *)    break;;
  60.     esac
  61. done
  62.  
  63. # Set default srcdir and config if not set by command line
  64. # (Not all systems have dirname)
  65. case $srcdir in
  66. '')    case $0 in
  67.     */*)    srcdir=`echo $0 | sed 's,/[^/]*$,,'`;;
  68.     *)    srcdir=.;;
  69.     esac;;
  70. esac
  71. case $config in
  72. '')    config=$srcdir/config.c.in;;
  73. esac
  74. case $makepre in
  75. '')    makepre=Makefile.pre;;
  76. esac
  77.  
  78. # Newline for sed i and a commands
  79. NL='\
  80. '
  81.  
  82. # Main loop
  83. for i in ${*-Setup}
  84. do
  85.     case $i in
  86.     -n)    echo '*noobjects*';;
  87.     *)    echo '*doconfig*'; cat "$i";;
  88.     esac
  89. done |
  90. sed -e 's/[     ]*#.*//' -e '/^[     ]*$/d' |
  91. (
  92.     rulesf="@rules.$$"
  93.     trap 'rm -f $rulesf' 0 1 2 3
  94.     echo "
  95. # Rules appended by makedepend
  96. " >$rulesf
  97.     DEFS=
  98.     MODS=
  99.     SHAREDMODS=
  100.     OBJS=
  101.     LIBS=
  102.     LOCALLIBS=
  103.     BASELIBS=
  104.     while read line
  105.     do
  106.         # to handle backslashes for sh's that don't automatically
  107.         # continue a read when the last char is a backslash
  108.         while echo $line | grep '\\$' > /dev/null
  109.         do
  110.             read extraline
  111.             line=`echo $line| sed s/.$//`$extraline
  112.         done
  113.  
  114.         # Output DEFS in reverse order so first definition overrides
  115.         case $line in
  116.         *=*)    DEFS="$line$NL$DEFS"; continue;;
  117.         'include '*)    DEFS="$line$NL$DEFS"; continue;;
  118.         '*noobjects*')
  119.             case $noobjects in
  120.             yes)    ;;
  121.             *)    LOCALLIBS=$LIBS; LIBS=;;
  122.             esac
  123.             noobjects=yes;
  124.             continue;;
  125.         '*doconfig*')    doconfig=yes; continue;;
  126.         '*static*')    doconfig=yes; continue;;
  127.         '*noconfig*')    doconfig=no; continue;;
  128.         '*shared*')    doconfig=no; continue;;
  129.         esac
  130.         srcs=
  131.         cpps=
  132.         libs=
  133.         mods=
  134.         skip=
  135.         for arg in $line
  136.         do
  137.             case $skip in
  138.             libs)    libs="$libs $arg"; skip=; continue;;
  139.             cpps)    cpps="$cpps $arg"; skip=; continue;;
  140.             srcs)    srcs="$srcs $arg"; skip=; continue;;
  141.             esac
  142.             case $arg in
  143.             -[IDUC]*)    cpps="$cpps $arg";;
  144.             -Xlinker)    libs="$libs $arg"; skip=libs;;
  145.             -rpath)        libs="$libs $arg"; skip=libs;;
  146.             -[A-Zl]*)    libs="$libs $arg";;
  147.             *.a)        libs="$libs $arg";;
  148.             *.so)        libs="$libs $arg";;
  149.             *.sl)        libs="$libs $arg";;
  150.             /*.o)        libs="$libs $arg";;
  151.             *.o)        srcs="$srcs `basename $arg .o`.c";;
  152.             *.[cC])        srcs="$srcs $arg";;
  153.             *.cc)        srcs="$srcs $arg";;
  154.             *.c++)        srcs="$srcs $arg";;
  155.             *.cxx)        srcs="$srcs $arg";;
  156.             *.cpp)        srcs="$srcs $arg";;
  157.             \$*)        libs="$libs $arg"
  158.                     cpps="$cpps $arg";;
  159.             *.*)        echo 1>&2 "bad word $arg in $line"
  160.                     exit 1;;
  161.             -u)        skip=libs; libs="$libs -u";;
  162.             [a-zA-Z_]*)    mods="$mods $arg";;
  163.             *)        echo 1>&2 "bad word $arg in $line"
  164.                     exit 1;;
  165.             esac
  166.         done
  167.         case $doconfig in
  168.         yes)
  169.             LIBS="$LIBS $libs"
  170.             MODS="$MODS $mods"
  171.             ;;
  172.         esac
  173.         case $noobjects in
  174.         yes)    continue;;
  175.         esac
  176.         objs=''
  177.         for src in $srcs
  178.         do
  179.             case $src in
  180.             *.c)   obj=`basename $src .c`.o; cc='$(CC)';;
  181.             *.cc)  obj=`basename $src .cc`.o; cc='$(CCC)';;
  182.             *.c++) obj=`basename $src .c++`.o; cc='$(CCC)';;
  183.             *.C)   obj=`basename $src .C`.o; cc='$(CCC)';;
  184.             *.cxx) obj=`basename $src .cxx`.o; cc='$(CCC)';;
  185.             *.cpp) obj=`basename $src .cpp`.o; cc='$(CCC)';;
  186.             *)     continue;;
  187.             esac
  188.             objs="$objs $obj"
  189.             case $src in
  190.             glmodule.c) ;;
  191.             /*) ;;
  192.             *) src='$(srcdir)/'$src;;
  193.             esac
  194.             case $doconfig in
  195.             no)    cc="$cc \$(CCSHARED)";;
  196.             esac
  197.             rule="$obj: $src; $cc $cpps \$(CFLAGS) -c $src"
  198.             echo "$rule" >>$rulesf
  199.         done
  200.         case $doconfig in
  201.         yes)    OBJS="$OBJS $objs";;
  202.         esac
  203.         for mod in $mods
  204.         do
  205.             case $objs in
  206.             *$mod.o*)    base=$mod;;
  207.             *)        base=${mod}module;;
  208.             esac
  209.             file="$base\$(SO)"
  210.             case $doconfig in
  211.             no)    SHAREDMODS="$SHAREDMODS $file";;
  212.             esac
  213.             rule="$file: $objs"
  214.             rule="$rule; \$(LDSHARED) $objs $libs -o $file"
  215.             echo "$rule" >>$rulesf
  216.         done
  217.     done
  218.  
  219.     case $SHAREDMODS in
  220.     '')    ;;
  221.     *)    DEFS="SHAREDMODS=$SHAREDMODS$NL$DEFS";;
  222.     esac
  223.  
  224.     case $noobjects in
  225.     yes)    BASELIBS=$LIBS;;
  226.     *)    LOCALLIBS=$LIBS;;
  227.     esac
  228.     LIBS='$(LOCALMODLIBS) $(BASEMODLIBS)'
  229.     DEFS="BASEMODLIBS=$BASELIBS$NL$DEFS"
  230.     DEFS="LOCALMODLIBS=$LOCALLIBS$NL$DEFS"
  231.  
  232.     EXTDECLS=
  233.     INITBITS=
  234.     for mod in $MODS
  235.     do
  236.         EXTDECLS="${EXTDECLS}extern void init$mod();$NL"
  237.         INITBITS="${INITBITS}    {\"$mod\", init$mod},$NL"
  238.     done
  239.  
  240.  
  241.     case $config in
  242.     -)  ;;
  243.     *)  sed -e "
  244.         1i$NL/* Generated automatically from $config by makesetup. */
  245.         /MARKER 1/i$NL$EXTDECLS
  246.  
  247.         /MARKER 2/i$NL$INITBITS
  248.  
  249.         " $config >config.c
  250.         ;;
  251.     esac
  252.  
  253.     case $makepre in
  254.     -)    ;;
  255.     *)    sedf="@sed.in.$$"
  256.         trap 'rm -f $sedf' 0 1 2 3
  257.         echo "1i\\" >$sedf
  258.         str="# Generated automatically from $makepre by makesetup."
  259.         echo "$str" >>$sedf
  260.         echo "s%_MODOBJS_%$OBJS%" >>$sedf
  261.         echo "s%_MODLIBS_%$LIBS%" >>$sedf
  262.         echo "/Definitions added by makesetup/a$NL$NL$DEFS" >>$sedf
  263.         sed -f $sedf $makepre >Makefile
  264.         cat $rulesf >>Makefile
  265.         rm -f $sedf
  266.         ;;
  267.     esac
  268.  
  269.     rm -f $rulesf
  270. )
  271.