# $MidnightBSD: src/usr.bin/perl/BSDmakefile,v 1.12 2011/01/10 13:51:56 laffer1 Exp $
#
# This makefile deals with binding perl's build system to our own.
# It is called BSDmakefile because perl's configure makes a 'Makefile',
# and it is not possible to change the name.
#
.include <bsd.own.mk>
.include <bsd.obj.mk>
.include <bsd.man.mk>

NOPROFILE=

SRCDIR= ${.CURDIR}/../../contrib/perl

DPADD=${LIBC}

# Perl builds with -fno-strict-aliasing, we want libperl to do the same
CFLAGS+=	-fno-strict-aliasing

#
# mksymlinks is perl's way of building away from the src dir.  It builds a bunch of symlinks
# so everthing is where Configure thinks it should be.  Hackish, but it works.
#
CONFIGURE_ARGS= -des -Dprefix=/usr -Dsiteprefix=/usr/local -Dvendorprefix=/usr \
		-Dsiteman1dir=/usr/local/man/man1 -Dsiteman3dir=/usr/local/man/man3 \
		-Dmksymlinks -Dsrc=${SRCDIR} -Duse64bitint -Duseshrplib

.if defined(TARGET_ARCH)
CONFIGURE_ARGS+=	-Dtargetarch=${TARGET_ARCH}
.endif
CONFIGURE_SCRIPT=    Configure
                
PERL_MAKEFILE= Makefile
                
all: perl
                
perl: ${PERL_MAKEFILE}
	cd ${.OBJDIR} && LD_LIBRARY_PATH=${DESTDIR}/lib ${MAKE} -f ${PERL_MAKEFILE}
	
${PERL_MAKEFILE}:
	cd ${.OBJDIR} && LD_LIBRARY_PATH=${DESTDIR}/lib ${SRCDIR}/${CONFIGURE_SCRIPT} ${CONFIGURE_ARGS}

# if OBJDIR is ., then don't delete ourselves.            
clean:
	cd ${.OBJDIR} && ls -A | grep -v 'BSDmakefile' | grep -v 'CVS' | xargs rm -r

install: install.perl install.man

TARGET_ARCH?=`/usr/bin/uname -p`

install.perl:
	cd ${.OBJDIR} && LD_LIBRARY_PATH=${.OBJDIR}:${DESTDIR}/lib ./perl installperl --destdir=${DESTDIR} 
	ln -fs ${DESTDIR}${LIBDIR}/perl5/5.10.0/${TARGET_ARCH}-midnightbsd/CORE/libperl.so ${DESTDIR}${LIBDIR}/libperl.so

#
# perl doesn't compress man pages, so we do a staged install
#
MANSECTIONS= 1 3
	
install.man: convertpods finalmaninstall

convertpods:
	@cd ${.OBJDIR} && LD_LIBRARY_PATH=${.OBJDIR}:${DESTDIR}/lib ./perl installman --destdir=${DESTDIR} --man1dir=${.OBJDIR}/rawmans/1 --man3dir=${.OBJDIR}/rawmans/3

finalmaninstall:
.for SEC in ${MANSECTIONS}
	@cd ${.OBJDIR}/rawmans/${SEC}; \
	rm -f *.gz; \
	for man in `ls`; do \
		${MCOMPRESS_CMD} $$man > $$man${MCOMPRESS_EXT}; \
		echo ${MINSTALL} $$man${MCOMPRESS_EXT} ${DESTDIR}${MANDIR}${SEC}/$$man${MCOMPRESS_EXT}; \
		${MINSTALL} $$man${MCOMPRESS_EXT} ${DESTDIR}${MANDIR}${SEC}/$$man${MCOMPRESS_EXT}; \
	done
.endfor
	
.PHONY: clean                                        
                                        
