Harmonize Unix Makefile template with Windows dito
[openssl.git] / Configurations / unix-Makefile.tmpl
index d5a64b5be3962e20cc006e7f56e35d01c3bf8c3e..6e023b75b28ccce26949b11a6e02f8bf5c407e37 100644 (file)
@@ -79,9 +79,11 @@ ENGINES={- join(" ", map { dso($_) } @{$unified_info{engines}}) -}
 PROGRAMS={- join(" ", map { $_.$exeext } grep { !m|^test/| } @{$unified_info{programs}}) -}
 TESTPROGS={- join(" ", map { $_.$exeext } grep { m|^test/| } @{$unified_info{programs}}) -}
 SCRIPTS={- join(" ", @{$unified_info{scripts}}) -}
+{- output_off() if $disabled{makedepend}; "" -}
 DEPS={- join(" ", map { (my $x = $_) =~ s|\.o$|$depext|; $x; }
                   grep { $unified_info{sources}->{$_}->[0] =~ /\.c$/ }
                   keys %{$unified_info{sources}}); -}
+{- output_on() if $disabled{makedepend}; "" -}
 
 BIN_SCRIPTS=$(BLDDIR)/tools/c_rehash
 MISC_SCRIPTS=$(SRCDIR)/tools/c_hash $(SRCDIR)/tools/c_info \
