File tree Expand file tree Collapse file tree 4 files changed +44
-5
lines changed Expand file tree Collapse file tree 4 files changed +44
-5
lines changed Original file line number Diff line number Diff line change @@ -11,8 +11,5 @@ include build/exports.mk
1111gen/deps.mk ::
1212 ${MSG} " [ GEN] $@ "
1313 @printf ' # %s\n' " $@ " > $@
14- @if build/cc.sh -MD -MP build/empty.c -o gen/.deps.out; then \
15- printf ' _CPPFLAGS += -MD -MP\n' ; \
16- fi >> $@ 2> $@ .log
17- ${VCAT} $@
1814 @printf -- ' -include %s\n' ${OBJS: .o=.d} >> $@
15+ ${VCAT} $@
Original file line number Diff line number Diff line change 1+ #! /bin/sh
2+
3+ # Copyright © Tavian Barnes <[email protected] >4+ # SPDX-License-Identifier: 0BSD
5+
6+ # Add flags to a makefile if a build succeeds
7+
8+ set -eu
9+
10+ FLAGS=$( sed -n ' \|^///|{s|^/// ||; s|[^=]*= ||; p}' " $1 " )
11+
12+ if build/cc.sh " $@ " $FLAGS ; then
13+ sed -n ' s|^/// \(.*=.*\)|\1|p' " $1 "
14+ else
15+ exit 1
16+ fi
Original file line number Diff line number Diff line change @@ -103,7 +103,11 @@ _LDLIBS := ${LDLIBS} ${EXTRA_LDLIBS} ${_LDLIBS}
103103
104104include build/exports.mk
105105
106- gen/flags.mk ::
106+ # Conditionally-supported flags
107+ AUTO_FLAGS := \
108+ gen/flags/deps.mk
109+
110+ gen/flags.mk : ${AUTO_FLAGS}
107111 ${MSG} " [ GEN] $@ "
108112 @printf ' # %s\n' " $@ " > $@
109113 @printf ' _CPPFLAGS := %s\n' " $$ XCPPFLAGS" >> $@
@@ -112,4 +116,18 @@ gen/flags.mk::
112116 @printf ' _LDLIBS := %s\n' " $$ XLDLIBS" >> $@
113117 @printf ' NOLIBS := %s\n' " $$ XNOLIBS" >> $@
114118 @test " ${OS} -${SAN} " ! = FreeBSD-y || printf ' POSTLINK = elfctl -e +noaslr $$@\n' >> $@
119+ @cat ${.ALLSRC} >> $@
115120 ${VCAT} $@
121+ .PHONY : gen/flags.mk
122+
123+ # The short name of the config test
124+ SLUG = ${@:gen/%.mk=%}
125+ # The source file to build
126+ CSRC = build/${SLUG}.c
127+ # The hidden output file name
128+ OUT = ${SLUG:flags/%=gen/flags/.%.out}
129+
130+ ${AUTO_FLAGS} ::
131+ @${MKDIR} ${@ D}
132+ @build/flags-if.sh ${CSRC} -o ${OUT} > $@ 2> $@ .log; \
133+ build/msg-if.sh " [ CC ] ${SLUG} .c" test $$? -eq 0
Original file line number Diff line number Diff line change 1+ // Copyright © Tavian Barnes <[email protected] > 2+ // SPDX-License-Identifier: 0BSD
3+
4+ /// _CPPFLAGS += -MD -MP
5+
6+ int main (void ) {
7+ return 0 ;
8+ }
You can’t perform that action at this time.
0 commit comments