# Edison Design Group C++ Front End.
# Makefile for utility programs (util directory).
# Makes cfe_daemon_client (used to communicate with edgcpfed),
#       edg_munch   (used to generate proper startup initialization),
#       edg_prelink (dynamic template instantiation prelinker),
#   and edg_decode  (name demangler).
# Uses an ANSI/ISO C++ compiler (that supports at least C++14).
#

CXXFLAGS =

LDFLAGS =

GOPTION =

EXECUTABLES = cfe_daemon_client edg_munch edg_prelink edg_decode

INSTALL_DIR = ../lib

ERROR_FILES = ../src/err_codes.h ../src/err_data.h

.c.o:
	$(CXX) -I../src -c $(CXXFLAGS) $*.c

default: $(EXECUTABLES)

cfe_daemon_client: $(ERROR_FILES) cfe_daemon_client.o
	@echo "Linking cfe_daemon_client:"
	$(CXX) -o cfe_daemon_client $(GOPTION) $(LDFLAGS) cfe_daemon_client.o

edg_munch: $(ERROR_FILES) edg_munch.o
	@echo "Linking edg_munch:"
	$(CXX) -o edg_munch $(GOPTION) $(LDFLAGS) edg_munch.o

edg_prelink: $(ERROR_FILES) edg_prelink.o decode.o
	@echo "Linking edg_prelink:"
	$(CXX) -o edg_prelink $(GOPTION) $(LDFLAGS) edg_prelink.o decode.o

edg_decode: $(ERROR_FILES) edg_decode.o decode.o
	@echo "Linking edg_decode:"
	$(CXX) -o edg_decode $(GOPTION) $(LDFLAGS) edg_decode.o decode.o

$(ERROR_FILES): ../src/error_msg.txt ../src/error_tag.txt
	@(cd ../src; $(MAKE) error_files)

$(INSTALL_DIR)/cfe_daemon_client: cfe_daemon_client
	rm -f $(INSTALL_DIR)/cfe_daemon_client
	cp cfe_daemon_client $(INSTALL_DIR)/cfe_daemon_client
	chmod -w $(INSTALL_DIR)/cfe_daemon_client

$(INSTALL_DIR)/edg_munch: edg_munch
	rm -f $(INSTALL_DIR)/edg_munch
	cp edg_munch $(INSTALL_DIR)/edg_munch
	chmod -w $(INSTALL_DIR)/edg_munch

$(INSTALL_DIR)/edg_prelink: edg_prelink
	rm -f $(INSTALL_DIR)/edg_prelink
	cp edg_prelink $(INSTALL_DIR)/edg_prelink
	chmod -w $(INSTALL_DIR)/edg_prelink

$(INSTALL_DIR)/edg_decode: edg_decode
	rm -f $(INSTALL_DIR)/edg_decode
	cp edg_decode $(INSTALL_DIR)/edg_decode
	chmod -w $(INSTALL_DIR)/edg_decode

install: $(INSTALL_DIR)/cfe_daemon_client $(INSTALL_DIR)/edg_munch \
	$(INSTALL_DIR)/edg_prelink $(INSTALL_DIR)/edg_decode

clean:
	rm -f core a.out include/* *.o

clobber: clean
	rm -f $(EXECUTABLES)

all: clobber default
