Recently it was pointed out that we don't link /usr/lib/libperl.so.* to
libm the way is expected for code that also links to libperl.  That led
me to go digging again into the customization we have around the perl
build and getting terribly confused.  That did somewhat clear up after
reading more about bsd.*.mk, but still feel like some of this mess was
to make the vax work, but I couldn't actually figure it out from the cvs
logs why it exists.

In any case, this patch does a few things, some of which I can split up
and put in separately if it comes to that.

* Puts back some of the upstream Makefile.SH that we removed
  * and a little Dynaloader too

* Changes Configure flags to -de instead of -dsE
  * So Configure does the work previously handled by depend.done

* Adjusts the installperl script to put libperl where we want it

* Moves some build flag discovery into hint/openbsd.sh
  (Which I can then push upstream)
  * Figuring out the correct PICFLAG, which means perl will now use the
    same one, not -fpic for things built by Makefile.bsdwapper on archs
    that want it and -fPIC for everything else.
  * Using no-tree-ter on alpha, due to a compiler bug.

* Lets the perl infrastructure build libperl again
  * Notably, this stops creating libperl.a, but I have a patch
    around that puts it back, just not sure if we need it.
  * Which means "we" don't actually build anything anymore, we leave all
    that to the perl upstream Makefile so all the "stuff" to do with
    that can go away.
  * Which means ldd now mentions libm as it should

* Some tidying of the rest of Makefile.bsd-wrapper*

It seems to build fine on my
  alpha, amd64, arm64, armv7, i386, macppc, octeon, and sparc64.


The individual changes are committed, in a clean-up-build branch, to the
GitHub repo where I keep track of them, along with build logs from my
test machines both with and without this patch:
https://github.com/afresh1/OpenBSD-perl/tree/clean-up-build


Does anyone know if we need any this and if so, why?
(especially libperl.a)

Is what I did in the hints file a reasonable way to find the PICFLAG?
This script should only ever run on OpenBSD, so should I just assume
bsd.own.mk exists?

There is probably further cleanup that can be done.

Thanks for your feedback.



Index: distrib/sets/lists/comp/mi
===================================================================
RCS file: /cvs/src/distrib/sets/lists/comp/mi,v
retrieving revision 1.1495
diff -u -p -r1.1495 mi
--- distrib/sets/lists/comp/mi  2 Mar 2020 20:59:38 -0000       1.1495
+++ distrib/sets/lists/comp/mi  9 Apr 2020 02:29:59 -0000
@@ -1531,7 +1531,6 @@
 ./usr/lib/libpanelw_p.a
 ./usr/lib/libpcap.a
 ./usr/lib/libpcap_p.a
-./usr/lib/libperl.a
 ./usr/lib/libpthread.a
 ./usr/lib/libpthread_p.a
 ./usr/lib/libradius.a
