# Makefile for GPLOT 
#
# Joe Chuma, TRIUMF, 31Jan2008
#
# set TOP_DIR to the parent directory for gplot
#
SHELL = /bin/sh

TOP_DIR = /triumfcs/trshare/chuma/private

# you shouldn't have to change anything below here

CC     = gcc
CFLAGS = -g

GCC_VERSION := $(shell $(CC) --version|head -1|awk -F" " '{printf $$3}'|awk -F"." '{printf $$1}')

ifeq (${GCC_VERSION},3)
  FORTRAN = g77
  MACROS  = -Dg77 -Dunix
  FFLAGS  = -Wall -g -fno-second-underscore -fno-automatic -static -malign-double
else
  FORTRAN = gfortran
  MACROS  = -Dgfortran -Dunix
  FFLAGS  = -Wall -g -fno-second-underscore -fno-automatic -static -malign-double -frecord-marker=4
endif

GPLOT_DIR    = $(TOP_DIR)/gplot
EXAMPLES_DIR = $(GPLOT_DIR)/examples
GPLOT_LIB    = $(GPLOT_DIR)/libgplot.a

# OTHER_LIBS is needed to make the examples
OTHER_LIBS = /usr/X11R6/lib/libX11.a -lpthread

FSRCS =  $(GPLOT_DIR)/src/amsinit.F \
         $(GPLOT_DIR)/src/arc.F \
         $(GPLOT_DIR)/src/arc_dwg.F \
         $(GPLOT_DIR)/src/arcv.F \
         $(GPLOT_DIR)/src/asort.F \
         $(GPLOT_DIR)/src/aux_port_out.F \
         $(GPLOT_DIR)/src/bell.F \
         $(GPLOT_DIR)/src/bitmap_free.F \
         $(GPLOT_DIR)/src/bitmap_get.F \
         $(GPLOT_DIR)/src/btd.F \
         $(GPLOT_DIR)/src/calculator.F \
         $(GPLOT_DIR)/src/cft.F \
         $(GPLOT_DIR)/src/ch_real.F \
         $(GPLOT_DIR)/src/check_buff.F \
         $(GPLOT_DIR)/src/check_buff2.F \
         $(GPLOT_DIR)/src/chsize.F \
         $(GPLOT_DIR)/src/cils2.F \
         $(GPLOT_DIR)/src/cltrans.F \
         $(GPLOT_DIR)/src/conv_r_to_ch.F \
         $(GPLOT_DIR)/src/conv_to_ch.F \
         $(GPLOT_DIR)/src/conv_to_uc.F \
         $(GPLOT_DIR)/src/convlc_to_uc.F \
         $(GPLOT_DIR)/src/copy_array.F \
         $(GPLOT_DIR)/src/datetime.F \
         $(GPLOT_DIR)/src/del_array.F \
         $(GPLOT_DIR)/src/deriv3.F \
         $(GPLOT_DIR)/src/dexp10.F \
         $(GPLOT_DIR)/src/dither.F \
         $(GPLOT_DIR)/src/dline.F \
         $(GPLOT_DIR)/src/dspl11.F \
         $(GPLOT_DIR)/src/dsplxy.F \
         $(GPLOT_DIR)/src/dspxys.F \
         $(GPLOT_DIR)/src/dwg_batch_cl.F \
         $(GPLOT_DIR)/src/dwg_close.F \
         $(GPLOT_DIR)/src/dwg_format.F \
         $(GPLOT_DIR)/src/dwg_next.F \
         $(GPLOT_DIR)/src/dwg_output.F \
         $(GPLOT_DIR)/src/dwg_stroke.F \
         $(GPLOT_DIR)/src/ellcon.F \
         $(GPLOT_DIR)/src/ellfit.F \
         $(GPLOT_DIR)/src/ellips.F \
         $(GPLOT_DIR)/src/end_plot.F \
         $(GPLOT_DIR)/src/erase_recta.F \
         $(GPLOT_DIR)/src/find_unit.F \
         $(GPLOT_DIR)/src/flush_plot.F \
         $(GPLOT_DIR)/src/fnice.F \
         $(GPLOT_DIR)/src/fourt.F \
         $(GPLOT_DIR)/src/free_space.F \
         $(GPLOT_DIR)/src/get_array.F \
         $(GPLOT_DIR)/src/get_plot_dev.F \
         $(GPLOT_DIR)/src/get_space.F \
         $(GPLOT_DIR)/src/gks_plot.F \
         $(GPLOT_DIR)/src/gksdum.F \
         $(GPLOT_DIR)/src/hardcopy_rng.F \
         $(GPLOT_DIR)/src/hatch.F \
         $(GPLOT_DIR)/src/hex_to_ascii.F \
         $(GPLOT_DIR)/src/houston_plot.F \
         $(GPLOT_DIR)/src/hpsub.F \
         $(GPLOT_DIR)/src/impress_plot.F \
         $(GPLOT_DIR)/src/iplot.F \
         $(GPLOT_DIR)/src/it_is.F \
         $(GPLOT_DIR)/src/jplot.F \
         $(GPLOT_DIR)/src/left_justify.F \
         $(GPLOT_DIR)/src/lensig.F \
         $(GPLOT_DIR)/src/lib_out.F \
         $(GPLOT_DIR)/src/line_thick.F \
         $(GPLOT_DIR)/src/lower_case.F \
         $(GPLOT_DIR)/src/lqline.F \
         $(GPLOT_DIR)/src/lwrcase.F \
         $(GPLOT_DIR)/src/minmax.F \
         $(GPLOT_DIR)/src/mod2.F \
         $(GPLOT_DIR)/src/monitor2_rng.F \
         $(GPLOT_DIR)/src/monitor_rng.F \
         $(GPLOT_DIR)/src/movec.F \
         $(GPLOT_DIR)/src/mxhelp.F \
         $(GPLOT_DIR)/src/nargs.F \
         $(GPLOT_DIR)/src/pack_buffer.F \
         $(GPLOT_DIR)/src/pack_buffer2.F \
         $(GPLOT_DIR)/src/pen_down.F \
         $(GPLOT_DIR)/src/pen_up.F \
         $(GPLOT_DIR)/src/pixel_extent.F \
         $(GPLOT_DIR)/src/plot_color.F \
         $(GPLOT_DIR)/src/plot_device.F \
         $(GPLOT_DIR)/src/plot_device2.F \
         $(GPLOT_DIR)/src/plot_end.F \
         $(GPLOT_DIR)/src/plot_level.F \
         $(GPLOT_DIR)/src/plot_level2.F \
         $(GPLOT_DIR)/src/plot_mode.F \
         $(GPLOT_DIR)/src/plot_mode2.F \
         $(GPLOT_DIR)/src/plot_mon.F \
         $(GPLOT_DIR)/src/plot_mon2.F \
         $(GPLOT_DIR)/src/plot_point.F \
         $(GPLOT_DIR)/src/plot_r.F \
         $(GPLOT_DIR)/src/plot_x.F \
         $(GPLOT_DIR)/src/plots.F \
         $(GPLOT_DIR)/src/plottplt.F \
         $(GPLOT_DIR)/src/ps_plot.F \
         $(GPLOT_DIR)/src/r_plot.F \
         $(GPLOT_DIR)/src/rdgl.F \
         $(GPLOT_DIR)/src/read_plot.F \
         $(GPLOT_DIR)/src/readline.F \
         $(GPLOT_DIR)/src/readln.F \
         $(GPLOT_DIR)/src/regis_mode.F \
         $(GPLOT_DIR)/src/regis_mode2.F \
         $(GPLOT_DIR)/src/ricon.F \
         $(GPLOT_DIR)/src/scale1.F \
         $(GPLOT_DIR)/src/scale2.F \
         $(GPLOT_DIR)/src/segment_cr.F \
         $(GPLOT_DIR)/src/segment_crh.F \
         $(GPLOT_DIR)/src/seiko_plot.F \
         $(GPLOT_DIR)/src/seiko_plot2.F \
         $(GPLOT_DIR)/src/set_plot_dev.F \
         $(GPLOT_DIR)/src/setc.F \
         $(GPLOT_DIR)/src/simq.F \
         $(GPLOT_DIR)/src/sinter.F \
         $(GPLOT_DIR)/src/status.F \
         $(GPLOT_DIR)/src/symbol.F \
         $(GPLOT_DIR)/src/transparent.F \
         $(GPLOT_DIR)/src/upper_case.F \
         $(GPLOT_DIR)/src/uprcase.F \
         $(GPLOT_DIR)/src/uprcasel.F \
         $(GPLOT_DIR)/src/vbuff.F \
         $(GPLOT_DIR)/src/vdt_cursor.F \
         $(GPLOT_DIR)/src/vhelp.F \
         $(GPLOT_DIR)/src/video_off.F \
         $(GPLOT_DIR)/src/window_clip.F \
         $(GPLOT_DIR)/src/write_hppai.F \
         $(GPLOT_DIR)/src/write_la100.F \
         $(GPLOT_DIR)/src/write_gks.F \
         $(GPLOT_DIR)/src/write_houst.F \
         $(GPLOT_DIR)/src/write_hpp.F \
         $(GPLOT_DIR)/src/write_impr.F \
         $(GPLOT_DIR)/src/write_ln03.F \
         $(GPLOT_DIR)/src/write_rdgl.F \
         $(GPLOT_DIR)/src/write_ps.F \
         $(GPLOT_DIR)/src/write_pt.F \
         $(GPLOT_DIR)/src/write_px.F \
         $(GPLOT_DIR)/src/zero_array.F \
         $(GPLOT_DIR)/src/chreal.F \
         $(GPLOT_DIR)/src/clear_plot.F \
         $(GPLOT_DIR)/src/cpu_limit.F \
         $(GPLOT_DIR)/src/cpu_time.F \
         $(GPLOT_DIR)/src/crosshair_r.F \
         $(GPLOT_DIR)/src/ctrlc_trap.F \
         $(GPLOT_DIR)/src/dsplft.F \
         $(GPLOT_DIR)/src/dwg.F \
         $(GPLOT_DIR)/src/dwg_batch.F \
         $(GPLOT_DIR)/src/dwg_list.F \
         $(GPLOT_DIR)/src/dwg_open.F \
         $(GPLOT_DIR)/src/findc.F \
         $(GPLOT_DIR)/src/findst.F \
         $(GPLOT_DIR)/src/formsg.F \
         $(GPLOT_DIR)/src/generic_term.F \
         $(GPLOT_DIR)/src/get_hardtype.F \
         $(GPLOT_DIR)/src/get_pltype.F \
         $(GPLOT_DIR)/src/get_prcnam.F \
         $(GPLOT_DIR)/src/get_termtype.F \
         $(GPLOT_DIR)/src/get_username.F \
         $(GPLOT_DIR)/src/graphics_hc.F \
         $(GPLOT_DIR)/src/igc.F \
         $(GPLOT_DIR)/src/lib_free_vm.F \
         $(GPLOT_DIR)/src/lib_get_vm.F \
         $(GPLOT_DIR)/src/list_fnames.F \
         $(GPLOT_DIR)/src/lswap.F \
         $(GPLOT_DIR)/src/node_name.F \
         $(GPLOT_DIR)/src/pause2.F \
         $(GPLOT_DIR)/src/plot_hardc.F \
         $(GPLOT_DIR)/src/print_buff.F \
         $(GPLOT_DIR)/src/print_buff2.F \
         $(GPLOT_DIR)/src/psym_dwg.F \
         $(GPLOT_DIR)/src/psymbold.F \
         $(GPLOT_DIR)/src/put_formsg.F \
         $(GPLOT_DIR)/src/put_sysmsg.F \
         $(GPLOT_DIR)/src/read_key.F \
         $(GPLOT_DIR)/src/realch.F \
         $(GPLOT_DIR)/src/sleep2.F \
         $(GPLOT_DIR)/src/sysmsg.F \
         $(GPLOT_DIR)/src/tt_get_input.F \
         $(GPLOT_DIR)/src/tt_input.F \
         $(GPLOT_DIR)/src/write_hp300.F \
         $(GPLOT_DIR)/src/write_hp300c.F \
         $(GPLOT_DIR)/src/write_hpjet.F \
         $(GPLOT_DIR)/src/write_hpjetc.F \
         $(GPLOT_DIR)/src/put_dwg.F \
         $(GPLOT_DIR)/src/ascebc.F \
         $(GPLOT_DIR)/src/pascebc.F \
         $(GPLOT_DIR)/src/pfont.F \
         $(GPLOT_DIR)/src/psym.F \
         $(GPLOT_DIR)/src/term_width.F \
         $(GPLOT_DIR)/src/g77/trigd.F \
         $(GPLOT_DIR)/src/unix/ctrlc_hand.F \
         $(GPLOT_DIR)/src/unix/evaluate.F \
         $(GPLOT_DIR)/src/unix/ibatch.F \
         $(GPLOT_DIR)/src/unix/lok_e_trap.F \
         $(GPLOT_DIR)/src/unix/read_key_res.F \
         $(GPLOT_DIR)/src/gplot/auto_scale.F \
         $(GPLOT_DIR)/src/gplot/axline.F \
         $(GPLOT_DIR)/src/gplot/axlog.F \
         $(GPLOT_DIR)/src/gplot/do_command.F \
         $(GPLOT_DIR)/src/gplot/gauto.F \
         $(GPLOT_DIR)/src/gplot/gaxis.F \
         $(GPLOT_DIR)/src/gplot/get_item.F \
         $(GPLOT_DIR)/src/gplot/getdyn.F \
         $(GPLOT_DIR)/src/gplot/getlab.F \
         $(GPLOT_DIR)/src/gplot/getnam.F \
         $(GPLOT_DIR)/src/gplot/getpcnt.F \
         $(GPLOT_DIR)/src/gplot/gplot.F \
         $(GPLOT_DIR)/src/gplot/gplot_conv.F \
         $(GPLOT_DIR)/src/gplot/gplot_disp_n.F \
         $(GPLOT_DIR)/src/gplot/gplot_menu.F \
         $(GPLOT_DIR)/src/gplot/gplot_number.F \
         $(GPLOT_DIR)/src/gplot/gplot_r.F \
         $(GPLOT_DIR)/src/gplot/gplot_r_init.F \
         $(GPLOT_DIR)/src/gplot/gplot_rest.F \
         $(GPLOT_DIR)/src/gplot/gplot_rest_f.F \
         $(GPLOT_DIR)/src/gplot/gplot_save.F \
         $(GPLOT_DIR)/src/gplot/gplot_save_f.F \
         $(GPLOT_DIR)/src/gplot/gplot_setup.F \
         $(GPLOT_DIR)/src/gplot/gplot_short.F \
         $(GPLOT_DIR)/src/gplot/gplot_symbol.F \
         $(GPLOT_DIR)/src/gplot/gplot_txt.F \
         $(GPLOT_DIR)/src/gplot/gploti.F \
         $(GPLOT_DIR)/src/gplot/gplt.F \
         $(GPLOT_DIR)/src/gplot/is_it_dynam.F \
         $(GPLOT_DIR)/src/gplot/labxy.F \
         $(GPLOT_DIR)/src/gplot/name_in_hex.F \
         $(GPLOT_DIR)/src/gplot/setlab.F \
         $(GPLOT_DIR)/src/gplot/setnam.F \
         $(GPLOT_DIR)/src/gplot/symbol2.F \
         $(GPLOT_DIR)/src/gplot/gline_sub.F \
         $(GPLOT_DIR)/src/gplot/gplot_cont.F \
         $(GPLOT_DIR)/src/gplot/gplot_line.F

