DEBUGGING    = Y
#STATIC       = Y
#FLTK117BUG    = Y
#LARGEFILE    = Y
TARGET        = /usr/local

# compiler names:
# temporarily added -g to gdb debug segmentation fault
#CXX		=g++ -march=i486 -mtune=i686 -Os -pipe -fno-exceptions -fno-rtti -g
CXX		=g++ -march=i486 -mtune=i686 -Os -pipe -fno-exceptions -fno-rtti


# flags C++ compiler libraries to link with:

ifdef LARGEFILE

  LARGEFLAG     = -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
  
else

  LARGEFLAG     =
  
endif    

  
ifdef DEBUGGING

  OPTIM		= -g3 -Wall -Wno-format-y2k -fno-exceptions $(LARGEFLAG)
  CXXFLAGS	= $(OPTIM) -I/usr/X11R6/include -I/usr/local/include -I/usr/include -I/usr/local/include/FL2 -DDEBUGGING
  LDLIBS	= -L/usr/X11R6/lib -lX11 -lXext -lm 
  
else

  OPTIM		= -O3 -Wall -Wno-format-y2k -fno-exceptions -s  $(LARGEFLAG)
  CXXFLAGS	= $(OPTIM) -I/usr/X11R6/include -I/usr/local/include -I/usr/include -I/usr/local/include/FL2 
  LDLIBS	= -L/usr/X11R6/lib -lX11 -lXext -lm -lmcheck 

endif

ifdef STATIC

  LINKFLTK	= -L/usr/lib  -L/usr/local/lib /usr/local/lib/libfltk.a
  
  LINKFLTKHELP  = /usr/local/lib/libfltk_images.a -L/usr/lib -L/usr/local/lib -lpng -lz -ljpeg /usr/local/lib/libfltk.a 

else

  LINKFLTK	= -L/usr/lib  -L/usr/local/lib -lfltk
  
  LINKFLTKHELP  = -L/usr/lib -L/usr/local/lib -lpng -lz -ljpeg -lfltk -lfltk_images  

endif

  FILEEXE   = mfmr
  
  FILECFGEXE = mfmcfg
  
  FILEEXECEXE = mfmexec
  
  FILEMOUNTEXE = mfmmount
  
  FILERENAMEEXE = mfmrename
  
  FILEBURNEXE = mfmburn  
  
  FILEFINDEXE = mfmfind
  
  FILEZIPEXE = mfmzip
  
  FILEHELPEXE = mfmhelp
  

# Be quiet when building...
.SILENT:

# Build commands and filename extensions...
.SUFFIXES:	.c .cxx .h .fl .o


CZZFILES = mfm.cxx mfm_util.cxx mfm_dnd.cxx \
           mfm_main_ui_fluid.cxx mfm_main_ui.cxx \
           mfm_main_scattered_ui.cxx \
           mfm_get_path_ui.cxx mfm_get_path_ui_fluid.cxx \
           fl_file_sort.cxx file_info.cxx \
	   table.cxx mfm_main_table.cxx \
	   mfm_input_ui_fluid.cxx mfm_input_ui.cxx \
	   mfm_confirm_ui_fluid.cxx mfm_confirm_ui.cxx \
	   mfm_attrib_ui_fluid.cxx mfm_attrib_ui.cxx \
	   mfm_stat_ui_fluid.cxx mfm_stat_ui.cxx \
           mfm_dir_ui.cxx mfm_dir_ui_fluid.cxx
           

ifdef FLTK117BUG

  CXXFILES = $(CZZFILES) Fl_Menu.cxx
  
else
  
  CXXFILES = $(CZZFILES)  
           
endif           

	         
CXXCFGFILES = mfmcfg.cxx mfmcfg_ui.cxx mfmcfg_ui_fluid.cxx

CXXEXECFILES = mfmexec.cxx mfmexec_ui.cxx mfmexec_ui_fluid.cxx

CXXMOUNTFILES = mfmmount.cxx mfmmount_ui.cxx mfmmount_ui_fluid.cxx table.cxx

CXXRENAMEFILES = mfmrename.cxx mfmrename_ui.cxx mfmrename_ui_fluid.cxx table.cxx

CXXBURNFILES = mfmburn.cxx mfmburn_ui.cxx mfmburn_ui_fluid.cxx getline2.cxx

CXXFINDFILES = mfmfind.cxx mfmfind_ui.cxx mfmfind_ui_fluid.cxx mfm_confirm_ui_fluid.cxx mfm_confirm_ui.cxx 

CXXZIPFILES = mfmzip.cxx mfmzip_ui.cxx mfmzip_ui_fluid.cxx

CXXHELPFILES = mfmhelp.cxx 
	         
OBJECTS = $(CXXFILES:.cxx=.o)

OBJECTSCFG = $(CXXCFGFILES:.cxx=.o)

OBJECTSEXEC = $(CXXEXECFILES:.cxx=.o)

