# "@(#)x11:contrib/clients/xloadimage/Makefile.std 6.9 92/03/30 Labtam"
# Makefile for xli. 
#
# WARNING: if you use gcc 1.37, there is an optimizer bug which causes GIF
# images to come out black and colormap reduction to fail.  Use gcc-1-37 as
# your make target if you have gcc 1.37.

SYSPATHFILE=/usr/lib/X11/Xloadimage
INSTALLDIR=/usr/bin/X11
SHELL= /bin/sh
MAKE= make
STD_CC= cc
GCC= gcc
CP= cp
LN= ln -s
RM= rm -f
LIBS= -lX11 -lm
CFLAGS= -O -DSYSPATHFILE=\"$(SYSPATHFILE)\" $(EXTRAFLAGS)
GCCFLAGS= -fstrength-reduce -finline-functions
GCC137FLAGS= -fforce-mem -fforce-addr -fstrength-reduce -finline-functions

MISC= Imakefile Makefile.std README README.orig build-imake \
      buildshar.c xli.man xliguide.man xlito.man patchlevel release 

INCS= cmuwmrast.h copyright.h fbm.h g3.h gif.h image.h imagetypes.h \
      img.h jpeg.h kljcpyrght.h mac.h mcidas.h mrmcpyrght.h options.h \
      pbm.h rle.h sunraster.h tgncpyrght.h xloadimage.h xwd.h mit.cpyrght

SRCS1= bright.c clip.c cmuwmrast.c compress.c dither.c faces.c fbm.c \
       fill.c  g3.c gif.c halftone.c imagetypes.c img.c mac.c mcidas.c \
       mc_tables.c merge.c misc.c new.c options.c path.c pbm.c pcx.c \
       reduce.c jpeg.c rle.c rlelib.c root.c rotate.c send.c smooth.c \
       sunraster.c value.c window.c xbitmap.c xloadimage.c xpixmap.c xwd.c \
       zio.c zoom.c

OBJS1= bright.o clip.o cmuwmrast.o compress.o dither.o faces.o fbm.o \
       fill.o  g3.o gif.o halftone.o imagetypes.o img.o mac.o mcidas.o \
       mc_tables.o merge.o misc.o new.o options.o path.o pbm.o pcx.o \
       reduce.o jpeg.o rle.o rlelib.o root.o rotate.o send.o smooth.o \
       sunraster.o value.o window.o xbitmap.o xloadimage.o xpixmap.o xwd.o \
       zio.o zoom.o

SRCS2= xlito.c

OBJS2= xlito.o

ALL= $(MISC) $(INCS) $(SRCS1) $(SRCS2)

# standard target.  this is for BSD-like environments, generally, although
# it will also work in many System-V environments.

std:
	@echo "Building standard distribution.  If this fails, consider trying"
	@echo "'make sysv'."
	$(MAKE) all CC=$(STD_CC)

# system-v target.  use this if you have a system-v compliant system.
	
sysv:
	@echo "Building standard distribution for System-V."
	$(MAKE) all CC=$(STD_CC) EXTRAFLAGS=-DSYSV

# gcc target.  use this if you have a gcc that is not version 1.37.  you
# should add -DSYSV between the quotes in EXTRAFLAGS if your system is
# system-v compliant as well.

gcc:
	@echo "Building distribution with GNU cc."
	@echo "**************************************************************"
	@echo "If you use gcc 1.37, you should abort and type 'make gcc-1-37'"
	@echo "instead.  If GIF images always display solid black or if"
	@echo "color images reduce to only a single color, your version"
	@echo "of gcc has a bug and you should use the gcc-1-37 target."
	@echo "If something else doesn't work, try using 'make gcc-1-37' and"
	@echo "then 'make std' before reporting a bug."
	@echo "**************************************************************"
	$(MAKE) all CC=$(GCC) EXTRAFLAGS="$(GCCFLAGS)"

# this target is for systems which use gcc 1.37.  there is a compiler bug
# in gcc 1.37 which causes some xli functions to fail with the
# standard optimizations.  use this if GIF loading and colormap reduction
# product black pictures.

gcc-1-37:
	@echo "Building distribution with GNU cc using flags for gcc 1.37."
	@echo "If something doesn't work, try using std before reporting"
	@echo "a bug."
	$(MAKE) all CC=$(GCC) EXTRAFLAGS="$(GCC137FLAGS)"

