home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pyth_os2.zip / python-1.0.2 / Modules / makesetup < prev    next >
Encoding:
Text File  |  1994-02-18  |  3.7 KB  |  157 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. # -m file:      alternative Makefile template (default ./Makefile.pre)
  12. #
  13. # Remaining arguments are one or more Setup files (default ./Setup).
  14. # Setup files after a -n option are used for their variables, modules
  15. # and libraries but not for their .o files.
  16. #
  17. # See Setup.in for a description of the format of the Setup file.
  18. #
  19. # The following edits are made:
  20. #
  21. # Copying config.c.in to config.c:
  22. # - insert an identifying comment at the start
  23. # - for each <module> mentioned in Setup:
  24. #   + insert 'extern void init<module>();' before MARKER 1
  25. #   + insert '{"<module>", initmodule},' before MARKER 2
  26. #
  27. # Copying Makefile.pre to Makefile:
  28. # - insert an identifying comment at the start
  29. # - replace @MODOBJS@ by the list of objects from Setup (except for
  30. #   Setup files after a -n option)
  31. # - replace @MODLIBS@ by the list of libraries from Setup
  32. # - for each object file mentioned in Setup, insert a rule
  33. #   '<file>.o: <file>.c; <build commands>' before the comment
  34. #   'Rules added by makesetup'
  35. # - for each variable definition found in Setup, insert the definition
  36. #   before the comment 'Definitions added by makesetup'
  37.  
  38. # Loop over command line options
  39. usage='
  40. usage: makesetup [-s srcdir] [-c config.c.in] [-m Makefile.pre]
  41.                  [Setup] ... [-n [Setup] ...]'
  42. srcdir=''
  43. config=''
  44. makepre=''
  45. noobjects=''
  46. while :
  47. do
  48.     case $1 in
  49.     -s)    shift; srcdir=$1; shift;;
  50.     -c)    shift; config=$1; shift;;
  51.     -m)    shift; makepre=$1; shift;;
  52.     --)    shift; break;;
  53.     -n)    noobjects=yes;;
  54.     -*)    echo "$usage" 1>&2; exit 2;;
  55.     *)    break;;
  56.     esac
  57. done
  58.  
  59. # Set default srcdir and config if not set by command line
  60. # (Not all systems have dirname)
  61. case $srcdir in
  62. '')    case $0 in
  63.     */*)    srcdir=`echo $0 | sed 's,/[^/]*$,,'`;;
  64.     *)    srcdir=.;;
  65.     esac;;
  66. esac
  67. case $config in
  68. '')    config=$srcdir/config.c.in;;
  69. esac
  70. case $makepre in
  71. '')    makepre=Makefile.pre;;
  72. esac
  73.  
  74. # Newline for sed i and a commands
  75. NL="\\
  76. "
  77.  
  78. # Main loop
  79. for i in ${*-Setup}
  80. do
  81.     case $i in
  82.     -n)    echo '<noobjects>';;
  83.     *)    cat "$i";;
  84.     esac
  85. done |
  86. sed -e 's/[     ]*#.*//' -e '/^[     ]*$/d' |
  87. (
  88.     DEFS=
  89.     MODS=
  90.     OBJS=
  91.     LIBS=
  92.     RULES=
  93.     while read line
  94.     do
  95.         # Output DEFS in reverse order so first definition overrides
  96.         case $line in
  97.         *=*)    DEFS="$line$NL$DEFS"; continue;;
  98.         '<noobjects>')    noobjects=yes; continue;; 
  99.         esac
  100.         objs=
  101.         cpps=
  102.         set $line
  103.         for arg
  104.         do
  105.             case $arg in
  106.             -[IDUC]*)    cpps="$cpps $arg";;
  107.             -[A-Zl]*)    LIBS="$LIBS $arg";;
  108.             *.a)        LIBS="$LIBS $arg";;
  109.             *.o)        objs="$objs $arg";;
  110.             *.*)        echo 1>&2 "bad word $arg in $line"
  111.                     exit 1;;
  112.             [a-zA-Z_]*)    MODS="$MODS $arg";;
  113.             *)        echo 1>&2 "bad word $arg in $line"
  114.                     exit 1;;
  115.             esac
  116.         done
  117.         case $noobjects in
  118.         yes)    continue;;
  119.         esac
  120.         for obj in $objs
  121.         do
  122.           src=`basename $obj .o`.c
  123.           case $src in
  124.           glmodule.c) ;;
  125.           *) src='$(srcdir)/'$src;;
  126.           esac
  127.           RULES="$RULES$obj: $src; \$(CC) \$(CFLAGS) $cpps -c $src$NL"
  128.         done
  129.         OBJS="$OBJS $objs"
  130.     done
  131.  
  132.     EXTDECLS=
  133.     INITBITS=
  134.     for mod in $MODS
  135.     do
  136.         EXTDECLS="${EXTDECLS}extern void init$mod();$NL"
  137.         INITBITS="${INITBITS}    {\"$mod\", init$mod},$NL"
  138.     done
  139.  
  140.     sed -e "
  141.         1i$NL/* Generated automatically from $config by makesetup. */
  142.         /MARKER 1/i$NL$EXTDECLS
  143.         /MARKER 2/i$NL$INITBITS
  144.  
  145.         " $config >config.c
  146.  
  147.     sed -e "
  148.         1i$NL# Generated automatically from $makepre by makesetup.
  149.         s%@MODOBJS@%$OBJS%
  150.         s%@MODLIBS@%$LIBS%
  151.         /Rules added by makesetup/a$NL$NL$RULES
  152.         /Definitions added by makesetup/a$NL$NL$DEFS
  153.  
  154.         " $makepre >Makefile
  155.  
  156. )
  157.