# $Id: Makefile,v 1.87 2007/05/03 21:26:51 craig Exp $
# BroadOn Communication Corp

include $(ROOT)/usr/include/make/NGdefs

HOSTTYPE := $(shell uname)
vpath %.c = ../../rvl/os/di

# Large files are bigger than 2G in size.  RVL disks are > 2G in capacity...
ifeq ($(HOSTTYPE), CYGWIN_NT-5.1)
    # Cygwin doesn't have getconf, so must hardcode the proper options
    LARGE_FILE_CFLAGS := -D_FILE_OFFSET_BITS=64
    LARGE_FILE_LDFLAGS := 
else
    LARGE_FILE_CFLAGS := $(shell getconf LFS_CFLAGS)
    LARGE_FILE_LDFLAGS := $(shell getconf LFS_LDFLAGS)
endif


#Build tools and flags
CC = 		gcc
DEFINES =       $(LARGE_FILE_CFLAGS) -D_LARGEFILE64_SOURCE -DNEXT_GEN \
		-D__USE_LARGEFILE -D_LANGUAGE_C

INCS    =       -I$(ROOT)/usr/include -I../../rvl/os/di \
                -I$(ROOT)/usr/include/rvl -I.
CFLAGS =        -Wall -std=c99 $(DEFINES) $(INCS)
#CFLAGS +=       -g -O0
CFLAGS +=       -O2


# Notes:
#                                 tmdIRD      devel PKI      stripped down
# rvl_devel_partition               y             y                n
# rvl_devel_partitionIRD            y             y                y
# rvl_devel_partition (J. Cho)      n             y                n
# rvl_prod_partition                n             n                n
#
# tmdIRD - Uses IRD version of tmd and ticket which restrict the
#          program options that can be used.
# Stripped down - no help, no verbose, no mention of encryption

# Compile Flags
#                                
# rvl_devel_partition               DEVELOPER
# rvl_devel_partitionIRD            DEVELOPER IRD
# rvl_devel_partition (J. Cho)      DEVELOPER JOHN_CHO_HACK
# rvl_prod_partition                PRODUCTION

# The 'JOHN_CHO_HACK' #define is used to create a rvl_devel_partition
# that uses the non-IRD tmd and ticket, but otherwise uses developer
# PKI.

#CFLAGS +=       -DJOHN_CHO_HACK

ifeq ($(HOSTTYPE), CYGWIN_NT-5.1)
    LDFLAGS +=       -Wl,--stack,8388608
endif

LDFLAGS += $(LARGE_FILE_LDFLAGS)

PROGS      =    dvd_raw test_ftello find_sub_file part_to_rvlbin \
                slice random_file decomp_disk img_to_rvlbin \
                aes_file file_pattern corrupt_image make_ndev_partition \
                rvl_devel_partition rvl_devel_partitionIRD rvl_prod_partition \
                dump_partition check_ndev_partition decrypt_rvl_partition \
                bin2include make_production decrypt_rvl_data clsCompose \
                rvl0_image imageCompose
                
PRODUCTS   =    rvl_devel_partition rvl_prod_partition make_ndev_partition \
                decrypt_rvl_partition make_production prepPart genPart \
                rvl_devel_partitionIRD decomp_disk

RVL_PRODUCTS =  rvl_prod_partition make_ndev_partition \
                decrypt_rvl_partition rvl_devel_partitionIRD \
                rvl_devel_partition decomp_disk

TEST_OBJS  =	aes.o aes_api.o aes_imp.o key.o
SRCS       =    aes_api.c aes.c aes_imp.c decomp_common.c decrypt_common.c \
                decrypt_common.c decrypt_rvl_partition.c\
                disk_common.c tool_common.c dvd_raw.c \
                image_superblock.c make_production.c md5.c \
                partition_common.c rvl_partition.c sha1.c \
                slice.c test_rvl_image.c getRoot.c