Index: gnu/usr.bin/perl/installperl
===================================================================
RCS file: /cvs/src/gnu/usr.bin/perl/installperl,v
retrieving revision 1.49
diff -u -p -r1.49 installperl
--- gnu/usr.bin/perl/installperl        30 Dec 2019 02:15:16 -0000      1.49
+++ gnu/usr.bin/perl/installperl        9 Apr 2020 02:30:06 -0000
@@ -383,7 +383,7 @@ elsif ($Is_Cygwin) { # On Cygwin symlink
     # [als] hard-coded 'libperl' name... not good!
     #@corefiles = <*.h libperl*.* perl*$Config{lib_ext}>;
     @corefiles = <*.h *.inc perl*$Config{lib_ext}>;
-    push(@corefiles,<libperl*.*>) unless defined($ENV{"NOLIBINSTALL"});
+    install($libperl, "$opts{destdir}$Config{glibpth}/$libperl", "0444");
 
     # AIX needs perl.exp installed as well.
     push(@corefiles,'perl.exp') if $^O eq 'aix';
Index: gnu/usr.bin/perl/hints/openbsd.sh
===================================================================
RCS file: /cvs/src/gnu/usr.bin/perl/hints/openbsd.sh,v
retrieving revision 1.71
diff -u -p -r1.71 openbsd.sh
--- gnu/usr.bin/perl/hints/openbsd.sh   30 Dec 2019 02:15:18 -0000      1.71
+++ gnu/usr.bin/perl/hints/openbsd.sh   9 Apr 2020 02:30:37 -0000
@@ -47,7 +47,11 @@ alpha-2.[0-8]|mips-2.[0-8]|powerpc-2.[0-
        test -z "$usedl" && usedl=$define
        # We use -fPIC here because -fpic is *NOT* enough for some of the
        # extensions like Tk on some OpenBSD platforms (ie: sparc)
-       cccdlflags="-DPIC -fPIC $cccdlflags"
+       PICFLAG=-fPIC
+       if [ -e /usr/share/mk/bsd.own.mk ]; then
+               PICFLAG=`make -f /usr/share/mk/bsd.own.mk -V PICFLAG`
+       fi
+       cccdlflags="-DPIC ${PICFLAG} $cccdlflags"
        case "$osvers" in
        [01].*|2.[0-7]|2.[0-7].*)
                lddlflags="-Bshareable $lddlflags"
@@ -58,7 +62,7 @@ alpha-2.[0-8]|mips-2.[0-8]|powerpc-2.[0-
                ;;
        *) # from 3.1 onwards
                ld=${cc:-cc}
-               lddlflags="-shared -fPIC $lddlflags"
+               lddlflags="-shared ${PICFLAG} $lddlflags"
                libswanted=`echo $libswanted | sed 's/ dl / /'`
                ;;
        esac
@@ -84,6 +88,7 @@ esac
 # around for old NetBSD binaries.
 libswanted=`echo $libswanted | sed 's/ crypt / /'`
 
+# OpenBSD hasn't ever needed linking to libutil
 libswanted=`echo $libswanted | sed 's/ util / /'`
 
 # Configure can't figure this out non-interactively
@@ -101,6 +106,18 @@ m88k-3.4)
 *)
    test "$optimize" || optimize='-O2'
    ;;
+esac
+
+#
+# Unaligned access on alpha with -ftree-ter
+# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59679
+# More details
+# https://rt.perl.org/Public/Bug/Display.html?id=120888
+#
+case "${ARCH}-${osvers}" in
+    alpha-*)
+    ccflags="-fno-tree-ter $ccflags"
+    ;;
 esac
 
 # Special per-arch specific ccflags
Index: gnu/usr.bin/perl/Makefile.bsd-wrapper
===================================================================
RCS file: /cvs/src/gnu/usr.bin/perl/Makefile.bsd-wrapper,v
retrieving revision 1.109
diff -u -p -r1.109 Makefile.bsd-wrapper
--- gnu/usr.bin/perl/Makefile.bsd-wrapper       4 Jul 2017 13:10:13 -0000       
1.109
+++ gnu/usr.bin/perl/Makefile.bsd-wrapper       9 Apr 2020 02:30:01 -0000
@@ -3,8 +3,7 @@
 # Build wrapper for Perl
 #
 
-
-CONFIGURE_ARGS= -dsE -Dopenbsd_distribution=defined 
-Dccflags='-DNO_LOCALE_NUMERIC -DNO_LOCALE_COLLATE'
+CONFIGURE_ARGS=        -de -Dopenbsd_distribution=defined
 
 .if !exists(${.OBJDIR}/config.over)
 CONFIGURE_ARGS+= -Dmksymlinks
@@ -12,51 +11,21 @@ CONFIGURE_ARGS+= -Dmksymlinks
 
 .MAIN: all
 
