Installing xv on a Mac

I use John Bradley's program, xv, on a regular basis. It's a great Xwindows program for viewing, editing, and saving images. I recently installed it on a Mac.



Edit: Thursday September 20, 2018 -- I am transitioning to a new MacBook Air laptop, and went to download and install xv. I ran into some difficulty, and did an on-line search for help. When this page that I wrote popped up on the first page of search results, I knew I was in for some trouble! Fortunately, I found a solution that worked well: I downloaded MacPorts and installed it. From the command line, this is what I did next:

port version
sudo port selfupdate
port help
sudo port install xv
sudo port install XQuartz
sudo port install xfig

Legal note: I'm not officially endorsing these products, I'm not a developer of any of them, and I'm not making money off of them. Use them at your own discretion.




(Below is the continuation of my notes from 2009.)
I tried the "make" command after downloading the files, but had some problems. Below, I show how to correct these problems.

I had to modify several files to get "make" to work on this Mac. Below are the changes (I used the "diff" utility to show them).

Notes about using xv on a Mac:

-MCW Feb 2009

Original Makefile:
4,5c4,8
< CC = cc
< # CC = gcc -ansi
---
Changed Makefile:
> # CC = cc
> # CC = gcc -ansi
> # from http://www.justlinux.com/forum/showthread.php?t=36721
> CC = gcc -ansi -I/usr/X11R6/include/ -L/usr/X11R6/lib/



vdcomp.c:
116c116,118
< # include <malloc.h>
---
> /* MCW changed the line below
> # include <malloc.h> */
> # include <sys/malloc.h>


xcmap.c:
13a14,15
> /* MCW added the line below */
> #include <stdlib.h> // for exit() function


xv.h:
118a119
> /* MCW commented out next line


xv.h:
167c168,170
< # include <malloc.h>
---
> /* MCW changed the line below:
> # include <malloc.h> */
> # include <sys/malloc.h>

Below is a script showing what I did to get xv to work on a Mac.

Script started on Thu Feb 12 18:01:39 2009
bash-3.2$ cd /usr/local
bash: cd: /usr/local: No such file or directory
bash-3.2$ cd /usr
bash-3.2$ ls
X11 bin lib sbin standalone
X11R6 include libexec share
bash-3.2$ sudo mkdir local

WARNING: Improper use of the sudo command could lead to data loss
or the deletion of important system files. Please double-check your
typing when using sudo. Type "man sudo" for more information.

To proceed, enter your password, or type Ctrl-C to abort.

Password:
bash-3.2$ cd local/
bash-3.2$ sudo mkdir bin
bash-3.2$ sudo mkdir src
bash-3.2$ cd src
bash-3.2$ sudo tar xvf ~/Desktop/xv-3.10a.tar
xv-3.10a/
xv-3.10a/xvxwd.c
xv-3.10a/xv.c
xv-3.10a/xv.h

... [stuff deleted]

xv-3.10a/.xvpics/xvxwd.c
xv-3.10a/.xvpics/xvxwd.o
bash-3.2$ ls -l
total 0
drwxr-xr-x@ 71 9097 15 2414 Jan 23 1995 xv-3.10a
bash-3.2$ cd xv-3.10a/
bash-3.2$ ls
BUGS docs xvbutt.c xvgraf.c xvrle.c
CHANGELOG jpeg xvcolor.c xviff.c xvroot.c
IDEAS tiff xvctrl.c xvimage.c xvscrl.c
INSTALL unsupt xvcut.c xvinfo.c xvsmooth.c
Imakefile vdcomp.c xvdflt.c xviris.c xvsunras.c
Makefile vms xvdflt.h xvjpeg.c xvtarga.c
Makefile.std vprintf.c xvdial.c xvmisc.c xvtext.c
README xcmap.c xvdir.c xvpbm.c xvtiff.c
bggen.c xv.c xvevent.c xvpcx.c xvtiffwr.c
bits xv.h xvfits.c xvpds.c xvxbm.c
c2b xv24to8.c xvgam.c xvpictoppm.c xvxpm.c
cleandir xvalg.c xvgif.c xvpm.c xvxwd.c
config.h xvbmp.c xvgifwr.c xvpopup.c
copyright.h xvbrowse.c xvgrab.c xvps.c
bash-3.2$ make
cd jpeg ; ./configure CC='cc'
./configure: line 311: ./config.log: Permission denied
make: *** [jpeg/jconfig.h] Error 1