#         $(GPLOT_DIR)/src/mplot.F \
#         $(GPLOT_DIR)/src/pebcasc.F \

CSRCS =  $(GPLOT_DIR)/src/keypress.c \
         $(GPLOT_DIR)/src/png_setup.c \
         $(GPLOT_DIR)/src/readpng.c \
         $(GPLOT_DIR)/src/resize_act.c \
         $(GPLOT_DIR)/src/rpng-x.c \
         $(GPLOT_DIR)/src/sig_off_on.c \
         $(GPLOT_DIR)/src/x_alpha.c \
         $(GPLOT_DIR)/src/x_close_z.c \
         $(GPLOT_DIR)/src/x_create_z.c \
         $(GPLOT_DIR)/src/x_crosshair.c \
         $(GPLOT_DIR)/src/x_define_col.c \
         $(GPLOT_DIR)/src/x_draw_fsc.c \
         $(GPLOT_DIR)/src/x_draw_zb.c \
         $(GPLOT_DIR)/src/x_error.c \
         $(GPLOT_DIR)/src/x_event.c \
         $(GPLOT_DIR)/src/x_plot.c \
         $(GPLOT_DIR)/src/x_plot_col.c \
         $(GPLOT_DIR)/src/x_plot_rep.c \
         $(GPLOT_DIR)/src/x_refresh.c \
         $(GPLOT_DIR)/src/x_replay.c \
         $(GPLOT_DIR)/src/x_setup.c \
         $(GPLOT_DIR)/src/x_store.c \
         $(GPLOT_DIR)/src/x_sync.c \
         $(GPLOT_DIR)/src/x_wname.c \
         $(GPLOT_DIR)/src/x_zoom.c \
         $(GPLOT_DIR)/src/unix/fgetcpulimit.c \
         $(GPLOT_DIR)/src/unix/fitof.c \
         $(GPLOT_DIR)/src/unix/read_key_trp.c \
         $(GPLOT_DIR)/src/unix/tcgeta.c \
         $(GPLOT_DIR)/src/unix/tcseta.c \
         $(GPLOT_DIR)/src/unix/tcsetaf.c \
         $(GPLOT_DIR)/src/unix/tistor_put.c \
         $(GPLOT_DIR)/src/g77/getc.c \
         $(GPLOT_DIR)/src/g77/getpid.c \
         $(GPLOT_DIR)/src/g77/malloc.c \
         $(GPLOT_DIR)/src/g77/perror.c \
         $(GPLOT_DIR)/src/g77/sleep.c

