#
# Makefile for SaVi - src directory. Run top-level Makefile instead.
#
# $Id: Makefile,v 1.11 2004/01/17 14:26:31 lloydwood Exp $

include Makefile_defs.$(ARCH)


     SUBDIRS = include
       SHELL = /bin/sh
          RM = /bin/rm -f
          MV = /bin/mv
          CP = /bin/cp

     SAVIBIN = savi-bin
     PROGRAM = $(SAVIBIN).$(MACH)
 INCLUDE_DIR = include

        LIBS = $(TCL_LIBS) $(X11_LIBS) $(OTHER_LIBS) -lm


        SRCS = \
		main.c \
		globals.c \
		tcl_utils.c \
		satCmd.c \
		sats.c \
		modules.c \
		axes.c \
		logo.c \
		orbits.c \
		cones.c \
		footprints.c \
		plane.c \
		earth.c \
		stars.c \
		coverage.c \
		coverage_vis.c \
		fisheye.c \
		time.c \
		Satellite.c \
		gv_init.c \
		satellites.c \
		orbit_utils.c \
		stats_utils.c \
		gv_utils.c \
		utils.c \
		tkPlot.c

    INCLUDES = \
		$(INCLUDE_DIR)/Satellite.h \
		$(INCLUDE_DIR)/constants.h \
		$(INCLUDE_DIR)/coverage_vis.h \
		$(INCLUDE_DIR)/fisheye.h \
		$(INCLUDE_DIR)/globals.h \
		$(INCLUDE_DIR)/gv_utils.h \
		$(INCLUDE_DIR)/orbit_utils.h \
		$(INCLUDE_DIR)/sats.h \
		$(INCLUDE_DIR)/savi.h \
		$(INCLUDE_DIR)/stats_utils.h \
		$(INCLUDE_DIR)/tcl_utils.h \
		$(INCLUDE_DIR)/tkPlot.h \
		$(INCLUDE_DIR)/utils.h


   OTHER_SRCS = Makefile_defs.linux Makefile_defs.irix Makefile_defs.sun \
		Makefile_defs.cygwin Makefile_defs.

#
# commands and flags
#


   GCC_FLAGS = -O2 -Wshadow -Wpointer-arith -Wcast-qual \
	-Wcast-align -Wwrite-strings -Wconversion -Waggregate-return \
	-Wmissing-prototypes -Wmissing-declarations -Wnested-externs
    DEBUGFLAGS = -Wall
#   DEBUGFLAGS = -g -fullwarn
    CFLAGS = $(GCC_FLAGS) $(DEBUGFLAGS) \
		-I$(INCLUDE_DIR) $(TCL_INCLUDES) $(X11_INCLUDES)


#
# derived objects
#
     OBJS = $(SRCS:.c=.o)

#
# targets
#

$(PROGRAM): $(OBJS) version.o
	$(CC) $(CFLAGS) -o $(PROGRAM) $(OBJS) version.o $(LIBS)
	$(MV) $(PROGRAM) ../bin/$(PROGRAM)
	$(RM) ../bin/$(SAVIBIN)
	ln -s ../bin/$(PROGRAM) ../bin/$(SAVIBIN)

all:
	@make $(PROGRAM)
	@$(MAKE_SUBDIRS:target=all)

version.c: FORCE
	@echo "char *Version = \"SaVi was compiled with 'make ARCH=$(ARCH)'\nVersion" `cat ../VERSION`"\nBuilt by $(USER)@$(HOST)$(HOSTNAME), `date`\";" > version.c


objs: $(OBJS)

$(OBJS): $(INCLUDES)

tarfilelist::
	@srcs="Makefile $(SRCS) $(OTHER_SRCS)" ; \
	for i in $$srcs ; do \
	  echo "$(CURRENT_DIR)/$$i" >> $(TOP)/fileslist ; \
	done
	@$(MAKE_SUBDIRS:target=tarfilelist)

clean:
	$(RM) *~ *.o version.c core $(PROGRAM)
	@$(MAKE_SUBDIRS:target=clean)

FORCE:

# macros

MAKE_SUBDIRS = \
	dirs="$(SUBDIRS)" ; \
	for i in $$dirs ; do \
	  (cd $$i; \
	   echo "making" target "in $(CURRENT_DIR)/$$i..."; \
	   $(MAKE) $(MFLAGS) target CURRENT_DIR=$(CURRENT_DIR)/$$i TOP=$(TOP)) ; \
	done
# END
