# Main build and setup script.

######################
## User configuration:

## Edit the lines acording the instructions.
## If multiple choises, select one putting and removing
## comments (the # symbol).
## Only one choise can be selected at a time.

## 3dfc directory
#DIR=/usuarios/lebe/3dfc/des/res/
DIR = /uzi/3dfc/des/res/

## compiler command line name
CC = g++
#CC = checkerg++

## build flags acording development purpose
## normal
#BUILD = -Wall -mpentium
## optimized
#BUILD = -O3 -Wall -mpentium -ffast-math -fomit-frame-pointer
## debug
BUILD = -g -gstabs -Wall
## profile (after, execute program: gprof foo gmon.out)
#BUILD = -pg -Wall

## memory allocation
## debug with electric-fence (wrap malloc)
#EFENCE = -lefence

## end configuration
######################



.EXPORT_ALL_VARIABLES:



.SUFFIXES:
.SUFFIXES: .o .cc .h .a



LIBS = $(EFENCE)
CFLAGS = $(BUILD) $(LIBS)
CXXFLAGS = $(CFLAGS)
CXX = $(CC)
LDFLAGS = -lbase -llao -L $(DIR)lib
EXAMPLES-DIR = ./doc/examples/bin


# show main instructions
init:
	@echo "Main options:"
	@echo " make dep    - define dependencies"
	@echo " make all    - build object and library files, examples and tools"
	@echo " make clean  - remove all generated files (need bash, ls, find, rm, test)"
	@echo " make backup - create a backup archive (need date, bash, tar, gzip)"
	@echo " make edit   - edit sources with emacs"
#	@echo " make ci     - makes checkin: update files repository (need PRCS)"



# define dependencies
dep:
	cd src/base ; $(CC) *.cc -MM > dep.mak
	cd src/sbase ; $(CC) *.cc -MM > dep.mak
	cd src/lao ; $(CC) *.cc -MM > dep.mak
	cd src/stdcomp ; $(CC) *.cc -MM > dep.mak
	cd $(EXAMPLES-DIR) ; $(CC) *.cc -MM > dep.mak



# build all (start searching examples; build them, if need)
all:	doc-dir

doc-dir:
	cd doc ; make



# clear all generated files
clean: clean-production clean-release

clean-production:
	rm -f *.o *.~?~ *.bak
	for dir in `find -type d`; do\
		rm -f $$dir/*.o $$dir/*.~?~ $$dir/*.bak $$dir/*~;\
	done

clean-release:
	rm -f lib/*.a
	for file in `ls $(EXAMPLES-DIR)`; do\
		if test -x $(EXAMPLES-DIR)/$$file ; then\
			rm -f $(EXAMPLES-DIR)/$$file ;\
		fi\
	done
 


# make a backup archive
backup:
	cd tools ; ./backup.sh



# update PRCS repository
ci:
	cd tools ; ./prcs-checkin.sh



# edit sources
edit:
	emacs ../doc/dbug.txt include/sbase/*.h src/sbase/*.cc &



# format the source code     dbug - don't work!
format:
	cd tools ; ./format-code.sh ../src/lao/*.cc
	cd tools ; ./format-code.sh ../src/sbase/*.cc
	cd tools ; ./format-code.sh ../src/base/*.cc
	cd tools ; ./format-code.sh ../include/lao/*.h
	cd tools ; ./format-code.sh ../include/base/*.h
	cd tools ; ./format-code.sh ../$(EXAMPLES-DIR)/*.cc