-# Arguments passed to Configure...
-
-CPPFLAGS+= -DPERL_CORE -DNO_LOCALE_NUMERIC -DNO_LOCALE_COLLATE -DBIG_TIME -I.
-
-GEN_AFTER=     bitcount.h config.h mg_data.h uudmap.h cflags makedepend \
-               myconfig Makefile Policy.sh pod/Makefile
-
-GENERATED=     config.sh ${GEN_AFTER}
-
-${GEN_AFTER}: config.sh
-
-CLEANFILES=    config.sh Policy.sh DynaLoader.c
-
-# nothing!
-depend:
-       @:
-
-depend.done: ${GENERATED}
-       cd ${.OBJDIR} && exec ${MAKE} depend
-       touch $@
+CLEANFILES=    config.sh
 
 config.sh:     ${.CURDIR}/config.over
        cd ${.OBJDIR} && PATH="/bin:/usr/bin:/sbin:/usr/sbin" \
            exec /bin/sh ${.CURDIR}/Configure ${CONFIGURE_ARGS}
 
-Makefile cflags makedepend makedir myconfig Policy.sh config.h:
-       cd ${.OBJDIR} && exec /bin/sh ${@:S/./_/}.SH
-
-pod/Makefile:
-       cd ${.OBJDIR}/pod && exec /bin/sh Makefile.SH
-
-uudmap.h: bitcount.h
-mg_data.h: bitcount.h
-
-bitcount.h: generate_uudmap
-       ./generate_uudmap uudmap.h bitcount.h mg_data.h
-
-generate_uudmap: generate_uudmap.o
-       ${CC} ${CPPFLAGS} ${CFLAGS} -o generate_uudmap generate_uudmap.o
+# nothing!
+depend:
+       @:
 
 test:
-       -@if [ -e Makefile ]; then ${MAKE} test; fi
+       -@test -e Makefile && ${MAKE} test
 
 clean:
-       -@if [ -e Makefile ]; then ${MAKE} realclean; fi
+       -@test -e Makefile && ${MAKE} realclean
 
 cleandir:
        -@if [ ${.CURDIR} != ${.OBJDIR} ]; then \
@@ -65,10 +34,10 @@ cleandir:
            test -e Makefile && ${MAKE} distclean; \
            rm -f ${CLEANFILES}; \
        fi
-       @cd ${.CURDIR} && ${MAKE} -f Makefile.bsd-wrapper1 cleandir
+       cd ${.CURDIR} && ${MAKE} -f Makefile.bsd-wrapper1 cleandir
 
-all:   depend.done
-       cd ${.CURDIR} && exec ${MAKE} -f Makefile.bsd-wrapper1 perl.build 
CPPFLAGS="${CPPFLAGS}" GENERATED="${GENERATED}"
+all:   config.sh
+       cd ${.CURDIR} && exec ${MAKE} -f Makefile.bsd-wrapper1 perl.build
        cd ${.CURDIR} && exec ${MAKE} -f Makefile.bsd-wrapper1 mansrc.build
 
 install:
Index: gnu/usr.bin/perl/Makefile.bsd-wrapper1
===================================================================
RCS file: /cvs/src/gnu/usr.bin/perl/Makefile.bsd-wrapper1,v
retrieving revision 1.38
diff -u -p -r1.38 Makefile.bsd-wrapper1
--- gnu/usr.bin/perl/Makefile.bsd-wrapper1      30 Dec 2019 02:15:16 -0000      
1.38
+++ gnu/usr.bin/perl/Makefile.bsd-wrapper1      9 Apr 2020 02:30:01 -0000
@@ -1,43 +1,9 @@
 .include <bsd.own.mk>
 
-# There is no point in building a profiled libperl that is never used.
-NOPROFILE=
-
-# Perl builds with -fno-strict-aliasing, we want libperl to do the same
-CFLAGS+= -fno-strict-aliasing
-
-H2PH=          /usr/bin/h2ph
-
-LIB=   perl
-
-SRCS1= gv.c toke.c perly.c pad.c regcomp.c dump.c util.c mg.c reentr.c \
-       mro_core.c keywords.c hv.c av.c run.c pp_hot.c sv.c pp.c scope.c 
pp_ctl.c \
-       pp_sys.c doop.c doio.c dquote.c regexec.c utf8.c taint.c deb.c 
universal.c \
-       globals.c perlio.c perlapi.c numeric.c mathoms.c locale.c time64.c \
-       pp_pack.c pp_sort.c caretx.c
-SRCS=  ${SRCS1} op.c perl.c
-
-# We must not try to mkdep DynaLoader.c as it requires miniperl
-OBJS+= DynaLoader.o
-
-# For generating DynaLoader.c
-.if defined(NOPIC)
-DYNALOADER=ext/DynaLoader/dl_none.xs
-.else
-DYNALOADER=ext/DynaLoader/dl_dlopen.xs
-.endif
-
 .if defined (INSTALL_STRIP) && ${INSTALL_STRIP} == "-s"
 STRIPFLAGS='-s'
 .endif
 
