#########################################################################
#
#       MAKEFILE FOR STAND-ALONE XT CODE APPLICATION.  
#
#       EXECUTABLE      is the name of the executable to be created 
#       MAIN            is the .c file containing your main() function 
#       INTERFACES      is a list of the generated C code files
#       APP_OBJS        is a (possibly empty) list of the object code
#                       files that form the non-interface portion of
#                       your application
#
#       In the first three statements, the variables on the right 
#	of the equal sign will be replaced with their corresponding
#       values when the makefile is automatically generated.
#
#       This template is used for makefiles which do not reference 
#       the Ux runtime library.
#
#  	$Date: 2016-08-08 14:24:02 -0400 (Mon, 08 Aug 2016) $ 		$Revision: 31059 $
#########################################################################

CUR_REL_PATH = base/uxsig_lib
PACKAGE := base-uxsig_lib

include ../../config.mk

ifdef ENABLE_NLS
  SUBDIRS = po
endif

INSTALL_APPS = sigxbell errdiag
APPS = $(INSTALL_APPS) uxutils
LIB = libuxsig.a
RESOURCE_FILE := uxutils.rf
INST_INCLUDES = uxsig_lib.h

APPS_OBJS = $(patsubst %,%.o,$(APPS))
LIB_OBJS = uxsig_lib_nls_init.o \
	uxutilsshell.o \
	uxprinter_setup.o \
	uxmsgbox.o \
	uxfileselbox.o \
	uxselbox.o \
	uxpromptbox.o \
	uxAddRemoveDiag.o \
	uxDualSysSelDiag.o \
	printer_setup.o \
	xfunc.o \
	grabImage.o \
	uxcommon_cbf.o\
	output_file_format.o\
	UxXt.o \
	UxMethod.o \
	UxInterf.o

OBJS = $(APPS_OBJS) $(LIB_OBJS)
DEPS = $(patsubst %.o,%.d,$(OBJS))

PRE_CPPFLAGS += -I../antenna_lib -I../fileformats_lib -I../include -I../user_lib
CPPFLAGS	+= -DMOTIF -DXT_CODE -DXOPEN_CATALOG
LDFLAGS += $(LPATH_X11)
LDLIBS  += -lXm -lXt -lX11 -lm $(LSEARCH_BSD)
LDLIBS_uxutils += -lfileformats -lhimath -luser \
            $(LTIFF) $(LJPEG) $(LPNG) -lXpm

UIMX_FILES := $(wildcard *.i)
UIMX_CXXFILES := $(patsubst %.i,%.C,$(APPS))

all: $(LIB_DIR)/$(LIB) $(APPS)
	$(foreach dir,$(SUBDIRS),$(MAKE) -C $(dir) $@;)

post_uimx:
	$(foreach file,$(UIMX_CXXFILES),\
	sed -i.bak -e "s/\"{/_(\"/g" -e "s/}\"/\")/g" $(file);)

clean:
	rm -f *.o *~ *.a *.d *.d.bak UxXt.h $(APPS) $(LIB_DIR)/$(LIB)
	$(foreach dir,$(SUBDIRS),$(MAKE) -C $(dir) $@;)

install: all $(IRIS_INCLUDE) $(IRIS_BIN) $(IRIS_APP_DEFAULTS) $(IRIS_LIB)
	install -m 0664 -o $(IRIS_USER) -g $(IRIS_GROUP) $(INST_INCLUDES) $(IRIS_INCLUDE)
	install -m 0664 -o $(IRIS_USER) -g $(IRIS_GROUP) $(LIB) $(IRIS_LIB)
	install -m 0775 -o $(IRIS_USER) -g $(IRIS_GROUP) $(STRIP_OPT) $(INSTALL_APPS) $(IRIS_BIN)
	$(foreach APP, $(INSTALL_APPS), \
        install -m 0664 $(RESOURCE_FILE) $(SYS_APP_DEFAULTS)/$(APP); \
	install -m 0664 -o $(IRIS_USER) -g $(IRIS_GROUP) \
			$(RESOURCE_FILE) $(IRIS_APP_DEFAULTS)/$(APP);)
	$(foreach dir,$(SUBDIRS),$(MAKE) -C $(dir) $@;)

test:
	$(foreach dir,$(SUBDIRS),$(MAKE) -C $(dir) $@;)

uninstall:
	$(foreach dir,$(SUBDIRS),$(MAKE) -C $(dir) $@;)
	if [ -d $(IRIS_BIN) ]; then \
		cd $(IRIS_BIN) && rm -f $(INSTALL_APPS); fi
	if [ -d $(IRIS_LIB) ]; then cd $(IRIS_LIB) && rm -f $(LIB); fi
	if [ -d $(IRIS_INCLUDE) ]; then \
		cd $(IRIS_INCLUDE) && rm -f $(INST_INCLUDES); fi
	if [ -d $(SYS_APP_DEFAULTS) ]; then \
		cd $(SYS_APP_DEFAULTS) && rm -f $(APPS); fi
	if [ -d $(IRIS_APP_DEFAULTS) ]; then \
		cd $(IRIS_APP_DEFAULTS) && rm -f $(APPS); fi

$(APPS): $(LIB_DIR)/$(LIB)

$(LIB): $(LIB_OBJS)
	rm -f $@; $(AR) -rsc $@ $^

$(OBJS): Makefile

-include $(DEPS)
