#------------------------------------------------------------------------------#
#                                                                              #
#                                                                              #
# Makefile for all code of MaMA -- a Media editor for FrameMaker documents     #
#                                                                              #
#                                                                              #
#------------------------------------------------------------------------------#

################################################################################
#                                                                              #
# Initialization                                                               #
#                                                                              #
################################################################################

#
# Directory variables
#
NetworkSource = /home/sioux/MAEstro/Source/NetworkProtocol
					# Directory with MAEstro code
VARIANT = Objects.MaMA/
WHICH = MaMA

#
# Source files
#
SOURCES.c += MaMA_filelist.c		# file list functions
SOURCES.c += MaMA_actionlist.c		# action list functions
SOURCES.c += MaMA_editlist.c		# edit list functions
SOURCES.c += MaMA_write.c		# functions for writing to file
SOURCES.c += MaMA_read.c		# functions for reading from file
SOURCES.c += MaMA_buf.c			# functions for writing to buffer
SOURCES.c += MaMA_misc.c		# miscelaneous functions
SOURCES.c += MaMA_perform.c		# functions for link to FrameMaker
SOURCES.c += MaMA_TT.c			# functions for ToolTalk communication
SOURCES.c += MaMA_Xrc.c			# functions for Xresources
SOURCES.c += MaMA_automnt.c		# functions for auto mount directories
X_SOURCES.c += getopt.c			# for scanning commandline params
X_SOURCES.c += xdr.c			# Generated by rpcgen
#
# Choose MaMA_client...c depending on the FrameMaker version you're using !!
#
 SOURCES.c += MaMA_client30.c		# FrameMaker 3.0/3.1A client functions
#SOURCES.c += MaMA_client211.c		# FrameMaker 2.1.1 client functions


#
# include files
#
SOURCES.h += $(MaMAHOME)/MaMA/include/MaMA_include.h
					# all include files
SOURCES.h += $(MaMAHOME)/MaMA/include/MaMA_global.h
					# global definitions
SOURCES.h += $(MaMAHOME)/MaMA/include/MaMA_main_include.h
					# all include files for MaMA_stubs.c
SOURCES.h += $(MaMAHOME)/MaMA/include/MaMA_main_global.h
					# global definitions for MaMA_stubs.c
SOURCES.h += $(MaMAHOME)/MaMA/MaMA_ui.h	# GUI definitions

SOURCES.G = MaMA.G			# GUI data for `gxv`
STUBS.G = MaMA.G

#
# Derived parameters
#
SOURCES = \
	$(SOURCES.G) \
	$(SOURCES.h) \
	$(X_SOURCES.c) \
 	$(MAEstro_SOURCES.c) \
	$(SOURCES.c)

TARGETS.c = \
	$(SOURCES.G:%.G=%_ui.c) \
	$(STUBS.G:%.G=%_stubs.c)

TARGETS.h = \
	$(SOURCES.G:%.G=%_ui.h)

TARGETS.other = \
	$(SOURCES.G:%.G=%.info)

TARGETS = \
	$(TARGETS.other) \
	$(TARGETS.h) \
	$(TARGETS.c)

OBJECTS = \
	$(TARGETS.c:%.c=$(VARIANT)%.o) \
	$(SOURCES.c:%.c=$(VARIANT)%.o) \
 	$(MAEstro_SOURCES.c:./%.c=%.o) \
	$(X_SOURCES.c:%.c=$(VARIANT)%.o)

#
# Compiler flags
#
CC = gcc				# Compile ANSI-C code

CFLAGS = -g 				# C debug mode
GXVFLAGS = -g				# gxv debug mode
GXVFLAGS += -r				# for internationalization
GXVFLAGS += -ansi			# generate ANSI-C code

