home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / Languages / python / PyObjC-0.47-MIHS / pyobjc-0.47-src / Modules / makesetup next >
Encoding:
Text File  |  1996-10-10  |  6.3 KB  |  267 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. # Lele Gaifax, on 3 October 1996:
  42. # This is an augmented version of the Python 1.4's makesetup script.
  43. # It differs from the original in that it supports ObjC .m sources:
  44. # they get compiled by $(OOC), which must be initialized in the Setup
  45. # file.
  46.  
  47. # Loop over command line options
  48. usage='
  49. usage: makesetup [-s srcdir] [-c config.c.in] [-m Makefile.pre]
  50.                  [Setup] ... [-n [Setup] ...]'
  51. srcdir=''
  52. config=''
  53. makepre=''
  54. noobjects=''
  55. doconfig=yes
  56. while :
  57. do
  58.     case $1 in
  59.     -s)    shift; srcdir=$1; shift;;
  60.     -c)    shift; config=$1; shift;;
  61.     -m)    shift; makepre=$1; shift;;
  62.     --)    shift; break;;
  63.     -n)    noobjects=yes;;
  64.     -*)    echo "$usage" 1>&2; exit 2;;
  65.     *)    break;;
  66.     esac
  67. done
  68.  
  69. # Set default srcdir and config if not set by command line
  70. # (Not all systems have dirname)
  71. case $srcdir in
  72. '')    case $0 in
  73.     */*)    srcdir=`echo $0 | sed 's,/[^/]*$,,'`;;
  74.     *)    srcdir=.;;
  75.     esac;;
  76. esac
  77. case $config in
  78. '')    config=$srcdir/config.c.in;;
  79. esac
  80. case $makepre in
  81. '')    makepre=Makefile.pre;;
  82. esac
  83.  
  84. # Newline for sed i and a commands
  85. NL='\
  86. '
  87.  
  88. # Main loop
  89. for i in ${*-Setup}
  90. do
  91.     case $i in
  92.     -n)    echo '*noobjects*';;
  93.     *)    echo '*doconfig*'; cat "$i";;
  94.     esac
  95. done |
  96. sed -e 's/[     ]*#.*//' -e '/^[     ]*$/d' |
  97. (
  98.     rulesf="@rules.$$"
  99.     trap 'rm -f $rulesf' 0 1 2 3
  100.     echo "
  101. # Rules appended by makedepend
  102. " >$rulesf
  103.     DEFS=
  104.     MODS=
  105.     SHAREDMODS=
  106.     OBJS=
  107.     LIBS=
  108.     LOCALLIBS=
  109.     BASELIBS=
  110.     while read line
  111.     do
  112.         # Output DEFS in reverse order so first definition overrides
  113.         case $line in
  114.         *=*)    DEFS="$line$NL$DEFS"; continue;;
  115.         '*noobjects*')
  116.             case $noobjects in
  117.             yes)    ;;
  118.             *)    LOCALLIBS=$LIBS; LIBS=;;
  119.             esac
  120.             noobjects=yes;
  121.             continue;;
  122.         '*doconfig*')    doconfig=yes; continue;;
  123.         '*static*')    doconfig=yes; continue;;
  124.         '*noconfig*')    doconfig=no; continue;;
  125.         '*shared*')    doconfig=no; continue;;
  126.         esac
  127.         srcs=
  128.         cpps=
  129.         libs=
  130.         mods=
  131.         skip=
  132.         for arg in $line
  133.         do
  134.             case $skip in
  135.             libs)    libs="$libs $arg"; skip=; continue;;
  136.             cpps)    cpps="$cpps $arg"; skip=; continue;;
  137.             srcs)    srcs="$srcs $arg"; skip=; continue;;
  138.             esac
  139.             case $arg in
  140.             -[IDUC]*)    cpps="$cpps $arg";;
  141.             -[A-Zl]*)    libs="$libs $arg";;
  142.             *.a)        libs="$libs $arg";;
  143.             *.so)        libs="$libs $arg";;
  144.             *.sl)        libs="$libs $arg";;
  145.             *.o)        srcs="$srcs `basename $arg .o`.c";;
  146.             *.[cC])        srcs="$srcs $arg";;
  147.             *.cc)        srcs="$srcs $arg";;
  148.             *.c++)        srcs="$srcs $arg";;
  149.             *.m)        srcs="$srcs $arg";;
  150.             \$*)        libs="$libs $arg"
  151.                     cpps="$cpps $arg";;
  152.             *.*)        echo 1>&2 "bad word $arg in $line"
  153.                     exit 1;;
  154.             -u)        skip=libs; libs="$libs -u";;
  155.             [a-zA-Z_]*)    mods="$mods $arg";;
  156.             *)        echo 1>&2 "bad word $arg in $line"
  157.                     exit 1;;
  158.             esac
  159.         done
  160.         case $doconfig in
  161.         yes)
  162.             LIBS="$LIBS $libs"
  163.             MODS="$MODS $mods"
  164.             ;;
  165.         esac
  166.         case $noobjects in
  167.         yes)    continue;;
  168.         esac
  169.         objs=''
  170.         for src in $srcs
  171.         do
  172.             case $src in
  173.             *.c)   obj=`basename $src .c`.o; cc='$(CC)';;
  174.             *.cc)  obj=`basename $src .cc`.o; cc='$(CCC)';;
  175.             *.c++) obj=`basename $src .c++`.o; cc='$(CCC)';;
  176.             *.C)   obj=`basename $src .C`.o; cc='$(CCC)';;
  177.             *.m)   obj=`basename $src .m`.o; cc='$(OCC)';;
  178.             *)     continue;;
  179.             esac
  180.             objs="$objs $obj"
  181.             case $src in
  182.             glmodule.c) ;;
  183.             *) src='$(srcdir)/'$src;;
  184.             esac
  185.             case $doconfig in
  186.             no)    cc="$cc \$(CCSHARED)";;
  187.             esac
  188.             rule="$obj: $src; $cc \$(CFLAGS) $cpps -c $src"
  189.             echo "$rule" >>$rulesf
  190.         done
  191.         case $doconfig in
  192.         yes)    OBJS="$OBJS $objs";;
  193.         esac
  194.         for mod in $mods
  195.         do
  196.             case $objs in
  197.             *$mod.o*)    base=$mod;;
  198.             *)        base=${mod}module;;
  199.             esac
  200.             file="$base\$(SO)"
  201.             case $doconfig in
  202.             no)    SHAREDMODS="$SHAREDMODS $file";;
  203.             esac
  204.             rule="$file: $objs"
  205.             rule="$rule; \$(LDSHARED) $objs $libs -o $file"
  206.             echo "$rule" >>$rulesf
  207.         done
  208.     done
  209.  
  210.     case $SHAREDMODS in
  211.     '')    ;;
  212.     *)    DEFS="SHAREDMODS=$SHAREDMODS$NL$DEFS";;
  213.     esac
  214.  
  215.     case $noobjects in
  216.     yes)    BASELIBS=$LIBS;;
  217.     *)    LOCALLIBS=$LIBS;;
  218.     esac
  219.     LIBS='$(LOCALMODLIBS) $(BASEMODLIBS)'
  220.     DEFS="BASEMODLIBS=$BASELIBS$NL$DEFS"
  221.     DEFS="LOCALMODLIBS=$LOCALLIBS$NL$DEFS"
  222.  
  223.     EXTDECLS=
  224.     INITBITS=
  225.     for mod in $MODS
  226.     do
  227.         EXTDECLS="${EXTDECLS}extern void init$mod();$NL"
  228.         INITBITS="${INITBITS}    {\"$mod\", init$mod},$NL"
  229.     done
  230.  
  231.  
  232.     case $config in
  233.     -)  ;;
  234.     *)  sed -e "
  235.         1i$NL/* Generated automatically from $config by makesetup. */
  236.         /MARKER 1/i$NL$EXTDECLS
  237.         /MARKER 2/i$NL$INITBITS
  238.  
  239.         " $config >config.c
  240.         ;;
  241.     esac
  242.  
  243.     case $makepre in
  244.     -)    ;;
  245.     *)    sedf="@sed.in.$$"
  246.         trap 'rm -f $sedf' 0 1 2 3
  247.         echo "1i\\" >$sedf
  248.         str="# Generated automatically from $makepre by makesetup."
  249.         echo "$str" >>$sedf
  250.         echo "s%_MODOBJS_%$OBJS%" >>$sedf
  251.         echo "s%_MODLIBS_%$LIBS%" >>$sedf
  252.         echo "/Definitions added by makesetup/a$NL$NL$DEFS" >>$sedf
  253.         sed -f $sedf $makepre >Makefile
  254.         cat $rulesf >>Makefile
  255.         rm -f $sedf
  256.         ;;
  257.     esac
  258.  
  259.     rm -f $rulesf
  260. )
  261.  
  262. #
  263. # Local Variables:
  264. # change-log-default-name:"../ChangeLog.PyObjC"
  265. # End:
  266. #
  267.