home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Libraries / stdwin / Conf / makemakefile < prev    next >
Encoding:
Makefile  |  1990-08-09  |  2.2 KB  |  103 lines  |  [TEXT/????]

  1. #!/bin/sh
  2.  
  3. # makemakefile - create a Makefile
  4.  
  5. PROGNAME=`basename $0`
  6. USAGE="usage: $PROGNAME topdir os arch port srcdir builddir"
  7.  
  8. # Check and get arguments
  9. #
  10. case $# in
  11. 6)    ;;
  12. *)  echo "$USAGE" 1>&2
  13.     echo '  <src> may be relative to <top>' 1>&2
  14.     echo '  <build> may be relative to <top>/Build/<arch>/<port>' 1>&2
  15.     exit 2
  16.     ;;
  17. esac
  18.  
  19. TOPDIR=$1; shift
  20. OS=$1; shift
  21. ARCH=$1; shift
  22. PORT=$1; shift
  23. SRCDIR=$1; shift
  24. BLDDIR=$1; shift
  25.  
  26.  
  27. # Set derived pathnames
  28.  
  29. CONFDIR=$TOPDIR/Conf
  30.  
  31. case $SRCDIR in
  32. /*)    ;;
  33. *)    SRCDIR=$TOPDIR/$SRCDIR;;
  34. esac
  35.  
  36. case $BLDDIR in
  37. /*)    ;;
  38. *)    BLDDIR=$TOPDIR/Build/$ARCH/$PORT/$BLDDIR;;
  39. esac
  40.  
  41. OSPROTO=$CONFDIR/proto.os.$OS
  42. ARCHPROTO=$CONFDIR/proto.arch.$ARCH
  43. PORTPROTO=$CONFDIR/proto.port.$PORT
  44. CONFPROTO=$CONFDIR/proto.conf
  45. SRCPROTO=$SRCDIR/Make.proto
  46.  
  47. # Make sure the source prototype exists, else there's no use in proceeding.
  48. # This test is made to avoid creating junk build directories.
  49. # (Missing other files are detected by the cat command.)
  50.  
  51. if test ! -f $SRCPROTO
  52. then
  53.     echo "$PROGNAME: can't find Makefile prototype $SRCPROTO" 1>&2
  54.     exit 1
  55. fi
  56.  
  57. # Make sure the build directory exists, create it if necessary
  58. # (only one level deep though!)
  59. #
  60. if test -d $BLDDIR
  61. then
  62.     :
  63. else
  64.     echo "$PROGNAME: creating new build directory $BLDDIR" 1>&2
  65.     mkdir $BLDDIR ||
  66.     { echo "$PROGNAME: can't create build directory $BLDDIR" 1>&2; exit 1;}
  67. fi
  68.  
  69.  
  70. # Now begin doing the real work
  71. #
  72. PRELUDE="$OSPROTO $ARCHPROTO $PORTPROTO $CONFPROTO $SRCPROTO"
  73.  
  74. BOOTMAKE=$BLDDIR/Mf.boot
  75. echo "$PROGNAME: creating bootstrap Makefile ..." 1>&2
  76.  
  77. { echo "TOP=$TOPDIR" &&
  78.   cat $PRELUDE;
  79. } >$BOOTMAKE ||
  80. { echo "$PROGNAME: can't create bootstrap Makefile $BOOTMAKE" 1>&2; exit 1; }
  81.  
  82. TEMPMAKE=$BLDDIR/Mf.temp
  83. echo "$PROGNAME: creating temp Makefile ..." 1>&2
  84.  
  85. { echo "TOP=$TOPDIR" &&
  86.   cat $PRELUDE &&
  87.   make -f $BOOTMAKE _bootstrap; } >$TEMPMAKE ||
  88. { echo "$PROGNAME: can't create temp Makefile $TEMPMAKE" 1>&2; exit 1; }
  89.  
  90. MAKEFILE=$BLDDIR/Makefile
  91. echo "$PROGNAME: moving temp Makefile to Makefile ..." 1>&2
  92.  
  93. if test -f $MAKEFILE
  94. then
  95.     BACKUP=$MAKEFILE.bak
  96.     echo "$PROGNAME: NB: moving previous Makefile to backup" 1>&2
  97.     rm -f $BACKUP
  98.     mv $MAKEFILE $BACKUP
  99. fi
  100.  
  101. mv $TEMPMAKE $MAKEFILE &&
  102. echo "$PROGNAME: done." 1>&2
  103.