# Unix gmake Makefile for VITESS modules
# this is a template
# generated by mmake.pl 
#
# You may call mmake.pl on your Unix system  (Linux, Darwin) to obtain a Makefile,
# or copy this template to Makefile and edit options below.
#
# Then do with GNU make
# make
# make install

INSTDIR = ../MODULES/

# change this to your needs
SUBDIR = Linux

# the macro ALL knows all modules to be compiled

ALL = ascii2bin \
monitor1 \
mon2_div \
mon2_pos \
mon2_posdiv \
mon2_tofwl \
mon2_wldiv \
mon2_kdiv \
mon2_rdiv \
velselect \
writeout \
gener_batch \
lattice_dist \
mirror_coating \
surface_file \
guide_shape \
spin_reset \
capture_flux \
runtime \
chopper_disc \
chopper_fermi \
chopper_fermi_parallel \
collimator_soller \
collimator \
slit \
grid \
source \
spacewindow \
spacewindow_multiple \
space \
lenses \
beamstop \
detector \
eval_elast \
eval_elast2 \
eval_inelast \
frame \
guide \
guide_parallel \
monitorpol_1d \
monitorpol_pos \
monochr_analyser \
polariser_sm \
polariser_sm_parallel \
polariser_he3 \
flipper_coil \
pol_mirror \
collimator_radial \
precessionfield \
sesans_field \
sample_elasticisotr \
sample_inelast \
sample_reflectom \
define_direction \
sample_singcryst \
cas_v40 \
mirror_elliptical \
monitor2D \
rotating_field \
flipper_gradient \
resonator_drabkin \
sample_powder \
sample_s_q \
sample_sans \
sample_environment \
bender \
visual \
sm_ensemble \
sm_ensemble_parallel \
dist_time \
chop_phases \
standard_deviation \
direct_view

# these macros define dependencies

TOOL = init.o general.o message.o softabort.o
ITOOL = intersection.o $(TOOL)
MTOOL = matrix.o $(ITOOL)
MGTOOL = $(MTOOL)
STOOL = sample.o $(MTOOL)
NTOOL = mathvector.o mathmatrix.o mon2D.o $(TOOL)

# edit here to your needs

CFLAGS = -pthread -s -O3 -Wall -Wpointer-arith -Wcast-qual -Wwrite-strings -fomit-frame-pointer -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -Irng
CCOMP = gcc
CC = $(CCOMP) $(CFLAGS)
CPLUSCOMP = g++
CPLUS = $(CPLUSCOMP) $(CFLAGS)
LIBS = -Lrng/Linux -lgslran -lm
GDOPEN = g2_open_gd
GRALIB = -DDO_PNG -DDO_X11 -DDO_GD -DVT_GRAPH -I. -Lrng/Linux -lgslran -I./g2-0.72/include -I./g2-0.72/Linux -L./g2-0.72/Linux -L/usr/local/lib -L/usr/X11R6/lib -lX11 -lg2 -lgd -lpng -lz -lfreetype -lXpm -lttf -lm

# You need not change the rest unless you add modules.
# To do so just add rules for new modules

.KEEP_STATE :

all: $(ALL)

rotating_field : rotating_field.c $(MGTOOL)
	$(CC) -o $@ $^ $(LIBS)

chop_phases : chop_phases.c 
	$(CC) -o $@ $^ $(LIBS)

flipper_coil : flipper_coil.c $(MTOOL)
	$(CC) -o $@ $^ $(LIBS)

mon2_tofwl : mon2_tofwl.c $(TOOL)
	$(CC) -o $@ $^ $(LIBS)

spin_reset : spin_reset.c $(TOOL)
	$(CC) -o $@ $^ $(LIBS)

velselect : velselect.c $(TOOL)
	$(CC) -o $@ $^ $(LIBS)

collimator_radial : collimator_radial.c $(MTOOL)
	$(CC) -o $@ $^ $(LIBS)

bender : bender.c bendtest.c bendchtr.c bendertr.c bender_inter_data.c cpgplot.c $(ITOOL)
	$(CC) -o $@ $^ $(GRALIB)

sample_sans : sample_sans.c $(STOOL)
	$(CC) -o $@ $^ $(LIBS)

