##################################################################
# dtvmkfs - Make DTV flash filesystem                            #
##################################################################
# $Id: Makefile,v 1.11 2008-10-13 21:42:00 spiff Exp $
# Makefile                                                       #
##################################################################
# Author: Mikkel Holm Olsen (dtv@symlink.dk)                     #
##################################################################
# dtvmkfs is free software; you can redistribute it and/or       #
# modify it under the terms of the GNU General Public License    #
# as published by the Free Software Foundation; either version 2 #
# of the License, or (at your option) any later version.         #
#                                                                #
# dtvmkfs is distributed in the hope that it will be useful,     #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  #
# GNU General Public License for more details.                   #
#                                                                #
# You should have received a copy of the GNU General Public      #
# License along with dtvmkfs; if not, write to the Free Software #
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,         #
# MA  02110-1301  USA                                            #
##################################################################

CC=gcc
MAKE=make
ZLIB_SRC=zlib-1.2.3/
ZLIB=$(ZLIB_SRC)libz.a
UNZIP_SRC=$(ZLIB_SRC)contrib/minizip/
LFLAGS=
CFLAGS=-Wall -I$(UNZIP_SRC) -I$(ZLIB_SRC)
CPPFLAGS=
SOURCES=main.c clopts.c flash.c hex.c dirlist.c zipfile.c \
	filelist.c dtvpack.c number.c
UNZIP_OBJS = $(UNZIP_SRC)unzip.o $(UNZIP_SRC)ioapi.o
PROG=dtvmkfs
OBS=$(SOURCES:.c=.o)

all:	$(PROG)

clean:	
	rm -f *~ *.o *.d $(PROG)

distclean: clean
	make -C $(ZLIB_SRC) clean
	rm -f $(ZLIB_SRC)Makefile
	make -C $(UNZIP_SRC) clean

######################################################################
#
# primary target

$(PROG): $(OBS) $(UNZIP_OBJS) $(ZLIB)
	$(CC) $(CFLAGS) $(LFLAGS) -o $(PROG) $(OBS) $(UNZIP_OBJS) $(ZLIB)

######################################################################
#
# secondary targets:

$(UNZIP_SRC)unzip.o: $(UNZIP_SRC)unzip.c
	make -C $(UNZIP_SRC) unzip.o

$(UNZIP_SRC)ioapi.o: $(UNZIP_SRC)ioapi.c
	make -C $(UNZIP_SRC) ioapi.o

$(ZLIB):
	@$(SHELL) -c 'HERE=`pwd`;cd $(ZLIB_SRC); \
        $(SHELL) ./configure ; cd $(HERE)'
	make -C $(ZLIB_SRC)


######################################################################
#
# .c to .o

%.o:	%.c
	$(CC) $(CFLAGS) -c $<

######################################################################
#
# Automatic dependencies

%.d:	%.c
	@$(SHELL) -ec '$(CC) -MM $(CFLAGS) $< \
        | sed '\''s/\($*\)\.o[ :]*/\1.o $@ : /g'\'' > $@; \
        [ -s $@ ] || rm -f $@'

######################################################################
#
# Include automatic dependencies

-include $(SOURCES:.c=.d)




