diff --git a/commands/Makefile b/commands/Makefile index 94e987cb..8f1b884f 100644 --- a/commands/Makefile +++ b/commands/Makefile @@ -12,10 +12,9 @@ SRCS = CmdSubrs.c CmdAB.c CmdCD.c CmdE.c CmdFI.c \ module: ${MAGICDIR}/readline/readline lib${MODULE}.o +# Delegate this task to the readline/Makefile ${MAGICDIR}/readline/readline: - @if ( ! test -f ${MAGICDIR}/readline/readline ) ; then \ - (cd ${MAGICDIR}/readline; ln -s `ls | grep readline` readline) ; \ - fi + ${MAKE} -C ${MAGICDIR}/readline readline-create-symlinks include ${MAGICDIR}/defs.mak include ${MAGICDIR}/rules.mak diff --git a/readline/Makefile b/readline/Makefile index 5dbf33f5..1ef05d7b 100644 --- a/readline/Makefile +++ b/readline/Makefile @@ -2,7 +2,7 @@ MAGICDIR = .. include ${MAGICDIR}/defs.mak -module: readline readline/libreadline.a readline/libhistory.a +module: readline-create-symlinks libreadline.a libhistory.a depend: @@ -11,17 +11,58 @@ depend: # link has been removed, and code is now just in real directory # "readline". -readline: +# +# The symlink resolves where the source for readline is coming from, +# so it is a well known path ${top_builddir}/readline/readline +# +# For the purpose of #include to work +# +# Then we do an out of tree build in build-readline subdir in $builddir +# +# Then we symlink the output archives inside build-readline to +# ${top_builddir}/readline/lib*.a so they are on a well known path +# for the project to find and link against. +# -readline/libhistory.a: readline/libreadline.a +.PHONY: readline-create-symlinks +readline-create-symlinks: + @if ! test -e readline ; then \ + readline_target_dir=$$(ls | grep readline | grep -v "^readline$$" | tail -n1); \ + if test -d "$${readline_target_dir}" ; then \ + $(LN) -nsf "$${readline_target_dir}" ./readline ; \ + fi; \ + fi -readline/libreadline.a: - @echo --- building GNU readline - (cd readline; CC="${CC}" CFLAGS="${CFLAGS}" LOCAL_DEFS="${READLINE_DEFS}" ./configure --disable-shared ; ${MAKE}) +libhistory.a: build-readline/libhistory.a + @if ! test -e libhistory.a ; then \ + $(LN) -nsf build-readline/libreadline.a libhistory.a ; \ + fi + +libreadline.a: build-readline/libreadline.a + @if ! test -e libreadline.a ; then \ + $(LN) -nsf build-readline/libreadline.a libreadline.a ; \ + fi + +build-readline/libreadline.a build-readline/libhistory.a: readline-create-symlinks build-readline + +.PHONY: build-readline +build-readline: + @if ! test -e build-readline/Makefile ; then \ + echo --- building GNU readline ; \ + $(MKDIR) -p build-readline ; \ + (cd build-readline && CC="${CC}" CFLAGS="${CFLAGS}" LOCAL_DEFS="${READLINE_DEFS}" \ + "../readline/configure" --disable-shared) || exit 1 ; \ + fi + @(cd build-readline && ${MAKE}) || exit 1 clean: - @if ( test -f readline/Makefile ) ; then \ - (cd readline && ${MAKE} distclean) ; \ + @if test -f build-readline/Makefile ; then \ + (cd build-readline && ${MAKE} distclean) ; \ fi - ${RM} readline + @for d in build-readline/doc build-readline/examples build-readline/shlib build-readline ; do \ + test -d "$$d" && $(RMDIR) "$$d" 2>/dev/null ; \ + done ; true + $(RM) libhistory.a + $(RM) libreadline.a + $(RM) readline