detector : detector.c $(MTOOL)
	$(CC) -o $@ $^ $(LIBS)

sample_s_q : sample_s_q.c sq_calc.c $(STOOL)
	$(CC) -o $@ $^ $(LIBS)

collimator : collimator.c $(ITOOL)
	$(CC) -o $@ $^ $(LIBS)

capture_flux : capture_flux.c $(TOOL)
	$(CC) -o $@ $^ $(LIBS)

source : source.c src_modchar.c source_csns.c $(ITOOL)
	$(CC) -o $@ $^ $(LIBS)

guide_parallel : guide_parallel.c threadHelper.c $(MTOOL)
	$(CC) -pthread -o $@ $^ $(LIBS)

frame : frame.c $(MTOOL)
	$(CC) -o $@ $^ $(LIBS)

chopper_disc : chopper_disc.c bender_inter_data.c $(ITOOL)
	$(CC) -o $@ $^ $(LIBS)

ascii2bin : ascii2bin.c $(TOOL)
	$(CC) -o $@ $^ $(LIBS)

mirror_elliptical : mirror_elliptical.c mirrrefl.c $(MTOOL)
	$(CC) -o $@ $^ $(LIBS)

mon2_div : mon2_div.c $(TOOL)
	$(CC) -o $@ $^ $(LIBS)

flipper_gradient : flipper_gradient.c $(MGTOOL)
	$(CC) -o $@ $^ $(LIBS)

pol_mirror : pol_mirror.c $(MTOOL)
	$(CC) -o $@ $^ $(LIBS)

direct_view : direct_view.c 
	$(CC) -o $@ $^ $(LIBS)

mon2_rdiv : mon2_rdiv.c $(TOOL)
	$(CC) -o $@ $^ $(LIBS)

monitor2D : monitor2D.cpp $(NTOOL)
	$(CPLUS) -o $@ $^ $(LIBS)

polariser_sm : polariser_sm.c $(MTOOL)
	$(CC) -o $@ $^ $(LIBS)

monitorpol_1d : monitorpol_1d.c $(MTOOL)
	$(CC) -o $@ $^ $(LIBS)

sesans_field : sesans_field.c $(MTOOL)
	$(CC) -o $@ $^ $(LIBS)

sample_environment : sample_environment.c $(STOOL)
	$(CC) -o $@ $^ $(LIBS)

slit : slit.c $(ITOOL)
	$(CC) -o $@ $^ $(LIBS)

sm_ensemble_parallel : sm_ensemble_parallel.c threadHelper.c cpgplot.c $(MTOOL)
	$(CC) -pthread -o $@ $^ $(GRALIB)

chopper_fermi : chopper_fermi.c $(ITOOL)
	$(CC) -o $@ $^ $(LIBS)

mon2_posdiv : mon2_posdiv.c $(TOOL)
	$(CC) -o $@ $^ $(LIBS)

spacewindow_multiple : spacewindow_multiple.c bender_inter_data.c $(ITOOL)
	$(CC) -o $@ $^ $(LIBS)

sample_reflectom : sample_reflectom.c $(MTOOL)
	$(CC) -o $@ $^ $(LIBS)

resonator_drabkin : resonator_drabkin.c $(MGTOOL)
	$(CC) -o $@ $^ $(LIBS)

spacewindow : spacewindow.c bender_inter_data.c $(ITOOL)
	$(CC) -o $@ $^ $(LIBS)

chopper_fermi_parallel : chopper_fermi_parallel.c threadHelper.c $(ITOOL)
	$(CC) -pthread -o $@ $^ $(LIBS)

sample_inelast : sample_inelast.c $(MTOOL)
	$(CC) -o $@ $^ $(LIBS)

polariser_he3 : polariser_he3.c $(MTOOL)
	$(CC) -o $@ $^ $(LIBS)

lattice_dist : lattice_dist.c $(TOOL)
	$(CC) -o $@ $^ $(LIBS)

eval_elast : eval_elast.c $(MTOOL)
	$(CC) -o $@ $^ $(LIBS)

monitorpol_pos : monitorpol_pos.c $(MTOOL)
	$(CC) -o $@ $^ $(LIBS)