FOBJS = ${FSRCS:.F=.o}
COBJS = ${CSRCS:.c=.o}

EXAMPLES = $(EXAMPLES_DIR)/example1 \
	   $(EXAMPLES_DIR)/example2 \
	   $(EXAMPLES_DIR)/example3 \
	   $(EXAMPLES_DIR)/example4

all :		$(GPLOT_LIB) $(EXAMPLES)

$(GPLOT_LIB) :	$(FOBJS) $(COBJS)
		ar rsv $@ $?

$(EXAMPLES_DIR)/example1 :	$(EXAMPLES_DIR)/example1.f
				$(FORTRAN) $(FFLAGS) -o $@ $? $(GPLOT_LIB) $(OTHER_LIBS)

$(EXAMPLES_DIR)/example2 :	$(EXAMPLES_DIR)/example2.f
				$(FORTRAN) $(FFLAGS) -o $@ $? $(GPLOT_LIB) $(OTHER_LIBS)

$(EXAMPLES_DIR)/example3 :	$(EXAMPLES_DIR)/example3.f
				$(FORTRAN) $(FFLAGS) -o $@ $? $(GPLOT_LIB) $(OTHER_LIBS)

$(EXAMPLES_DIR)/example4 :	$(EXAMPLES_DIR)/example4.f
				$(FORTRAN) $(FFLAGS) -o $@ $? $(GPLOT_LIB) $(OTHER_LIBS)

clean:
	/bin/rm -vf $(FOBJS) $(COBJS) $(GPLOT_LIB) $(EXAMPLES)

.SUFFIXES:	.c .F .o

.c.o :
	$(CC) $(MACROS) $(CFLAGS) -o $*.o -c $<

.F.o :
	$(FORTRAN) $(MACROS) $(FFLAGS) -o $*.o -c $<
