Changeset View
Changeset View
Standalone View
Standalone View
sys/conf/automation.mk
- This file was added.
# | |||||
# SPDX-License-Identifier: BSD-2-Clause-FreeBSD | |||||
# | |||||
# Copyright (c) 2023 Hans Petter Selasky <hselasky@freebsd.org> | |||||
# | |||||
# Redistribution and use in source and binary forms, with or without | |||||
# modification, are permitted provided that the following conditions | |||||
# are met: | |||||
# 1. Redistributions of source code must retain the above copyright | |||||
# notice, this list of conditions and the following disclaimer. | |||||
# 2. Redistributions in binary form must reproduce the above copyright | |||||
# notice, this list of conditions and the following disclaimer in the | |||||
# documentation and/or other materials provided with the distribution. | |||||
# | |||||
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | |||||
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |||||
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |||||
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |||||
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
# SUCH DAMAGE. | |||||
# | |||||
# $FreeBSD$ | |||||
AUTOMATION_BASE=automation | |||||
CLEANFILES+=\ | |||||
${AUTOMATION_BASE}.txt \ | |||||
${AUTOMATION_BASE}.o | |||||
DEPENDOBJS+=\ | |||||
${AUTOMATION_BASE}.txt \ | |||||
${AUTOMATION_BASE}.o | |||||
AUTOMATION_HEADER=(\ | |||||
echo "/*" ; \ | |||||
echo " * This file was automatically generated. " ; \ | |||||
echo " * Please do not edit. " ; \ | |||||
echo " */ " ; \ | |||||
echo "" ; \ | |||||
echo "\#include <sys/cdefs.h>" ; \ | |||||
echo "\#include <sys/linker_set.h>" ; \ | |||||
echo "" ; \ | |||||
echo "struct sysinit;" ; \ | |||||
echo "" ; \ | |||||
echo "\#define SYSINIT(var) \\" ; \ | |||||
echo "extern struct sysinit var; \\" ; \ | |||||
echo "DATA_WSET(sysinit_set,var)" ; \ | |||||
echo "" ; \ | |||||
echo "\#define SYSUNINIT(var) \\" ; \ | |||||
echo "extern struct sysinit var; \\" ; \ | |||||
echo "DATA_WSET(sysuninit_set,var)" ; \ | |||||
echo "" \ | |||||
) | |||||
# Define hint to make global variables uniq | |||||
CFLAGS+= \ | |||||
-DAUTOMATION_HINT=${.TARGET:C/.*\///g:S/./_/g:S/-/_/g} | |||||
${AUTOMATION_BASE}.o: ${OBJS:N${AUTOMATION_BASE}_sysinit.o} | |||||
@${LD} -T /dev/null -o ${.TARGET} -r ${.ALLSRC} | |||||
${AUTOMATION_BASE}.txt: ${AUTOMATION_BASE}.o | |||||
@${OBJCOPY} -j set_automation -O binary ${.ALLSRC} ${.TARGET} | |||||
${AUTOMATION_BASE}_sysinit.c: ${AUTOMATION_BASE}.txt | |||||
@ ${AUTOMATION_HEADER} > ${.TARGET} | |||||
@cat ${AUTOMATION_BASE}.txt | tr '\0' '\n' | grep -E "^sysinit " | sort -f | ${AWK} '{print "SYSINIT(" $$4 "); /* " $$2 " " $$3 " */"}' >> ${.TARGET} | |||||
@echo "" >> ${.TARGET} | |||||
@cat ${AUTOMATION_BASE}.txt | tr '\0' '\n' | grep -E "^sysuninit " | sort -fr | ${AWK} '{print "SYSUNINIT(" $$4 "); /* " $$2 " " $$3 " */"}' >> ${.TARGET} |