# $NetBSD: Makefile.common,v 1.10 2022/10/31 13:30:33 micha Exp $
# used by archivers/star/Makefile
# used by archivers/tartest/Makefile
# used by devel/smake/Makefile
# used by security/mdigest/Makefile
# used by shells/bosh/Makefile
# used by shells/pbosh/Makefile
# used by sysutils/cdrtools/Makefile

# All packages based on the schilytools tarball should include this Makefile
# fragment to inherit and share the same pkgsrc platform specific code.

WRKSRC=		${WRKDIR}/schilytools

# smake ignores the "-j" option
MAKE_JOBS_SAFE=	no

# Map PKGSRC_COMPILER to CCOM used by schilytools build system.
.if !empty(PKGSRC_COMPILER:Mgcc)
MAKE_FLAGS+=	CCOM=gcc
.elif !empty(PKGSRC_COMPILER:Mclang)
MAKE_FLAGS+=	CCOM=clang
# Other compilers are currently untested, try to use them as cc
.else
MAKE_FLAGS+=	CCOM=cc
.endif

MAKE_FLAGS+=	LINKMODE=static

# OS rules
# Some rules were copied from old packages (that are now part of schilytools
# too) to not break what people have done in the past.
pre-configure:
	printf "Create OS rules...\n"
	cd ${WRKSRC}/RULES && . ${WRKSRC}/RULES/MKLINKS
	printf "Create pkgsrc OS rules...\n"
	cd ${WRKSRC}/RULES && unset r ;					\
	for i in arm mipsel mips64eb x86_64 sparc64 powerpc ;		\
	do								\
		r="$$r i386-netbsd-gcc.rul@$$i-netbsd-gcc.rul" ;	\
		r="$$r i386-netbsd-cc.rul@$$i-netbsd-cc.rul" ;		\
	done ;								\
	r="$$r i386-freebsd-gcc.rul@x86_64-freebsd-gcc.rul" ;		\
	r="$$r i386-freebsd-cc.rul@x86_64-freebsd-cc.rul" ;		\
	for i in netbsd-clang.rul netbsd-cc.rul netbsd-gcc.rul ;	\
	do								\
		r="$$r i386-$$i@${MACHINE}-$$i" ;			\
	done ;								\
									\
	for i in $$r ;							\
	do								\
		existing=`printf "%s\\n" $$i | ${SED} -e 's/@.*//'` ;	\
		target=`printf "%s\\n" $$i | ${SED} -e 's/.*@//'` ;	\
		printf "%s " "$$target";				\
		if ${TEST} -e "$$existing" ; then : ;			\
		else							\
			printf "(Link target %s not present)\n"		\
				"$$existing";				\
			continue ;					\
		fi;							\
		if ${TEST} -e "$$target" ;				\
		then							\
			printf "(already present)\n" ;			\
		else							\
			${LN} -s "$$existing" "$$target" ;		\
			printf "(created)\n" ;				\
		fi;							\
	done

# Man pages with documentation of file formats should go to section 4 on
# SysV based systems. All supported systems that are treated by schilytools
# with "MANSTYLE= sysv" in the RULES/os-${OPSYS}.def" files must be caught
# by this check (IRIX and OSF/1 are treated with BSD style by schilytools).
PLIST_VARS+=	bsd sysv
.if ${OPSYS} == "AIX" ||		\
	${OPSYS} == "HPUX" ||		\
	${OPSYS} == "Interix" ||	\
	${OPSYS} == "SCO_SV" ||		\
	${OPSYS} == "SunOS" ||		\
	${OPSYS} == "UnixWare"
PLIST.sysv=	yes
.else
PLIST.bsd=	yes
.endif

# tbl(1) of NetBSD 9 cannot be used and cripples the man pages, but man(1)
# from mandoc uses a builtin tbl that is good enough.
# This check should catch all supported OS that needs processed tables for
# man pages and have a tbl that can be used to do that.
.if ${OPSYS} == "AIX" ||		\
	${OPSYS} == "Cygwin" ||		\
	${OPSYS} == "Darwin" ||		\
	${OPSYS} == "DragonFly" ||	\
	${OPSYS} == "Haiku" ||		\
	${OPSYS} == "HPUX" ||		\
	${OPSYS} == "IRIX" ||		\
	${OPSYS} == "Linux" ||		\
	${OPSYS} == "Minix" ||		\
	${OPSYS} == "MirBSD" ||		\
	${OPSYS} == "OSF1" ||		\
	${OPSYS} == "QNX" ||		\
	${OPSYS} == "SunOS"
USE_TOOLS+=	tbl
.endif
