#!/bin/bash

#
# Convert omap headers to use plat except for the headers
# arm compile expects to find under mach
#
# Usage: omap-header-fixup.sh filename1 filename2 filename3 ..
#
# Or to refresh a patch:
# $ git show | diffstat -l | xargs omap-header-fixup.sh

plat_dir="arch/arm/plat-omap/include/plat"

mach_files="clkdev.h gpio.h hardware.h io.h irqs.h memory.h \
smp.h system.h timex.h uncompress.h vmalloc.h"

# Generated with:$ echo $(cd arch/arm/plat-omap/include/plat/ && ls *.h)
plat_files="blizzard.h board-ams-delta.h board.h board-sx1.h board-voiceblue.h \
clkdev.h clockdomain.h clock.h common.h control.h cpu.h dma.h dmtimer.h \
dsp_common.h fpga.h gpio.h gpio-switch.h gpmc.h gpmc-smc91x.h hardware.h \
hwa742.h io.h iommu2.h iommu.h iovmm.h irda.h irqs.h keypad.h lcd_mipid.h \
led.h mailbox.h mcbsp.h mcspi.h memory.h menelaus.h mmc.h mux.h nand.h \
omap1510.h omap16xx.h omap24xx.h omap34xx.h omap44xx.h omap730.h omap7xx.h \
omap850.h omap-alsa.h omap_device.h omapfb.h omap_hwmod.h omap-pm.h onenand.h \
param.h powerdomain.h prcm.h sdrc.h serial.h smp.h sram.h system.h tc.h \
timer-gp.h timex.h uncompress.h usb.h vmalloc.h"

for file in $*; do
	for plat_hdr in $plat_files; do
		is_mach=0
		for mach_hdr in $mach_files; do
			if [ "$plat_hdr" = "$mach_hdr" ]; then
				is_mach=1
			fi
		done
		if [ "$is_mach" -eq 0 ]; then
			old="#include <mach\/$plat_hdr"
			new="#include <plat\/$plat_hdr"
			if [ -f $file ]; then
				sed -i "s/$old/$new/" $file
			fi
		fi
	done
done