home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / perl / 7730 < prev    next >
Encoding:
Text File  |  1993-01-09  |  1.4 KB  |  61 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!darwin.sura.net!uvaarpa!mmdf
  3. From: Kevin Burton <noran!iowa!kburton@uunet.uu.net>
  4. Subject: Makefile parsing (challenge)
  5. Message-ID: <1993Jan9.215626.25646@uvaarpa.Virginia.EDU>
  6. Sender: mmdf@uvaarpa.Virginia.EDU (Mail System)
  7. Reply-To: noran!iowa!kburton@uunet.uu.net
  8. Organization: The Internet
  9. Date: Sat, 9 Jan 1993 21:56:26 GMT
  10. Lines: 49
  11.  
  12.  
  13. I want to extract certain variables defined in a makefile. If the makefile
  14. looks like:
  15.  
  16.         . 
  17.         .
  18.         .
  19.  
  20.     SOURCES= foo.c boo.c\
  21.     tmp.c tmp1.c \
  22.     a.c b.c c.c
  23.  
  24.     # This is a comment
  25.     a.c : a.h
  26.         al;kdjfl;kajdfl;jkadf
  27.     b.c
  28.  
  29.         . 
  30.         .
  31.         .
  32.  
  33.  
  34. I want to end up with a single string of "foo.c boo.c tmp.c tmp1.c a.c b.c c.c".
  35. I want to be able to specifie the string or expression for a string that
  36. describes the variable that I am trying to extract. I came up with the
  37. following hard-coded perl script. I am a beginner and I know there is a
  38. better solution than this. This is not even a complete solution, just
  39. a start. Any ideas ?
  40.  
  41.     #!/usr/local/bin/perl
  42.     # Extract the SOURCE files in a makefile
  43.     
  44.     $* = 1;
  45.     while(<>) {
  46.         $file .= $_;
  47.     }
  48.  
  49.     $file =~ s/\\\n//g;
  50.     $_ = $file;
  51.     $file =~ s/(LIB)?SOURCES\s*=\s*(\w*\.c\s*)+//;
  52.     print $&
  53.  
  54.  
  55. -
  56. Kevin Burton
  57. Noran Instruments                voice: (608) 831-6511 x317
  58. 2551 West Beltline Highway, Room 532          FAX: (608) 836-7224
  59. Middleton, WI 53562                email: kburton@noran.com
  60.  
  61.