#              This file is part of the New World OS project
#                  Copyright (C) 2005-2007  QRW Software
#            J. Scott Edwards - j.scott.edwards.nwos@gmail.com 
#                       http://www.qrwsoftware.com
#                       http://nwos.sourceforge.com
# 
#  NWOS 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, or (at your option) any later version.  This
#  software is distributed with 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 this package;  see the file COPYING.  If not, write to:
# 
#       Free Software Foundation, Inc.
#       59 Temple Place - Suite 330
#       Boston, MA 02111-1307, USA.
# 
#  $Log: Makefile,v $
#  Revision 1.54  2007/06/23 13:12:01  jsedwards
#  Add 'uninstall' command and add -p to install to preserve times.
#
#  Revision 1.53  2007/06/21 16:24:30  jsedwards
#  Added sha1.o and md5c.o to compress_sparse because it computes the
#  checksum for the output file now.
#
#  Revision 1.52  2007/06/19 18:46:45  jsedwards
#  Removed defines and passing file when building export_c_structs, since
#  public objects file is now separate, there is no need for special stuff
#  when building or running export_c_structs.
#
#  Revision 1.51  2007/05/24 13:25:18  jsedwards
#  Added 'device' object.
#
#  Revision 1.50  2007/05/24 11:47:19  jsedwards
#  Add 'acronym' to objects.
#
#  Revision 1.49  2007/05/10 14:40:58  jsedwards
#  Add "NO_INDEX_FILE" define when compiling export_c_structs.
#
#  Revision 1.48  2007/04/26 13:37:47  jsedwards
#  Added identify_disc program.
#
#  Revision 1.47  2007/04/22 15:22:43  jsedwards
#  Add 'financial' object.
#
#  Revision 1.46  2007/04/22 14:27:36  jsedwards
#  Add url object.
#
#  Revision 1.45  2007/03/15 13:47:17  jsedwards
#  Added diff_compressed and patch_compressed programs.
#
#  Revision 1.44  2007/03/09 13:44:30  jsedwards
#  Pass public.obj file to export_c_structs so it doesn't need a disk or
#  partition already in existence.
#
#  Revision 1.43  2007/03/08 13:08:03  jsedwards
#  Changed to create the c_structs.h file using the new 'export_c_structs'
#  program instead of 'convert_csv_to_c_structs'.
#
#  Revision 1.42  2007/02/27 12:25:57  jsedwards
#  Added libobjectify to expand_sparce because it now uses the functions in
#  objectify.c instead of having duplicate copies of some functions.
#
#  Revision 1.41  2007/01/28 16:31:27  jsedwards
#  Added sha1 directory to clean_all.
#
#  Revision 1.40  2007/01/27 17:39:33  jsedwards
#  Added 'verify_file' program.
#
#  Revision 1.39  2007/01/17 14:05:39  jsedwards
#  Add temporary add_password program.
#
#  Revision 1.38  2007/01/17 13:04:40  jsedwards
#  Added log.o to expand_sparse so it can log it's arguments.
#
#  Revision 1.37  2007/01/14 22:18:52  jsedwards
#  Add define HAVE_STDINT_H to CFLAGS so that including the .h file in sha1
#  won't puke.  Add building sha1.o.  And add 'install' target.
#
#  Revision 1.36  2006/12/27 14:15:25  jsedwards
#  Move log functions out of objectify.c and into a new file log.c.
#
#  Revision 1.35  2006/12/25 12:01:49  jsedwards
#  Because prep_disc now includes libobjectify.a it doesn't need to include
#  time_stamp.o anymore.
#
#  Revision 1.34  2006/12/13 14:22:07  jsedwards
#  The prep_disk program now needs libobjectify.
#
#  Revision 1.33  2006/12/09 18:50:36  jsedwards
#  Add number object file.
#
#  Revision 1.32  2006/12/05 14:15:06  jsedwards
#  Add libobjectify to dependencies for check_objects.
#
#  Revision 1.31  2006/12/05 14:00:22  jsedwards
#  Moved big_bang.c to attic, as it should only be run once to create the
#  public objects and then never again.
#
#  Revision 1.30  2006/12/05 12:46:52  jsedwards
#  Removed building of export_0005_to_csv and import_from_0005_csv because
#  they have been moved to the attic.
#
#  Revision 1.29  2006/12/04 04:38:17  jsedwards
#  Changed because prep_disk now needs the time stamp module.
#
#  Revision 1.28  2006/12/02 17:36:12  jsedwards
#  Move to attic.
#
#  Revision 1.27  2006/11/30 01:46:51  jsedwards
#  Removed making of export_0005_to_csv and import_from_0005_csv by default.
#  They should only be used once so there is no need to compile them each
#  time we build.  When needed just type "make export_0005_to_csv
#   import_from_0005_csv".
#
#  Revision 1.26  2006/11/28 13:19:04  jsedwards
#  Changed to use $(MAKE) instead of make in case "make" isn't GNU make.
#
#  Revision 1.25  2006/11/19 13:56:27  jsedwards
#  Added "disc_list" program.
#
#  Revision 1.24  2006/11/17 12:03:38  jsedwards
#  Changed "clean" to only clean local directory, added "clean_all" to clean
#  subdirectories too.
#
#  Revision 1.23  2006/11/11 15:22:50  jsedwards
#  Added reference_list object file.
#
#  Revision 1.22  2006/11/11 12:29:18  jsedwards
#  Update e-mail address to something that works.
#
#  Revision 1.21  2006/11/08 02:18:05  jsedwards
#  Add check_objects program.
#
#  Revision 1.20  2006/11/07 14:10:02  jsedwards
#  Added list_discs program.
#
#  Revision 1.19  2006/11/04 18:54:57  jsedwards
#  Added 'log_disc' program.
#
#  Revision 1.18  2006/11/03 04:16:11  jsedwards
#  Change to generate c_structs.h file using attic/convert_csv_to_c_structs
#  program.
#
#  Revision 1.17  2006/10/26 01:51:22  jsedwards
#  Merged alpha_05_branch back into main trunk.
#
#  Revision 1.16.2.11  2006/10/17 12:41:47  jsedwards
#  Added cleaning of md5 directory.
#
#  Revision 1.16.2.10  2006/10/08 13:47:47  jsedwards
#  Added "check_block_maps" and "disk_usage" programs.
#
#  Revision 1.16.2.9  2006/10/07 12:32:22  jsedwards
#  Added list_files program and added a list of programs for all and clean.
#
#  Revision 1.16.2.8  2006/10/02 18:14:09  jsedwards
#  Made CFLAGS conditional for optimized (default) or debug.
#
#  Revision 1.16.2.7  2006/09/26 20:15:03  jsedwards
#  Added "prep_disk".
#
#  Revision 1.16.2.6  2006/09/18 01:44:41  jsedwards
#  Added "import_file" and "export_file" programs.
#
#  Revision 1.16.2.5  2006/09/17 13:55:02  jsedwards
#  Add "compress_sparse" and "expand_sparse" programs.
#
#  Revision 1.16.2.4  2006/09/17 12:17:12  jsedwards
#  Added "import_from_0005_csv" program.
#
#  Revision 1.16.2.3  2006/09/10 21:17:18  jsedwards
#  Added building of export_0005_to_csv program.
#
#  Revision 1.16.2.2  2006/08/24 12:54:23  jsedwards
#  Added building of md5 sum object file in md5 subdirectory.
#
#  Revision 1.16.2.1  2006/08/18 12:54:44  jsedwards
#  Added new "file" module.
#
#  Revision 1.16  2006/01/10 14:03:53  jsedwards
#  Removed the find_phone app, it's function is done with the "computer" app
#  now.
#
#  Revision 1.15  2006/01/01 19:38:56  jsedwards
#  Removed the "create_phone" app, as it has been incorporated into the
#  "computer" app.
#
#  Revision 1.14  2005/12/31 17:22:37  jsedwards
#  Added "class_definition" and "person" objects.  Changed "create_person"
#  app to simply "computer".
#
#  Revision 1.13  2005/12/31 15:15:08  jsedwards
#  Made an "OBJS" declaration instead of listing them all under dependencies
#  for libobjectify.a.
#
#  Revision 1.12  2005/12/29 16:59:12  jsedwards
#  Added crypto library for Blowfish encryption.
#
#  Revision 1.11  2005/12/27 18:01:13  jsedwards
#  Removed base32.o file (no longer using 64 bit filenames).
#  Added security.o file with password junk in it.
#  Renamed ccd (create_class_definitions) to "big_bang".
#
#  Revision 1.10  2005/12/22 13:29:39  jsedwards
#  Added the find_phone app.
#
#  Revision 1.9  2005/12/21 23:32:45  jsedwards
#  Added create_phone app.
#
#  Revision 1.8  2005/12/21 16:52:47  jsedwards
#  Added phone.o.
#
#  Revision 1.7  2005/12/21 03:45:32  jsedwards
#  Added address and us_state files.
#
#  Revision 1.6  2005/12/11 16:44:18  jsedwards
#  Added language.o file.
#
#  Revision 1.5  2005/12/04 14:01:28  jsedwards
#  Changed to use CFLAGS when compiling the apps.
#
#  Revision 1.4  2005/12/03 23:10:52  jsedwards
#  Added date, name, and word object files.
#
#  Revision 1.3  2005/12/02 20:30:52  jsedwards
#  Added cperson to clean target.
#
#  Revision 1.2  2005/12/02 13:05:59  jsedwards
#  Added building create_person.
#
#  Revision 1.1  2005/11/26 15:13:19  jsedwards
#  Initial version (just builds libobjectify.a and ccd).
#

