MAKEFLAGS += -rR
.SUFFIXES:
.SECONDEXPANSION:

ifndef top_srcdir
__dir_list   = . .. ../.. ../../.. ../../../.. ../../../../..
__dir_list  += ../../../../../.. ../../../../../../.. ../../../../../../../..
__dir_search = $(firstword $(foreach v,$1,$(if $(wildcard $v/$2),$v)) $3)
top_srcdir := $(call __dir_search,$(__dir_list),src/bele.h,NOT_FOUND)
endif

default.targets = all
STUBS = NO_STUBS
include $(top_srcdir)/src/stub/Makefile
STUBS =


# /***********************************************************************
# // powerpc-lzma
# ************************************************************************/

ifneq ($(wildcard $(UPX_LZMADIR)/C/7zip/.),)

STUBS += lzma_d_cf.S lzma_d_cs.S

lzma_d_c%.S : tc_list = powerpc-lzma powerpc-linux.elf default
lzma_d_c%.S : tc_bfdname = elf32-powerpc

tc.powerpc-lzma.gcc      = $(tc.powerpc-linux.elf.gcc)
tc.powerpc-lzma.gcc     += -mcpu=405 -fPIC
tc.powerpc-lzma.gcc     += -Os
tc.powerpc-lzma.gcc     += -ffunction-sections
tc.powerpc-lzma.gcc     += -I$(UPX_LZMADIR)
tc.powerpc-lzma.gcc     += -I$(top_srcdir)/src

lzma_d_c%.S : lzma_d_c.c
	$(call tc,gcc) $(PP_FLAGS) -c $< -o tmp/$T.o
	$(call tc,objstrip) tmp/$T.o
	$(call tc,objcopy) -O binary --only-section .text.LzmaDecode tmp/$T.o tmp/$T.bin
	head -c-4 tmp/$T.bin > tmp/$T.out
	$(call tc,objdump) -b binary -m powerpc -D tmp/$T.out > tmp/$T.out.lst
	$(call tc,bin2h) --mode=gas tmp/$T.out $@

lzma_d_cf.% : PP_FLAGS = -DFAST
lzma_d_cs.% : PP_FLAGS = -DSMALL

endif
