# This is a -*- Makefile -*- fragment.
#
LINUX_SYMCTL_FILES=$(srcdir)/common.symctl $(srcdir)/lib/stubs-syscalls.symctl
symctl.in: $(LINUX_SYMCTL_FILES) \
	   $(srcdir)/config/i386/Linux/gccchecker.symctl \
	   $(srcdir)/config/i386/Linux/gc-gnulibc1.symctl
	if echo $(host) | grep -q libc1; then \
	  cat $(LINUX_SYMCTL_FILES) \
		$(srcdir)/config/i386/Linux/gc-gnulibc1.symctl > $@; \
	else \
	  cat $(LINUX_SYMCTL_FILES) \
		$(srcdir)/config/i386/Linux/gccchecker.symctl > $@; \
	fi

gccchecker.o: $(OBJS) symctl symctl.in
	$(LD) $(LDFLAGS_FOR_CHKR) -o gccchecker.o $(OBJS)
	./symctl -s symctl.in gccchecker.o

# Should only be used by maintainers to quickly install the binary.
update: gccchecker.o
	$(INSTALL_DATA) $< $(DESTDIR)$(libsubdir)

install.specs: $(DESTDIR)$(libsubdir)/specs

$(DESTDIR)$(libsubdir)/specs: Makefile
	sed -e \
	's|:crt1\.o\%s|:\%{!checker:crt1\.o\%s} \%{checker:$(libsubdir)/chkr-crt1.o\%s}|' \
	< `$(CC) --print-file-name=specs` > $@

./specs: Makefile
	sed -e \
	"s|:crt1\.o\%s|:\%{!checker:crt1\.o\%s} \%{checker:$$PWD/chkr-crt1.o\%s}|" \
	< `$(CC) --print-file-name=specs` > $@

#install: $(TARGET) install.dir install.stubs install.common install.specs
#	$(INSTALL_DATA) chkr-crti.o $(DESTDIR)$(libsubdir)
#	echo done.

install.include:
	test -d ./include/asm || mkdir ./include/asm
	test -d ./include/bits || mkdir ./include/bits
	$(INSTALL_DATA) $(srcdir)/$(confdir)/inc-asm-byteorder.h \
	  ./include/asm/byteorder.h
	$(INSTALL_DATA) $(srcdir)/$(confdir)/inc-asm-bitops.h \
	  ./include/asm/bitops.h
	$(INSTALL_DATA) $(srcdir)/$(confdir)/inc-bits-byteswap.h \
	  ./include/bits/byteswap.h
	$(INSTALL_DATA) $(srcdir)/$(confdir)/inc-bits-select.h \
	  ./include/bits/select.h
	$(INSTALL_DATA) $(srcdir)/$(confdir)/inc-ctype.h \
	  ./include/ctype.h

install: $(TARGET) install.dir install.stubs install.include install.specs \
	install.common
	$(INSTALL_DATA) chkr-crt1.o $(DESTDIR)$(libsubdir)
	echo done.
