From eea688b71189ebc76a196c2e2382a724ff245453 Mon Sep 17 00:00:00 2001
From: Sascha Wildner <saw@online.de>
Date: Sat, 8 Jul 2017 15:16:13 +0200
Subject: [PATCH] WIP wakecode

---
 Makefile.inc1                           |  2 +-
 sys/dev/acpica/Makefile                 |  9 ++++++---
 sys/platform/pc64/acpica/Makefile       | 25 -------------------------
 sys/platform/pc64/acpica/genwakecode.sh | 15 ---------------
 sys/platform/pc64/conf/files            | 18 ++++++++++++++----
 5 files changed, 21 insertions(+), 48 deletions(-)
 delete mode 100644 sys/platform/pc64/acpica/Makefile
 delete mode 100644 sys/platform/pc64/acpica/genwakecode.sh

diff --git a/Makefile.inc1 b/Makefile.inc1
index 4a8188cfc3..2b7cd60a95 100644
--- a/Makefile.inc1
+++ b/Makefile.inc1
@@ -873,7 +873,7 @@ BSTRAPDIRS2= \
 	usr.bin/mkdep usr.bin/mktemp usr.bin/lorder usr.bin/file2c \
 	usr.bin/tsort usr.bin/tr usr.bin/join usr.bin/wc usr.bin/basename \
 	usr.bin/gencat usr.bin/chflags usr.bin/expand usr.bin/paste \
-	usr.bin/uuencode usr.bin/hexdump \
+	usr.bin/uuencode \
 	usr.bin/cap_mkdb usr.bin/true usr.bin/false \
 	usr.bin/cmp usr.bin/xargs usr.bin/id usr.bin/env usr.bin/dirname \
 	usr.bin/tail usr.bin/unifdef usr.bin/tic \
diff --git a/sys/dev/acpica/Makefile b/sys/dev/acpica/Makefile
index 730a9f2852..4d21f865d5 100644
--- a/sys/dev/acpica/Makefile
+++ b/sys/dev/acpica/Makefile
@@ -111,9 +111,12 @@ SRCS+=	pmtimer.c
 .endif
 CLEANFILES+=	acpi_wakecode.h acpi_wakecode.o acpi_wakecode.bin
 
-acpi_wakecode.h: acpi_wakecode.S
-	${MAKE} -f ${SYSDIR}/${OSACPI_MD_DIR}/Makefile \
-		MAKESRCPATH=${SYSDIR}/${OSACPI_MD_DIR}
+acpi_wakecode.h: acpi_wakecode.bin
+	file2c -sx 'static char wakecode[] = {' '};' < acpi_wakecode.bin > ${.TARGET}
+acpi_wakecode.bin: acpi_wakecode.o
+	objcopy -S -O binary acpi_wakecode.o ${.TARGET}
+
+acpi_wakecode.o: acpi_wakecode.S
 
 SUBDIR=	acpi_asus acpi_dock acpi_fujitsu acpi_hp acpi_panasonic acpi_pvpanic
 SUBDIR+=acpi_sony acpi_thinkpad acpi_toshiba acpi_video acpi_wmi aibs
diff --git a/sys/platform/pc64/acpica/Makefile b/sys/platform/pc64/acpica/Makefile
deleted file mode 100644
index 395793e51a..0000000000
--- a/sys/platform/pc64/acpica/Makefile
+++ /dev/null
@@ -1,25 +0,0 @@
-# $FreeBSD: src/sys/i386/acpica/Makefile,v 1.6 2004/04/13 13:43:11 des Exp $
-#
-
-# Correct path for kernel builds
-# Don't rely on the kernel's .depend file
-.ifdef MAKESRCPATH
-.PATH: ${MAKESRCPATH}
-DEPENDFILE=
-.else
-MAKESRCPATH= ${.CURDIR}
-CLEANFILES= acpi_wakecode.h acpi_wakecode.bin acpi_wakecode.o
-.endif
-CFLAGS+=	-I. -I@
-
-all: acpi_wakecode.h
-
-acpi_wakecode.o: acpi_wakecode.S
-
-acpi_wakecode.bin: acpi_wakecode.o
-	objcopy -S -O binary acpi_wakecode.o acpi_wakecode.bin
-
-acpi_wakecode.h: acpi_wakecode.bin acpi_wakecode.o
-	sh ${MAKESRCPATH}/genwakecode.sh > acpi_wakecode.h
-
-.include <bsd.prog.mk>
diff --git a/sys/platform/pc64/acpica/genwakecode.sh b/sys/platform/pc64/acpica/genwakecode.sh
deleted file mode 100644
index 5090f4a824..0000000000
--- a/sys/platform/pc64/acpica/genwakecode.sh
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/bin/sh
-# $FreeBSD: src/sys/i386/acpica/genwakecode.sh,v 1.1 2002/05/01 21:52:34 peter Exp $
-#
-echo "/* generated from `pwd`/acpi_wakecode.o */"
-echo 'static char wakecode[] = {';
-hexdump -bv acpi_wakecode.bin | \
-    sed -e 's/^[0-9a-f][0-9a-f]*//' -e 's/\([[:digit:]]\{1,\}\) */0\1,/g'
-echo '};'
-
-nm -n acpi_wakecode.o | while read offset dummy what
-do
-    echo "#define ${what}	0x${offset}"
-done
-
-exit 0
diff --git a/sys/platform/pc64/conf/files b/sys/platform/pc64/conf/files
index de170d8f4a..eeb2c151f6 100644
--- a/sys/platform/pc64/conf/files
+++ b/sys/platform/pc64/conf/files
@@ -54,11 +54,21 @@ ${OSACPI_MD_DIR}/acpi_machdep.c		optional        acpi
 ${OSACPI_MD_DIR}/acpi_pstate_machdep.c	optional	acpi
 ${OSACPI_MD_DIR}/acpi_cstate_machdep.c	optional	acpi
 ${OSACPI_MD_DIR}/acpi_wakeup.c		optional        acpi
-acpi_wakecode.h				optional        acpi		\
-	dependency	"$S/${OSACPI_MD_DIR}/acpi_wakecode.S"		\
-	compile-with	"${MAKE} -f $S/${OSACPI_MD_DIR}/Makefile MAKESRCPATH=$S/${OSACPI_MD_DIR}" \
+acpi_wakecode.o				optional	acpi		\
+	dependency	"$S/platform/pc64/acpica/acpi_wakecode.S assym.s" \
+	compile-with	"${NORMAL_S}"					\
 	no-obj no-implicit-rule before-depend				\
-	clean           "acpi_wakecode.h acpi_wakecode.o acpi_wakecode.bin"
+	clean		"acpi_wakecode.o"
+acpi_wakecode.bin			optional	acpi		\
+	dependency	"acpi_wakecode.o"				\
+	compile-with	"${OBJCOPY} -S -O binary acpi_wakecode.o ${.TARGET}" \
+	no-obj no-implicit-rule	before-depend				\
+	clean		"acpi_wakecode.bin"
+acpi_wakecode.h				optional	acpi		\
+	dependency	"acpi_wakecode.bin"				\
+	compile-with	"file2c -sx 'static char wakecode[] = {' '};' < acpi_wakecode.bin > ${.TARGET}" \
+	no-obj no-implicit-rule	before-depend				\
+	clean		"acpi_wakecode.h"
 #
 dev/crypto/aesni/aesencdec_x86_64.S	optional	aesni
 dev/crypto/aesni/aeskeys_x86_64.S	optional	aesni
-- 
2.12.1