visual : visual.c cpgplot.c $(TOOL)
	$(CC) -o $@ $^ $(GRALIB)

lenses : lenses.c lensetr.c cpgplot.c $(ITOOL)
	$(CC) -o $@ $^ $(GRALIB)

eval_inelast : eval_inelast.c $(MTOOL)
	$(CC) -o $@ $^ $(LIBS)

standard_deviation : standard_deviation.c 
	$(CC) -o $@ $^ $(LIBS)

guide : guide.c $(MTOOL)
	$(CC) -o $@ $^ $(LIBS)

sm_ensemble : sm_ensemble.c cpgplot.c $(MTOOL)
	$(CC) -o $@ $^ $(GRALIB)

writeout : writeout.c $(TOOL)
	$(CC) -o $@ $^ $(LIBS)

runtime : runtime.c $(TOOL)
	$(CC) -o $@ $^ $(LIBS)

polariser_sm_parallel : polariser_sm_parallel.c threadHelper.c $(MTOOL)
	$(CC) -pthread -o $@ $^ $(LIBS)

precessionfield : precessionfield.c magneticmap.c $(MTOOL)
	$(CC) -o $@ $^ $(LIBS)

collimator_soller : collimator_soller.c $(ITOOL)
	$(CC) -o $@ $^ $(LIBS)

gener_batch : gener_batch.c gener_fct.c $(TOOL)
	$(CC) -o $@ $^ $(LIBS)

sample_singcryst : sample_singcryst.c $(MTOOL)
	$(CC) -o $@ $^ $(LIBS)

mon2_pos : mon2_pos.c $(TOOL)
	$(CC) -o $@ $^ $(LIBS)

dist_time : dist_time.c cpgplot.c $(TOOL)
	$(CC) -o $@ $^ $(GRALIB)

beamstop : beamstop.c $(ITOOL)
	$(CC) -o $@ $^ $(LIBS)

eval_elast2 : eval_elast2.c $(MTOOL)
	$(CC) -o $@ $^ $(LIBS)

sample_elasticisotr : sample_elasticisotr.c $(MTOOL)
	$(CC) -o $@ $^ $(LIBS)

monochr_analyser : monochr_analyser.c ma_functions.c ma_geom.c $(MTOOL)
	$(CC) -o $@ $^ $(LIBS)

mirror_coating : mirror_coating.c $(TOOL)
	$(CC) -o $@ $^ $(LIBS)

sample_powder : sample_powder.c $(STOOL)
	$(CC) -o $@ $^ $(LIBS)

grid : grid.c bender_inter_data.c $(ITOOL)
	$(CC) -o $@ $^ $(LIBS)

mon2_kdiv : mon2_kdiv.c $(TOOL)
	$(CC) -o $@ $^ $(LIBS)

mon2_wldiv : mon2_wldiv.c $(TOOL)
	$(CC) -o $@ $^ $(LIBS)

space : space.c $(ITOOL)
	$(CC) -o $@ $^ $(LIBS)

surface_file : surface_file.c $(TOOL)
	$(CC) -o $@ $^ $(LIBS)

cas_v40 : cas_v40.c $(MTOOL)
	$(CC) -o $@ $^ $(LIBS)

guide_shape : guide_shape.c $(TOOL)
	$(CC) -o $@ $^ $(LIBS)

define_direction : define_direction.c $(MTOOL)
	$(CC) -o $@ $^ $(LIBS)

monitor1 : monitor1.c $(TOOL)
	$(CC) -o $@ $^ $(LIBS)

.c.o:
	$(CC) -c $<
.cpp.o:
	$(CPLUS) -c $<

# make install just moves binaries to the correct subdirectory
install:
	a=_$(SUBDIR) ; h=$(INSTDIR) ; for l in $(ALL) ; do mv $$l $$h$$l$$a ; done
	-rm -f *.o

# make Copy does the same, but leave binaries in the SRC directory
Copy:
	a=_$(SUBDIR) ; h=$(INSTDIR) ; for l in $(ALL) ; do cp $$l $$h$$l$$a ; done

# make clean removes objects and binaries from the SRC directory
clean :
	-rm -f *.o $(ALL)
