#  Makefile for wn.

# @(#)Makefile	1.28 18/2/92

SHELL = /bin/sh
RANLIB = ranlib

X11LIBS = -lX11					# Installed X11 Xlib library.
SUNVIEWLIBS = -lsuntool -lsunwindow -lpixrect	# Sunview libraries

WSNAME = X11
WSINSTNAME = x11
WSLIBS = ${X11LIBS}
WDEF = -D${WSNAME}

# Optional multi-architecture support
# Note that even if none of the variables are set we still drop
# binaries below directories named after the window system.
D = ${OBJDIR}${SLASH}${WSNAME}/
S = ${SRCDIR}${SLASH}../

#  Default target.
target: ${OBJDIR}${SLASH}${WSNAME}/libwn.a

test: $Dtestwn

#  Directories for the header files and libraries
LIBNAME = wn
LIB = /usr/local/lib
INCLUDE = /usr/include/local
SHLIB = /usr/local/lib
SCCSCHECK_DIRS =

# Flags for cc. CCFLAGS is read from the environment
DEPS_DEVELHDRS = -Idevelhdrs
DEVELHDRS = -I$Sdevelhdrs
CFLAGS = ${CCFLAGS} ${WDEF} ${DEVELHDRS} ${INCLUDEDIRS} ${ARCH_CFLAGS} ${MORE_CFLAGS}

CCLINE = cd ${OBJDIR}${SLASH}${WSNAME} && ${CC} -c ${CFLAGS} $S

SCCS = sccs

OBJS	= \
	$Dwn_color.o $Dwn_cu.o $Dwn_sc.o $Dwn_font.o $Dwn_event.o \
	$Dwn_rop.o $Dwn_xrop.o $Dwn_mrop.o $Dwn_bm.o $Dwn_misc.o  \
	$Dwn_init.o $Dwn_win.o $Dwn_sunframe.o $Dwn_framed.o \
	$Dwn_icon.o $Dwn_replay.o $Dsccsdata.o

MKSCCS_SRCS  = \
	wn_color.c     wn_cu.c       wn_sc.c      wn_font.c      wn_event.c \
	wn_rop.c      wn_xrop.c      wn_mrop.c      wn_bm.c      wn_misc.c  \
	wn_init.c      wn_win.c      wn_sunframe.c     wn_framed.c \
	wn_icon.c     wn_replay.c

SRCS = ${MKSCCS_SRCS} sccsdata.c

SUNVIEWHDRS = framed.h wn_framed.h wn_sunframe.h

HDRS = \
	${SUNVIEWHDRS} \
	sccsdata.h wn.h wn_bm.h wn_color.h wn_cu.h wn_event.h wn_icon.h \
	wn_init.h wn_misc.h wn_priv.h wn_replay.h wn_rop.h wn_sc.h \
	wn_win.h wn_xrop.h 

DOCS = doc/wn.tex doc/wn-list.tex

MKSCCS_FILES = ${HDRS} ${MKSCCS_SRCS} ${DOCS} edump.c framed.c testwn.c Makefile
FILES = ${MKSCCS_FILES} sccsdata.c

CHECKSCCS = sccsinfo ${SCCSCHECK_DIRS} ${FILES} && newer sccsdata.c ${FILES}

checksccs:
	@${CHECKSCCS}

sccssnapshot:
	@mksccs -changefile CHANGES -wh -c t_snapshot.c -h t_snapshot.h ${LIBNAME} ${MKSCCS_FILES}

sccsfile:
	@sccsinfo ${SCCSCHECK_DIRS} ${FILES}
	@checklist
	@newer CHANGES ${FILES}
	@${SCCS} edit sccsdata.c
	@mksccs -changefile CHANGES -wh ${LIBNAME} ${MKSCCS_FILES}
	@${SCCS} delget sccsdata.c

install: ${LIB}/lib${WSINSTNAME}wn.a ${INCLUDE}/wn.h

${LIB}/lib${WSINSTNAME}wn.a: $Dlibwn.a
	@${CHECKSCCS}
	install -c -m 644 -o root $? $@
	cd ${LIB} && ${RANLIB} lib${WSINSTNAME}wn.a

${INCLUDE}/wn.h: wn.h
	@${CHECKSCCS}
	@echo updating wn.h - diffs in t_hdrdiffs
	@-diff $? $@ > t_hdrdiffs
	@-/etc/chown mtr t_hdrdiffs
	install -c -m 644 -o root $? $@

${LIB}/ukcframed: $Dukcframed
	@${CHECKSCCS}
	install -c -m 755 -o bin -s $? $@
	
# X windows
testrop: $Dtestrop.o $Dlibwn.a
	rm -f testrop
	${CC} ${CFLAGS} ${LINKFLAGS} -o $@ $Dtestrop $Dlibwn.a ${WSLIBS}