CPPFLAGS += -I$(GUIDEHOME)/include	# Devguide includes
CPPFLAGS += -I$(OPENWINHOME)/include	# OpenWindows includes
CPPFLAGS += -I$(MaMAHOME)/MaMA/include 	# MaMA includes
CPPFLAGS += -I$(NetworkSource)		# MAEstro messaging system includes
CPPFLAGS += -D$(WHICH)			# define MAIN
CPPFLAGS += -DDEBUG			# define DEBUG

LDFLAGS += -L$(GUIDEHOME)/lib		# Devguide library directory
LDFLAGS += -L$(OPENWINHOME)/lib		# OpenWindow library directory

LDLIBS += -lguidexv			# Devguide xview library
LDLIBS += -lguide 			# Devguide library
LDLIBS += -lxview			# xview library
LDLIBS += -lolgx			# library
LDLIBS += -lX11				# library
LDLIBS += -lXt				# library
LDLIBS += -ltt				# ToolTalk library
LDLIBS += -lce				# classing engine library
LDLIBS += -ldl				# library
LDLIBS += -lrpcsvc			# RPC library

################################################################################
#                                                                              #
# targets                                                                      #
#                                                                              #
################################################################################

objects: $(SOURCES.c) $(TARGETS.c) $(TARGETS.h) $(OBJECTS)
sources: $(SOURCES)
targets: $(SOURCES) $(TARGETS)

MaMA := VARIANT = Objects.MaMA/
MaMA := WHICH = MaMA
MaMA := SOURCES.c += MaMA_link.c
MaMA := MAEstro_SOURCES.c += $(NetworkSource)/MAEstroClient.c
MaMA := MAEstro_SOURCES.c += $(NetworkSource)/MAEstroxdr.c
MaMA := MAEstro_SOURCES.c += $(NetworkSource)/Receiver.c
MaMA := MAEstro_SOURCES.c += $(NetworkSource)/Sender.c
MaMA := MAEstro_SOURCES.c += $(NetworkSource)/rpcModifications.c
MaMA := CPPFLAGS += -I$(NetworkSource)		# MAEstro protocol includes
MaMA := LDFLAGS += -L$(NetworkSource)/libMAEstro.a
					# MAEstro library directory

SaM := VARIANT = Objects.SaM/
SaM := WHICH = SaM

#.KEEP_STATE:

.INIT: Objects.MaMA Objects.SaM

Objects.MaMA Objects.SaM:
	@test -d $@ || mkdir $@

#
# Generate .._ui.c for each .. .G file
#
%_ui.c: %.G
	@echo "--- GXV ..."
	@$(GUIDEHOME)/bin/gxv $(GXVFLAGS) $*

#
# linking the .o files of the sub-directory
#
MaMA SaM: $$(OBJECTS) 
	@echo "--- Linking $@ ..."
	@$(LINK.c) -o $@ $(OBJECTS) $(LDLIBS) #; strip $@

#
# compiling .o files in sub-directory
#
$$(VARIANT)%.o: %.c
	@echo "--- Compiling $< ..."
	@$(COMPILE.c) $< -o $@

#
# Classing Engine info
#
CE: $(CE_FILE)
	@bin.sh/CE.sh

#
# rpcgen
#
include/stdfm_rpc.h: stdfm_rpc.x
	@bin.sh/rpcgen.sh

xdr.c: stdfm_rpc.h
	@echo "--- Generating rpc code ..."
	@rpcgen -c -o xdr.c stdfm_rpc.x

#
# touch .._ui.c for each .. .c file
#
%_ui.h: %.c
	touch $@

#
# touch .._stubs.c for each .. .c file
#
%_stubs.c: %.c
	touch $@

#
# touch .._info.c for each .. .c file
#
%.info: %.c
	touch $@

#
# remove all generated and compiled files
#
clean:
	@echo "--- cleaning up ..."
	$(RM) $(SOURCES.G:%.G=%_ui.c) $(TARGETS.other) $(TARGETS.h) $(OBJECTS) *.BAK *.delta core