ifeq ($(type),DEBUG)
CFLAGS=-Wall -g -DHAVE_STDINT_H
else
CFLAGS=-Wall -O3 -DHAVE_STDINT_H
endif

OBJS=acronym.o \
     address.o \
     class_definition.o \
     crc32.o \
     date.o \
     device.o \
     file.o \
     financial.o \
     language.o \
     log.o \
     name.o \
     number.o \
     objectify.o \
     person.o \
     phone.o \
     reference_list.o \
     security.o \
     spelling.o \
     time_stamp.o \
     url.o \
     us_state.o \
     word.o

PROGS=add_password \
      check_block_maps \
      check_objects \
      compress_sparse \
      computer \
      diff_compressed \
      diff_sparse \
      disc_list \
      disk_usage \
      expand_sparse \
      export_file \
      identify_disc \
      import_file \
      list_discs \
      list_files \
      log_disc \
      patch_compressed \
      prep_disk \
      verify_file

all: c_structs.h $(PROGS)

md5c.o:
	$(MAKE) -C md5
	cp -p md5/md5c.o .

sha1.o:
	$(MAKE) -C sha1
	cp -p sha1/sha1.o .

c_structs.h: export_c_structs
	./export_c_structs > c_structs.h

export_c_structs: md5c.o sha1.o
	gcc ${CFLAGS} -DUSE_PREDEFINED_STRUCTS \
            -o export_c_structs export_c_structs.c objectify.c reference_list.c time_stamp.c \
            crc32.c log.c class_definition.c name.c spelling.c security.c sha1.o md5c.o \
            -lrt -lcrypto 

