Don't distribute team internal config targets
[openssl.git] / Configurations / unix-Makefile.tmpl
index 78b1a5e514c009bff4d8122b244cbd0b17b4c8c5..799eaa88059265aec2397b8b2ab573f4701c3422 100644 (file)
@@ -12,6 +12,7 @@
      our $shlibextsimple = $target{shared_extension_simple} || ".so";
      our $shlibextimport = $target{shared_import_extension} || "";
      our $dsoext = $target{dso_extension} || ".so";
+     our $makedepprog = $disabled{makedepend} ? undef : $config{makedepprog};
 
      sub windowsdll { $config{target} =~ /^(?:Cygwin|mingw)/ }
 
@@ -105,13 +106,9 @@ DEPS={- join(" ", map { (my $x = $_) =~ s|\.o$|$depext|; $x; }
                   grep { $unified_info{sources}->{$_}->[0] =~ /\.c$/ }
                   keys %{$unified_info{sources}}); -}
 {- output_on() if $disabled{makedepend}; "" -}
-GENERATED_MANDATORY={- join(" ", @{$unified_info{depends}->{""}} ) -}
-GENERATED={- join(" ",
-                  ( map { (my $x = $_) =~ s|\.S$|\.s|; $x }
-                    grep { defined $unified_info{generate}->{$_} }
-                    map { @{$unified_info{sources}->{$_}} }
-                    grep { /\.o$/ } keys %{$unified_info{sources}} ),
-                  ( grep { /\.h$/ } keys %{$unified_info{generate}} )) -}
+GENERATED_MANDATORY={- join(" ", @{$unified_info{depends}->{""}}) -}
+GENERATED={- # common0.tmpl provides @generated
+             join(" ", @generated ) -}
 
 INSTALL_LIBS={- join(" ", map { lib($_) } @{$unified_info{install}->{libraries}}) -}
 INSTALL_SHLIBS={- join(" ", map { shlib($_) } @{$unified_info{install}->{libraries}}) -}
@@ -188,61 +185,141 @@ HTMLSUFFIX=html
 # For "optional" echo messages, to get "real" silence
 ECHO = echo
 
