CC := gcc
CXX := g++
# General setup GNU Makefile for EROS. To be included in all makefiles.  
# Define  makefile variables according to CPU
# MACHEROSD = `uname | sed 's/-//'`   i.e. { AIX HPUX OSF1 ULTRIX }
# 
# Makefile variables set are:
# - Path to Exec, Include, Libs, Obj directories (from EROSBASEREP env. var.)
#     i.e. variables LIB, OBJ, EXE, INC 
#---------------------------------------------------------------------------

# define MACHEROS from uname
MACHEROS := $(shell echo `uname`)
# define the -D option
MACHEROSD := $(shell echo `uname | sed 's/-//'`)

#-
#-     Optimization option different for HP...
ifeq (${MACHEROS},HP-UX)
  O := +O
else
  O := -O
endif
#-
#-   Define Makefile paths
#-  
 PP  := ${EROSBASEREP}/${MACHEROS}/
 LIB := ${PP}/Libs/
 SLB := ${PP}/ShLibs/
 OBJ := ${PP}/Objs/
 EXE := ${PP}/Exec/
 INC := ${EROSBASEREP}/Include/
 CCI := ${INC}/CInc/
 CXI := ${INC}/CxxInc/
#--

#-
#-    Define default compilation flags
#--
ifeq (${MACHEROS},HP-UX)                                    
  CFLAGS   :=  -Aa
  FFLAGS   :=  -Aa -I${INC} -D${MACHEROSD}  
  CPPFLAGS :=  -I${INC} -D${MACHEROSD} \
               -D_INCLUDE_POSIX_SOURCE -D_INCLUDE_XOPEN_SOURCE
else
  FFLAGS   :=  -I${INC} -D${MACHEROSD}  
  CPPFLAGS :=  -I${INC} -D${MACHEROSD}
endif
AR       := ar
ARFLAGS  := -rcs

ifeq ($(CC), gcc)
CFLAGS       := -g -O -Wall -Wpointer-arith \
                -Wmissing-prototypes -Wsynth -I$(INC)
//CXXFLAGS     := $(CFLAGS) -fno-implicit-templates -I$(CXI)
CXXFLAGS     := $(CFLAGS) -I$(CXI)
endif

#- redefine implicit rule. Les .o sont dans $(OBJ).
$(OBJ)%.o:%.c
	$(COMPILE.c) -o $@ $<

$(OBJ)%.o:%.cc
	$(COMPILE.cc) -o $@ $<

$(OBJ)%.o:%.f
	$(COMPILE.f) -o $@ $< 

#OSF1
#LDFC est f77
#LDFCFLAGS est rien

#parfois
#LDFC est cc
#LDFCFLAGS est -ltruc

#------------------------------------------------- End of Makefile.h ------- 
 
all: $(LIB)libPI.a  
$(LIB)libPI.a : $(OBJ)ex_dessin.o $(OBJ)piapplgen.o $(OBJ)piapplx.o $(OBJ)pibwdggen.o $(OBJ)pibwdgx.o $(OBJ)picmap.o $(OBJ)picmapgen.o $(OBJ)picmapx.o $(OBJ)picontainergen.o $(OBJ)picontainerx.o $(OBJ)pidrawwin.o $(OBJ)pifilechogen.o $(OBJ)pifilechox.o $(OBJ)pihisto.o $(OBJ)piimage.o $(OBJ)pimenubargen.o $(OBJ)pimenubarx.o $(OBJ)pimenugen.o $(OBJ)pimenux.o $(OBJ)pimsghandler.o $(OBJ)pioptmenugen.o $(OBJ)pioptmenux.o $(OBJ)pipixmapgen.o $(OBJ)pipixmapx.o $(OBJ)piscdrawwdg.o $(OBJ)pistdwdggen.o $(OBJ)pistdwdgx.o $(OBJ)piwdggen.o $(OBJ)piwdgx.o $(OBJ)piwindowgen.o $(OBJ)piwindowx.o $(OBJ)pixtbase.o 
	ar -rs $@ $?

$(OBJ)ex_dessin.o: ex_dessin.cc ex_dessin.h pisysdep.h pibwdgx.h pibwdggen.h \
 piwdgx.h piwdggen.h pimsghandler.h
$(OBJ)piapplgen.o: piapplgen.cc piapplgen.h pimsghandler.h pisysdep.h \
 picontainerx.h picontainergen.h piwdgx.h piwdggen.h pimenubarx.h \
 pimenubargen.h pimenux.h pimenugen.h
$(OBJ)piapplx.o: piapplx.cc piapplx.h piapplgen.h pimsghandler.h pisysdep.h \
 picontainerx.h picontainergen.h piwdgx.h piwdggen.h pimenubarx.h \
 pimenubargen.h pimenux.h pimenugen.h
$(OBJ)pibwdggen.o: pibwdggen.cc pibwdggen.h pisysdep.h piwdgx.h piwdggen.h \
 pimsghandler.h
$(OBJ)pibwdgx.o: pibwdgx.cc pibwdgx.h pisysdep.h pibwdggen.h piwdgx.h \
 piwdggen.h pimsghandler.h pixtbaseP.h pixtbase.h
