summaryrefslogblamecommitdiffstats
path: root/config-figure-this-out-for-me.mk
blob: 0ba409ec58c8129b249eabba1f20cde3474fd5bb (plain) (tree)
1
2
3
4
5
6
7
8
9
10
                                                     






                                                

                                                                                           



                                                                                                    
                                                                                          
















                                                                                                                           
                               





                                               



















                                                                                     




















                                                                                                       
# See LICENSE file for copyright and license details.
BASECONFIG !=\
	set -e; \
	if test -n "$(BASECONFIG)"; then \
		printf '%s\n' "$(BASECONFIG)"; \
	else \
		rm -f -- .config.mk.tmp; \
		(set -e; \
			e="$$(printf '\033\n')"; \
			sed 's/^[[:space:]]*DOWNLOAD[[:space:]]*=/'"$$e"'&/' < config.mk; \
			for testscript in */what-architecture-am-i-using; do \
				if test "$$testscript" = "util/what-architecture-am-i-using"; then \
					continue; \
				fi; \
				os="$$(dirname -- "$$testscript" | tr '[a-z]' '[A-Z]')"; \
				support="$${os}_SUPPORT"; \
				q=\'; \
				printf '%s_ != test -z "$$(%s_)" || printf %s%%s\\n%s "$$(%s)"\n' \
				       "$$support"        "$$support"      $$q  $$q      "$$support"; \
				printf '%s !=\\\n' \
				       "$$support"; \
				printf '\tif test -n "$$(%s_)"; then \\\n' \
				                        "$$support"; \
				printf '\t\tprintf '\''%%s\\n'\'' "$$(%s_)"; \\\n' \
				                                     "$$support"; \
				printf '\telse \\\n'; \
				printf '\t\tset +e; \\\n'; \
				printf '\t\t%s false >/dev/null 2>&1; \\\n' \
				           "$${testscript}"; \
				printf '\t\tif test $$$$? -lt 2; then printf %syes\\n%s; else printf %sno\\n%s; fi; \\\n' \
				                                             $$q     $$q             $$q    $$q; \
				printf '\tfi\n'; \
			done; \
		) > .config.mk.tmp; \
		printf '%s\n' .config.mk.tmp; \
	fi;

include $(BASECONFIG)

HAVE_BUILTIN_FFSLL !=\
	testmk=.a-$$$$.tmp; \
	testbin=.b-$$$$.tmp; \
	testsrc=.c-$$$$.tmp.c; \
	printf 'int main() {return !(1' > $$testsrc; \
	printf ' && __builtin_ffsll(%s) == %s' 0 0 1 1 2 2 4 3 0x58 4 >> $$testsrc; \
	printf ');}\n' >> $$testsrc; \
	(set -e; \
		printf '.POSIX:\n'; \
		cat -- $(BASECONFIG); \
		printf '\nall:\n'; \
		printf '\t$$(CC) -o %s %s\n' "$$testbin" "$$testsrc"; \
	) > $$testmk; \
	if (make -f $$testmk all && ./$$testbin) 2>/dev/null >/dev/null; then \
		printf '%s\n' -DHAVE_BUILTIN_FFSLL; \
	fi; \
	rm -f -- $$testmk $$testbin $$testsrc;

CPPFLAGS += $(HAVE_BUILTIN_FFSLL)

DOWNLOAD !=\
	if test -n "$(DOWNLOAD)"; then printf '%s\n' "$(DOWNLOAD)"; \
	elif curl --version >/dev/null 2>&1; then printf 'curl --\n'; \
	elif wget --version >/dev/null 2>&1; then printf 'wget -O - --\n'; \
	else printf 'curl --\n'; fi

DEFAULT_OS_SUPPORT_SELECTION != :

SUPPORTED_ARCHES_ != test -z "$(SUPPORTED_ARCHES_)" || printf '%s\n' "$(SUPPORTED_ARCHES)"

SUPPORTED_ARCHES !=\
	if test -n "$(SUPPORTED_ARCHES_)"; then printf '%s\n' "$(SUPPORTED_ARCHES_)"; \
	else util/what-architecture-am-i-using true; fi

DEFAULT_OS_SUPPORT_SELECTION != printf 'no\n'

IMPORTANT_CFLAGS !=\
	printf '%s\n' $(IMPORTANT_CFLAGS) &&\
	if ! printf '%s\n' $(CC) $(CFLAGS) $(IMPORTANT_CFLAGS) | grep '^-std=c..$$' > /dev/null; then \
		sed -n 's/^.*\(-std=c..\).*$$/\1/p' < .config.mk.tmp | sed 1q; \
	fi