-perl.build:    perl.lib DynaLoader.c
-       cd ${.OBJDIR} && exec ${MAKE}
-
-# Never try to regenerate perly.c or perly.h
-perly.c perly.h: perly.y
-       -@true
-
 # If we are cross-compiling, we use the native pod2man.
 # Otherwise, we use the pod2man (and libperl) we just
 # built since we don't know what's in the tree.
@@ -842,76 +810,22 @@ stamp-mansrc.build:
 
 .PHONY: mansrc.build
 
+perl.build:
+       cd ${.OBJDIR} && exec ${MAKE}
+
 cleandir:
        rm -f ${MAN} stamp-mansrc.build
 
-.include <bsd.lib.mk>
-# These have to come after the inclusion of <bsd.lib.mk>
-
-# Need -fPIC, not -fpic on sparc
-.if ($(TARGET_MACHINE_ARCH) == sparc)
-PICFLAG=-fPIC
-.endif
-
-# Unaligned access on alpha with -ftree-ter
-# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59679
-# More details
-# https://rt.perl.org/Public/Bug/Display.html?id=120888
-.if ($(TARGET_MACHINE_ARCH) == alpha)
-CFLAGS+= -fno-tree-ter
-.endif
-
-# The DynaLoader extension is now compiled statically into libperl
-miniperl: ${GENERATED} ${SRCS1:S/.c/.o/g} opmini.o perlmini.o miniperlmain.o
-       ${CC} ${CPPFLAGS} ${CFLAGS} -o $@ ${SRCS1:S/.c/.o/g} opmini.o 
perlmini.o miniperlmain.o ${LDFLAGS} -lm -lutil
-
-opmini.c: op.c
-       rm -f opmini.c
-       cp op.c opmini.c
-
-opmini.o: opmini.c
-       ${CC} ${CPPFLAGS} ${CFLAGS} -DPERL_EXTERNAL_GLOB -c  $> -o $@
-
-perlmini.o: perlmini.c
-       ${CC} ${CPPFLAGS} ${CFLAGS} -DPERL_EXTERNAL_GLOB -DPERL_IS_MINIPERL -c 
$> -o $@
-
-lib/Config.pm: miniperl config.sh
-       cd ${.OBJDIR} && exec ${MAKE} preplibrary
-
-DynaLoader.c: miniperl ${DYNALOADER} lib/Config.pm
-       ./miniperl -Ilib -Idist/Cwd -Idist/Cwd/lib -Idist/ExtUtils-ParseXS/lib \
-           -Icpan/Getopt-Long/lib -Idist/constant/lib -Iext/re \
-           -mExtUtils::Typemaps dist/ExtUtils-ParseXS/lib/ExtUtils/xsubpp \
-           -noprototypes -typemap ../../lib/ExtUtils/typemap ${DYNALOADER} | \
-           sed -f ${.CURDIR}/DynaLoader.sed > $@; test -s $@ || rm -f $@
-
-perl.lib:      ${GENERATED} ${_LIBS}
-
-install: install.lib install.perl maninstall
+install: install.perl maninstall
        -chmod -R a+rX ${DESTDIR}/usr/libdata/perl5
 
 install.perl:
        cd ${.OBJDIR}; INSTALL=${INSTALL} INSTALL_COPY=${INSTALL_COPY} \