all:    $(PROGS)

dvd_raw: dvd_raw.o
	 $(CC) $(CFLAGS) -o dvd_raw dvd_raw.o

test_rvl_image: test_rvl_image.o md5.o dvd_low_rvl.o aes.o aes_api.o \
                aes_imp.o sha1.o key.o crypto_stub.o
	$(CC) $(CFLAGS) -o $@ $^

slice: slice.o
	$(CC) $(CFLAGS) -o $@ $^

make_rvl_image: make_rvl_image.o image_superblock.o sha1.o aes.o aes_api.o \
           aes_imp.o md5.o
	$(CC) $(CFLAGS) $^ -o $@

aes_file: aes_file.o aes.o aes_api.o aes_imp.o
	$(CC) $(CFLAGS) $^ -o aes_file

random_file: random_file.o rand.o
	$(CC) $(CFLAGS) -o $@ $^

file_pattern: file_pattern.o
	$(CC) $(CFLAGS) -o $@ $^

make_ndev_partition: make_ndev_partition.o partition_common_prod.o \
                     disk_common.o ndev_common.o getRoot_prod.o \
                     tool_common.o
	$(CC) $(CFLAGS) $^ -o $@

check_ndev_partition: check_ndev_partition.o partition_common_devel.o \
                      md5.o disk_common.o tool_common.o getRoot_devel.o
	$(CC) $(CFLAGS) $^ -o $@

dump_partition: dump_partition.o md5.o
	$(CC) $(CFLAGS) $^ -o $@

test_ftello: test_ftello.o
	$(CC) $(CFLAGS) $^ -o $@

bin2include: bin2include.o
	$(CC) $(CFLAGS) $^ -o $@

decrypt_rvl_partition: decrypt_rvl_partition.o decrypt_common.o sha1.o \
                       aes.o aes_api.o aes_imp.o getRoot_devel.o \
                       disk_common.o tool_common.o
	$(CC) $(CFLAGS) $^ -o $@

decrypt_rvl_data: decrypt_rvl_data.o decrypt_common.o sha1.o \
                  aes.o aes_api.o aes_imp.o
	$(CC) $(CFLAGS) $^ -o $@

make_production: make_production.o disk_common.o tool_common.o
	$(CC) $(CFLAGS) $^ -o $@

decomp_disk: decomp_disk.o decomp_common.o tool_common.o disk_common.o
	$(CC) $(CFLAGS) $^ -o $@

corrupt_image: corrupt_image.o decomp_common.o tool_common.o
	$(CC) $(CFLAGS) $^ -o $@

img_to_rvlbin: img_to_rvlbin.o decomp_common.o ndev_common.o tool_common.o
	$(CC) $(CFLAGS) $^ -o $@

part_to_rvlbin: part_to_rvlbin.o decomp_common.o ndev_common.o disk_common.o \
                tool_common.o
	$(CC) $(CFLAGS) $^ -o $@

clsCompose: clsCompose.o disk_common.o tool_common.o
	$(CC) $(CFLAGS) $^ -o $@

imageCompose: imageCompose.o disk_common.o tool_common.o
	$(CC) $(CFLAGS) $^ -o $@

rvl0_image: rvl0_image.o disk_common.o
	$(CC) $(CFLAGS) $^ -o $@

# rvl_devel_partition needs the AES files because it needs to
# encrypt the title key file.
rvl_devel_partition: rvl_devel_partition.o partition_common_devel.o aes.o \
                     aes_api.o aes_imp.o disk_common.o getRoot_devel.o \
                     tool_common.o
	$(CC) $(CFLAGS) -DDEVELOPER $^ -o $@

rvl_devel_partitionIRD: rvl_devel_partitionIRD.o partition_common_develIRD.o \
                        aes.o aes_api.o aes_imp.o disk_common.o \
                        getRoot_develIRD.o tool_common.o

	$(CC) $(CFLAGS) -DDEVELOPER -DIRD $^ -o $@