sysv-gcc:
	@echo "Building System-V distribution with GNU cc."
	@echo "Building distribution with GNU cc."
	@echo "***********************************************************"
	@echo "If you use gcc 1.37, you should abort and type"
	@echo "'make sysv-gcc-1-37' instead.  If GIF images always display"
	@echo "solid black or if color images reduce to only a single"
	@echo "color, your version of gcc has a bug and you should use"
	@echo "the gcc-1-37 target.  If something else doesn't work, try"
	@echo "using 'make sysv-gcc-1-37' and then 'make std' before"
	@echo "reporting a bug."
	@echo "***********************************************************"
	$(MAKE) all CC=$(GCC) EXTRAFLAGS="-DSYSV $(GCCFLAGS)"

# see comment for gcc-1-37 target.

sysv-gcc-1-37:
	@echo "Building System-V distribution with GNU cc using flags for"
	@echo "gcc 1.37.  If something doesn't work, try using std before"
	@echo "reporting a bug."
	$(MAKE) all CC=$(GCC) EXTRAFLAGS="-DSYSV $(GCC137FLAGS)"

install:: $(SYSPATHFILE)
	$(RM) $(INSTALLDIR)/xli
	$(RM) $(INSTALLDIR)/xsetbg
	$(RM) $(INSTALLDIR)/xview
	$(CP) xli $(INSTALLDIR)/xli
	$(LN) $(INSTALLDIR)/xli $(INSTALLDIR)/xsetbg
	$(LN) $(INSTALLDIR)/xli $(INSTALLDIR)/xview

xli: $(OBJS1)
	$(CC) $(CFLAGS) -o xli $(OBJS1) $(LIBS)

xlito: $(OBJS2)
	$(CC) $(CFLAGS) -o xlito $(OBJS2)

all:: xli xlito

.c.o: xloadimage.h
	$(CC) -c $(CFLAGS) $*.c

clean::
	rm -f *.o *~ xli xlito buildshar doshar shar.* *.tar *.tar.Z

$(SYSPATHFILE):
	@echo "*** Creating default $(SYSPATHFILE) since you"
	@echo "*** don't have one. This file is used to set up default places"
	@echo "*** and names to look for images.  You probably want to edit"
	@echo "*** it for your site.  See the xli manual page for"
	@echo "*** details on the contents of this file."
	cp /dev/null $(SYSPATHFILE)
	echo "path= /usr/local/images" \
		>> $(SYSPATHFILE)
	echo "extension=.gif .jpg .rle .csun .msun .sun .face .xbm .bm" \
		>>$(SYSPATHFILE)

# this is for building Imakefiles and such for distributions

Imakefile: Makefile.std
	$(RM) -f Imakefile
	sh ./build-imake "$(SRCS1)" "$(OBJS1)" "$(SRCS2)" "$(OBJS2)"

# these targets are for building shar distributions

buildshar: buildshar.o
	$(CC) -o buildshar buildshar.o

shar: buildshar new-imake
	rm -f shar.* doshar
	./buildshar $(ALL) > doshar
	sh doshar
	rm -f doshar

# targets for building tar distributions

tar: xli.tar.Z.uu

xli.tar.Z.uu: xli.tar.Z
	uuencode xli.tar.Z xli.tar.Z > xli.tar.Z.uu

xli.tar.Z: xli.tar
	compress xli.tar

xli.tar: $(ALL)
	tar cf xli.tar $(ALL)

# target for building debuggable versions

debug:
	@echo Building a debugging version of xli.
	make xli CC=$(STD_CC) CFLAGS="-g -DDEBUG -DSYSPATHFILE=\\\"$(SYSPATHFILE)\\\""

debug-sysv:
	@echo Building a debugging version of xli for System-V.
	make xli CC=$(STD_CC) CFLAGS="-g -DDEBUG -DSYSPATHFILE=\\\"$(SYSPATHFILE)\\\" -DSYSV"

# these targets are for those of us who have Saber-C

# load all objects in saber.  useful if you then swap the portions to debug
# for source.

objinsaber:
	#setopt ccargs -g -DSYSPATHFILE=\\\"$(SYSPATHFILE)\\\"
	#load $(OBJS) $(LIBS)
	#link

# load all sources in saber.  not as useful as the last one.

srcinsaber:
	#setopt load_flags -DSYSPATHFILE=\\\"$(SYSPATHFILE)\\\"
	#load $(SRCS) $(LIBS)
	#link