-        STRIPFLAGS=${STRIPFLAGS} INSTALLFLAGS=-o NOLIBINSTALL=1 \
-        LD_LIBRARY_PATH=${.OBJDIR} exec ./perl installperl --user=${LIBOWN} 
--group=${LIBGRP} --destdir=${DESTDIR} -o ${STRIPFLAGS}
+        STRIPFLAGS=${STRIPFLAGS} INSTALLFLAGS=-o \
+        LD_LIBRARY_PATH=${.OBJDIR} exec ./perl installperl \
+         --user=${LIBOWN} --group=${LIBGRP} \
+         --destdir=${DESTDIR} -o ${STRIPFLAGS}
 
-install.lib:
-       ${INSTALL} ${INSTALL_COPY} -o ${LIBOWN} -g ${LIBGRP} -m 600 lib${LIB}.a 
\
-           ${DESTDIR}${LIBDIR}
-.if (${INSTALL_COPY} != "-p")
-       ${RANLIB} -t ${DESTDIR}${LIBDIR}/lib${LIB}.a
-.endif
-       chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}.a
-.if !defined(NOPROFILE)
-       ${INSTALL} ${INSTALL_COPY} -o ${LIBOWN} -g ${LIBGRP} -m 600 \
-           lib${LIB}_p.a ${DESTDIR}${LIBDIR}
-.if (${INSTALL_COPY} != "-p")
-       ${RANLIB} -t ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
-.endif
-       chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
-.endif
-.if !defined(NOPIC) && defined(major) && defined(minor)
-       ${INSTALL} ${INSTALL_COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
-           lib${LIB}.so.${major}.${minor} ${DESTDIR}${LIBDIR}
-.endif
-.PHONY: perl.lib install.lib perl.build install.perl man.build
+.PHONY: perl.build install.perl man.build
+
+.include <bsd.man.mk>
Index: gnu/usr.bin/perl/Makefile.SH
===================================================================
RCS file: /cvs/src/gnu/usr.bin/perl/Makefile.SH,v
retrieving revision 1.50
diff -u -p -r1.50 Makefile.SH
--- gnu/usr.bin/perl/Makefile.SH        9 Apr 2020 01:32:11 -0000       1.50
+++ gnu/usr.bin/perl/Makefile.SH        9 Apr 2020 02:30:01 -0000
@@ -821,11 +821,11 @@ CCDLFLAGS         = `echo $ccdlflags|sed -e 's@
 LIBPERL_NONSHR         = libperl_nonshr$(LIB_EXT)
 MINIPERL_NONSHR                = miniperl_nonshr$(EXE_EXT)
 
-#$(LIBPERL_NONSHR): $(perllib_objs)
-#      $(RMS) $(LIBPERL_NONSHR)
-#      $(AR) rc $(LIBPERL_NONSHR) $(perllib_objs)
+$(LIBPERL_NONSHR): $(perllib_objs)
+       $(RMS) $(LIBPERL_NONSHR)
+       $(AR) rc $(LIBPERL_NONSHR) $(perllib_objs)
 
-$(MINIPERL_NONSHR): miniperlmain$(OBJ_EXT) opmini$(OBJ_EXT)  perlmini$(OBJ_EXT)
+$(MINIPERL_NONSHR): $(LIBPERL_NONSHR) miniperlmain$(OBJ_EXT) opmini$(OBJ_EXT)  
perlmini$(OBJ_EXT)
        $(CC) $(LDFLAGS) -o $(MINIPERL_NONSHR) miniperlmain$(OBJ_EXT) \
            opmini$(OBJ_EXT) perlmini$(OBJ_EXT) $(LIBPERL_NONSHR) $(LIBS)
 
@@ -924,33 +924,33 @@ $(DTRACE_MAIN_O): perldtrace.d perlmain$
 !NO!SUBS!
                ;;
     esac
-#      $spitshell >>$Makefile <<'!NO!SUBS!'
-#$(LIBPERL): $& $(perllib_dep) $(DYNALOADER) $(LIBPERLEXPORT)
-#!NO!SUBS!
-#      case "$useshrplib" in
-#      true)
-#              $spitshell >>$Makefile <<'!NO!SUBS!'
-#      rm -f $@
-#      $(LD) -o $@ $(SHRPLDFLAGS) $(perllib_objs) $(DYNALOADER) $(libs)
-#!NO!SUBS!
-#              case "$osname" in
-#              aix)
-#                      $spitshell >>$Makefile <<'!NO!SUBS!'
-#      rm -f libperl$(OBJ_EXT)
-#      mv $@ libperl$(OBJ_EXT)
-#      $(AR) qv $(LIBPERL) libperl$(OBJ_EXT)
-#!NO!SUBS!
-#                      ;;
-#              esac
-#              ;;
-#      *)
-#              $spitshell >>$Makefile <<'!NO!SUBS!'
-#      rm -f $(LIBPERL)
-#      $(AR) rc $(LIBPERL) $(perllib_objs) $(DYNALOADER)
-#      @$(ranlib) $(LIBPERL)
-#!NO!SUBS!
-#              ;;
-#      esac
+       $spitshell >>$Makefile <<'!NO!SUBS!'
+$(LIBPERL): $& $(perllib_dep) $(DYNALOADER) $(LIBPERLEXPORT)
+!NO!SUBS!
+       case "$useshrplib" in
+       true)
+               $spitshell >>$Makefile <<'!NO!SUBS!'
+       rm -f $@
+       $(LD) -o $@ $(SHRPLDFLAGS) $(perllib_objs) $(DYNALOADER) $(libs)
+!NO!SUBS!
+               case "$osname" in
+               aix)
+                       $spitshell >>$Makefile <<'!NO!SUBS!'
+       rm -f libperl$(OBJ_EXT)
+       mv $@ libperl$(OBJ_EXT)
+       $(AR) qv $(LIBPERL) libperl$(OBJ_EXT)
+!NO!SUBS!
+                       ;;
+               esac
+               ;;
+       *)
+               $spitshell >>$Makefile <<'!NO!SUBS!'
+       rm -f $(LIBPERL)
+       $(AR) rc $(LIBPERL) $(perllib_objs) $(DYNALOADER)
+       @$(ranlib) $(LIBPERL)
+!NO!SUBS!
+               ;;
+       esac
        $spitshell >>$Makefile <<'!NO!SUBS!'
 
 # How to build executables.
@@ -1016,6 +1016,10 @@ NAMESPACEFLAGS = -force_flat_namespace
                esac
                $spitshell >>$Makefile <<'!NO!SUBS!'
 lib/buildcustomize.pl: $& $(miniperl_objs) write_buildcustomize.pl
+       -@rm -f miniperl.xok
+       $(CC) $(CLDFLAGS) $(NAMESPACEFLAGS) -o $(MINIPERL_EXE) \
+           $(miniperl_objs) $(libs)
+       $(LDLIBPTH) ./miniperl$(HOST_EXE_EXT) -w -Ilib -Idist/Exporter/lib 
-MExporter -e '<?>' || sh -c 'echo >&2 Failed to build miniperl.  Please run 
make minitest; exit 1'
        $(MINIPERL) -f write_buildcustomize.pl
 !NO!SUBS!
                ;;
Index: gnu/usr.bin/perl/ext/DynaLoader/Makefile.PL
===================================================================
RCS file: /cvs/src/gnu/usr.bin/perl/ext/DynaLoader/Makefile.PL,v
retrieving revision 1.23
diff -u -p -r1.23 Makefile.PL
--- gnu/usr.bin/perl/ext/DynaLoader/Makefile.PL 30 Dec 2019 02:15:18 -0000      
1.23
+++ gnu/usr.bin/perl/ext/DynaLoader/Makefile.PL 9 Apr 2020 02:30:36 -0000
@@ -65,8 +65,8 @@ sub MY::static {
 
     return "
 $object : \$(FIRST_MAKEFILE) \$(OBJECT)
-       #\$(RM_RF) $object
-       #\$(CP) \$(OBJECT) $object
+       \$(RM_RF) $object
+       \$(CP) \$(OBJECT) $object
 
 static :: $object
 ";

Reply via email to