$(OBJ)picmap.o: picmap.cc picmap.h pisysdep.h picmapx.h picmapgen.h
$(OBJ)picmapgen.o: picmapgen.cc picmapgen.h pisysdep.h picmapx.h picmap.h
$(OBJ)picmapx.o: picmapx.cc piwdgx.h piwdggen.h pimsghandler.h picmapx.h \
 picmapgen.h pisysdep.h
$(OBJ)picontainergen.o: picontainergen.cc picontainergen.h pisysdep.h \
 piwdgx.h piwdggen.h pimsghandler.h
$(OBJ)picontainerx.o: picontainerx.cc picontainerx.h pisysdep.h \
 picontainergen.h piwdgx.h piwdggen.h pimsghandler.h
$(OBJ)pidrawwin.o: pidrawwin.cc pidrawwin.h pisysdep.h piwindowx.h \
 piwindowgen.h picontainerx.h picontainergen.h piwdgx.h piwdggen.h \
 pimsghandler.h piscdrawwdg.h pibwdgx.h pibwdggen.h
$(OBJ)pifilechogen.o: pifilechogen.cc pifilechogen.h pisysdep.h piwdgx.h \
 piwdggen.h pimsghandler.h
$(OBJ)pifilechox.o: pifilechox.cc pisysdep.h pifilechox.h pifilechogen.h \
 piwdgx.h piwdggen.h pimsghandler.h piwindowx.h piwindowgen.h \
 picontainerx.h picontainergen.h
$(OBJ)pihisto.o: pihisto.cc pihisto.h piscdrawwdg.h pisysdep.h pibwdgx.h \
 pibwdggen.h piwdgx.h piwdggen.h pimsghandler.h \
 $(INC)histos.h $(INC)peida.h \
 $(INC)defs.h $(INC)utils.h \
 $(INC)machine.h \
 $(INC)perrors.h \
 $(INC)exceptions.h
$(OBJ)piimage.o: piimage.cc piimage.h $(INC)cimage.h \
 $(INC)rzimage.h \
 $(INC)rzvect.h \
 $(INC)machine.h $(INC)defs.h \
 $(INC)exceptions.h \
 $(INC)perrors.h \
 $(INC)datatypes.h $(INC)lut.h \
 pisysdep.h pipixmapx.h pipixmapgen.h pibwdgx.h pibwdggen.h piwdgx.h \
 piwdggen.h pimsghandler.h picmap.h picmapx.h picmapgen.h pistdwdgx.h \
 pistdwdggen.h $(INC)imageop.h
$(OBJ)pimenubargen.o: pimenubargen.cc pimenubargen.h pisysdep.h pimenux.h \
 pimenugen.h piwdgx.h piwdggen.h pimsghandler.h piapplx.h piapplgen.h \
 picontainerx.h picontainergen.h pimenubarx.h
$(OBJ)pimenubarx.o: pimenubarx.cc pimenubarx.h pimenubargen.h pisysdep.h \
 pimenux.h pimenugen.h piwdgx.h piwdggen.h pimsghandler.h piapplx.h \
 piapplgen.h picontainerx.h picontainergen.h
$(OBJ)pimenugen.o: pimenugen.cc pimenugen.h pisysdep.h piwdgx.h piwdggen.h \
 pimsghandler.h
$(OBJ)pimenux.o: pimenux.cc pimenux.h pimenugen.h pisysdep.h piwdgx.h \
 piwdggen.h pimsghandler.h
$(OBJ)pimsghandler.o: pimsghandler.cc pimsghandler.h
$(OBJ)pioptmenugen.o: pioptmenugen.cc pioptmenugen.h pisysdep.h \
 picontainerx.h picontainergen.h piwdgx.h piwdggen.h pimsghandler.h \
 pimenux.h pimenugen.h
$(OBJ)pioptmenux.o: pioptmenux.cc pisysdep.h pioptmenux.h pioptmenugen.h \
 picontainerx.h picontainergen.h piwdgx.h piwdggen.h pimsghandler.h \
 pimenux.h pimenugen.h pistdwdgx.h pistdwdggen.h
$(OBJ)pipixmapgen.o: pipixmapgen.cc pipixmapgen.h pisysdep.h pibwdgx.h \
 pibwdggen.h piwdgx.h piwdggen.h pimsghandler.h picmap.h picmapx.h \
 picmapgen.h
$(OBJ)pipixmapx.o: pipixmapx.cc pipixmapx.h pipixmapgen.h pisysdep.h \
 pibwdgx.h pibwdggen.h piwdgx.h piwdggen.h pimsghandler.h picmap.h \
 picmapx.h picmapgen.h
$(OBJ)piscdrawwdg.o: piscdrawwdg.cc piscdrawwdg.h pisysdep.h pibwdgx.h \
 pibwdggen.h piwdgx.h piwdggen.h pimsghandler.h \
 $(INC)generalfit.h \
 $(INC)exceptions.h \
 $(INC)defs.h $(INC)matrix.h \
 $(INC)peida.h $(INC)utils.h \
 $(INC)machine.h \
 $(INC)perrors.h \
 $(INC)ppersist.h \
 $(INC)pclassids.h \
 $(INC)cvector.h
