#
# Makefile for SaVi - src directory. Run top-level Makefile instead.
#
# $Id: Makefile,v 1.23 2006/07/18 17:51:55 lloydwood Exp $

include Makefile_defs_$(ARCH)


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

     SAVIBIN = savi-bin

# We retain . here to avoid cygwin appending .exe
     PROGRAM = $(SAVIBIN).$(ARCH)
 INCLUDE_DIR = ./include


# remove -DNO_ZLIB from end to use zlib from http://www.gzip.org/zlib
# zlib enables transparent gzip compression of dynamic texture scratchfiles.

   GCC_FLAGS = -O2 -DNO_ZLIB

# -lz is for zlib http://www.gzip.org/zlib enables compressed scratchfile textures.
        LIBS = $(TCL_LIBS) $(OTHER_LIBS) -lm -lz


    DEBUGFLAGS = -Wall -Wconversion

# For as many error messages as possible (bar traditional C):
#   DEBUGFLAGS = -Wshadow -Wpointer-arith -Wcast-qual \
#	-Wcast-align -Wwrite-strings -Wconversion -Waggregate-return \
#	-Wmissing-prototypes -Wmissing-declarations -Wnested-externs

# For compiling a binary for use with gdb:
#   DEBUGFLAGS = -g 

# On non-gcc compilers:
#   DEBUGFLAGS = fullwarn

        SRCS = \
		main.c \
		globals.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 \
		utils.c \
		gv_utils.c \
		tcl_utils.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)/utils.h


   OTHER_SRCS = Makefile_defs_ Makefile_defs_linux Makefile_defs_cygwin \
		Makefile_defs_debian Makefile_defs_freebsd \
		Makefile_defs_irix Makefile_defs_sun Makefile_defs_sun4

#
# commands and flags
#
    CFLAGS = $(GCC_FLAGS) $(DEBUGFLAGS) \
		-I$(INCLUDE_DIR) $(TCL_INCLUDES)


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

#
# targets
#

$(PROGRAM): $(OBJS) version.o
	$(CC) $(CFLAGS) -o $(PROGRAM) $(OBJS) version.o $(LIBS)
	$(MV) $(PROGRAM) ../bin/$(PROGRAM)
	$(CP) ../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