-CROSS_COMPILE= {- $config{cross_compile_prefix} -}
-CPPFLAGS={- our $cppflags = join(" ",
-                                 (map { "-D".$_} @{$config{defines}}),
-                                 (map { "-I".$_} @{$config{includes}}),
-                                 @{$config{cppflags}}) -}
-CPPFLAGS_Q={- $cppflags =~ s|([\\"])|\\$1|g; $cppflags -}
-CC= $(CROSS_COMPILE){- $config{cc} -}
-CFLAGS={- join(' ', @{$config{cflags}}) -}
-CXX={- $config{cxx} ? "\$(CROSS_COMPILE)$config{cxx}" : '' -}
-CXXFLAGS={- join(' ', @{$config{cxxflags}}) -}
-LDFLAGS= {- join(' ', @{$config{lflags}}) -}
-PLIB_LDFLAGS= {- join(' ', @{$config{plib_lflags}}) -}
-EX_LIBS= {- join(' ', @{$config{ex_libs}}) -}
-
-LIB_CPPFLAGS={- join(' ', '$(CPPFLAGS)',
-                          $target{shared_cppflag} || (),
-                          (map { '-D'.$_ }
-                               ('OPENSSLDIR="\"$(OPENSSLDIR)\""',
-                                'ENGINESDIR="\"$(ENGINESDIR)\""'))) -}
-LIB_CFLAGS={- join(' ', '$(CFLAGS)', $target{shared_cflag} || ()) -}
-LIB_CXXFLAGS={- join(' ', '$(CXXFLAGS)', $target{shared_cxxflag} || ()) -}
-LIB_LDFLAGS={- join(' ', '$(LDFLAGS)', $target{shared_ldflag} || (), $config{shared_ldflag} || ()) -}
-DSO_CPPFLAGS={- join(' ', '$(CPPFLAGS)', $target{dso_cppflags} || ()) -}
-DSO_CFLAGS={- join(' ', '$(CFLAGS)', $target{dso_cflags} || ()) -}
-DSO_CXXFLAGS={- join(' ', '$(CXXFLAGS)', $target{dso_cxxflags} || ()) -}
-DSO_LDFLAGS={- join(' ', '$(LDFLAGS)', $target{dso_lflags} || ()) -}
-BIN_CPPFLAGS={- join(' ', '$(CPPFLAGS)', $target{bin_cppflags} || ()) -}
-BIN_CFLAGS={- join(' ', '$(CFLAGS)', $target{bin_cflags} || ()) -}
-BIN_CXXFLAGS={- join(' ', '$(CXXFLAGS)', $target{bin_cxxflags} || ()) -}
-BIN_LDFLAGS={- join(' ', '$(LDFLAGS)', $target{bin_lflags} || ()) -}
+##### User defined commands and flags ################################
+
+# We let the C compiler driver to take care of .s files. This is done in
+# order to be excused from maintaining a separate set of architecture
+# dependent assembler flags. E.g. if you throw -mcpu=ultrasparc at SPARC
+# gcc, then the driver will automatically translate it to -xarch=v8plus
+# and pass it down to assembler.  In any case, we do not define AS or
+# ASFLAGS for this reason.
+
+CROSS_COMPILE={- $config{CROSS_COMPILE} -}
+CC=$(CROSS_COMPILE){- $config{CC} -}
+CXX={- $config{CXX} ? "\$(CROSS_COMPILE)$config{CXX}" : '' -}
+CPPFLAGS={- our $cppflags1 = join(" ",
+                                  (map { "-D".$_} @{$config{CPPDEFINES}}),
+                                  (map { "-I".$_} @{$config{CPPINCLUDES}}),
+                                  @{$config{CPPFLAGS}}) -}
+CFLAGS={- join(' ', @{$config{CFLAGS}}) -}
+CXXFLAGS={- join(' ', @{$config{CXXFLAGS}}) -}
+LDFLAGS= {- join(' ', @{$config{LDFLAGS}}) -}
+EX_LIBS= {- join(' ', @{$config{LDLIBS}}) -}
+
+MAKEDEPEND={- $config{makedepprog} -}
 
 PERL={- $config{perl} -}
 
-AR=$(CROSS_COMPILE){- $config{ar} -}
-ARFLAGS= {- join(' ', @{$config{arflags}}) -}
-RANLIB={- $config{ranlib} ? "\$(CROSS_COMPILE)$config{ranlib}" : "true"; -}
-RC= $(CROSS_COMPILE){- $target{rc} || "windres" -}
-RCFLAGS={- join(' ', @{$config{rcflags}}) -} {- $target{shared_rcflag} -}
+AR=$(CROSS_COMPILE){- $config{AR} -}
+ARFLAGS= {- join(' ', @{$config{ARFLAGS}}) -}
+RANLIB={- $config{RANLIB} ? "\$(CROSS_COMPILE)$config{RANLIB}" : "true"; -}
+RC= $(CROSS_COMPILE){- $config{RC} -}
+RCFLAGS={- join(' ', @{$config{RCFLAGS}}) -} {- $target{shared_rcflag} -}
+
 RM= rm -f
 RMDIR= rmdir
-TAR= {- $target{tar} || "tar" -}
-TARFLAGS= {- $target{tarflags} -}
-MAKEDEPEND={- $config{makedepprog} -}
+TAR= {- $target{TAR} || "tar" -}
+TARFLAGS= {- $target{TARFLAGS} -}
 
 BASENAME=       openssl
 NAME=           $(BASENAME)-$(VERSION)
 TARFILE=        ../$(NAME).tar
 
-# We let the C compiler driver to take care of .s files. This is done in
-# order to be excused from maintaining a separate set of architecture
-# dependent assembler flags. E.g. if you throw -mcpu=ultrasparc at SPARC
-# gcc, then the driver will automatically translate it to -xarch=v8plus
-# and pass it down to assembler.
-AS={- $config{as} ? "\$(CROSS_COMPILE)$config{as}" : '$(CC) -c' -}
-ASFLAGS={- join(' ', @{$config{asflags}}) || '$(CFLAGS)' -}
+##### Project flags ##################################################
+
+# Variables starting with CNF_ are common variables for all product types
+
+CNF_CPPFLAGS={- our $cppflags2 =
+                    join(' ', $target{cppflags} || (),
+                              (map { "-D".$_} @{$target{defines}},
+                                              @{$config{defines}}),
+                              (map { "-I".$_} @{$target{includes}},
+                                              @{$config{includes}}),
+                              @{$config{cppflags}}) -}
+CNF_CFLAGS={- join(' ', $target{cflags} || (),
+                        @{$config{cflags}}) -}
+CNF_CXXFLAGS={- join(' ', $target{cxxflags} || (),
+                          @{$config{cxxflags}}) -}
+CNF_LDFLAGS={- join(' ', $target{lflags} || (),
+                         @{$config{lflags}}) -}
+CNF_EX_LIBS={- join(' ', $target{ex_libs} || (),
+                         @{$config{ex_libs}}) -}
+
+# Variables starting with LIB_ are used to build library object files
+# and shared libraries.
+# Variables starting with DSO_ are used to build DSOs and their object files.
+# Variables starting with BIN_ are used to build programs and their object
+# files.
+
+LIB_CPPFLAGS={- our $lib_cppflags =
+                join(' ', $target{lib_cppflags} || (),
+                          $target{shared_cppflag} || (),
+                          (map { '-D'.$_ }
+                               @{$config{lib_defines}},
+                               @{$config{shared_defines}}),
+                          @{$config{lib_cppflags}},
+                          @{$config{shared_cppflag}});
+                join(' ', $lib_cppflags,
+                          (map { '-D'.$_ }
+                               'OPENSSLDIR="\"$(OPENSSLDIR)\""',
+                               'ENGINESDIR="\"$(ENGINESDIR)\""'),
+                          '$(CNF_CPPFLAGS)', '$(CPPFLAGS)') -}
+LIB_CFLAGS={- join(' ', $target{lib_cflags} || (),
+                        $target{shared_cflag} || (),
+                        @{$config{lib_cflags}},
+                        @{$config{shared_cflag}},
+                        '$(CNF_CFLAGS)', '$(CFLAGS)') -}
+LIB_CXXFLAGS={- join(' ', $target{lib_cxxflags} || (),
+                          $target{shared_cxxflag} || (),
+                          @{$config{lib_cxxflags}},
+                          @{$config{shared_cxxflag}},
+                          '$(CNF_CXXFLAGS)', '$(CXXFLAGS)') -}
+LIB_LDFLAGS={- join(' ', $target{shared_ldflag} || (),
+                         $config{shared_ldflag} || (),
+                         '$(CNF_LDFLAGS)', '$(LDFLAGS)') -}
+LIB_EX_LIBS=$(CNF_EX_LIBS) $(EX_LIBS)
+DSO_CPPFLAGS={- join(' ', $target{dso_cppflags} || (),
+                          $target{module_cppflags} || (),
+                          @{$config{dso_cppflags}},
+                          @{$config{module_cppflags}},
+                          '$(CNF_CPPFLAGS)', '$(CPPFLAGS)') -}
+DSO_CFLAGS={- join(' ', $target{dso_cflags} || (),
+                        $target{module_cflags} || (),
+                        @{$config{dso_cflags}},
+                        @{$config{module_cflags}},
+                        '$(CNF_CFLAGS)', '$(CFLAGS)') -}
+DSO_CXXFLAGS={- join(' ', $target{dso_cxxflags} || (),
+                          $target{module_cxxflags} || (),
+                          @{$config{dso_cxxflags}},
+                          @{$config{module_cxxflag}},
+                          '$(CNF_CXXFLAGS)', '$(CXXFLAGS)') -}
+DSO_LDFLAGS={- join(' ', $target{dso_ldflags} || (),
+                         $target{module_ldflags} || (),
+                         @{$config{dso_ldflags}},
+                         @{$config{module_ldflags}},
+                         '$(CNF_LDFLAGS)', '$(LDFLAGS)') -}
+DSO_EX_LIBS=$(CNF_EX_LIBS) $(EX_LIBS)
+BIN_CPPFLAGS={- join(' ', $target{bin_cppflags} || (),
+                          @{$config{bin_cppflags}},
+                          '$(CNF_CPPFLAGS)', '$(CPPFLAGS)') -}
+BIN_CFLAGS={- join(' ', $target{bin_cflags} || (),
+                        @{$config{bin_cflags}},
+                        '$(CNF_CFLAGS)', '$(CFLAGS)') -}
+BIN_CXXFLAGS={- join(' ', $target{bin_cxxflags} || (),
+                          @{$config{bin_cxxflags}},
+                          '$(CNF_CXXFLAGS)', '$(CXXFLAGS)') -}
+BIN_LDFLAGS={- join(' ', $target{bin_lflags} || (),
+                         @{$config{bin_lflags}},
+                         '$(CNF_LDFLAGS)', '$(LDFLAGS)') -}
+BIN_EX_LIBS=$(CNF_EX_LIBS) $(EX_LIBS)
+
+# CPPFLAGS_Q is used for one thing only: to build up buildinf.h
+CPPFLAGS_Q={- $cppflags1 =~ s|([\\"])|\\$1|g;
+              $cppflags2 =~ s|([\\"])|\\$1|g;
+              $lib_cppflags =~ s|([\\"])|\\$1|g;
+              join(' ', $lib_cppflags || (), $cppflags2 || (),
+                        $cppflags1 || ()) -}
+
 PERLASM_SCHEME= {- $target{perlasm_scheme} -}
 
 # For x86 assembler: Set PROCESSOR to 386 if you want to support
@@ -276,6 +353,11 @@ build_apps build_tests: build_programs
 # Convenience target to prebuild all generated files, not just the mandatory
 # ones
 build_all_generated: $(GENERATED_MANDATORY) $(GENERATED)
+       @ : {- output_off() if $disabled{makedepend}; "" -}
+       @echo "Warning: consider configuring with no-makedepend, because if"
+       @echo "         target system doesn't have $(PERL),"
+       @echo "         then make will fail..."
+       @ : {- output_on() if $disabled{makedepend}; "" -}
 
 test: tests
 {- dependmagic('tests'); -}: build_programs_nodep build_engines_nodep link-utils
@@ -308,9 +390,13 @@ uninstall: uninstall_docs uninstall_sw
 
 libclean:
        @set -e; for s in $(SHLIB_INFO); do \
+               if [ "$$s" = ";" ]; then continue; fi; \
                s1=`echo "$$s" | cut -f1 -d";"`; \
                s2=`echo "$$s" | cut -f2 -d";"`; \
-               $(ECHO) $(RM) $$s1; \
+               $(ECHO) $(RM) $$s1; {- output_off() unless windowsdll(); "" -}\
+               $(RM) apps/$$s1; \
+               $(RM) test/$$s1; \
+               $(RM) fuzz/$$s1; {- output_on() unless windowsdll(); "" -}\
                $(RM) $$s1; \
                if [ "$$s1" != "$$s2" ]; then \
                        $(ECHO) $(RM) $$s2; \
@@ -322,7 +408,7 @@ libclean:
 
 clean: libclean
        $(RM) $(PROGRAMS) $(TESTPROGS) $(ENGINES) $(SCRIPTS)
-       $(RM) $(GENERATED)
+       $(RM) $(GENERATED_MANDATORY) $(GENERATED)
        -$(RM) `find . -name '*{- $depext -}' -a \! -path "./.git/*"`
        -$(RM) `find . -name '*{- $objext -}' -a \! -path "./.git/*"`
        $(RM) core
@@ -340,19 +426,9 @@ distclean: clean
 # concatenate only if that is true.
 depend:
        @: {- output_off() if $disabled{makedepend}; "" -}
-       @if egrep "^# DO NOT DELETE THIS LINE" Makefile >/dev/null && [ -z "`find $(DEPS) -newer Makefile 2>/dev/null; exit 0`" ]; then :; else \
-         ( $(PERL) -pe 'exit 0 if /^# DO NOT DELETE THIS LINE.*/' < Makefile; \
-           echo '# DO NOT DELETE THIS LINE -- make depend depends on it.'; \
-           echo; \
-           for f in $(DEPS); do \
-             if [ -f $$f ]; then cat $$f; fi; \
-           done ) > Makefile.new; \
-         if cmp Makefile.new Makefile >/dev/null 2>&1; then \
-           rm -f Makefile.new; \
-         else \
-           mv -f Makefile.new Makefile; \
-         fi; \
-       fi
+       @$(PERL) $(SRCDIR)/util/add-depends.pl {-
+                defined $makedepprog  && $makedepprog =~ /\/makedepend/
+                 ? 'makedepend' : 'gcc' -}
        @: {- output_on() if $disabled{makedepend}; "" -}
 
 # Install helper targets #############################################
@@ -651,13 +727,18 @@ generate_crypto_bn:
        ( cd $(SRCDIR); $(PERL) crypto/bn/bn_prime.pl > crypto/bn/bn_prime.h )
 
 generate_crypto_objects:
+       ( cd $(SRCDIR); $(PERL) crypto/objects/objects.pl -n \
+                               crypto/objects/objects.txt \
+                               crypto/objects/obj_mac.num \
+                               > crypto/objects/obj_mac.new && \
+           mv crypto/objects/obj_mac.new crypto/objects/obj_mac.num )
        ( cd $(SRCDIR); $(PERL) crypto/objects/objects.pl \
                                crypto/objects/objects.txt \
                                crypto/objects/obj_mac.num \
-                               include/openssl/obj_mac.h )
+                               include/openssl/obj_mac.h )
        ( cd $(SRCDIR); $(PERL) crypto/objects/obj_dat.pl \
                                include/openssl/obj_mac.h \
-                               crypto/objects/obj_dat.h )
+                               crypto/objects/obj_dat.h )
        ( cd $(SRCDIR); $(PERL) crypto/objects/objxref.pl \
                                crypto/objects/obj_mac.num \
                                crypto/objects/obj_xref.txt \
@@ -707,7 +788,7 @@ tags TAGS: FORCE
 
 # If your tar command doesn't support --owner and --group, make sure to
 # use one that does, for example GNU tar
-TAR_COMMAND=$(TAR) $(TARFLAGS) --owner 0 --group 0 -cvf -
+TAR_COMMAND=$(TAR) $(TARFLAGS) --owner 0 --group 0 -cf -
 PREPARE_CMD=:
 tar:
        set -e; \
@@ -716,7 +797,7 @@ tar:
        mkdir -p $$TMPDIR/$$DISTDIR; \
        (cd $(SRCDIR); \
         excl_re=`git submodule status | sed -e 's/^.//' | cut -d' ' -f2`; \
-        excl_re="^(fuzz/corpora|`echo $$excl_re | sed -e 's/ /$$|/g'`\$$)"; \
+        excl_re="^(fuzz/corpora|Configurations/.*\.norelease\.conf|`echo $$excl_re | sed -e 's/ /$$|/g'`\$$)"; \
         echo "$$excl_re"; \
         git ls-tree -r --name-only --full-tree HEAD \
         | egrep -v "$$excl_re" \
@@ -767,7 +848,7 @@ libcrypto.pc:
            echo 'Description: OpenSSL cryptography library'; \
            echo 'Version: '$(VERSION); \
            echo 'Libs: -L$${libdir} -lcrypto'; \
-           echo 'Libs.private: $(EX_LIBS)'; \
+           echo 'Libs.private: $(LIB_EX_LIBS)'; \
            echo 'Cflags: -I$${includedir}' ) > libcrypto.pc
 
 libssl.pc:
@@ -872,20 +953,6 @@ EOF
               bin => '$(BIN_CFLAGS) $(BIN_CPPFLAGS)'
           } -> {$args{intent}};
           if (defined($generator)) {
-              # If the target is named foo.S in build.info, we want to
-              # end up generating foo.s in two steps.
-              if ($args{src} =~ /\.S$/) {
-                   (my $target = $args{src}) =~ s|\.S$|.s|;
-                   return <<"EOF";
-$target: $args{generator}->[0] $deps
-       ( trap "rm -f \$@.*" INT 0; \\
-         $generator \$@.S; \\
-         \$(CPP) $incs $cppflags \$@.S | \\
-         \$(PERL) -ne '/^#(line)?\\s*[0-9]+/ or print' > \$@.i && \\
-         mv -f \$@.i \$@ )
-EOF
-              }
-              # Otherwise....
               return <<"EOF";
 $args{src}: $args{generator}->[0] $deps
        $generator \$@
@@ -893,7 +960,7 @@ EOF
           }
           return <<"EOF";
 $args{src}: $args{generator}->[0] $deps
-       \$(CPP) $incs $cppflags $args{generator}->[0] | \\
+       \$(CC) $incs $cppflags -E $args{generator}->[0] | \\
        \$(PERL) -ne '/^#(line)?\\s*[0-9]+/ or print' > \$@
 EOF
       }
@@ -905,24 +972,17 @@ EOF
   sub src2obj {
       my %args = @_;
       (my $obj = $args{obj}) =~ s|\.o$||;
-      my @srcs = map { if ($unified_info{generate}->{$_}) {
-                           (my $x = $_) =~ s/\.S$/.s/; $x
-                       } else {
-                           $_
-                       }
-                     } ( @{$args{srcs}} );
+      my @srcs = @{$args{srcs}};
       my $srcs = join(" ",  @srcs);
       my $deps = join(" ", @srcs, @{$args{deps}});
       my $incs = join("", map { " -I".$_ } @{$args{incs}});
       my $cmd;
       my $cmdflags;
       my $cmdcompile;
-      my $makedepprog = $disabled{makedepend} ? undef : $config{makedepprog};
       if (grep /\.rc$/, @srcs) {
           $cmd = '$(RC)';
           $cmdflags = '$(RCFLAGS)';
           $cmdcompile = '';
-          $makedepprog = undef;
       } elsif (grep /\.(cc|cpp)$/, @srcs) {
           $cmd = '$(CXX)';
           $cmdcompile = ' -c';
@@ -940,12 +1000,27 @@ EOF
               bin => '$(BIN_CFLAGS) $(BIN_CPPFLAGS)'
           } -> {$args{intent}};
       }
-      $cmdflags .= $cmdcompile;
-      my $recipe = <<"EOF";
+      my $recipe;
+      # extension-specific rules
+      if (grep /\.s$/, @srcs) {
+          $recipe .= <<"EOF";
+$obj$objext: $deps
+       $cmd $cmdflags -c -o \$\@ $srcs
+EOF
+      } elsif (grep /\.S$/, @srcs) {
+          # Originally there was mutli-step rule with $(CC) -E file.S
+          # followed by $(CC) -c file.s. It compensated for one of
+          # legacy platform compiler's inability to handle .S files.
+          # The platform is long discontinued by vendor so there is
+          # hardly a point to drag it along...
+          $recipe .= <<"EOF";
 $obj$objext: $deps
+       $cmd $incs $cmdflags -c -o \$\@ $srcs
 EOF
-      if (defined $makedepprog && $makedepprog !~ /\/makedepend/) {
+      } elsif (defined $makedepprog && $makedepprog !~ /\/makedepend/
+               && !grep /\.rc$/, @srcs) {
           $recipe .= <<"EOF";
+$obj$objext: $deps
        $cmd $incs $cmdflags -MMD -MF $obj$depext.tmp -MT \$\@ -c -o \$\@ $srcs
        \@touch $obj$depext.tmp
        \@if cmp $obj$depext.tmp $obj$depext > /dev/null 2> /dev/null; then \\
@@ -956,18 +1031,13 @@ EOF
 EOF
       } else {
           $recipe .= <<"EOF";
-       $cmd $incs $cmdflags -o \$\@ $srcs
+$obj$objext: $deps
+       $cmd $incs $cmdflags $cmdcompile -o \$\@ $srcs
 EOF
           if (defined $makedepprog  && $makedepprog =~ /\/makedepend/) {
               $recipe .= <<"EOF";
-       -\$(MAKEDEPEND) -f- -o"|\$\@" -- $incs $cmdflags -- $srcs \\
-           >$obj$depext.tmp 2>/dev/null
-       -\$(PERL) -i -pe 's/^.*\\|//; s/ \\/(\\\\.|[^ ])*//; \$\$_ = undef if (/: *\$\$/ || /^(#.*| *)\$\$/); \$\$_.="\\n" unless !defined(\$\$_) or /\\R\$\$/g;' $obj$depext.tmp
-       \@if cmp $obj$depext.tmp $obj$depext > /dev/null 2> /dev/null; then \\
-               rm -f $obj$depext.tmp; \\
-       else \\
-               mv $obj$depext.tmp $obj$depext; \\
-       fi
+       \$(MAKEDEPEND) -f- -Y -- $incs $cmdflags -- $srcs 2>/dev/null \\
+           > $obj$depext
 EOF
           }
       }
@@ -992,10 +1062,10 @@ EOF
       my $linklibs = join("", map { my $f = basename($_);
                                     (my $l = $f) =~ s/^lib//;
                                     " -l$l" } @{$args{deps}});
-      my @objs = map { (my $x = $_) =~ s|\.o$|$objext|; $x }
-                 grep { $_ =~ m|\.o$| }
+      my @objs = map { (my $x = $_) =~ s|\.o$||; "$x$objext" }
+                 grep { $_ !~ m/\.(?:def|map)$/ }
                  @{$args{objs}};
-      my @defs = grep { $_ =~ /\.(def|map)$/ } @{$args{objs}};
+      my @defs = grep { $_ =~ /\.(?:def|map)$/ } @{$args{objs}};
       my @deps = compute_lib_depends(@{$args{deps}});
       die "More than one exported symbol map" if scalar @defs > 1;
       my $objs = join(" ", @objs);
@@ -1020,7 +1090,7 @@ EOF
 $target: $deps
        \$(CC) \$(LIB_CFLAGS) $linkflags\$(LIB_LDFLAGS)$shared_soname$shared_imp \\
                -o $target_full$shared_def $objs \\
-                \$(PLIB_LDFLAGS) $linklibs \$(EX_LIBS)
+                $linklibs \$(LIB_EX_LIBS)
 EOF
       if (windowsdll()) {
           $recipe .= <<"EOF";
@@ -1054,7 +1124,9 @@ EOF
       my $linklibs = join("", map { my $f = basename($_);
                                     (my $l = $f) =~ s/^lib//;
                                     " -l$l" } @{$args{deps}});
-      my @objs = map { (my $x = $_) =~ s|\.o$|$objext|; $x } @{$args{objs}};
+      my @objs = map { (my $x = $_) =~ s|\.o$||; "$x$objext" }
+                 grep { $_ !~ m/\.(?:def|map)$/ }
+                 @{$args{objs}};
       my @deps = compute_lib_depends(@{$args{deps}});
       my $objs = join(" ", @objs);
       my $deps = join(" ", @deps);
@@ -1063,7 +1135,7 @@ EOF
 $target: $objs $deps
        \$(CC) \$(DSO_CFLAGS) $linkflags\$(DSO_LDFLAGS) \\
                -o $target $objs \\
-                \$(PLIB_LDFLAGS) $linklibs \$(EX_LIBS)
+                $linklibs \$(DSO_EX_LIBS)
 EOF
   }
   sub obj2lib {
@@ -1082,7 +1154,7 @@ EOF
       my $bin = $args{bin};
       my $bind = dirname($bin);
       my $binn = basename($bin);
-      my $objs = join(" ", map { (my $x = $_) =~ s|\.o$|$objext|; $x }
+      my $objs = join(" ", map { (my $x = $_) =~ s|\.o$||; "$x$objext" }
                            @{$args{objs}});
       my $deps = join(" ",compute_lib_depends(@{$args{deps}}));
       my @linkdirs = ();
@@ -1111,7 +1183,7 @@ $bin$exeext: $objs $deps
        rm -f $bin$exeext
        \$\${LDCMD:-$cmd} $cmdflags $linkflags\$(BIN_LDFLAGS) \\
                -o $bin$exeext $objs \\
-               \$(PLIB_LDFLAGS) $linklibs \$(EX_LIBS)
+               $linklibs \$(BIN_EX_LIBS)
 EOF
   }
   sub in2script {