190380Smsmith#!/bin/sh
290380Smsmith# $FreeBSD$
390380Smsmith#
490380Smsmith# Unpack an ACPI CA drop and restructure it to fit the FreeBSD layout
590380Smsmith#
690380Smsmith
798146Siwasakiif [ ! $# -eq 1 ]; then
898146Siwasaki	echo "usage: $0 acpica_archive"
998146Siwasaki	exit
1098146Siwasakifi
1198146Siwasaki
1290380Smsmithsrc=$1
13235945Sjkimwrk="$(realpath .)/_acpi_ca_unpack"
14235945Sjkimdst="$(realpath .)/acpi_ca_destination"
1590380Smsmith
16123333Snjl# files that should keep their full directory path
17231844Sjkimfulldirs="common compiler components include os_specific"
18193529Sjkim
1990380Smsmith# files to remove
20231844Sjkimstripdirs="generate libraries tests tools"
21239340Sjkimstripfiles="Makefile README accygwin.h acefi.h achaiku.h acintel.h	\
22250838Sjkim	aclinux.h acmacosx.h acmsvc.h acnetbsd.h acos2.h acwin.h	\
23252279Sjkim	acwin64.h new_table.txt osfreebsdtbl.c oslinuxtbl.c osunixdir.c	\
24254745Sjkim	osunixmap.c oswindir.c oswintbl.c oswinxf.c readme.txt utclib.c"
25193529Sjkim
26151946Sjkim# include files to canonify
27239340Sjkimsrc_headers="acapps.h acbuffer.h accommon.h acconfig.h acdebug.h	\
28239340Sjkim	acdisasm.h acdispat.h acevents.h acexcep.h acglobal.h achware.h	\
29239340Sjkim	acinterp.h aclocal.h acmacros.h acnames.h acnamesp.h acobject.h	\
30239340Sjkim	acopcode.h acoutput.h acparser.h acpi.h acpiosxf.h acpixf.h	\
31239340Sjkim	acpredef.h acresrc.h acrestyp.h acstruct.h actables.h actbl.h	\
32239340Sjkim	actbl1.h actbl2.h actbl3.h actypes.h acutils.h amlcode.h	\
33239340Sjkim	amlresrc.h platform/acenv.h platform/acfreebsd.h		\
34239340Sjkim	platform/acgcc.h"
35213806Sjkimcomp_headers="aslcompiler.h asldefine.h aslglobal.h aslmessages.h	\
36234623Sjkim	aslsupport.l asltypes.h dtcompiler.h dttemplate.h preprocess.h"
37193529Sjkimplatform_headers="acfreebsd.h acgcc.h"
3890380Smsmith
3990380Smsmith# pre-clean
4090380Smsmithecho pre-clean
41193529Sjkimrm -rf ${wrk} ${dst}
4290380Smsmithmkdir -p ${wrk}
4390380Smsmithmkdir -p ${dst}
4490380Smsmith
4590380Smsmith# unpack
4690380Smsmithecho unpack
4790380Smsmithtar -x -z -f ${src} -C ${wrk}
4890380Smsmith
4990380Smsmith# strip files
5090380Smsmithecho strip
5190380Smsmithfor i in ${stripdirs}; do
52209746Sjkim	find ${wrk} -name ${i} -type d -print | xargs rm -r
5390380Smsmithdone
5490380Smsmithfor i in ${stripfiles}; do
55151946Sjkim	find ${wrk} -name ${i} -type f -delete
5690380Smsmithdone
5790380Smsmith
58193529Sjkim# copy files
59123333Snjlecho copying full dirs
60123333Snjlfor i in ${fulldirs}; do
61209746Sjkim	find ${wrk} -name ${i} -type d -print | xargs -J % mv % ${dst}
62123333Snjldone
63193529Sjkimecho copying remaining files
64209746Sjkimfind ${wrk} -type f -print | xargs -J % mv % ${dst}
6590380Smsmith
66151604Sobrien# canonify include paths
67151946Sjkimfor H in ${src_headers}; do
68220663Sjkim	find ${dst} -name "*.[chly]" -type f -print |	\
69193529Sjkim	xargs sed -i "" -e "s|[\"<]$H[\">]|\<contrib/dev/acpica/include/$H\>|g"
70151946Sjkimdone
71151946Sjkimfor H in ${comp_headers}; do
72235945Sjkim	find ${dst}/common ${dst}/compiler ${dst}/components \
73235945Sjkim	    -name "*.[chly]" -type f |	\
74151946Sjkim	xargs sed -i "" -e "s|[\"<]$H[\">]|\<contrib/dev/acpica/compiler/$H\>|g"
75151946Sjkimdone
76193529Sjkimfor H in ${platform_headers}; do
77209746Sjkim	find ${dst}/include/platform -name "*.h" -type f -print |	\
78193529Sjkim	xargs sed -i "" -e "s|[\"<]$H[\">]|\<contrib/dev/acpica/include/platform/$H\>|g"
79193529Sjkimdone
80151604Sobrien
8190380Smsmith# post-clean
8290380Smsmithecho post-clean
8398146Siwasakirm -rf ${wrk}
84114244Snjl
85114244Snjl# assist the developer in generating a diff
86228110Sjkimecho "Directories you may want to 'svn diff':"
87228110Sjkimecho "    sys/contrib/dev/acpica sys/dev/acpica \\"
88228110Sjkimecho "    sys/amd64/acpica sys/i386/acpica sys/ia64/acpica sys/x86/acpica \\"
89228110Sjkimecho "    sys/amd64/include sys/i386/include sys/ia64/include \\"
90228110Sjkimecho "    sys/boot sys/conf sys/modules/acpi usr.sbin/acpi"
91