libobjectify.a: $(OBJS) md5c.o sha1.o
	ar rv libobjectify.a $?


add_password: libobjectify.a add_password.c
	gcc ${CFLAGS} -o $@ add_password.c libobjectify.a -lrt -lcrypto

check_block_maps: objectify_private.h objectify.h check_block_maps.c
	gcc ${CFLAGS} -o $@ check_block_maps.c

check_objects: libobjectify.a objectify_private.h objectify.h check_objects.c
	gcc ${CFLAGS} -o $@ check_objects.c libobjectify.a -lrt -lcrypto

compress_sparse: objectify_private.h objectify.h compress_sparse.c md5c.o sha1.o
	gcc ${CFLAGS} -o $@ compress_sparse.c md5c.o sha1.o

computer: libobjectify.a computer.c
	gcc ${CFLAGS} -o $@ computer.c libobjectify.a -lrt -lcrypto

diff_compressed: objectify_private.h objectify.h diff_compressed.c
	gcc ${CFLAGS} -o $@ diff_compressed.c

diff_sparse: objectify_private.h objectify.h diff_sparse.c
	gcc ${CFLAGS} -o $@ diff_sparse.c

disc_list: libobjectify.a disc_list.c
	gcc ${CFLAGS} -o $@ disc_list.c libobjectify.a -lrt -lcrypto

disk_usage: objectify_private.h objectify.h disk_usage.c
	gcc ${CFLAGS} -o $@ disk_usage.c

expand_sparse: objectify_private.h objectify.h expand_sparse.c libobjectify.a
	gcc ${CFLAGS} -o $@ expand_sparse.c log.o libobjectify.a -lrt -lcrypto

export_file: libobjectify.a export_file.c
	gcc ${CFLAGS} -o $@ export_file.c libobjectify.a -lrt -lcrypto

identify_disc: libobjectify.a identify_disc.c
	gcc ${CFLAGS} -o $@ identify_disc.c libobjectify.a -lrt -lcrypto

import_file: libobjectify.a import_file.c
	gcc ${CFLAGS} -o $@ import_file.c libobjectify.a -lrt -lcrypto

list_discs: libobjectify.a list_discs.c
	gcc ${CFLAGS} -o $@ list_discs.c libobjectify.a -lrt -lcrypto

list_files: libobjectify.a list_files.c
	gcc ${CFLAGS} -o $@ list_files.c libobjectify.a -lrt -lcrypto

log_disc: libobjectify.a log_disc.c
	gcc ${CFLAGS} -o $@ log_disc.c libobjectify.a -lrt -lcrypto

patch_compressed: objectify_private.h objectify.h patch_compressed.c
	gcc ${CFLAGS} -o $@ patch_compressed.c

prep_disk: libobjectify.a config.h prep_disk.c
	gcc ${CFLAGS} -o $@ prep_disk.c libobjectify.a -lrt -lcrypto

verify_file: libobjectify.a verify_file.c
	gcc ${CFLAGS} -o $@ verify_file.c libobjectify.a -lrt -lcrypto


install:
	install -o root -g root -p $(PROGS) /usr/local/bin

uninstall:
	for file in $(PROGS); do rm -f /usr/local/bin/$$file; done

clean:
	rm -f export_c_structs c_structs.h *.o *.a $(PROGS)

clean_all: clean
	$(MAKE) -C md5 clean
	$(MAKE) -C sha1 clean
	$(MAKE) -C attic/convert_c_structs_to_csv clean
