Perl String Substitution Question

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
s243a
Posts: 2580
Joined: Tue 02 Sep 2014, 04:48
Contact:

Perl String Substitution Question

#1 Post by s243a »

My knowledge of perl is rather limited. I'm looking at line 1727 of openssl/configure

Code: Select all

s/^SHARED_LIBS=.*/SHARED_LIBS=\$(SHARED_CRYPTO) \$(SHARED_SSL)/ if (!$no_shared);
and I want to make sure that I understand this line of code.

It looks to me that at the line of "Makefile.org" where the start of the line is

Code: Select all

SHARED_LIBS=
that we are replacing the rest of the line with what we get from

Code: Select all

SHARED_LIBS=\$(SHARED_CRYPTO) \$(SHARED_SSL)
after expanding variables.

Then I think the if statement throws away the result if !no_shared evaluates to true. So is this like a perl control structure (i.e. replace-if).


One weird thing that I notice about this is that they throw away the rest of the line. Wouldn't it make more sense to do this?

Code: Select all

s/^SHARED_LIBS=(.*)/SHARED_LIBS=\$1 \$(SHARED_CRYPTO) \$(SHARED_SSL)/ if (!$no_shared);
That way people could add extra libs in Makfile.org if they wanted those also built as shared libraries. This line is relevant to me because I'm trying to build the shared libraries for gost-engine (see my other thread) and if this variable isn't set then the makefile for gost-engine won't build the shared libraries (see line of #44 of /openssl/engines/ccgost/Makefile.

s243a
Posts: 2580
Joined: Tue 02 Sep 2014, 04:48
Contact:

#2 Post by s243a »

So, I created some files for debugging (the old fashion way with print statements because I don't know a better way in this environment).

runConfigEcho.sh consists of:

Code: Select all

perl ./ConfigureEcho linux-elf -fPIC -DOPENSSL_PIC -march=pentium -Wa,--noexecstack
these are the arguments past by the config script to the configure file in my system. Then in place of configure I created ConfigureEcho

with the following debugging statments:

Code: Select all

	print "1728 $_";
	if ($_ =~ /^SHARED_LIBS=.*/)
	   {print "1730 SHARED_CRYPTO= $(SHARED_CRYPTO) \n";
	   print "1731 SHARED_SSL= $(SHARED_SSL) \n";	   
	   print "1732 no)shared= $no_shared \n";}	   	   
	s/^SHARED_LIBS=.*/SHARED_LIBS=\$(SHARED_CRYPTO) \$(SHARED_SSL)/ if (!$no_shared);
	print "1734 $_";
Here's some output

Code: Select all

1728 SHARED_LIBS=1730 SHARED_CRYPTO= 0 0 2 100 101 102 103 104 105 106 107 108 109 110 112SHARED_CRYPTO) 
1731 SHARED_SSL= 0 0 2 100 101 102 103 104 105 106 107 108 109 110 112SHARED_SSL) 
1732 no)shared= 1 
1734 SHARED_LIBS=1750 
I'm not sure why all these random numbers appear like this:
"0 0 2 100 101 102 103 104 105 106 107 108 109 110 112"

I'm not sure why SHARED_CRYPTO is surrounded in $() given that there is no command called SHARED_CRYPTO. It just seems to output a string.

I'm a bit confused but learning something about pearl :)

Post Reply