diff --git a/Configurations/00-base-templates.conf b/Configurations/00-base-templates.conf index ce59fbf296..f1539929ef 100644 --- a/Configurations/00-base-templates.conf +++ b/Configurations/00-base-templates.conf @@ -59,18 +59,12 @@ my %targets=( inherit_from => [ "BASE_common" ], template => 1, + lflags => + sub { $withargs{zlib_lib} ? "-L".$withargs{zlib_lib} : () }, ex_libs => - sub { - unless ($disabled{zlib}) { - if (defined($disabled{"zlib-dynamic"})) { - if (defined($withargs{zlib_lib})) { - return "-L".$withargs{zlib_lib}." -lz"; - } else { - return "-lz"; - } - } - } - return (); }, + sub { !defined($disabled{zlib}) + && defined($disabled{"zlib-dynamic"}) + ? "-lz" : () }, build_scheme => [ "unified", "unix" ], build_file => "Makefile", diff --git a/Configurations/10-main.conf b/Configurations/10-main.conf index 08bb839de5..bc7c496351 100644 --- a/Configurations/10-main.conf +++ b/Configurations/10-main.conf @@ -169,7 +169,7 @@ my %targets = ( release => "-O3"), thread_scheme => "(unknown)", sys_id => "VOS", - lflags => "-Wl,-map", + lflags => add("-Wl,-map"), bn_ops => "BN_LLONG", shared_extension => ".so", }, @@ -564,7 +564,8 @@ my %targets = ( cc => "gcc", cflags => "-D_ENDIAN -DBN_DIV2W -O3 -D_POSIX_SOURCE -D_SOCKET_SOURCE -I/SYSLOG/PUB", sys_id => "MPE", - ex_libs => add("-L/SYSLOG/PUB -lsyslog -lsocket -lcurses"), + lflags => add("-L/SYSLOG/PUB"), + ex_libs => add("-lsyslog -lsocket -lcurses"), thread_scheme => "(unknown)", bn_ops => "BN_LLONG", }, @@ -1384,10 +1385,10 @@ my %targets = ( : " /MC"; }), debug => "/Od -DDEBUG -D_DEBUG", release => "/O1i"), - lflags => combine("/nologo /opt:ref", - sub { vc_wince_info()->{lflags}; }, - sub { defined(env('PORTSDK_LIBPATH')) - ? "/entry:mainCRTstartup" : (); }), + lflags => add(combine("/nologo /opt:ref", + sub { vc_wince_info()->{lflags}; }, + sub { defined(env('PORTSDK_LIBPATH')) + ? "/entry:mainCRTstartup" : (); })), sys_id => "WINCE", bn_ops => "BN_LLONG EXPORT_VAR_AS_FN", ex_libs => add(sub { @@ -1639,49 +1640,51 @@ my %targets = ( cc => "ccppc", cflags => "-D_REENTRANT -mrtp -mhard-float -mstrict-align -fno-implicit-fp -DPPC32_fp60x -O2 -fstrength-reduce -fno-builtin -fno-strict-aliasing -Wall -DCPU=PPC32 -DTOOL_FAMILY=gnu -DTOOL=gnu -I\$(WIND_BASE)/target/usr/h -I\$(WIND_BASE)/target/usr/h/wrn/coreip", sys_id => "VXWORKS", - ex_libs => add("-Wl,--defsym,__wrs_rtp_base=0xe0000000 -L \$(WIND_BASE)/target/usr/lib/ppc/PPC32/common"), + lflags => add("-L \$(WIND_BASE)/target/usr/lib/ppc/PPC32/common"), + ex_libs => add("-Wl,--defsym,__wrs_rtp_base=0xe0000000"), }, "vxworks-ppcgen" => { inherit_from => [ "BASE_unix" ], cc => "ccppc", cflags => "-D_REENTRANT -mrtp -msoft-float -mstrict-align -O1 -fno-builtin -fno-strict-aliasing -Wall -DCPU=PPC32 -DTOOL_FAMILY=gnu -DTOOL=gnu -I\$(WIND_BASE)/target/usr/h -I\$(WIND_BASE)/target/usr/h/wrn/coreip", sys_id => "VXWORKS", - ex_libs => add("-Wl,--defsym,__wrs_rtp_base=0xe0000000 -L \$(WIND_BASE)/target/usr/lib/ppc/PPC32/sfcommon"), + lflags => add("-L \$(WIND_BASE)/target/usr/lib/ppc/PPC32/sfcommon"), + ex_libs => add("-Wl,--defsym,__wrs_rtp_base=0xe0000000"), }, "vxworks-ppc405" => { inherit_from => [ "BASE_unix" ], cc => "ccppc", cflags => "-g -msoft-float -mlongcall -DCPU=PPC405 -I\$(WIND_BASE)/target/h", sys_id => "VXWORKS", - lflags => "-r", + lflags => add("-r"), }, "vxworks-ppc750" => { inherit_from => [ "BASE_unix" ], cc => "ccppc", cflags => "-ansi -nostdinc -DPPC750 -D_REENTRANT -fvolatile -fno-builtin -fno-for-scope -fsigned-char -Wall -msoft-float -mlongcall -DCPU=PPC604 -I\$(WIND_BASE)/target/h \$(DEBUG_FLAG)", sys_id => "VXWORKS", - lflags => "-r", + lflags => add("-r"), }, "vxworks-ppc750-debug" => { inherit_from => [ "BASE_unix" ], cc => "ccppc", cflags => "-ansi -nostdinc -DPPC750 -D_REENTRANT -fvolatile -fno-builtin -fno-for-scope -fsigned-char -Wall -msoft-float -mlongcall -DCPU=PPC604 -I\$(WIND_BASE)/target/h -DPEDANTIC -DDEBUG -g", sys_id => "VXWORKS", - lflags => "-r", + lflags => add("-r"), }, "vxworks-ppc860" => { inherit_from => [ "BASE_unix" ], cc => "ccppc", cflags => "-nostdinc -msoft-float -DCPU=PPC860 -DNO_STRINGS_H -I\$(WIND_BASE)/target/h", sys_id => "VXWORKS", - lflags => "-r", + lflags => add("-r"), }, "vxworks-simlinux" => { inherit_from => [ "BASE_unix" ], cc => "ccpentium", cflags => "-B\$(WIND_BASE)/host/\$(WIND_HOST_TYPE)/lib/gcc-lib/ -D_VSB_CONFIG_FILE=\"\$(WIND_BASE)/target/lib/h/config/vsbConfig.h\" -DL_ENDIAN -DCPU=SIMLINUX -DTOOL_FAMILY=gnu -DTOOL=gnu -fno-builtin -fno-defer-pop -DNO_STRINGS_H -I\$(WIND_BASE)/target/h -I\$(WIND_BASE)/target/h/wrn/coreip -DOPENSSL_NO_HW_PADLOCK", sys_id => "VXWORKS", - lflags => "-r", + lflags => add("-r"), ranlib => "ranlibpentium", }, "vxworks-mips" => { @@ -1690,7 +1693,8 @@ my %targets = ( cflags => combine("-mrtp -mips2 -O -G 0 -B\$(WIND_BASE)/host/\$(WIND_HOST_TYPE)/lib/gcc-lib/ -D_VSB_CONFIG_FILE=\"\$(WIND_BASE)/target/lib/h/config/vsbConfig.h\" -DCPU=MIPS32 -msoft-float -mno-branch-likely -DTOOL_FAMILY=gnu -DTOOL=gnu -fno-builtin -fno-defer-pop -DNO_STRINGS_H -I\$(WIND_BASE)/target/usr/h -I\$(WIND_BASE)/target/h/wrn/coreip", threads("-D_REENTRANT")), sys_id => "VXWORKS", - ex_libs => add("-Wl,--defsym,__wrs_rtp_base=0xe0000000 -L \$(WIND_BASE)/target/usr/lib/mips/MIPSI32/sfcommon"), + lflags => add("-L \$(WIND_BASE)/target/usr/lib/mips/MIPSI32/sfcommon"), + ex_libs => add("-Wl,--defsym,__wrs_rtp_base=0xe0000000"), thread_scheme => "pthreads", perlasm_scheme => "o32", ranlib => "ranlibmips", diff --git a/Configurations/50-djgpp.conf b/Configurations/50-djgpp.conf index fa8e6625d8..b4d19e20ac 100644 --- a/Configurations/50-djgpp.conf +++ b/Configurations/50-djgpp.conf @@ -8,7 +8,8 @@ my %targets = ( cc => "gcc", cflags => "-I/dev/env/WATT_ROOT/inc -DTERMIOS -DL_ENDIAN -fomit-frame-pointer -O2 -Wall", sys_id => "MSDOS", - ex_libs => add("-L/dev/env/WATT_ROOT/lib -lwatt"), + lflags => add("-L/dev/env/WATT_ROOT/lib"), + ex_libs => add("-lwatt"), bn_ops => "BN_LLONG", perlasm_scheme => "a.out", }, diff --git a/Configurations/unix-Makefile.tmpl b/Configurations/unix-Makefile.tmpl index 43b1f03a2b..601a8ea3c1 100644 --- a/Configurations/unix-Makefile.tmpl +++ b/Configurations/unix-Makefile.tmpl @@ -189,7 +189,7 @@ CFLAGS={- our $cflags2 = join(" ",(map { "-D".$_} @{$target{defines}}, @{$config CFLAGS_Q={- $cflags2 =~ s|([\\"])|\\$1|g; $cflags2 -} {- $config{cflags} -} CXX= $(CROSS_COMPILE){- $target{cxx} -} CXXFLAGS={- our $cxxflags2 = join(" ",(map { "-D".$_} @{$target{defines}}, @{$config{defines}}),"-DOPENSSLDIR=\"\\\"\$(OPENSSLDIR)\\\"\"","-DENGINESDIR=\"\\\"\$(ENGINESDIR)\\\"\"") -} {- $target{cxxflags} -} {- $config{cxxflags} -} -std=c++11 -LDFLAGS= {- $target{lflags} -} +LDFLAGS= {- $config{lflags} -} {- $target{lflags} -} PLIB_LDFLAGS= {- $target{plib_lflags} -} EX_LIBS= {- $target{ex_libs} -} {- $config{ex_libs} -} LIB_CFLAGS={- $target{shared_cflag} || "" -} @@ -944,10 +944,15 @@ EOF my $libd = dirname($lib); my $libn = basename($lib); (my $libname = $libn) =~ s/^lib//; - my $linklibs = join("", map { my $d = dirname($_); - my $f = basename($_); + my @linkdirs = (); + foreach (@{args{deps}}) { + my $d = dirname($_); + push @linkdirs, $d unless grep { $d eq $_ } @linkdirs; + } + my $linkflags = join("", map { "-L$_ " } @linkdirs); + my $linklibs = join("", map { my $f = basename($_); (my $l = $f) =~ s/^lib//; - " -L$d -l$l" } @{$args{deps}}); + " -l$l" } @{$args{deps}}); my @objs = map { (my $x = $_) =~ s|\.o$|$objext|; $x } grep { $_ =~ m|\.o$| } @{$args{objs}}; @@ -974,7 +979,7 @@ EOF # simplest, {libname}\$(SHLIB_EXT_IMPORT) for Windows POSIX layers and # {libname}\$(SHLIB_EXT_SIMPLE) for the Unix platforms. $target: $deps - \$(CC) \$(CFLAGS) \$(LIB_CFLAGS) \$(LIB_LDFLAGS)$shared_soname$shared_imp \\ + \$(CC) \$(CFLAGS) \$(LIB_CFLAGS) $linkflags\$(LIB_LDFLAGS)$shared_soname$shared_imp \\ -o $target_full$shared_def $objs \\ \$(PLIB_LDFLAGS) $linklibs \$(EX_LIBS) EOF @@ -999,10 +1004,15 @@ EOF my $dso = $args{lib}; my $dsod = dirname($dso); my $dson = basename($dso); - my $linklibs = join("", map { my $d = dirname($_); - my $f = basename($_); + my @linkdirs = (); + foreach (@{args{deps}}) { + my $d = dirname($_); + push @linkdirs, $d unless grep { $d eq $_ } @linkdirs; + } + my $linkflags = join("", map { "-L$_ " } @linkdirs); + my $linklibs = join("", map { my $f = basename($_); (my $l = $f) =~ s/^lib//; - " -L$d -l$l" } @{$args{deps}}); + " -l$l" } @{$args{deps}}); my @objs = map { (my $x = $_) =~ s|\.o$|$objext|; $x } @{$args{objs}}; my @deps = compute_lib_depends(@{$args{deps}}); my $objs = join(" ", @objs); @@ -1010,7 +1020,7 @@ EOF my $target = dso($dso); return <<"EOF"; $target: $objs $deps - \$(CC) \$(CFLAGS) \$(DSO_CFLAGS) \$(DSO_LDFLAGS) \\ + \$(CC) \$(CFLAGS) \$(DSO_CFLAGS) $linkflags\$(DSO_LDFLAGS) \\ -o $target $objs \\ \$(PLIB_LDFLAGS) $linklibs \$(EX_LIBS) EOF @@ -1034,14 +1044,19 @@ EOF my $objs = join(" ", map { (my $x = $_) =~ s|\.o$|$objext|; $x } @{$args{objs}}); my $deps = join(" ",compute_lib_depends(@{$args{deps}})); + my @linkdirs = (); + foreach (@{args{deps}}) { + next if $_ =~ /\.a$/; + my $d = dirname($_); + push @linkdirs, $d unless grep { $d eq $_ } @linkdirs; + } + my $linkflags = join("", map { "-L$_ " } @linkdirs); my $linklibs = join("", map { if ($_ =~ /\.a$/) { " $_"; } else { - my $d = dirname($_); my $f = basename($_); - $d = "." if $d eq $f; (my $l = $f) =~ s/^lib//; - " -L$d -l$l" + " -l$l" } } @{$args{deps}}); my $cmd = '$(CC)'; @@ -1053,7 +1068,8 @@ EOF return <<"EOF"; $bin$exeext: $objs $deps rm -f $bin$exeext - \$\${LDCMD:-$cmd} $cmdflags \$(LDFLAGS) \$(BIN_LDFLAGS) -o $bin$exeext $objs \\ + \$\${LDCMD:-$cmd} $cmdflags $linkflags\$(LDFLAGS) \$(BIN_LDFLAGS) \\ + -o $bin$exeext $objs \\ \$(PLIB_LDFLAGS) $linklibs \$(EX_LIBS) EOF } diff --git a/Configure b/Configure index b66e2513f5..b172595ece 100755 --- a/Configure +++ b/Configure @@ -526,6 +526,7 @@ $config{openssl_algorithm_defines}=[]; $config{openssl_thread_defines}=[]; $config{openssl_sys_defines}=[]; $config{openssl_other_defines}=[]; +my $ldflags=""; my $libs=""; my $target=""; $config{options}=""; @@ -729,7 +730,11 @@ while (@argvcopy) { read_config $1; } - elsif (/^-[lL](.*)$/ or /^-Wl,/) + elsif (/^-L(.*)$/) + { + $ldflags.=$_." "; + } + elsif (/^-l(.*)$/ or /^-Wl,/) { $libs.=$_." "; } @@ -1050,6 +1055,7 @@ $config{build_file} = $target{build_file}; $config{defines} = []; $config{cflags} = ""; $config{cxxflags} = ""; +$config{lflags} = ""; $config{ex_libs} = ""; $config{shared_ldflag} = ""; @@ -1121,6 +1127,7 @@ if (!$disabled{dso} && $target{dso_scheme} ne "") } $config{ex_libs}="$libs$config{ex_libs}" if ($libs ne ""); +$config{lflags}="$config{lflags}$ldflags" if ($ldflags ne ""); # If threads aren't disabled, check how possible they are unless ($disabled{threads}) { @@ -2176,6 +2183,7 @@ print "DEFINES =",join(" ", @{$target{defines}}, @{$config{defines}}),"\n" #print "RANLIB =", $target{ranlib} eq '$(CROSS_COMPILE)ranlib' ? # "$config{cross_compile_prefix}ranlib" : # "$target{ranlib}", "\n"; +print "LDFLAGS =$config{lflags} $target{lflags}\n"; print "EX_LIBS =$target{ex_libs} $config{ex_libs}\n"; my %builders = (