# Make file for datmiss

# Uncomment to hide makefile commands
.SILENT:

targets:
	@echo "************************************************************"
	@echo "* Targets:"
	@echo "*  datmiss"
	@echo "************************************************************"

######################################################################
# Tools/defines

include ../compile.mak
# CC_OPTS_LOCAL = $(CC_OPTS) -DHOST_LINUX -I.

LDFLAGS = -lm 

DEP_DIR = deps

CC = gcc
FLEX = flex

C_SRCS = \
		convert.c \
		datio.c \
		datmap.c \
		datmiss.c \
		datorb.c \
		datprt.c \
		datutils.c \
		ephdb.c \
		ephio.c \
		geo.c \
		gpstime.c \
		mfree.c \
		minverse.c \
		mmalloc.c \
		mmult.c \
		mtransp.c \
		orbit.c \
		orbitpri.c \
		p_string.c \
		p_trace.c \
		printlog.c \
		ptypemap.c \
		rinex.c \
		rnx_fmt.c \
		rnx_orb3.c \
		rnx_orbi.c \
		rnx_util.c \
		rnxi_obs.c \
		xyztoltp.c

OBJS = $(C_SRCS:.c=.o)

######################################################################
# Targets

datmiss: $(OBJS)
	@echo "Linking into 'datmiss'"
	$(CC) $(OBJS) $(LDFLAGS) -o datmiss

# List path with objects
MYPWD = `pwd`
OBJS_PATH = $(addprefix $(MYPWD)/,$(OBJS))
objlist:
	echo $(OBJS_PATH)

######################################################################
# Compile rules

#...for "C" modules--
%.o: %.c
	@echo "...Compiling    $<" 1>&2
	rm -f $*.o $*.A $*.O
	$(CC) $(CC_OPTS) -o $@ $<

%.c: %.flex
	@echo "...Flexing   $<" 1>&2
	rm -f $@
	if $(FLEX) $(FLEX_FLAGS) -o$@ $< ;\
	then : ; else rm $@ ;exit 1;fi

########################################################################
# Rules for dependency file generation
#
# Generates a *.d file based on a *.c.  *.d is suitable for inclusion in
# a Makefile as a dependencies list.  These files are automatically
# generated every time the source C file is touched. 

$(DEP_DIR)/%.d: %.c
	echo "...Generating dependencies for $*.c" 1>&2
    # if the dependencies directory doesn't exist, then create it
	if [ ! -d $(DEP_DIR) ] ;\
	then \
		mkdir $(DEP_DIR) ; \
	fi 

    # Using the GNU tools, in particular gcc.  The -MM flag causes gcc
    # to output a dependency rule for the given c file The sed script
    # adds the .d file to the dependency rule, so it will be rebuilt
    # when any of the dependent .h files are changed.

	$(CC) -M $(CC_OPTS) $*.c | sed 's#\(.*\).o:#\1.o $(DEP_DIR)/\1.d:#' > $@

#
# Only include dependencies if really necessary.
#
DEPENDENCIES = $(addprefix $(DEP_DIR)/,$(C_SRCS:.c=.d))

ifneq ($(MAKECMDGOALS), del_deps)
  -include $(DEPENDENCIES)
endif

