
VERSION=0.60
# ver 0.20 old
# ver 0.60 20x39in 202051209
NAME=spectrum
LATEX=/usr/bin/latex
DVIPS=/usr/bin/dvips
GS=/usr/bin/gs
CC=gcc

#for when "a drawing error occurred" in acroread
# GS=gs-gpl

all: numbers spectrum

# Make the spectrum chart
spectrum: pictures
	$(LATEX) tex/spectrum.tex
	$(DVIPS) -Ppdf -T 21in,40in spectrum.dvi -f > spectrum.eps
	# $(GS) -dSAFER -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=spectrum_current.pdf -dSAFER -c .setpdfwrite -f spectrum.eps
	$(GS) -dSAFER -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=spectrum_current.pdf -dSAFER -f spectrum.eps

pictures:
	cd pictures && make

cmyk:
	$(GS) -dSAFER -dBATCH -dNOPAUSE -dNOCACHE -sDEVICE=pdfwrite \
	-sColorConversionStrategy=CMYK -dProcessColorModel=/DeviceCMYK \
	-sOutputFile=spectrum_20100428_cmyk.pdf spectrum_20100428_test.pdf

thumbnail:
	convert spectrum.eps -scale 300 full_thumbnail.jpg

# makes a huge JPEG file with decent resolution for printing
jpeg:
	$(GS) -sDEVICE=jpeg -sOutputFile=spectrum.jpg -r300x300 -dGraphicsAlphaBits=4 spectrum.eps

jpeg600:
	$(GS) -sDEVICE=jpeg -sOutputFile=spectrum.jpg -r600x600 -dGraphicsAlphaBits=4 spectrum.eps

# Split poster up into smaller printable sheets
# This function may not work too well with newer versions of "poster" program.
split:
	poster -v -c5% -s1 -mletter  spectrum.eps -ospectrum_pages.eps
	ps2pdf spectrum_pages.eps
	zip spectrum_pages spectrum_pages.pdf

# Compile the C program that generates the numbers on the scales
numbers: numbers.c
	$(CC) -lm -o numbers numbers.c
	./numbers > tex/numbers.tex &

# Compile the utility to convert frequencies to positions on chart
xpos: xpos.c xpose6.c
	$(CC) -lm -o xpos xpos.c
	$(CC) -lm -o xpose6 xpose6.c

cell:
	cat tex/3G-F.txt  | ./xpose6 1e6 0.000 0.020 > tex/3Gbands.tex
	cat tex/LTE-F.txt | ./xpose6 1e6 0.020 0.020 > tex/4Gbands.tex
	cat tex/5G-F1.txt | ./xpose6 1e6 0.040 0.020 > tex/5GF1bands.tex
	cat tex/5G-F2.txt | ./xpose6 1e9 0.040 0.020 > tex/5GF2bands.tex

# Compile the utility to convert a frequency range to positions on chart
kuband:
	echo "% Upload channels 1-16" > kbandTV.txt
	./xposrange.pl 14014.75e6 16 30.5e6 >> kbandTV.txt
	echo "% Download channels 17-32" >> kbandTV.txt
	./xposrange.pl 14027.75e6 16 30.5e6 >> kbandTV.txt 
	echo "% Download channels 1-16" >> kbandTV.txt
	./xposrange.pl 11714.75e6 16 30.5e6 >> kbandTV.txt
	echo "% Download channels 17-32" >> kbandTV.txt
	./xposrange.pl 11727.75e6 16 30.5e6 >> kbandTV.txt


# Compile the scales program
scale: scale.c
	$(CC) -lm -o scale scale.c

# remove compiled temporary files
clean:
	cd pictures && $(MAKE) clean
	rm -f *.dvi
	rm -f *.aux
	rm -f spectrum.eps
	rm -f *.log

distclean: clean
	rm -rf autom4te.cache
	rm -f tex/numbers.tex
	rm -f numbers
	rm -f config.status
	rm -f spectrum_current.pdf

# new update to website, modified for more recent changes.
new:
	cp spectrum_current.pdf /home/anthony/web/unihedron/projects/spectrum/downloads/
	sitecopy --update unihedron

# make a distributable file of the source code
dist:
	if test -d "$(NAME)-$(VERSION)"; then rm -rf $(NAME)-$(VERSION); fi
	if test -f "$(NAME)-$(VERSION).tar.gz"; then rm -f $(NAME)-$(VERSION).tar.gz; fi
	mkdir $(NAME)-$(VERSION)
	cp Makefile $(NAME)-$(VERSION)
	cp -R doc $(NAME)-$(VERSION)
	cp -R tex $(NAME)-$(VERSION)
	cp -R sizes $(NAME)-$(VERSION)
	cp -R sources $(NAME)-$(VERSION)
	cp -R pictures $(NAME)-$(VERSION)
	cp numbers.c $(NAME)-$(VERSION)
	cp xpos.c $(NAME)-$(VERSION)
	cp scale.c $(NAME)-$(VERSION)
	tar cvzf $(NAME)-$(VERSION).tar.gz $(NAME)-$(VERSION)
	rm -rf $(NAME)-$(VERSION)

configure: configure.ac
	autoconf

config.status: configure
	[ ! -f config.status ] || ./config.status --recheck