OBJECTSMOUNT = $(CXXMOUNTFILES:.cxx=.o)

OBJECTSRENAME = $(CXXRENAMEFILES:.cxx=.o)

OBJECTSBURN = $(CXXBURNFILES:.cxx=.o)

OBJECTSFIND = $(CXXFINDFILES:.cxx=.o)

OBJECTSZIP = $(CXXZIPFILES:.cxx=.o)

OBJECTSHELP = $(CXXHELPFILES:.cxx=.o)


all: $(FILEEXE) $(FILECFGEXE) $(FILEEXECEXE) $(FILEMOUNTEXE) $(FILERENAMEEXE) $(FILEBURNEXE) $(FILEFINDEXE) $(FILEZIPEXE) $(FILEHELPEXE)
	echo
	echo In main window, if you don\'t see filelist, please uncomment LARGEFILE option
	echo and recompile program with \"make clean\; make\".
	echo        

cfg: $(FILECFGEXE)

exec: $(FILEEXECEXE)

mount: $(FILEMOUNTEXE)

rename: $(FILERENAMEEXE)

burn: $(FILEBURNEXE)

find: $(FILEFINDEXE)

zip: $(FILEZIPEXE)

help: $(FILEHELPEXE)

$(FILEEXE):    $(OBJECTS)
	echo Linking $@...
	$(CXX) $(CXXFLAGS) -o $@ $(OBJECTS) $(LINKFLTK) $(LDLIBS) 
	
$(FILECFGEXE):    $(OBJECTSCFG)
	echo Linking $@...
	$(CXX) $(CXXFLAGS) -o $@ $(OBJECTSCFG) $(LINKFLTK) $(LDLIBS) 
	
$(FILEEXECEXE):    $(OBJECTSEXEC)
	echo Linking $@...
	$(CXX) $(CXXFLAGS) -o $@ $(OBJECTSEXEC) $(LINKFLTK) $(LDLIBS) 

$(FILEMOUNTEXE):    $(OBJECTSMOUNT)
	echo Linking $@...
	$(CXX) $(CXXFLAGS) -o $@ $(OBJECTSMOUNT) $(LINKFLTK) $(LDLIBS) 

$(FILERENAMEEXE):    $(OBJECTSRENAME)
	echo Linking $@...
	$(CXX) $(CXXFLAGS) -o $@ $(OBJECTSRENAME) $(LINKFLTK) $(LDLIBS) 

$(FILEBURNEXE):    $(OBJECTSBURN)
	echo Linking $@...
	$(CXX) $(CXXFLAGS) -o $@ $(OBJECTSBURN) $(LINKFLTK) $(LDLIBS) 
	
$(FILEFINDEXE):    $(OBJECTSFIND)
	echo Linking $@...
	$(CXX) $(CXXFLAGS) -o $@ $(OBJECTSFIND) $(LINKFLTK) $(LDLIBS) 
	
$(FILEZIPEXE):    $(OBJECTSZIP)
	echo Linking $@...
	$(CXX) $(CXXFLAGS) -o $@ $(OBJECTSZIP) $(LINKFLTK) $(LDLIBS) 
	
$(FILEHELPEXE):    $(OBJECTSHELP)
	echo Linking $@...
	$(CXX) $(CXXFLAGS) -o $@ $(OBJECTSHELP) $(LINKFLTKHELP) $(LDLIBS) 

.c.o:
	echo Compiling $<...
	$(CC) $(CXXFLAGS) -c $<
	
.cc.o:
	echo Compiling $<...
	$(CC) $(CXXFLAGS) -c $<	

.cxx.o:
	echo Compiling $<...
	$(CXX) $(CXXFLAGS) -c $<
	

clean:
	rm -f *.o $(FILEEXE)  $(FILECFGEXE) $(FILEEXECEXE) $(FILEMOUNTEXE) $(FILERENAMEEXE) $(FILEBURNEXE) $(FILEFINDEXE) $(FILEZIPEXE) $(FILEHELPEXE)


install: 

	cp $(FILEEXE)  $(FILECFGEXE) $(FILEEXECEXE) $(FILEMOUNTEXE) $(FILERENAMEEXE) $(FILEBURNEXE) $(FILEFINDEXE) $(FILEZIPEXE) $(FILEHELPEXE) $(TARGET)/bin
	cp mfm.html $(TARGET)/share/doc
        
uninstall: 

	rm $(TARGET)/bin/$(FILEEXE)  $(TARGET)/bin/$(FILECFGEXE) $(TARGET)/bin/$(FILEEXECEXE) 
	rm $(TARGET)/bin/$(FILEMOUNTEXE) $(TARGET)/bin/$(FILERENAMEEXE) $(TARGET)/bin/$(FILEBURNEXE)
	rm $(TARGET)/bin/$(FILEFINDEXE) $(TARGET)/bin/$(FILEZIPEXE) $(TARGET)/bin/$(FILEHELPEXE)
	rm $(TARGET)/share/doc/mfm.html