[ forgot to use sudo, since I don't have write permissions here ]

bash-3.2$ sudo make
cd jpeg ; ./configure CC='cc'
checking for gcc... cc
checking whether we are using GNU C... yes
checking whether cc accepts -O... yes

... [stuff deleted]

cc -O -DDOJPEG -Ijpeg -DDOTIFF -Itiff -DDOPDS -c xv.c
In file included from xv.c:11:
xv.h:119: error: conflicting types for ‘sys_errlist’
/usr/include/stdio.h:274: error: previous declaration of ‘sys_errlist’ was here
In file included from xv.c:11:
xv.h:167:23: error: malloc.h: No such file or directory
make: *** [xv.o] Error 1

[ malloc.h is there, just not where the system expects it]

bash-3.2$ sudo cp xv.h xv_old.h
bash-3.2$ sudo vi xv.h

[ now show the difference between the original and changed file ]

bash-3.2$ diff xv_old.h xv.h
119c119
< extern char *sys_errlist[]; /* this too... */
---
> /* extern char *sys_errlist[]; /* this too... */

[ I commented out the definition of sys_errlist ]

167c167
< # include <malloc.h>
---
> # include <sys/malloc.h> /* it's in 'sys' on Macs, too */

[ I told it where to find malloc.h ]

bash-3.2$ sudo make
cc -O -DDOJPEG -Ijpeg -DDOTIFF -Itiff -DDOPDS -c xv.c
cc -O -DDOJPEG -Ijpeg -DDOTIFF -Itiff -DDOPDS -c xvevent.c
cc -O -DDOJPEG -Ijpeg -DDOTIFF -Itiff -DDOPDS -c xvroot.c

... [stuff deleted]

cc -O -DDOJPEG -Ijpeg -DDOTIFF -Itiff -DDOPDS -c xvfits.c
cc -o xv -O -DDOJPEG -Ijpeg -DDOTIFF -Itiff -DDOPDS xv.o xvevent.o xvroot.o x
vmisc.o xvimage.o xvcolor.o xvsmooth.o xv24to8.o xvgif.o xvpm.o xvinfo.o xvctrl.o xvsc
rl.o xvalg.o xvgifwr.o xvdir.o xvbutt.o xvpbm.o xvxbm.o xvgam.o xvbmp.o xvdial.o xvgra
f.o xvsunras.o xvjpeg.o xvps.o xvpopup.o xvdflt.o xvtiff.o xvtiffwr.o xvpds.o xvrle.o
xviris.o xvgrab.o vprintf.o xvbrowse.o xvtext.o xvpcx.o xviff.o xvtarga.o xvxpm.o xvcu
t.o xvxwd.o xvfits.o -lX11 jpeg/libjpeg.a tiff/libtiff.a -lm
ld: library not found for -lX11
collect2: ld returned 1 exit status
make: *** [xv] Error 1

[ like earlier, the file it needs is on the computer, just not
where it expects the file to be. ]

bash-3.2$ sudo cp Makefile oldMakefile
bash-3.2$ sudo vi Makefile
bash-3.2$ diff oldMakefile Makefile
4c4
< CC = cc
---
> # CC = cc
5a6,7
> # from http://www.justlinux.com/forum/showthread.php?t=36721
> CC = gcc -ansi -I/usr/X11R6/include/ -L/usr/X11R6/lib/

[ I redefined the compile command in the Makefile, according to a
web-site that discussed this problem. ]

bash-3.2$ sudo make
gcc -ansi -I/usr/X11R6/include/ -L/usr/X11R6/lib/ -o xv -O -DDOJPEG -Ijpeg -DDOTIFF -
Itiff -DDOPDS xv.o xvevent.o xvroot.o xvmisc.o xvimage.o xvcolor.o xvsmooth.o
xv24to8.o xvgif.o xvpm.o xvinfo.o xvctrl.o xvscrl.o xvalg.o xvgifwr.o xvdir.o xvbutt.o
xvpbm.o xvxbm.o xvgam.o xvbmp.o xvdial.o xvgraf.o xvsunras.o xvjpeg.o xvps.o xvpopup.
o xvdflt.o xvtiff.o xvtiffwr.o xvpds.o xvrle.o xviris.o xvgrab.o vprintf.o xvbrowse.o
xvtext.o xvpcx.o xviff.o xvtarga.o xvxpm.o xvcut.o xvxwd.o xvfits.o -lX11 jpeg/libjpeg
.a tiff/libtiff.a -lm
gcc -ansi -I/usr/X11R6/include/ -L/usr/X11R6/lib/ -O -DDOJPEG -Ijpeg -DDOTIFF -Itiff
-DDOPDS -o bggen bggen.c -lX11 jpeg/libjpeg.a tiff/libtiff.a -lm
bggen.c: In function ‘main’:
bggen.c:221: warning: incompatible implicit declaration of built-in function ‘malloc’
bggen.c:229: warning: incompatible implicit declaration of built-in function ‘exit’
bggen.c: In function ‘usage’:
bggen.c:319: warning: incompatible implicit declaration of built-in function ‘exit’
gcc -ansi -I/usr/X11R6/include/ -L/usr/X11R6/lib/ -O -DDOJPEG -Ijpeg -DDOTIFF -Itiff
-DDOPDS -o vdcomp vdcomp.c
vdcomp.c:116:23: error: malloc.h: No such file or directory
make: *** [vdcomp] Error 1

[ We have the same problem with malloc.h not being where the system expects
it. The fix is the same. A BETTER way to fix this would be to set a flag
for the Mac like the NeXT flag. ]

bash-3.2$ sudo cp vdcomp.c vdcomp_old.c
bash-3.2$ sudo vi vdcomp.c
bash-3.2$ diff vdcomp_old.c vdcomp.c
116c116
< # include <malloc.h>
---
> # include <sys/malloc.h> /* it's in 'sys' on Macs, too */

[ Added "sys/". ]

bash-3.2$ sudo make
gcc -ansi -I/usr/X11R6/include/ -L/usr/X11R6/lib/ -O -DDOJPEG -Ijpeg -DDOTIFF -Itiff
-DDOPDS -o vdcomp vdcomp.c
gcc -ansi -I/usr/X11R6/include/ -L/usr/X11R6/lib/ -O -DDOJPEG -Ijpeg -DDOTIFF -Itiff
-DDOPDS -o xcmap xcmap.c -lX11 jpeg/libjpeg.a tiff/libtiff.a -lm
xcmap.c: In function ‘Syntax’:
xcmap.c:235: warning: incompatible implicit declaration of built-in function ‘exit’
xcmap.c: In function ‘FatalError’:
xcmap.c:244: warning: incompatible implicit declaration of built-in function ‘exit’
xcmap.c: In function ‘Quit’:
xcmap.c:251: warning: incompatible implicit declaration of built-in function ‘exit’
gcc -ansi -I/usr/X11R6/include/ -L/usr/X11R6/lib/ -O -DDOJPEG -Ijpeg -DDOTIFF -Itiff
-DDOPDS -o xvpictoppm xvpictoppm.c

[ The "exit" function exists, but we have to include the right header file. ]

bash-3.2$ sudo cp xcmap.c xcmap_old.c
bash-3.2$ sudo vi xcmap.c
bash-3.2$ diff xcmap_old.c xcmap.c
13a14
> #include <stdlib.h> // for exit() function

[ Added this line. ]

bash-3.2$ sudo make
gcc -ansi -I/usr/X11R6/include/ -L/usr/X11R6/lib/ -O -DDOJPEG -Ijpeg -DDOTIFF -Itiff
-DDOPDS -o xcmap xcmap.c -lX11 jpeg/libjpeg.a tiff/libtiff.a -lm
bash-3.2$ sudo make install
cp xv bggen vdcomp xcmap xvpictoppm /usr/local/bin
cp docs/xv.man /usr/local/man/man1/xv.1
cp: /usr/local/man/man1/xv.1: No such file or directory
make: *** [install] Error 1

[ The documentation did not copy. But the program is there. ]

--
Michael Weeks, copyright © 2009, 2018