rvl_prod_partition: rvl_prod_partition.o partition_common_prod.o \
                    disk_common.o getRoot_prod.o tool_common.o
	$(CC) $(CFLAGS) -DPRODUCTION $^ -o $@

rvl_devel_partition.o: rvl_partition.c 
	$(CC) $(CFLAGS) -c -DDEVELOPER $^ -o $@

rvl_devel_partitionIRD.o: rvl_partition.c 
	$(CC) $(CFLAGS) -c -DDEVELOPER -DIRD $^ -o $@

rvl_prod_partition.o: rvl_partition.c 
	$(CC) $(CFLAGS) -c -DPRODUCTION $^ -o $@

partition_common_devel.o: partition_common.c 
	$(CC) $(CFLAGS) -c -DDEVELOPER $^ -o $@

partition_common_develIRD.o: partition_common.c 
	$(CC) $(CFLAGS) -c -DDEVELOPER -DIRD $^ -o $@

partition_common_prod.o: partition_common.c 
	$(CC) $(CFLAGS) -c -DPRODUCTION $^ -o $@

getRoot_devel.o: getRoot.c 
	$(CC) $(CFLAGS) -c -DDEVELOPER $^ -o $@

getRoot_develIRD.o: getRoot.c 
	$(CC) $(CFLAGS) -c -DDEVELOPER -DIRD $^ -o $@

getRoot_prod.o: getRoot.c 
	$(CC) $(CFLAGS) -c -DPRODUCTION $^ -o $@

find_sub_file: find_sub_file.o disk_common.o
	$(CC) $(CFLAGS) $^ -o $@

.PHONY:  clean clobber depend exports headers install

clean clobber:
	rm -f *.o $(PROGS)

headers:
exports:

install: $(PRODUCTS)
	$(INSTALL) $(PRODUCTS) $(ROOT)/usr/bin/x86

installRVL: $(RVL_PRODUCTS)
	strip rvl_devel_partitionIRD.exe
	$(INSTALL) $(RVL_PRODUCTS) $(REVOLUTION_SDK_ROOT)/x86/bin

depend:
	makedepend -DDEVELOPER -Y -f Makefile $(DEFINES) $(INCS) $(SRCS)

# DO NOT DELETE THIS LINE -- make depend depends on it.

aes_api.o: aes_api.h aes_imp.h
aes.o: bsstypes.h aes.h aes_api.h
aes_imp.o: aes_imp.h
decomp_common.o: disk_format.h
decomp_common.o: decomp_common.h DF_structs.h tool_common.h
decrypt_common.o: aes.h sha1.h image_superblock.h
decrypt_common.o: disk_format.h
decrypt_common.o: aes.h sha1.h image_superblock.h
decrypt_common.o: disk_format.h
decrypt_rvl_partition.o: aes.h sha1.h image_superblock.h
decrypt_rvl_partition.o: disk_format.h
decrypt_rvl_partition.o: devel_key.h
decrypt_rvl_partition.o: decrypt_common.h getRoot.h disk_common.h
decrypt_rvl_partition.o: tool_common.h
disk_common.o: disk_common.h
image_superblock.o: aes.h
image_superblock.o: sha1.h
image_superblock.o: image_superblock.h
make_production.o: disk_format.h
make_production.o: disk_common.h
make_production.o: tool_common.h masterimage.h master_common.h DF_structs.h
md5.o: md5.h
partition_common.o: aes.h sha1.h image_superblock.h
partition_common.o: disk_format.h
partition_common.o: partition_common.h disk_common.h getRoot.h
rvl_partition.o: aes.h sha1.h image_superblock.h
rvl_partition.o: disk_format.h
rvl_partition.o: md5.h
rvl_partition.o: partition_common.h disk_common.h tool_common.h devel_key.h
sha1.o: sha1.h
