# Makefile - Unified tool - UG
#
SHELL=/usr/bin/sh
XERCESROOTDIR=../../xmlparsers/xerces-c2_0_0-HP11ACC

COMP=$(UGII_BASE_DIR)/ugopen/ufcomp \
	-ac  "+w1 +ESlit -I$(XERCESROOTDIR)/include/" \
	-acc "-Aa -I$(XERCESROOTDIR)/include/"
LINK=$(UGII_BASE_DIR)/ugopen/uflink -d -m \
	-L "-L $(XERCESROOTDIR)/lib -lxerces-c"

PROGRAM_NAME = ut_main

OBJ_FILES_COMMON = ut_getComment.o ut_taskplans_func.o \
	ut_attributelist.o ut_createKFRule.o ut_wave_assembly.o \
	ut_xmlparser.o ut_part_func.o ut_kf_func.o \
	ut_requiredParameter.o ut_parameterGroup.o \
	ut_requiredTag.o ut_taggingGroup.o \
	ut_faceSubdiv.o	ut_xmlvalidator.o ut_system_func.o \
	ut_ops.o ut_toolBody.o

OBJ_FILES_INTERNAL_ONLY = ut_internal_func.o \
	ut_picktaskplan.o ut_picktaskplan_func.o \
	ut_exprs_input.o ut_exprs_input_func.o \
	ut_files.o ut_files_func.o \
	ut_refset.o ut_refset_func.o \
	ut_selection_func.o ut_dialogs.o \
	ut_change_limits_template.o udrt_ufx_gui.o

OBJ_FILES_EXTERNAL_ONLY = ut_external_func.o ut_cmdline_funcs.o

KF2UFUNC_LIB_NAME = udrt_kf2ufunc_lib
OBJ_FILES_KF2UFUNC_LIB = udrt_copy_body.o udrt_bbox_object.o \
	udrt_delete_rule.o udrt_check_object_type.o \
	udrt_askPointStrictlyOnFace.o udrt_refObjectByName.o

default: all

all: internal external kf2ufunc

internal: $(PROGRAM_NAME).o $(OBJ_FILES_COMMON) $(OBJ_FILES_INTERNAL_ONLY)
	$(LINK) -r $(PROGRAM_NAME) $(OBJ_FILES_COMMON) $(OBJ_FILES_INTERNAL_ONLY)
	if [ ! -d ../startup ]; then mkdir ../startup; fi
	mv ut_main.sl ../startup/.

kf2ufunc: $(KF2UFUNC_LIB_NAME).o $(OBJ_FILES_KF2UFUNC_LIB)
	$(LINK) -r -noui $(KF2UFUNC_LIB_NAME) $(OBJ_FILES_KF2UFUNC_LIB)
	if [ ! -d ../startup ]; then mkdir ../startup; fi
	mv udrt_kf2ufunc_lib.sl ../startup/.

external: $(PROGRAM_NAME).o $(OBJ_FILES_COMMON) $(OBJ_FILES_EXTERNAL_ONLY)
	$(LINK) $(PROGRAM_NAME) $(OBJ_FILES_COMMON) $(OBJ_FILES_EXTERNAL_ONLY)
	if [ ! -d ../startup ]; then mkdir ../startup; fi
	mv ut_main ../startup/.

clean:
	rm -f $(PROGRAM_NAME).o $(OBJ_FILES_COMMON) \
	$(OBJ_FILES_INTERNAL_ONLY) $(OBJ_FILES_EXTERNAL_ONLY) \
	$(PROGRAM_NAME) $(PROGRAM_NAME).sl \
	$(KF2UFUNC_LIB_NAME).o $(OBJ_FILES_KF2UFUNC_LIB) \
	*.complog *.errors *.map *.bak *~ core

# The .SILENT target suppresses echoing of commands to std output
.SILENT:

# We use the UG supplied 'ufcomp' routine for compilation. So need the extra
#   code to temporarily store the return value, print out warnings or error msgs
#   from the .complog file and then give the actual return value back to 'make'.
# Without using that dummy 'if' statement (then and else have the same cmds), 
#   'make' will exit as soon as the compilation fails. So we won't get a chance
#   to dump the contents of the .complog file.
.SUFFIXES: .o .c .C .cpp
.c.o :
	(if { $(COMP) $<;} then { UT_RET=$$?;} else { UT_RET=$$?;} fi; \
	cat `ls -1rt *.complog | tail -1`; exit $$UT_RET; )
.C.o :
	(if { $(COMP) $<;} then { UT_RET=$$?;} else { UT_RET=$$?;} fi; \
	cat `ls -1rt *.complog | tail -1`; exit $$UT_RET; )
.cpp.o :
	(if { $(COMP) $<;} then { UT_RET=$$?;} else { UT_RET=$$?;} fi; \
	cat `ls -1rt *.complog | tail -1`; exit $$UT_RET; )