$Dtestwn: $Dtestwn.o $Dlibwn.a
	rm -f $@
	${CC} ${CFLAGS} ${LINKFLAGS} -o $@ $Dtestwn.o $Dlibwn.a ${WSLIBS} ${STDLIBS}

$Dedump: $Dedump.o $Dlibwn.a
	rm -f $@
	${CC} ${CFLAGS} ${LINKFLAGS} -o $@ $Dedump.o $Dlibwn.a ${WSLIBS} ${STDLIBS}

# Use $D/. so we don't get a null target when $D is undefined.
# We say sh -c to avoid exit status problems from the || construct.
$D/.:
	sh -c 'IFS=/; for i in $D; do test -d $$i || mkdir $$i; cd $$i; done'

$Dlibwn.a: $D/. ${OBJS}
	rm -f $@
	ar cq $@ ${OBJS}
	cd ${OBJDIR}${SLASH}${WSNAME} && ${RANLIB} libwn.a

FRAMED_OBJS = $Dframed.o $Dwn_framed.o

$Dukcframed: ${FRAMED_OBJS}
	rm -f $@
	${CC} ${CFLAGS} ${LINKFLAGS} -o $@ ${FRAMED_OBJS} ${SUNVIEWSTDLIBS} ${STDLIBS}

clean:
	rm -f ${OBJS} ${FRAMED_OBJS} $Dukcframed $Dlibwn.a $Dtestwn
	-rmdir ${OBJDIR}${SLASH}${WSNAME}

tags: ${SRCS} ${HDRS}
	ctags -tw  ${SRCS} ${HDRS}
	
list:
	@echo README ${FILES} | tr ' ' '\012'

count:
	wc ${FILES}

deps: ${SRCS} framed.c testwn.c
	ddeps ${WDEF} ${DEPS_DEVELHDRS} ${SRCS} framed.c testwn.c > t_deps

# .o file dependencies (generated by make deps)
$Dwn_color.o: wn_color.c wn.h wn_priv.h wn_color.h wn_misc.h wn_cu.h 
	${CCLINE}wn_color.c
$Dwn_cu.o: wn_cu.c wn.h wn_priv.h wn_xrop.h wn_misc.h wn_bm.h wn_cu.h 
	${CCLINE}wn_cu.c
$Dwn_sc.o: wn_sc.c wn.h wn_priv.h wn_sc.h wn_misc.h 
	${CCLINE}wn_sc.c
$Dwn_font.o: wn_font.c wn.h wn_priv.h wn_misc.h wn_sc.h 
	${CCLINE}wn_font.c
$Dwn_event.o: wn_event.c wn.h wn_priv.h wn_sc.h wn_win.h wn_misc.h \
  wn_event.h wn_replay.h 
	${CCLINE}wn_event.c
$Dwn_rop.o: wn_rop.c wn.h wn_priv.h wn_sc.h wn_xrop.h wn_bm.h wn_misc.h \
  wn_rop.h 
	${CCLINE}wn_rop.c
$Dwn_xrop.o: wn_xrop.c wn.h wn_priv.h wn_misc.h wn_xrop.h 
	${CCLINE}wn_xrop.c
$Dwn_mrop.o: wn_mrop.c wn.h wn_priv.h wn_misc.h wn_bm.h wn_xrop.h 
	${CCLINE}wn_mrop.c
$Dwn_bm.o: wn_bm.c wn.h wn_priv.h wn_misc.h wn_bm.h 
	${CCLINE}wn_bm.c
$Dwn_misc.o: wn_misc.c wn.h wn_priv.h wn_misc.h 
	${CCLINE}wn_misc.c
$Dwn_init.o: wn_init.c wn.h wn_priv.h wn_bm.h wn_event.h wn_cu.h wn_rop.h \
  wn_misc.h wn_win.h wn_init.h wn_replay.h sccsdata.h 
	${CCLINE}wn_init.c
$Dwn_win.o: wn_win.c wn.h wn_priv.h wn_init.h wn_icon.h wn_event.h wn_misc.h \
  wn_win.h 
	${CCLINE}wn_win.c
$Dwn_sunframe.o: wn_sunframe.c 
	${CCLINE}wn_sunframe.c
$Dwn_framed.o: wn_framed.c 
	${CCLINE}wn_framed.c
$Dwn_icon.o: wn_icon.c wn.h wn_priv.h wn_win.h wn_misc.h wn_icon.h 
	${CCLINE}wn_icon.c
$Dwn_replay.o: wn_replay.c wn.h wn_priv.h wn_replay.h wn_init.h 
	${CCLINE}wn_replay.c
$Dsccsdata.o: sccsdata.c sccsdata.h 
	${CCLINE}sccsdata.c
$Dframed.o: framed.c develhdrs/mtrutil/gendefs.h wn_framed.h 
	${CCLINE}framed.c
$Dtestwn.o: testwn.c wn.h 
	${CCLINE}testwn.c
