#! /bin/sh

# without that no way :)
touch ${WRKSRC}/makefile

# driverselection
/usr/bin/dialog --title "Ghostscript 4 driver configuration" --clear \
	--checklist "\n\
This new ghostscript driver configuration dialog allows you to choose \n\
only those gs drivers, you really need. Don't think too economical, since \n\
other programs in the ports collection might need some of the default gs \n\
file format drivers. The gs4 default drivers are preselected. \n\
Have fun with this new configuration style !     -andreas \n\n\
  Please choose options by pressing SPACE to TOGGLE an option ON/ON ?" -1 -1 9\
  "x11"      "X Windows version 11, release >=4" ON \
  "x11alpha" "X Windows masquer. as device with alpha capability" ON \
  "x11cmyk"  "X Windows masquer. as 1-bit-per-plane CMYK device" ON \
  "x11gray2" "X Windows as a 2-bit gray-scale device" ON \
  "x11mono"  "X Windows masquer. as black-and-white device" ON \
  "sxlcrt"   "CRT sixels, e.g. for VT240-like terminals" ON \
  "ap3250"   "Epson AP3250" ON \
  "appledmp" "Apple Dot Matrix Printer / Imagewriter" ON \
  "bj10e"    "Canon BubbleJet BJ10e" ON \
  "bj200"    "Canon BubbleJet BJ200" ON \
  "bjc600"   "Canon Color BubbleJet BJC-600/4000/70+Apple StyleWriter 2x00" ON \
  "bjc800"   "Canon Color BubbleJet BJC-800" ON \
  "ccr"      "CalComp Raster format" ON \
  "cdeskjet" "HP DeskJet 500C, 1 bit/pixel color" ON \
  "cdjcolor" "HP DeskJet 500C/540C, 24 bit/pixel color + FS dithering" ON \
  "cdjmono"  "HP DeskJet 500/510/520/540C b/w printing" ON \
  "cdj500"   "HP DeskJet 500C (same as cdjcolor)" ON \
  "cdj550"   "HP DeskJet 550C/560C" ON \
  "cdj850"   "HP DeskJet 850/855/870/890" ON \
  "cp50"     "Mitsubishi CP50 color" ON \
  "declj250" "alternate DEC LJ250 driver" ON \
  "deskjet"  "HP DeskJet and DeskJet Plus" ON \
  "djet500"  "HP DeskJet 500" ON \
  "djet500c" "HP DeskJet 500C alternate driver, not for 550/560C" ON \
  "dnj650c"  "HP DesignJet 650C" ON \
  "epson"    "Epson-compatible dot matrix, 9/24-pin" ON \
  "eps9mid"  "Epson-compatible 9-pin, medium resol" ON \
  "eps9high" "Epson-compatible 9-pin, high resol" ON \
  "epsonc"   "Epson LQ-2550 and Fujitsu 3400/2400/1200 color" ON \
  "ibmpro"   "IBM 9-pin Proprinter" ON \
  "imagen"   "Imagen ImPress printers" ON \
  "iwhi"     "Apple Imagewriter, high-resolution mode" ON \
  "iwlo"     "Apple Imagewriter, low-resolution mode" ON \
  "iwlq"     "Apple Imagewriter LQ in 320 x 216 dpi mode" ON \
  "jetp3852" "IBM Jetprinter ink-jet color (Model #3852)" ON \
  "laserjet" "HP LaserJet" ON \
  "la50"     "DEC LA50 printer" ON \
  "la70"     "DEC LA70 printer" ON \
  "la70t"    "DEC LA70 printer with low resol. text enhancement" ON \
  "la75"     "DEC LA75 printer" ON \
  "la75plus" "DEC LA75plus printer" ON \
  "lbp8"     "Canon LBP-8II laser printer" ON \
  "lips3"    "Canon LIPS III laser printer in English/CaPSL mode" ON \
  "ln03"     "DEC LN03 printer" ON \
  "lj250"    "DEC LJ250 Companion color printer" ON \
  "ljet2p"   "HP LaserJet IId/IIp/III* with TIFF compression" ON \
  "ljet3"    "HP LaserJet III* with Delta Row compression" ON \
  "ljet3d"   "HP LaserJet IIID with duplex capability" ON \
  "ljet4"    "HP LaserJet 4 (defaults to 600 dpi)" ON \
  "lj4dith"  "HP LaserJet 4 with Floyd-Steinberg dithering" ON \
  "ljetplus" "HP LaserJet Plus" ON \
  "lj5mono"  "HP LaserJet 5 and 6 family (PCL5 / PCL XL), bitmap" ON \
  "lj5gray"  "HP LaserJet 5 and 6 family, gray-scale bitmap" ON \
  "lp2563"   "HP 2563B line printer" ON \
  "lp8000"   "EPSON LP-8000 line printer" ON \
  "lq850"    "EPSON LQ-850 (360x360), ok for Canon BJ300 in LQ850 emul" ON \
  "m8510"    "C.Itoh M8510 printer" ON \
  "necp6"    "NEC P6/P6+/P60, 360x360 DPI resol" ON \
  "oce9050"  "OCE 9050 printer" ON \
  "oki182"   "Okidata MicroLine 182" ON \
  "okiibm"   "Okidata MicroLine IBM-compatible printers" ON \
  "paintjet" "alternate HP PaintJet color printer" ON \
  "pj"       "HP PaintJet XL driver " ON \
  "pjetxl"   "alternate HP PaintJet XL driver" ON \
  "pjxl"     "HP PaintJet XL color printer" ON \
  "pjxl300"  "HP PaintJet XL300 color printer (also for 1200C)" ON \
  "pxlmono"  "HP black-and-white PCL XL printers (LaserJet 5 and 6 family)" ON \
  "pxlcolor" "HP color PCL XL printers (none available yet)" ON \
  "r4081"    "Ricoh 4081 laser printer" ON \
  "sj48"     "StarJet 48 inkjet printer" ON \
  "st800"    "Epson Stylus 800 printer" ON \
  "stcolor"  "Epson Stylus Color" ON \
  "t4693d2"  "Tektronix 4693d color, 2 bits per R/G/B component" ON \
  "t4693d4"  "Tektronix 4693d color, 4 bits per R/G/B component" ON \
  "t4693d8"  "Tektronix 4693d color, 8 bits per R/G/B component" ON \
  "tek4696"  "Tektronix 4695/4696 inkjet plotter" ON \
  "uniprint" "Configurable Color ESC/P,ESC/P2,HP-RTL/PCL mono/color driver" ON \
  "xes"      "Xerox XES printers (2700, 3700, 4045, etc.)" ON \
  "dfaxhigh" "DigiBoard, DigiFAX software format (high resol)" ON \
  "dfaxlow"  "DigiFAX low (normal) resol" ON \
  "faxg3"    "Group 3 fax, with EOLs but no header or EOD" ON \
  "faxg32d"  "Group 3 2-D fax, with EOLs but no header or EOD" ON \
  "faxg4"    "Group 4 fax, with EOLs but no header or EOD" ON \
  "tiffcrle" "TIFF CCITT RLE 1 dim = Group 3 fax with no EOLs" ON \
  "tiffg3"   "TIFF Group 3 fax with EOLs" ON \
  "tiffg32d" "TIFF Group 3 2-D fax" ON \
  "tiffg4"   "TIFF Group 4 fax" ON \
  "epswrite" "EPS output (like PostScript Distillery)" ON \
  "pdfwrite" "PDF output (like Adobe Acrobat Distiller)" ON \
  "pswrite"  "PostScript output (like PostScript Distillery)" ON \
  "pxlmono"  "Black-and-white PCL XL" ON \
  "pxlcolor" "Color PCL XL" ON \
  "bit"      "Plain bits, monochrome" ON \
  "bitrgb"   "Plain bits, RGB" ON \
  "bitcmyk"  "Plain bits, CMYK" ON \
  "bmpmono"  "Monochrome MS Windows .BMP file format" ON \
  "bmp16"    "4-bit EGA/VGA .BMP file format" ON \
  "bmp256"   "8-bit 256-color .BMP file format" ON \
  "bmp16m"   "24-bit .BMP file format" ON \
  "cgmmono"  "Monochrome CGM -- LOW LEVEL OUTPUT ONLY" ON \
  "cgm8"     "8-bit 256-color CGM -- DITTO" ON \
  "cgm24"    "24-bit color CGM -- DITTO" ON \
  "cif"      "CIF file format for VLSI" ON \
  "jpeg"     "JPEG format, RGB output" ON \
  "jpeggray" "JPEG format, gray output" ON \
  "miff24"   "ImageMagick MIFF, 24-bit direct color, RLE compressed" ON \
  "mgrmono"  "1-bit monochrome MGR devices" ON \
  "mgrgray2" "2-bit gray scale MGR devices" ON \
  "mgrgray4" "4-bit gray scale MGR devices" ON \
  "mgrgray8" "8-bit gray scale MGR devices" ON \
  "mgr4"     "4-bit (VGA) color MGR devices" ON \
  "mgr8"     "8-bit color MGR devices" ON \
  "pcxmono"  "PCX file format, monochrome 1-bit b/w" ON \
  "pcxgray"  "PCX file format, 8-bit gray scale" ON \
  "pcx16"    "PCX file format, 4-bit planar EGA/VGA color" ON \
  "pcx256"   "PCX file format, 8-bit chunky color" ON \
  "pcx24b"   "PCX file format, 24-bit color 3x8-bit planes" ON \
  "pcxcmyk"  "PCX file format, 4-bit chunky CMYK color" ON \
  "pbm"      "Portable Bitmap,  plain format" ON \
  "pbmraw"   "Portable Bitmap,  raw format" ON \
  "pgm"      "Portable Graymap, plain format" ON \
  "pgmraw"   "Portable Graymap, raw format" ON \
  "pgnm"     "Portable Graymap, plain format, optim. to PBM" ON \
  "pgnmraw"  "Portable Graymap, raw format, optim. to PBM" ON \
  "pnm"      "Portable Pixmap,  plain format RGB, optim. to PGM/PBM" ON \
  "pnmraw"   "Portable Pixmap,  raw format RGB, optim. to PGM/PBM" ON \
  "ppm"      "Portable Pixmap,  plain format RGB" ON \
  "ppmraw"   "Portable Pixmap,  raw format RGB" ON \
  "pkm"      "Portable inKmap (plain format) (4-bit CMYK => RGB)" ON \
  "pkmraw"   "Portable inKmap (raw format) (4-bit CMYK => RGB)" ON \
  "pngmono"  "Monochrome Portable Network Graphics, PNG" ON \
  "pnggray"  "8-bit gray Portable Network Graphics, PNG" ON \
  "png16"    "4-bit color Portable Network Graphics, PNG" ON \
  "png256"   "8-bit color Portable Network Graphics, PNG" ON \
  "png16m"   "24-bit color Portable Network Graphics, PNG" ON \
  "psmono"   "PostScript, Level 1, monochrome image" ON \
  "psgray"   "PostScript (Level 1) 8-bit gray image" ON \
  "sgirgb"   "SGI RGB pixmap format" ON \
  "tiff12nc" "TIFF 12-bit RGB, no compression" ON \
  "tiff24nc" "TIFF 24-bit RGB, no compression, NeXT std. format)" ON \
  "tifflzw"  "TIFF LZW,      tag = 5,     mono" ON \
  "tiffpack" "TIFF PackBits, tag = 32773, mono" ON 2> /tmp/checklist.tmp.$$

retval=$?

choice=`cat /tmp/checklist.tmp.$$`
rm -f /tmp/checklist.tmp.$$

case $retval in
	0)	if [ -z choice ]; then
			echo "Nothing selected"
			exit 1;
		fi
		;;
	1)	echo "Cancel pressed."
		exit 1
		;;
esac

# bring it into the right format with '.dev' appended to each driver name
echo "DEVICE_DEVS=$choice" \
	| sed -e "s/\"//g" \
	| sed -e "s/ /.dev /g" \
	| sed -e "s/$/.dev/g" \
	> ${WRKSRC}/unix-gcc.mak.new

# create one new Makefile, where DEVICE_DEVS contains all wanted devices
cat ${WRKSRC}/unix-gcc.mak >> ${WRKSRC}/unix-gcc.mak.new
mv ${WRKSRC}/unix-gcc.mak.new ${WRKSRC}/unix-gcc.mak