home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / OPENSTEP / Languages / Python / python-14-src / Modules / makesetup < prev    next >
Encoding:
Text File  |  1997-03-22  |  7.1 KB  |  298 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] [-C config] [-m file] [-M Makefile] [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. # -M file:      alternative Makefile to create (default ./Makefile)
  15. # -C file:      alternative config.c to create
  16. # -r:           do not append make rules
  17. #
  18. # Remaining arguments are one or more Setup files (default ./Setup).
  19. # Setup files after a -n option are used for their variables, modules
  20. # and libraries but not for their .o files.
  21. #
  22. # See Setup.in for a description of the format of the Setup file.
  23. #
  24. # The following edits are made:
  25. #
  26. # Copying config.c.in to config.c:
  27. # - insert an identifying comment at the start
  28. # - for each <module> mentioned in Setup before *noconfig*:
  29. #   + insert 'extern void init<module>();' before MARKER 1
  30. #   + insert '{"<module>", initmodule},' before MARKER 2
  31. #
  32. # Copying Makefile.pre to Makefile:
  33. # - insert an identifying comment at the start
  34. # - replace _MODOBJS_ by the list of objects from Setup (except for
  35. #   Setup files after a -n option)
  36. # - replace _MODLIBS_ by the list of libraries from Setup
  37. # - for each object file mentioned in Setup, append a rule
  38. #   '<file>.o: <file>.c; <build commands>' to the end of the Makefile
  39. # - for each module mentioned in Setup, append a rule
  40. #   which creates a shared library version to the end of the Makefile
  41. # - for each variable definition found in Setup, insert the definition
  42. #   before the comment 'Definitions added by makesetup'
  43.  
  44. # Lele Gaifax, on 3 October 1996:
  45. # This is an augmented version of the Python 1.4's makesetup script.
  46. # It differs from the original in that it supports ObjC .m sources:
  47. # they get compiled by $(OOC), which must be initialized in the Setup
  48. # file.
  49.  
  50. # Lele Gaifax, on 18 March 1997:
  51. # Added an option -M to change the name of the created Makefile.
  52.  
  53. # Loop over command line options
  54. usage='
  55. usage: makesetup [-s srcdir] [-c config.c.in] [-m Makefile.pre] [-M Makefile]
  56.                  [Setup] ... [-n [Setup] ...]'
  57. srcdir=''
  58. config=''
  59. config_out=''
  60. makepre=''
  61. noobjects=''
  62. objdir=''
  63. doconfig=yes
  64. while :
  65. do
  66.     case $1 in
  67.     -s)    shift; srcdir=$1; shift;;
  68.     -c)    shift; config=$1; shift;;
  69.     -C)     shift; config_out=$1; shift;;
  70.     -m)    shift; makepre=$1; shift;;
  71.     -M)     shift; makefile=$1; shift;;
  72.     --)    shift; break;;
  73.     -n)    shift; noobjects=yes;;
  74.     -o)     shift; objdir=$1; shift;;
  75.     -*)    echo "$usage" 1>&2; exit 2;;
  76.     *)    break;;
  77.     esac
  78. done
  79.  
  80. # Set default srcdir and config if not set by command line
  81. # (Not all systems have dirname)
  82. case $srcdir in
  83. '')    case $0 in
  84.     */*)    srcdir=`echo $0 | sed 's,/[^/]*$,,'`;;
  85.     *)    srcdir=.;;
  86.     esac;;
  87. esac
  88. case $config in
  89. '')    config=$srcdir/config.c.in;;
  90. esac
  91. case $makepre in
  92. '')    makepre=Makefile.pre;;
  93. esac
  94. case $makefile in
  95. '')     makefile=Makefile;;
  96. esac
  97. case $config_out in
  98. '')     config_out=config.c;;
  99. esac
  100.  
  101. # Newline for sed i and a commands
  102. NL='\
  103. '
  104.  
  105. # Main loop
  106. for i in ${*-Setup}
  107. do
  108.     case $i in
  109.     -n)    echo '*noobjects*';;
  110.     *)    echo '*doconfig*'; cat "$i";;
  111.     esac
  112. done |
  113. sed -e 's/[     ]*#.*//' -e '/^[     ]*$/d' |
  114. (
  115.     rulesf="@rules.$$"
  116.     trap 'rm -f $rulesf' 0 1 2 3
  117.     echo "
  118. # Rules appended by makedepend
  119. " >$rulesf
  120.     DEFS=
  121.     MODS=
  122.     SHAREDMODS=
  123.     OBJS=
  124.     LIBS=
  125.     LOCALLIBS=
  126.     BASELIBS=
  127.     while read line
  128.     do
  129.         # Output DEFS in reverse order so first definition overrides
  130.         case $line in
  131.         *=*)    DEFS="$line$NL$DEFS"; continue;;
  132.         '*noobjects*')
  133.             case $noobjects in
  134.             yes)    ;;
  135.             *)    LOCALLIBS=$LIBS; LIBS=;;
  136.             esac
  137.             noobjects=yes;
  138.             continue;;
  139.         '*doconfig*')    doconfig=yes; continue;;
  140.         '*static*')    doconfig=yes; continue;;
  141.         '*noconfig*')    doconfig=no; continue;;
  142.         '*shared*')    doconfig=no; continue;;
  143.         esac
  144.         srcs=
  145.         cpps=
  146.         libs=
  147.         mods=
  148.         skip=
  149.         for arg in $line
  150.         do
  151.             case $skip in
  152.             libs)    libs="$libs $arg"; skip=; continue;;
  153.             cpps)    cpps="$cpps $arg"; skip=; continue;;
  154.             srcs)    srcs="$srcs $arg"; skip=; continue;;
  155.             esac
  156.             case $arg in
  157.             -[IDUC]*)    cpps="$cpps $arg";;
  158.             -[A-Zl]*)    libs="$libs $arg";;
  159.             *.a)        libs="$libs $arg";;
  160.             *.so)        libs="$libs $arg";;
  161.             *.sl)        libs="$libs $arg";;
  162.             *.o)        srcs="$srcs `basename $arg .o`.c";;
  163.             *.[cC])        srcs="$srcs $arg";;
  164.             *.cc)        srcs="$srcs $arg";;
  165.             *.c++)        srcs="$srcs $arg";;
  166.             *.m)        srcs="$srcs $arg";;
  167.             \$*)        libs="$libs $arg"
  168.                     cpps="$cpps $arg";;
  169.             *.*)        echo 1>&2 "bad word $arg in $line"
  170.                     exit 1;;
  171.             -u)        skip=libs; libs="$libs -u";;
  172.             [a-zA-Z_]*)    mods="$mods $arg";;
  173.             *)        echo 1>&2 "bad word $arg in $line"
  174.                     exit 1;;
  175.             esac
  176.         done
  177.         case $doconfig in
  178.         yes)
  179.             LIBS="$LIBS $libs"
  180.             MODS="$MODS $mods"
  181.             ;;
  182.         esac
  183.         case $noobjects in
  184.         yes)    continue;;
  185.         esac
  186.         objs=''
  187.         for src in $srcs
  188.         do
  189.             case $src in
  190.             *.c)   obj=`basename $src .c`.o; cc='$(CC)';;
  191.             *.cc)  obj=`basename $src .cc`.o; cc='$(CCC)';;
  192.             *.c++) obj=`basename $src .c++`.o; cc='$(CCC)';;
  193.             *.C)   obj=`basename $src .C`.o; cc='$(CCC)';;
  194.             *.m)   obj=`basename $src .m`.o; cc='$(OCC)';;
  195.             *)     continue;;
  196.             esac
  197.             objs="$objs $obj"
  198.             case $src in
  199.             glmodule.c) ;;
  200.             *) src='$(srcdir)/'$src;;
  201.             esac
  202.             case $doconfig in
  203.             no)    cc="$cc \$(CCSHARED)";;
  204.             esac
  205.             if test "$objdir"
  206.             then
  207.                 rule="$objdir/$obj: $src; $cc \$(CFLAGS) $cpps -c $src -o $objdir/$obj"
  208.             else
  209.                 rule="$obj: $src; $cc \$(CFLAGS) $cpps -c $src"
  210.             fi
  211.             echo "$rule" >>$rulesf
  212.         done
  213.         case $doconfig in
  214.         yes)    OBJS="$OBJS $objs";;
  215.         esac
  216.         for mod in $mods
  217.         do
  218.             case $objs in
  219.             *$mod.o*)    base=$mod;;
  220.             *)        base=${mod}module;;
  221.             esac
  222.             file="$base\$(SO)"
  223.             case $doconfig in
  224.             no)    SHAREDMODS="$SHAREDMODS $file";;
  225.             esac
  226.             if test "$objdir"
  227.             then
  228.                 objs_orig=$objs
  229.                 objs=""
  230.                 for o in $objs_orig
  231.                 do
  232.                     objs="$objs $objdir/$o"
  233.                 done
  234.             fi            
  235.             rule="$file: $objs"
  236.             rule="$rule; \$(LDSHARED) $objs $libs -o $file"
  237.             echo "$rule" >>$rulesf
  238.         done
  239.     done
  240.  
  241.     case $SHAREDMODS in
  242.     '')    ;;
  243.     *)    DEFS="SHAREDMODS=$SHAREDMODS$NL$DEFS";;
  244.     esac
  245.  
  246.     case $noobjects in
  247.     yes)    BASELIBS=$LIBS;;
  248.     *)    LOCALLIBS=$LIBS;;
  249.     esac
  250.     LIBS='$(LOCALMODLIBS) $(BASEMODLIBS)'
  251.     DEFS="BASEMODLIBS=$BASELIBS$NL$DEFS"
  252.     DEFS="LOCALMODLIBS=$LOCALLIBS$NL$DEFS"
  253.  
  254.     EXTDECLS=
  255.     INITBITS=
  256.     for mod in $MODS
  257.     do
  258.         EXTDECLS="${EXTDECLS}extern void init$mod();$NL"
  259.         INITBITS="${INITBITS}    {\"$mod\", init$mod},$NL"
  260.     done
  261.  
  262.  
  263.     case $config in
  264.     -)  ;;
  265.     *)  sed -e "
  266.         1i$NL/* Generated automatically from $config by makesetup. */
  267.         /MARKER 1/i$NL$EXTDECLS
  268.         /MARKER 2/i$NL$INITBITS
  269.  
  270.         " $config >$config_out
  271.         ;;
  272.     esac
  273.  
  274.     case $makepre in
  275.     -)    ;;
  276.     *)    sedf="@sed.in.$$"
  277.         trap 'rm -f $sedf' 0 1 2 3
  278.         echo "1i\\" >$sedf
  279.         str="# Generated automatically from $makepre by makesetup."
  280.         echo "$str" >>$sedf
  281.         echo "s%_MODOBJS_%$OBJS%" >>$sedf
  282.         echo "s%_MODLIBS_%$LIBS%" >>$sedf
  283.         echo "/Definitions added by makesetup/a$NL$NL$DEFS" >>$sedf
  284.         sed -f $sedf $makepre >$makefile
  285.         cat $rulesf >>$makefile
  286.         rm -f $sedf
  287.         ;;
  288.     esac
  289.  
  290.     rm -f $rulesf
  291. )
  292.  
  293. #
  294. # Local Variables:
  295. # change-log-default-name:"../ChangeLog.PyObjC"
  296. # End:
  297. #
  298.