home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!rpi!ghost.dsi.unimi.it!univ-lyon1.fr!chx400!sicsun!siisun.epfl.ch!brossard
- From: brossard@siisun.epfl.ch (Alain Brossard EPFL-SIC/SII)
- Newsgroups: comp.lang.perl
- Subject: Re: Makefile parsing (challenge)
- Message-ID: <1993Jan11.121155@siisun.epfl.ch>
- Date: 11 Jan 93 11:11:55 GMT
- References: <1993Jan9.215626.25646@uvaarpa.Virginia.EDU> <1iri8tINNspv@bach.mentor.dk>
- Sender: news@sicsun.epfl.ch
- Reply-To: brossard@sic.epfl.ch
- Organization: Ecole Polytechnique Federale de Lausanne
- Lines: 53
-
- |> Kevin Burton <noran!iowa!kburton@uunet.uu.net> writes:
- |>
- |> >I want to extract certain variables defined in a makefile.
-
- I wrote the following because I needed to do just that. You'll need
- to adapt it to your specific needs.
-
- # get_nis_passwd_file returns the name of the NIS password file and the
- # name of the shadow password file. Either can be replaced with the
- # string NIS if it thinks this is the master NIS machine but it couldn't find
- # the password file; or it returns an empty string otherwise (not an NIS master)
- .
- # It assumes that the current directory is /var/yp
- #
- local( %var );
- sub get_nis_passwd_file {
- local( $pwd, $pwd_adj );
- if( -e 'binding' && -e 'Makefile' && -e 'passwd.time' &&
- open( MAKE, "Makefile" ) ) {
- while( $_ = <MAKE> ) {
- if( /^\s*(\w+)\s*=\s*(.*)$/ ) {
- $var{ $1 } = $2; # record Make variables <===========
- } elsif ( /^passwd.time:\s*([^\s]+)/ ) {
- $pwd = &gnpf_expand_make_name( $1 );
- $pwd = '' if ! -e $pwd;
- }
- }
- close MAKE;
- $pwd = 'NIS' if ! $pwd;
- }
-
- return ( $pwd, $pwd_adj );
- }
- #
- # Expand any variables in the file name
- #
- sub gnpf_expand_make_name {
- local( $pwd ) = shift;
- local( $begin, $var, $end );
- while( $pwd =~ /^([^\$]*)\$[({](\w+)[)}](.*)$/ ) {
- $begin = $1; $var = $2; $end = $3;
- $var = $var{ $var }; # Doesn't matter if not defined!
- $pwd = $begin.$var.$end;
- }
- return $pwd;
- }
- 1;
-
- --
-
- Alain Brossard, Ecole Polytechnique Federale de Lausanne,
- SIC/SII, EL-Ecublens, CH-1015 Lausanne, Suisse, +41 21 693-2211
- brossard@sic.epfl.ch
-