@@ -149,23 +151,24 @@ CFLAGS_Q={- $cflags2 =~ s|([\\"])|\\$1|g; $cflags2 -} {- $config{cflags} -}
 LDFLAGS= {- $target{lflags} -}
 PLIB_LDFLAGS= {- $target{plib_lflags} -}
 EX_LIBS= {- $target{ex_libs} -} {- $config{ex_libs} -}
-SHARED_CFLAGS={- $target{shared_cflag} || "" -}
-SHARED_LDFLAGS={- $target{shared_ldflag}." ".$config{shared_ldflag}
-                  # Unlike other OSes (like Solaris, Linux, Tru64,
-                  # IRIX) BSD run-time linkers (tested OpenBSD, NetBSD
-                  # and FreeBSD) "demand" RPATH set on .so objects.
-                  # Apparently application RPATH is not global and
-                  # does not apply to .so linked with other .so.
-                  # Problem manifests itself when libssl.so fails to
-                  # load libcrypto.so. One can argue that we should
-                  # engrave this into Makefile.shared rules or into
-                  # BSD-* config lines above. Meanwhile let's try to
-                  # be cautious and pass -rpath to linker only when
-                  # $prefix is not /usr.
-                  . ($config{target} =~ m|^BSD-| && $prefix !~ m|^/usr/.*$|
-                     ? " -Wl,-rpath,\$\$(LIBRPATH)" : "") -}
-SHARED_RCFLAGS={- $target{shared_rcflag} -}
+LIB_CFLAGS={- $target{shared_cflag} || "" -}
+LIB_LDFLAGS={- $target{shared_ldflag}." ".$config{shared_ldflag}
+               # Unlike other OSes (like Solaris, Linux, Tru64,
+               # IRIX) BSD run-time linkers (tested OpenBSD, NetBSD
+               # and FreeBSD) "demand" RPATH set on .so objects.
+               # Apparently application RPATH is not global and
+               # does not apply to .so linked with other .so.
+               # Problem manifests itself when libssl.so fails to
+               # load libcrypto.so. One can argue that we should
+               # engrave this into Makefile.shared rules or into
+               # BSD-* config lines above. Meanwhile let's try to
+               # be cautious and pass -rpath to linker only when
+               # $prefix is not /usr.
+               . ($config{target} =~ m|^BSD-| && $prefix !~ m|^/usr/.*$|
+                  ? " -Wl,-rpath,\$\$(LIBRPATH)" : "") -}
+RCFLAGS={- $target{shared_rcflag} -}
 DSO_CFLAGS={- $target{shared_cflag} || "" -}
+DSO_LDFLAGS=$(LIB_LDFLAGS)
 BIN_CFLAGS={- "" -}
 
 PERL={- $config{perl} -}
@@ -178,7 +181,7 @@ RM= rm -f
 RMDIR= rmdir
 TAR= {- $target{tar} || "tar" -}
 TARFLAGS= {- $target{tarflags} -}
-MAKEDEPEND=$(CROSS_COMPILE){- $config{makedepprog} -}
+MAKEDEPEND={- $config{makedepprog} -}
 
 BASENAME=       openssl
 NAME=           $(BASENAME)-$(VERSION)
@@ -259,6 +262,7 @@ clean: libclean
 # was true, 1 if false, and most importantly, 2 if it doesn't
 # recognise the operator.
 depend:
+       @: {- output_off() if $disabled{makedepend}; "" -}
        @catdepends=false; \
        if [ Makefile -nt Makefile ] 2>/dev/null || [ $$? = 1 ]; then \
          for d in $(DEPS); do \
@@ -283,6 +287,7 @@ depend:
            rm -f Makefile.new; \
          fi; \
        fi
+       @: {- output_on() if $disabled{makedepend}; "" -}
 
 # Install helper targets #############################################
 
@@ -821,6 +826,7 @@ configdata.pm: {- $config{build_file_template} -} $(SRCDIR)/Configurations/commo
   sub generatesrc {
       my %args = @_;
       my $generator = join(" ", @{$args{generator}});
+      my $incs = join("", map { " -I".$_ } @{$args{incs}});
 
       if ($args{src} !~ /\.[sS]$/) {
           return <<"EOF";
@@ -845,9 +851,9 @@ EOF
                    (my $target = $args{src}) =~ s|\.S$|.s|;
                    return <<"EOF";
 $target: $args{generator}->[0]
-       ( trap "rm -f \$@.S" INT; \\
+       ( trap "rm -f \$@.*" INT 0; \\
          $generator \$@.S; \\
-         \$(CC) \$(CFLAGS) -E -P \$@.S > \$@ && rm -f \$@.S )
+         \$(CC) \$(CFLAGS) $incs -E -P \$@.S > \$@.i && mv -f \$@.i \$@ )
 EOF
               }
               # Otherwise....
@@ -858,11 +864,14 @@ EOF
           }
           return <<"EOF";
 $args{src}: $args{generator}->[0]
-       \$(CC) \$(CFLAGS) -E -P \$< > \$@
+       \$(CC) \$(CFLAGS) $incs -E -P \$< > \$@
 EOF
       }
   }
 
+  # Should one wonder about the end of the Perl snippet, it's because this
+  # second regexp eats up line endings as well, if the removed path is the
+  # last in the line.  We may therefore need to put back a line ending.
   sub src2obj {
       my %args = @_;
       my $obj = $args{obj};
@@ -870,30 +879,47 @@ EOF
       my $srcs = join(" ",  @srcs);
       my $deps = join(" ", @srcs, @{$args{deps}});
       my $incs = join("", map { " -I".$_ } @{$args{incs}});
-      my $ecflags = { lib => '$(SHARED_CFLAGS)',
+      my $ecflags = { lib => '$(LIB_CFLAGS)',
                       dso => '$(DSO_CFLAGS)',
                       bin => '$(BIN_CFLAGS)' } -> {$args{intent}};
       my $makedepprog = $config{makedepprog};
-      if ($makedepprog eq "makedepend") {
-          return <<"EOF";
+      my $recipe = "";
+      if (!$disabled{makedepend} && $makedepprog =~ /\/makedepend/) {
+          $recipe .= <<"EOF";
 $obj$depext: $deps
        rm -f \$\@.tmp; touch \$\@.tmp
-       -\$(MAKEDEPEND) -f\$\@.tmp -o"|$obj" -- \$(CFLAGS) $ecflags$incs -- $srcs \\
+       -\$(MAKEDEPEND) -f\$\@.tmp -o"|$obj$objext" -- \$(CFLAGS) $ecflags$incs -- $srcs \\
            2>/dev/null
-       sed -e 's/^.*|//' -e 's/ \\/\\(\\\\.\\|[^ ]\\)*//g' -e '/: *\$\$/d' -e '/^\\(#.*\\| *\\)\$\$/d' \$\@.tmp > \$\@
-       rm \$\@.tmp
-$obj$objext: $obj$depext
+       perl -i -pe 's/^.*\\|//; s/ \\/(\\\\.|[^ ])*//;               #\\
+                    \$\$_ = undef if (/: *\$\$/ || /^(#.*| *)\$\$/); #\\
+                    \$\$_.="\\n" unless !defined(\$\$_) or /\\R\$\$/g;' \$\@.tmp
+       \@if ! cmp \$\@.tmp \$\@ > /dev/null 2> /dev/null; then \\
+               mv \$\@.tmp \$\@; \\
+       else \\
+               rm -f \$\@.tmp; \\
+       fi
+EOF
+          $deps = $obj.$depext;
+      }
+      if ($disabled{makedepend} || $makedepprog =~ /\/makedepend/) {
+          $recipe .= <<"EOF";
+$obj$objext: $deps
        \$(CC) \$(CFLAGS) $ecflags$incs -c -o \$\@ $srcs
 EOF
       }
-      return <<"EOF";
+      if (!$disabled{makedepend} && $makedepprog !~ /\/makedepend/) {
+          $recipe .= <<"EOF";
 $obj$objext: $deps
        \$(CC) \$(CFLAGS) $ecflags$incs -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 \\
                mv $obj$depext.tmp $obj$depext; \\
+       else \\
+               rm -f $obj$depext.tmp; \\
        fi
 EOF
+      }
+      return $recipe;
   }
   # On Unix, we build shlibs from static libs, so we're ignoring the
   # object file array.  We *know* this routine is only called when we've
@@ -929,10 +955,10 @@ $target: $lib$libext $deps $ordinalsfile
                LIBDEPS="\$(PLIB_LDFLAGS) $linklibs \$(EX_LIBS)" \\
                LIBNAME=$libname LIBVERSION=\$(SHLIB_MAJOR).\$(SHLIB_MINOR) \\
                LIBCOMPATVERSIONS=";\$(SHLIB_VERSION_HISTORY)" \\
-               CC="\$(CC)" CFLAGS="\$(CFLAGS)" LDFLAGS="\$(LDFLAGS)" \\
-               CROSS_COMPILE="\$(CROSS_COMPILE)" \\
-               SHARED_LDFLAGS="\$(SHARED_LDFLAGS)" SHLIB_EXT=$shlibext \\
-               SHARED_RCFLAGS="\$(SHARED_RCFLAGS)" \\
+               CC="\$(CC)" CFLAGS="\$(CFLAGS) \$(LIB_CFLAGS)" \\
+               CROSS_COMPILE="\$(CROSS_COMPILE)" LDFLAGS="\$(LDFLAGS)" \\
+               SHARED_LDFLAGS="\$(LIB_LDFLAGS)" SHLIB_EXT=$shlibext \\
+               SHARED_RCFLAGS="\$(RCFLAGS)" \\
                link_shlib.$shlib_target
 EOF
          . (windowsdll() ? <<"EOF" : "");
@@ -963,8 +989,8 @@ $target: $objs $deps
                PERL=\$(PERL) SRCDIR="\$(SRCDIR)" DSTDIR="$libd" \\
                LIBDEPS="\$(PLIB_LDFLAGS) $shlibdeps \$(EX_LIBS)" \\
                LIBNAME=$libname LDFLAGS="\$(LDFLAGS)" \\
-               CC="\$(CC)" CFLAGS="\$(CFLAGS)" \\
-               SHARED_LDFLAGS="\$(SHARED_LDFLAGS)" \\
+               CC="\$(CC)" CFLAGS="\$(CFLAGS) \$(DSO_CFLAGS)" \\
+               SHARED_LDFLAGS="\$(DSO_LDFLAGS)" \\
                SHLIB_EXT=$dsoext \\
                LIBEXTRAS="$objs" \\
                link_dso.$shlib_target
@@ -1000,8 +1026,8 @@ $bin$exeext: $objs $deps
                PERL=\$(PERL) SRCDIR=\$(SRCDIR) \\
                APPNAME=$bin$exeext OBJECTS="$objs" \\
                LIBDEPS="\$(PLIB_LDFLAGS) $linklibs \$(EX_LIBS)" \\
-               CC="\$(CC)" CFLAGS="\$(CFLAGS)" LDFLAGS="\$(LDFLAGS)" \\
-               LIBRPATH="\$(INSTALLTOP)/\$(LIBDIR)" \\
+               CC="\$(CC)" CFLAGS="\$(CFLAGS) \$(BIN_CFLAGS)" \\
+               LDFLAGS="\$(LDFLAGS)" LIBRPATH="\$(INSTALLTOP)/\$(LIBDIR)" \\
                link_app.$shlib_target
 EOF
   }