#!/bin/sh
# --- Copyright University of Sussex 1996. All rights reserved. ----------
# File:             C.unix/com/mkXpm
# Purpose:			Build the Xpm library
# Author:           Julian Clinton (from $popcom/mkXpw) (see revisions)
# Documentation:
# Related Files:

# Usage: mkXpm [ -I<directory> ... ]

XPMDIR=$usepop/pop/x/Xpm
XPMLIB=libXpm.a

cd $XPMDIR

# Get Poplog configuration
CONFIG=`$popsys/basepop11 %noinit << \EEOOFF
	printf('%p%p%p.%p.%p\n', [%
		if lmember("elf", sys_os_type) then
			'elf_'
		else
			nullstring
		endif;
		sys_os_type(2),						;;; e.g. "sunos"
		if length(sys_os_type) > 2
		and isnumber(sys_os_type(3))
		then
			intof(sys_os_type(3))			;;; e.g. 5
		else
			nullstring
		endif,
		if isdefined("XLINK_TYPE") then
			valof("XLINK_TYPE")				;;; e.g. "openlook"
		else
			undef
		endif,
		sys_processor_type(1),				;;; e.g. "sparc"
	%]);
EEOOFF
`

# Where to find X include files
IDIRS=-I.
while [ $# -ne 0 ]; do
	case $1 in
		-I*) IDIRS="$IDIRS $1";;
	esac
	shift
done
IDIRS="$IDIRS -I$POP_X_INCLUDE"

# Compiler flags
CFLAGS="-O -DZPIPE"
case $CONFIG in
	sunos4*)
		;;
	sunos*)
		# SunOS 5+
		CFLAGS="-DSVR4 -Kpic $CFLAGS";;
	ncr*)
		# NCR SVR4
		CFLAGS="-DSVR4 -Kpic $CFLAGS";;
	svr4*)
		CFLAGS="-DSYSV -DSVR4_0 -Kpic $CFLAGS";;
	hpux9*)
		# PIC and no optimisation
		CFLAGS=+z;;
	riscos*)
		CFLAGS="-systype bsd43 $CFLAGS";;
	irix*)
		CFLAGS="-DSVR4 -cckr $CFLAGS";;
	linux*)
		CFLAGS="-w $CFLAGS";;
esac
case $CONFIG in
	*.mips)
		CFLAGS="-G 0 $CFLAGS";;
esac

# Archive commands
AR="ar crv $XPMLIB"
RANLIB="ranlib $XPMLIB"
LIBS=
case $CONFIG in
	sunos4*)
		;;
	sunos*|svr4*|ncr*)
		# SunOS 5+ (SVR4)
		XPMLIB=libXpm.so
		AR="/usr/ccs/bin/ld -G -o $XPMLIB"
		RANLIB=:
		;;
	irix4*)
		RANLIB=:
		;;
	irix*)
		# IRIX 5+
		XPMLIB=libXpm.so
		AR="ld -shared -o $XPMLIB"
		RANLIB=:
		;;
	hpux8*)
		RANLIB=:
		;;
	hpux*)
		# HP-UX 9+
		XPMLIB=libXpm.sl
		AR="ld -b -o $XPMLIB"
		RANLIB=:
		;;
	elf_linux*)
		XPMLIB=libXpm.so
		AR="gcc -shared -o $XPMLIB"
		RANLIB=
		;;
	osf1*)
		XPMLIB=libXpm.so
		AR="ld -shared -o $XPMLIB"
		LIBS="-lXt -lX11 -lc"
		RANLIB=:
		;;
esac

cc -c $CFLAGS $IDIRS *.c	&& \
$AR *.o $LIBS				&& \
$RANLIB						&& \
rm *.o						&& \
mv $XPMLIB $popexternlib


# --- Revision History ---------------------------------------------------
# --- Robert Duncan, Nov  5 1996 -- brought up to date with mkXpw
# --- Robert Duncan, Mar  4 1996 -- added -DSVR4 for Solaris & Irix
