freebsd-skq/lib/csu/i386/Makefile
John Baldwin 5944f899a2 Rework r234502 to include a modified CFLAGS along with ACFLAGS.
On most architectures crt objects are compiled in a multiple-step process
so that sed can be run on the generated assembly.  As the final step,
the C compiler generates an object file from the modified assembly output.
Currently this last step uses $CC with only $ACFLAGS.  However, for other
uses in the tree, $ACFLAGS is meant to include assembly-specific compiler
flags that are in addition to $CFLAGS (see default .S.o rules
bsd.suffixes.mk).  In particular, external toolchains may require
additional flags to select a non-default target which will be present
in CFLAGS but not ACFLAGS.  To support this while still mitigating the
issue with CFLAGS described in r234502, include a modified CFLAGS that
excludes "-g" when assembling the modified assembly files.

Note that normally an assembler ($AS) is used to assemble .s flags to
object files (see bsd.suffixes.mk).  However, llvm-based toolchains do
not currently have a stand-alone assembler.

Reviewed by:	imp
Sponsored by:	DARPA / AFRL
Differential Revision:	https://reviews.freebsd.org/D10085
2017-04-07 19:53:14 +00:00

58 lines
1.5 KiB
Makefile

# $FreeBSD$
.PATH: ${.CURDIR:H}/common
SRCS= crti.S crtn.S
OBJS= ${SRCS:N*.h:R:S/$/.o/g}
OBJS+= gcrt1.o crt1.o Scrt1.o
CFLAGS+= -I${.CURDIR:H}/common \
-I${SRCTOP}/lib/libc/include
FILES= ${OBJS}
FILESMODE= ${LIBMODE}
FILESOWN= ${LIBOWN}
FILESGRP= ${LIBGRP}
FILESDIR= ${LIBDIR}
# These FILES qualify as libraries for the purpose of LIBRARIES_ONLY.
.undef LIBRARIES_ONLY
CLEANFILES= ${OBJS} crt1_c.o crt1_s.o gcrt1_c.o Scrt1_c.o
CLEANFILES+= crt1_c.s gcrt1_c.s Scrt1_c.s
# See the comment in lib/csu/common/crtbrand.c for the reason crt1_c.c is not
# directly compiled to .o files.
gcrt1_c.s: crt1_c.c
${CC} ${CFLAGS} -DGCRT -S -o ${.TARGET} ${.CURDIR}/crt1_c.c
sed ${SED_FIX_NOTE} ${.TARGET}
gcrt1_c.o: gcrt1_c.s
${CC} ${CFLAGS:N-g} ${ACFLAGS} -c -o ${.TARGET} gcrt1_c.s
gcrt1.o: gcrt1_c.o crt1_s.o
${LD} ${_LDFLAGS} -o gcrt1.o -r crt1_s.o gcrt1_c.o
crt1_c.s: crt1_c.c
${CC} ${CFLAGS} -S -o ${.TARGET} ${.CURDIR}/crt1_c.c
sed ${SED_FIX_NOTE} ${.TARGET}
crt1_c.o: crt1_c.s
${CC} ${CFLAGS:N-g} ${ACFLAGS} -c -o ${.TARGET} crt1_c.s
crt1.o: crt1_c.o crt1_s.o
${LD} ${_LDFLAGS} -o crt1.o -r crt1_s.o crt1_c.o
${OBJCOPY} --localize-symbol _start1 crt1.o
Scrt1_c.s: crt1_c.c
${CC} ${CFLAGS} -fPIC -DPIC -S -o ${.TARGET} ${.CURDIR}/crt1_c.c
sed ${SED_FIX_NOTE} ${.TARGET}
Scrt1_c.o: Scrt1_c.s
${CC} ${CFLAGS:N-g} ${ACFLAGS} -c -o ${.TARGET} Scrt1_c.s
Scrt1.o: Scrt1_c.o crt1_s.o
${LD} ${_LDFLAGS} -o Scrt1.o -r crt1_s.o Scrt1_c.o
${OBJCOPY} --localize-symbol _start1 Scrt1.o
.include <bsd.lib.mk>