[Bio] / SoftRelTools / ldlink.mk Repository:
ViewVC logotype

View of /SoftRelTools/ldlink.mk

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (download) (annotate) (vendor branch)
Fri Dec 20 20:20:56 2002 UTC (15 years, 11 months ago) by efrank
Branch: BobJacobsen, MAIN
CVS Tags: Head-20-Dec-2002, HEAD
Changes since 1.1: +0 -0 lines

Import from SLAC.  Not sure this is going to serve us, but there is a ton
of experience in this package.

#############################################################################
#++ Target ldlink: it makes links in shlib/arch/ldlink for third-party shared
#   libraries based on -L in LDFLAGS and -l in SYSLIB. It is used by 'gmake
#   ldlink' and 'gmake <pkg>.ldlink' (testing purpose only).
#

ifneq (,$(filter ldlink,$(MAKECMDGOALS)))

override CHECKSRTPATH := libcheck-srtpath-$(notdir $(TOPDIR)).so

#--------------------------------------------------------------------------
#++ ldlink: make links for third-party shared libraries.
#	if [ -d $(TOPDIR)/SoftRelTools ]; then 

define ldlink
	t="\t"; if [ "$(findstring -Linux,$(BFARCH))" ];then t="  "};fi;\
	if [ "$(DEBUG27)" ]; then set -x; fi; \
	if [ ! -d $(shlibdir)ldlink ]; then mkdir -p $(shlibdir)ldlink; fi;\
	if [ ! -d $(shlibdir)LDLINK ]; then mkdir -p $(shlibdir)LDLINK; fi;\
	if [ ! -d $(TOPDIR)/SoftRelTools ]; then \
	    echo "** Must addpkg SoftRelTools to make $(CHECKSRTPATH)" >&2; \
	    exit 1; \
	else \
	    msg=`cd $(TOPDIR); $(MAKE) OPTIONS+=-Shared-Lshared-Lstatic-Skipdfile SoftRelTools.lib 2>&1`; \
	    if [ -r "$(TOPDIR)/shlib/$(BFARCH)/libSoftRelTools_$(BFCURRENT).so" ]; then \
	    	echo "made ...LDLINK/$(CHECKSRTPATH)"; \
	    	mv $(TOPDIR)/shlib/$(BFARCH)/libSoftRelTools_$(BFCURRENT).so $(shlibdir)LDLINK/$(CHECKSRTPATH); \
	    else \
	    	echo "** failed to make shlib/$(BFARCH)/libSoftRelTools_$(BFCURRENT).so. Error log as follows..\n $$msg" >&2; \
	    	exit 1; \
	    fi; \
	fi; \
	echo "creating links in ./shlib/$(BFARCH)/ldlink..." >&2; \
	cd $(shlibdir)ldlink; \
	SHAREDLIBS=`perl -e ' \
	    use File::Basename; \
	    sub mysort (@aa){ \
		my $$list=$$old=""; \
		foreach $$word (sort(@_)) { \
	    	    if ("$$word" eq "$$old") {next}; \
	    	    $$list="$$list $$word"; \
	    	    $$old=$$word; \
		} \
	    	$$list; \
	    }; \
	    $$t="\t"; if ("$(findstring -Linux,$(BFARCH))" ne "") {$$t="  "} \
	    $$n="\n"; \
	    if ("$(MAKECMDGOALS)" ne "ldlink") { \
		print STDERR "fixing \"-l\" in SYSLIB   $${t}[mp-1]\n" if ("$(DEBUG30)" ne ""); \
	    } \
	    $$sortsyslib="$(filter-out $(SYSLIB_REMOVALS),$(SYSLIB)) $(SYSLIB_REMOVALS)";\
	    if ("$(DEBUG26)" ne "") {print STDERR "mmm \"SYSLIB\"=$$sortsyslib  $${t}[mp-2]\n";} \
	    if ("$(DEBUG26)" ne "") {print STDERR "   \"LDFLAGS\"=$(LDFLAGS) $${t}[mp-3]\n";} \
	    $$mmm="+---find lib in SHAREDLIBRARIES"; \
	    if ("$(SHAREDLIBRARIES)" ne "") { \
		foreach my $$shlib (split(/ /,"$(SHAREDLIBRARIES)")) { \
	    	    $$target = basename($$shlib); \
	    	    $$dir = dirname($$shlib); \
	    	    ($$stem)= ($$target =~ /^lib(.*).so$$/ ); \
	    	    if ("$$stem" eq "") { \
			print STDERR "** error: bad SHAREDLIBRARIES, $$shlib should be in form of lib<stem>.so $${t}[mp-4]\n"; \
	    	    } else { \
			$$sortsyslib="$$sortsyslib -l$$stem"; \
			$$stemn=$$stem; $$stemn=~s/-/_/g; $$stemn=~s/\//_/g; $$stemn=~s/\./_/g; \
			$$SHDIR{$$stemn}="$$dir"; \
	    	    } \
		} \
	    } \
	    $$dnlist=""; \
	    $$mmm="+---get list of libraries in -L"; \
	    $$dlist="$(filter-out $(TOPDIR)/lib/$(BFARCH) $(BFDIST)/releases/$(BFCURRENT)/lib/$(BFARCH), $(patsubst -L%,%,$(filter -L%,$(LDFLAGS))))"; \
	    if ("$(DEBUG26)") {print STDERR "   \"Llist\"=$$dlist  $${t}[mp-5]\n";} \
	    print STDERR "mmm--- expand -L in LDFLAGS  $${t}[mp-6]\n" if ("$(DEBUG27)" ne "") ; \
	    $$missl=$$misslso=$$missL=""; \
	    foreach $$dir (split(/ /,$$dlist)) { \
		my $$libl; \
		my $$dirn=$$dir; $$dirn=~s/-/_/g; $$dirn=~s/\//_/g; $$dirn=~s/\./_/g; \
		if ($$dir =~ /^$$.*\/ldlink$$/) {next} \
		$$DIR{$$dirn}=$$dir; \
		$$dnlist="$$dirn $$dnlist"; \
		if (! -d "$$dir" ) { \
	    	    $$missL="$$missL %===-L$$dir"; \
		} else { \
	    	    chdir "$$dir";opendir (DH,"."); @flist=readdir(DH); closedir(DH);\
	    	    foreach $$fn (@flist) {\
	    		if (!($$fn =~ /^$$lib.*\.so$$/)) {next} \
	    		$$libl="$$libl $$fn"; \
	    	    } \
	    	    $$libsolist{$$dirn}=$$libl; \
	    	    chdir $$dir; opendir (DH,"."); @flist=readdir(DH); closedir(DH);\
	    	    foreach $$fn (@flist) {\
	    		if (!($$fn =~ /^$$lib.*\.a$$/)) {next} \
	    		$$libl="$$libl $$fn"; \
	    	    } \
	    	    $$libalist{$$dirn}=$$libl; \
	    	    print STDERR "mmm--- \"$$dir\" = $$libsolist{$$dirn} $$libalist{$$dirn}   $${t}[mp-7]\n" if ("$(DEBUG27)" ne ""); \
		} \
	    } \
	    print STDERR "mmm--- looping to find lib \"in SYSLIB\"  $${t}[mp-8]\n" if  ("$(DEBUG27)" ne ""); \
	    my $$Ignore_ldlink = "$(ignore_ldlink)"; \
	    $$Ignore_ldlink =~y/+/_/; \
	    print STDERR "Ignore_ldlink=$$Ignore_ldlink  [mp-8a]\n" if ("$(DEBUG27)" ne ""); \
	    $$pass2=""; \
loop3:      foreach $$lib (split(/ /,$$sortsyslib)) { \
		my ($$Lib)= ($$lib =~ /^(.*)$(LDLINKSUFFIX)$$/ ); \
		$$Lib= $$lib if ("$$Lib" eq ""); \
		$$Lib =~y/+/_/; \
		print STDERR "Lib=$$Lib Ignore_ldlink=$$Ignore_ldlink  [mp-9]\n" if ("$(DEBUG27)" ne ""); \
		if (" $$Ignore_ldlink " =~ /^.* $$Lib .*$$/) { \
	    	    print STDERR "mmm--- \"$$lib\" is on ignored_ldlink list  $${t}[mp-10]\n" if ("$(DEBUG27)" ne ""); \
	    	    $$ignored="$$ignored $$lib"; \
	    	    next loop3; \
		} ;\
		$$org=$$lib; \
		$$stem=""; \
		$$targetso=""; \
		$$targeta=""; \
		($$stem)= ($$lib =~ /^-l(.*)/ ); \
		$$hassuffix=""; \
		if ("$$stem" eq "") { \
	    	    next loop3; \
		} else { \
	    	    ($$tmp)= ($$stem =~ /^(.*)$(LDLINKSUFFIX)$$/ ); \
	    	    if ("$$tmp" ne "") { \
			$$stem=$$tmp; \
			$$hassuffix=1; \
			print STDERR "mmm--- \"$$org\" has suffix  $${t}[mp-11]\n" if ("$(DEBUG27)" ne ""); \
			$$targeta=""; \
	    	    } else { \
	    		print STDERR "mmm--- \"$$org\" has no suffix  $${t}[mp-12]\n" if ("$(DEBUG27)" ne ""); \
	    	    } \
	    	    $$targetso="lib$${stem}.so"; \
	    	    $$targeta="lib$${stem}.a"; \
		} \
		$$stemn=$$stem; $$stemn=~s/-/_/g; $$stemn=~s/\//_/g; $$stemn=~s/\./_/g; \
		print STDERR "mmm--- looping to search lib=\"$$lib\" targetso=$$targetso targeta=$$targeta stem=$$stem  org=$$org  $${t}[mp-13]\n" if ("$(DEBUG27)" ne ""); \
		$$ret=""; \
		my $$dirN; \
loop2:		foreach $$dirn (split(/ /,$$dnlist)) { \
	    	    $$dirN=$$dirn; \
	    	    $$libsolist=$$libsolist{$$dirn}; \
	    	    $$libalist=$$libalist{$$dirn}; \
	    	    $$found=""; $$foundso=""; $$founda=""; \
	    	    print STDERR "mmm--- looping to search shared $$lib in dir=$$DIR{$$dirn}  $${t}[mp-14]\n" if ("$(DEBUG27)" ne ""); \
loopso:	    	    foreach $$libname (split(/ /,$$libsolist)) { \
			if ("$$targetso" eq "") {last loopso}; \
			if ("$$libname" eq "$$targetso") { \
		    	    $$found=1; $$foundso=1; \
		    	    print STDERR "mmm--- found \"$$lib\" in $$DIR{$$dirn}  $${t}[mp-15]\n" if ("$(DEBUG27)" ne ""); \
		    	    if ("$$SHDIR{$$stemn}" eq "") { \
				$$pass2="$$pass2 $$org"; \
		    	    } \
		    	    last loopso; \
			} \
		    } \
	    	    print STDERR "mmm--- looping to search static $$lib in dir=$$DIR{$$dirn}  $${t}[mp-16]\n" if ("$(DEBUG27)" ne ""); \
loopa:	    	    foreach $$libname (split(/ /,$$libalist)) { \
			if ("$$targeta" eq "") {last loopa} \
			if ("$$libname" eq "$$targeta") { \
			    $$found=1; $$founda=1; \
		    	    print STDERR "mmm--- found \"$$targeta\"  $${t}[mp-17]\n" if ("$(DEBUG27)" ne ""); \
		    	    if ("$(MAKECMDGOALS)" ne "ldlink") { \
			    	$$ret="$$ret $${lib}" ; \
		    	    } \
		    	    last loopa; \
		    	} \
	    	    } \
	    	    if ("$$found" ne "") {last loop2}; \
		} \
		$$output=""; \
		$$stemn=$$stem; $$stemn=~s/-/_/g; $$stemn=~s/\//_/g; $$stemn=~s/\./_/g; \
		$$shdir=$$SHDIR{$$stemn}; \
		if ("$$shdir" ne "" && "$$hassuffix" eq "") { \
	    	    if (!(-e "$$shdir/lib$${stem}.so")) { \
	    		if ("$$foundso" ne "") { \
		    	    $$mmm="--- not in SHAREDLIBRARIES, but in -L"; \
			    $$missSH="$$missSH %===$${shdir}/lib$${stem}.so==($$DIR{$$dirN}/lib$$stem.so?)"; \
			} else { \
		    	    $$mmm="--- not in SHAREDLIBRARIES, and not in -L"; \
		    	    $$missSHo="$$missSHo $$shdir/lib$$stem.so"; \
			} \
	    	    } else { \
			$$dir=$$shdir; \
			$$dirn=$$dir; $$dirn=~s/-/_/g; $$dirn=~s/\//_/g; $$dirn=~s/\./_/g; \
			$$dirN=$$dirn; \
			$$DIR{$$dirn}=$$dir; \
			$$found=1; \
	    	    } \
		} \
		if ("$$found" eq "") { \
	    	    print STDERR "mmm--- \"$$lib\" not found   $${t}[mp-18]\n" if ("$(DEBUG27)" ne ""); \
	    	    if ("$$hassuffix" ne "") { \
			$$misslso="$$misslso $$org"; \
	    	    } else { \
			$$missl="$$missl $$org"; \
	    	    }; \
	    	    if ("$(MAKECMDGOALS)" ne "ldlink") {$$ret="$$lib"}; \
		} \
		if ("$$hassuffix" ne "" && "$$foundso" ne "") {$$output=1} \
		if ("$$hassuffix" eq "") { \
	    	    if ("$$foundso" ne "" && "$$founda" eq "") { \
			$$diffm="$${diffm} %===$$org@\[$$DIR{$$dirN}\]"; \
	    	    } elsif ("$$foundso" ne "" && "$$founda" ne "") { \
			$$diff="$${diff}  %===$$org@\[$$DIR{$$dirN}\]"; \
	    	    }; \
		} \
		if ("$(MAKECMDGOALS)" ne "ldlink") { \
	    	    $$ret="$$ret $${lib}$(LDLINKSUFFIX)" ; \
		} elsif ("$$output" ne "") { \
	    	    print STDERR "mmm--- output for \"LDLINK\"  $${t}[mp-19]\n" if ("$(DEBUG27)" ne ""); \
	    	    $$ret="$$DIR{$$dirN}/lib$${stem}.so" ; \
		} \
		$$realsyslib="$$realsyslib $$ret" if ("$ret" ne ""); \
	    } \
loop30:     foreach $$lib (split(/ /,$$pass2)) { \
		next loop30 if ("$$lib" eq ""); \
		$$mmm="--- pass2, check lib in multiple -L"; \
		$$org=$$lib; \
		($$stem)= ($$lib =~ /^-l(.*)/ ); \
		($$tmp)= ($$stem =~ /^(.*)$(LDLINKSUFFIX)$$/ ); \
		if ("$$tmp" ne "") {$$stem=$$tmp;} \
		$$stemn=$$stem; $$stemn=~s/-/_/g; $$stemn=~s/\//_/g; $$stemn=~s/\./_/g; \
	       	$$targetso="lib$${stem}.so"; \
loop20:		foreach $$dirn (split(/ /,$$dnlist)) { \
	    	    $$libsolist=$$libsolist{$$dirn}; \
	    	    print STDERR "mmm--- pass2: looping to search shared $$lib in dir=$$DIR{$$dirn}  $${t}[mp-20]\n" if ("$(DEBUG27)" ne ""); \
loopso2:    	    foreach $$libname (split(/ /,$$libsolist)) { \
			if ("$$targetso" eq "") {last loopso2}; \
			if ("$$libname" eq "$$targetso") { \
		    	    print STDERR "mmm--- pass2: found \"$$lib\" in $$DIR{$$dirn}  $${t}[mp-21]\n" if ("$(DEBUG27)" ne ""); \
		    	    $$Lpath=$$LPATH{$$stemn}; \
		    	    $$dir=$$DIR{$$dirn}; \
		    	    if ("$$Lpath" ne "") { \
			    	if (!($$Lpath =~ /^.* $$dir .*$$/)) { \
			    	    $$duplicate="$$duplicate $$stem"; \
			    	} \
			    } \
		            $$LPATH{$$stemn} = "$$Lpath $$dir "; \
		            last loopso2; \
		    	} \
	    	    } \
	    	} \
	    } \
	    if ("$(DEBUG26)" ne "") { \
	    	print STDERR "mmm REALSYSLIB=$$realsyslib  $${t}[mp-22]\n";  \
            } \
	    if ("$$ignored" ne "") { \
	    	$$ignored=&mysort(split / /,$$ignored); \
	    	print STDERR "++ The following are on ignored_ldlink list: $$ignored$${t}[mp-23]\n" if ("$(DEBUG26)" ne ""); \
	    } \
	    if ("$$missL" ne "") { \
	    	$$misSL=&mysort(split / /,$$missL); \
	    	$$misSL=~s/@/$${t}/g; $$misSL=~s/%/$${n}/g; $$misSL=~s/=/ /g; \
	    	print STDERR "Note: the following -L<path> in LDFLAGS are not found: $${t}[mp-24] $$misSL\n" if ("$(DEBUG30)" ne ""); \
	    } \
	    if ("$$missl" ne "") { \
	    	$$missl=&mysort(split / /,$$missl); \
	    	print STDERR "Note: the following -l<stem> in SYSLIB are not found, static or shared: [mp-25]\n  $$missl\n" if ("$(DEBUG30)" ne ""); \
	    } \
	    if ("$$diff" ne "") { \
	    	$$diFF=&mysort(split / /,$$diff); \
	    	$$diFF=~s/@/$${t}/g; $$diFF=~s/%/$${n}/g; $$diFF=~s/=/ /g; \
	    	print STDERR "Note: consider adding \$$\(LDLINKSUFFIX\) to these -l [has shared AND static]: [mp-26]$$diFF\n" if ("$(DEBUG30)" ne ""); } \
	    if ("$$duplicate" ne "" && "$(DEBUG30)" ne "") { \
	    	print STDERR "Note: the following -l are in multiple -L: [mp-27]\n"; \
	    	foreach my $$stem (split(/ /,"$$duplicate")) { \
		    next if ("$$stem" eq ""); \
		    $$stemn=$$stem; $$stemn=~s/-/_/g; $$stemn=~s/\//_/g; $$stemn=~s/\./_/g; \
		    print STDERR "   $$stem: $$LPATH{$$stemn} \n"; \
	    	} \
	    } \
	    if ("$$misslso" ne "") { \
	    	$$misslsotmp=&mysort(split / /,$$misslso); \
	    	$$misslsotmp=~s/_LDLINK//g; \
	    	print STDERR "** Cannot find lib<stem>.so for the following -l<stem>:  [mp-28]\n  $$misslsotmp\n"; \
	    } \
	    if ("$$missSH" ne "") { \
	    	$$missSh=&mysort(split / /,$$missSH); \
	    	$$missSh=~s/@/$${t}/g; $$missSh=~s/%/$${n}/g; $$missSh=~s/=/ /g; \
	    	print STDERR "** Missing lib in SHAREDLIBRARIES, found in -L<path>: $${t}[mp-29]$$missSh\n"; \
	    } \
	    if ("$$missSHo" ne "") { \
	    	$$missSHO=&mysort(split / /,$$missSHo); \
	    	print STDERR "** The following path defined in SHAREDLIBRARIES does not exist: $${t}[mp-30]\n   $$missSHO\n"; \
	    } \
	    if ("$$diffm" ne "") { \
	    	$$diffM=&mysort(split / /,$$diffm); \
	    	$$diffM=~s/@/$${t}/g; $$diffM=~s/%/$${n}/g; $$diffM=~s/=/ /g; \
	    	print STDERR "** Must add \$$\(LDLINKSUFFIX\) to following -l (has shared, no static): [mp-31]$$diffM\n"; \
	    } \
	    $$REALsyslib=&mysort(split / /,$$realsyslib); \
	    print "$$REALsyslib"; '`; \
	if [ "$(DEBUG26)" ]; then echo "SHAREDLIBS=$$SHAREDLIBS  $${t}[mp-32]"; fi; \
	count=0; \
	for lib in xx $$SHAREDLIBS; do \
	    if [ "$$lib" = 'xx' ]; then continue; fi; \
	    if [ ! -r "$$lib" ]; then echo "** $$lib is not usable. [mp-33]"; fi; \
	    soname=`objdump -p $$lib 2>/dev/null | grep SONAME`; \
	    if [ "$(DEBUG26)" ];then echo "lib=$$lib soname='$$soname  [mp-34]'">&2;fi;\
	    hassoname=""; \
	    if [ "$$soname" ]; then \
	        hassoname="[sn-2]"; \
		dir=`dirname $$lib`; \
		base=`echo $$soname | cut -f2 -d ' '`; \
		lib="$$dir/$$base"; \
		if [ ! -r "$$lib" ]; then echo "** $$lib does not exist. [sn-1]"; fi; \
	    fi; \
	    linkName=`basename $$lib`; \
	    if [ "$$linkName" = "$(CHECKSRTPATH)" ]; then lib="../LDLINK/$$linkName"; fi;\
	    $(RM) -f $$linkName; \
	    ln -s $$lib $$linkName; \
	    mmm="ln -s $$lib $$linkName  $$hassoname" >& 2; \
	    count=`expr $$count + 1`; \
	done; \
	echo "made $$count links" 
endef

endif   # Fixl or target=ldlink

#--------------------------------------------------------------------------
# Debugging
#  
# (1) gmake ldlink.mk DEBUG27=1 |& tee a.mk (2) Search for 'found' in
# a.mk. (3) Search for '"-l<stem>' in a.mk. (4) To find list of lib in
# <dir>, search for '"<dir>' in a.mk.

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3