# $Id$
# makefile usado pelo csmake

BUILD_BENCHS=0

# Pacote idl
IDL_DIR = ./idl
IDL_FILES = sga sga-daemon sga-manager
IDL_FILES := $(addsuffix .idl, $(IDL_FILES))
IDL_FILES := $(addprefix $(IDL_DIR)/, $(IDL_FILES))
                                                                                
ifdef WINDIR
  JACORB_DIR = ./csfs/libs/jacorb
  IDL_CMD = $(JACORB_DIR)/idlwin
else
  JACORB_DIR = ./csfs/libs/jacorb
  IDL_CMD = java  -classpath $(JACORB_DIR)/jacorb-idl-compiler-3.5.jar org.jacorb.idl.parser
endif


.PHONY: all clean doc run-tests

all:
    # Gera o executável sgad
	@cd src; tecmake; cd ..

    #Gera os executáveis dos benchmarks
    ifeq ($(BUILD_BENCHS),1)
        # build csbench
        ifeq ("${TEC_SYSNAME}", "Win32")
			@echo ${TEC_SYSNAME}
			@cd benchmarks/csbench; ./build.bat; cd ../..
        else
			@cd benchmarks/csbench; ./build; cd ../..
        endif
        # build iozone
        ifeq ("${TEC_SYSNAME}", "Win32")
			@cd benchmarks/iozone; make Windows; cd ../..
        else
            ifeq ("${TEC_SYSNAME}", "Linux")
				@cd benchmarks/iozone; make linux; cd ../..
            else
                ifeq ("${TEC_SYSNAME}", "AIX")
					@cd benchmarks/iozone; make AIX; cd ../..
                else
                    ifeq ("${TEC_SYSNAME}", "SunOS")
						@cd benchmarks/iozone; make Solaris; cd ../..
                    else
                        ifeq ("${TEC_SYSNAME}", "IRIX64")
							@cd benchmarks/iozone; make IRIX64; cd ../..
                        endif
                    endif
                endif
            endif
        endif
        # build iperf
        ifneq ("${TEC_SYSNAME}", "AIX") 
			@cd benchmarks/iperf; make clean; make config; make; cd ../..
        endif
    endif

clean:
	@rm -rf bin/${TEC_UNAME}
	@rm -rf obj
	@rm -rf src/*.dep
	@rm -rf sgaidl/*

    ifeq ("${TEC_SYSNAME}", "Win32")
		@cd benchmarks/csbench; rm -rf csBench.exe whet.exe *.dep *.wdep; cd ../..
    else
		@cd benchmarks/csbench; rm -rf csBench testUnixBench *.dep *.wdep; cd ../..
    endif

	@cd benchmarks/iozone; make clean; cd ../..

    ifneq ("${TEC_SYSNAME}", "AIX")
		@cd benchmarks/iperf; make clean; cd ../..
    endif

# regra vazia para o csmake
doc run-tests:
    
jacorb-stubs:
	@echo ""
	@echo " ---------------------------------------------------------------"
	@echo " # Compilando arquivos IDL do SGA..."
	@echo " ---------------------------------------------------------------"
	@echo "    + Compilando idl: sga-daemon.idl"
	@( $(IDL_CMD) $(IDL_DIR)/sga-daemon.idl )
	@echo "    + Compilando idl: sga-manager.idl"
	@( $(IDL_CMD) $(IDL_DIR)/sga-manager.idl )
	@echo " # Arquivos IDL do SGA compilados."
	@echo " # Compilando stubs."
	@(javac -classpath . sgaidl/*.java)
	@echo ""
	@echo " # Gerando JAR."
	@(jar -cvf sgaidl.jar sgaidl/*.class)

