# --------------------------------------------------------------- 
# (C) Copyright 2006,2007,                                        
# International Business Machines Corporation                     
# All Rights Reserved.                                            
#                                                                 
# THIS PROGRAM IS PROVIDED UNDER THE TERMS OF THE COMMON PUBLIC   
# LICENSE VERSION 1 ("AGREEMENT"). ANY USE, REPRODUCTION OR       
# DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE  
# OF THIS AGREEMENT.                                              
#                                                                 
# A copy of the Agreement accompanies this distribution, or see   
# <http://www.ibm.com/developerworks/library/os-cpl.html>.        
# --------------------------------------------------------------- 
# PROLOG END TAG zYx                                              

BUILD_DIR ?= ../../bin
BUILD_TOOL := $(BUILD_DIR)/spu-isolated-app

M32BIT := -m32

# The following is used to determine the correct libelf library to link.
# The tests are needed as not all variants of the elfutils-libelf rpm's install
# a .a archive or .so shared library for linking.
LIBELF := $(shell if [ -e /usr/lib/libelf.a ]; then echo "-lelf"; elif [ -e /usr/lib/libelf.so ]; then echo "/usr/lib/libelf.so"; elif [ `find /usr/lib -name libelf.so.* -true`  ]; then find /usr/lib -name "libelf.so.*" | head -1; else find /usr/lib -name "libelf-*.so" | head -1; fi)

CFLAGS := $(M32BIT) -O3 -Wall

CC := gcc
LD := gcc

objects := 	addSectionNames.o addSignature.o buildMemoryImage.o \
	combineSections.o encryptSection.o findSection.o pem2der.o \
	readElf.o readfile.o updatePgmHdr.o writeElf.o

.PHONY:	all clean

all:	$(BUILD_TOOL)

$(BUILD_TOOL):	main.o $(objects)
	mkdir -p $(BUILD_DIR)
	$(LD) $(M32BIT) -s -o $(BUILD_TOOL) main.o $(objects) -lcrypto $(LIBELF)

main.o:	main.c buildSecureApp.h \
	debug.h memoryImage.h myElf.h
	$(CC) $(CFLAGS) -O0 -c -o $@ $<

$(objects):	buildSecureApp.h debug.h memoryImage.h myElf.h

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