$(OBJ)pistdwdggen.o: pistdwdggen.cc pistdwdggen.h pisysdep.h piwdgx.h \
 piwdggen.h pimsghandler.h
$(OBJ)pistdwdgx.o: pistdwdgx.cc pisysdep.h pistdwdgx.h pistdwdggen.h \
 piwdgx.h piwdggen.h pimsghandler.h
$(OBJ)piwdggen.o: piwdggen.cc piwdggen.h pimsghandler.h picontainergen.h \
 pisysdep.h piwdgx.h
$(OBJ)piwdgx.o: piwdgx.cc piwdgx.h piwdggen.h pimsghandler.h picontainerx.h \
 pisysdep.h picontainergen.h
$(OBJ)piwindowgen.o: piwindowgen.cc piwindowgen.h pisysdep.h picontainerx.h \
 picontainergen.h piwdgx.h piwdggen.h pimsghandler.h
$(OBJ)piwindowx.o: piwindowx.cc piwindowx.h piwindowgen.h pisysdep.h \
 picontainerx.h picontainergen.h piwdgx.h piwdggen.h pimsghandler.h
$(OBJ)pixtbase.o: pixtbase.cc pixtbaseP.h pibwdgx.h pisysdep.h pibwdggen.h \
 piwdgx.h piwdggen.h pimsghandler.h pixtbase.h
$(OBJ)sc_sample.o: sc_sample.cc sc_sample.h pisysdep.h piscdrawwdg.h \
 pibwdgx.h pibwdggen.h piwdgx.h piwdggen.h pimsghandler.h
$(OBJ)pidemo.o: pidemo.cc pidemo.h pidemoup.h \
 $(INC)perrors.h \
 $(INC)exceptions.h \
 $(INC)defs.h \
 $(INC)fitsimage.h \
 $(INC)cimage.h \
 $(INC)rzimage.h \
 $(INC)rzvect.h \
 $(INC)machine.h \
 $(INC)datatypes.h \
 $(INC)fitsheader.h \
 $(INC)fitskeys.h pisysdep.h piapplx.h piapplgen.h \
 pimsghandler.h picontainerx.h picontainergen.h piwdgx.h piwdggen.h \
 pimenubarx.h pimenubargen.h pimenux.h pimenugen.h piwindowx.h \
 piwindowgen.h pioptmenux.h pioptmenugen.h pistdwdgx.h pistdwdggen.h \
 pifilechox.h pifilechogen.h piimage.h $(INC)lut.h \
 pipixmapx.h pipixmapgen.h pibwdgx.h pibwdggen.h picmap.h picmapx.h \
 picmapgen.h pihisto.h piscdrawwdg.h \
 $(INC)histos.h $(INC)peida.h \
 $(INC)utils.h pidrawwin.h
$(OBJ)pidemoup.o: pidemoup.cc  pidemoup.h \
 $(INC)perrors.h \
 $(INC)exceptions.h \
 $(INC)defs.h \
 $(INC)fitsimage.h \
 $(INC)cimage.h \
 $(INC)rzimage.h \
 $(INC)rzvect.h \
 $(INC)machine.h \
 $(INC)datatypes.h \
 $(INC)fitsheader.h \
 $(INC)fitskeys.h \
 $(INC)utils.h $(INC)peida.h 

piapp : $(EXE)piapp 
	
$(EXE)piapp  : $(OBJ)pidemo.o $(OBJ)pidemoup.o \
                $(SLB)libPI.so $(SLB)libpeida.so $(SLB)liberosc.so 
	cc -o $(EXE)piapp $(OBJ)pidemo.o $(OBJ)pidemoup.o \
              -L$(SLB) -lPI -lpeida -lerosc -lgcxx -lXm -lXt -lX11 -lm  

$(OBJ)pitestapp.o: pitestapp.cc pisysdep.h piapplx.h piapplgen.h \
 pimsghandler.h picontainerx.h picontainergen.h piwdgx.h piwdggen.h \
 pimenubarx.h pimenubargen.h pimenux.h pimenugen.h piwindowx.h \
 piwindowgen.h pioptmenux.h pioptmenugen.h pistdwdgx.h pistdwdggen.h \
 pibwdgx.h pibwdggen.h pipixmapx.h pipixmapgen.h picmap.h picmapx.h \
 picmapgen.h pifilechox.h pifilechogen.h ex_dessin.h piimage.h \
 $(INC)cimage.h \
 $(INC)rzimage.h \
 $(INC)rzvect.h \
 $(INC)machine.h $(INC)defs.h \
 $(INC)exceptions.h \
 $(INC)perrors.h \
 $(INC)datatypes.h $(INC)lut.h

pitest : $(EXE)pitest
	
$(EXE)pitest  : $(OBJ)pitestapp.o $(LIB)libPI.a
	g++ -v -o $(EXE)pitest $(OBJ)pitestapp.o -L$(LIB) -lPI -lImages -lOutils -lmath -lXm -lXt -lX11 -lm
