whats the difference between shellscript and makefile command invocation?

413 views Asked by At

story

I wrote a Makefile instead of a shellscript to build binary packages for gentoolinux. There are three targets available chroot, system and packages:

chroot: prepares a gentoo stage3 chroot environment, adds my overlay and set my custom profile as default.

system: rebuilds inside chroot with the new useflags and profile definition

packages: builds custom packages which should be available

vim is set as default editor in my profile and depends on dev-util/ctags.

problem

invoking this command in a shellscript or directly in a shell succeeds.

chroot /newroot/rootfs /env.sh emerge -q1 dev-util/ctags

Invoking it via a Makefile fails.

system:
    chroot /newroot/rootfs /env.sh emerge -q1 dev-util/ctags

My env.sh wrapper looks like this

#!/bin/bash

# chroot wrapper for a clean portage environment

if [ -z "${1}" ]; then
  echo "USAGE: ${0} <cmd> [<args>] [..]"
  exit 1
fi

export envArgs="${@}"

bash -c "env-update && source /etc/profile && ${envArgs}"

the error is as follow:

>>> Failed to emerge dev-util/ctags-20161028, Log file:
>>>  '/var/tmp/portage/dev-util/ctags-20161028/temp/build.log'
 * Package:    dev-util/ctags-20161028
 * Repository: gentoo
 * Maintainer: [email protected]
 * USE:        abi_x86_64 amd64 elibc_glibc kernel_linux userland_GNU
 * FEATURES:   preserve-libs sandbox userpriv usersandbox
 * Applying ctags-20161028-automagic-deps.patch ...
 [ ok ]
misc/dist-test-cases: line 9: git: command not found
autoreconf-2.69: Entering directory `.'
autoreconf-2.69: configure.ac: not using Gettext
autoreconf-2.69: running: aclocal --force 
autoreconf-2.69: configure.ac: tracing
autoreconf-2.69: configure.ac: not using Libtool
autoreconf-2.69: running: /usr/bin/autoconf-2.69 --force
autoreconf-2.69: running: /usr/bin/autoheader-2.69 --force
autoreconf-2.69: running: automake --add-missing --copy --force-missing
Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/\${ <-- HERE ([^ \t=:+{}]+)}/ at /usr/bin/automake-1.15 line 3936.
configure.ac:276: installing './compile'
configure.ac:23: installing './config.guess'
configure.ac:23: installing './config.sub'
configure.ac:11: installing './install-sh'
configure.ac:11: installing './missing'
Makefile.am: installing './depcomp'
/usr/share/automake-1.15/am/tags.am: warning: redefinition of 'ctags' ...
/usr/share/automake-1.15/am/program.am: ... 'ctags$(EXEEXT)' previously defined here
Makefile.am:6:   while processing program 'ctags'
autoreconf-2.69: Leaving directory `.'
optlib2c: translating make[1]: to make[1]:.c
cannot open the optlib file: "make[1]:" at ./misc/optlib2c line 220.
optlib2c: translating Entering to Entering.c
cannot open the optlib file: "Entering" at ./misc/optlib2c line 220.
optlib2c: translating directory to directory.c
cannot open the optlib file: "directory" at ./misc/optlib2c line 220.
optlib2c: translating '/var/tmp/portage/dev-util/ctags-20161028/work/ctags-20161028' to '/var/tmp/portage/dev-util/ctags-20161028/work/ctags-20161028'.c
./autogen.sh: line 10: '/var/tmp/portage/dev-util/ctags-20161028/work/ctags-20161028'.c: No such file or directory
optlib2c: translating optlib/CoffeeScript.ctags to optlib/CoffeeScript.c
optlib2c: translating optlib/ctags-optlib.ctags to optlib/ctags-optlib.c
optlib2c: translating optlib/gdbinit.ctags to optlib/gdbinit.c
optlib2c: translating optlib/man.ctags to optlib/man.c
optlib2c: translating optlib/pod.ctags to optlib/pod.c
optlib2c: translating make[1]: to make[1]:.c
cannot open the optlib file: "make[1]:" at ./misc/optlib2c line 220.
optlib2c: translating Leaving to Leaving.c
cannot open the optlib file: "Leaving" at ./misc/optlib2c line 220.
optlib2c: translating directory to directory.c
cannot open the optlib file: "directory" at ./misc/optlib2c line 220.
optlib2c: translating '/var/tmp/portage/dev-util/ctags-20161028/work/ctags-20161028' to '/var/tmp/portage/dev-util/ctags-20161028/work/ctags-20161028'.c
./autogen.sh: line 10: '/var/tmp/portage/dev-util/ctags-20161028/work/ctags-20161028'.c: No such file or directory
 * ERROR: dev-util/ctags-20161028::gentoo failed (prepare phase):
 *   (no error message)
 * 
 * Call stack:
 *     ebuild.sh, line 115:  Called src_prepare
 *   environment, line 381:  Called die
 * The specific snippet of code:
 *       ./autogen.sh || die
 * 
 * If you need support, post the output of `emerge --info '=dev-util/ctags-20161028::gentoo'`,
 * the complete build log and the output of `emerge -pqv '=dev-util/ctags-20161028::gentoo'`.
 * The complete build log is located at '/var/tmp/portage/dev-util/ctags-20161028/temp/build.log'.
 * The ebuild environment file is located at '/var/tmp/portage/dev-util/ctags-20161028/temp/environment'.
 * Working directory: '/var/tmp/portage/dev-util/ctags-20161028/work/ctags-20161028'
 * S: '/var/tmp/portage/dev-util/ctags-20161028/work/ctags-20161028'

 * Messages for package dev-util/ctags-20161028:

 * ERROR: dev-util/ctags-20161028::gentoo failed (prepare phase):
 *   (no error message)
 * 
 * Call stack:
 *     ebuild.sh, line 115:  Called src_prepare
 *   environment, line 381:  Called die
 * The specific snippet of code:
 *       ./autogen.sh || die
 * 
 * If you need support, post the output of `emerge --info '=dev-util/ctags-20161028::gentoo'`,
 * the complete build log and the output of `emerge -pqv '=dev-util/ctags-20161028::gentoo'`.
 * The complete build log is located at '/var/tmp/portage/dev-util/ctags-20161028/temp/build.log'.
 * The ebuild environment file is located at '/var/tmp/portage/dev-util/ctags-20161028/temp/environment'.
 * Working directory: '/var/tmp/portage/dev-util/ctags-20161028/work/ctags-20161028'
 * S: '/var/tmp/portage/dev-util/ctags-20161028/work/ctags-20161028'
../fnordpipe-overlay/Makefile:79: recipe for target 'system' failed
make: *** [system] Error 1

questions

  • what is the difference of both methods (make & shell invocation)?
  • how to follow up with investigation?

reference

if someone wants to reproduce it.

git clone https://github.com/fnordpipe/fnordpipe-overlay
WORKDIR=$(mktemp -d)
OVERLAYDIR="$(pwd)/fnordpipe-overlay"
mkdir $WORKDIR/rootfs/usr/local/fnordpipe-overlay
mount -o bind ./fnordpipe-overlay $WORKDIR/rootfs/usr/local/fnordpipe-overlay
cd $WORKDIR
make -f $OVERLAYDIR/Makefile chroot
make -f $OVERLAYDIR/Makefile system # <- fails in cause of the described problem

chroot ./rootfs /env.sh emerge -q dev-util/ctags # <- succeeds

additional

misc/dist-test-cases: line 9: git: command not found

this is an optional script. when git is installed before ctags it throws an error that there is no .git directory. ctags source is fetched from tarbal not from git. It doesn't matter.

add list of environment variables (inside the chroot) to see if there are conflicts with emerge or the ctags build.

XDG_VTNR=1
MANPATH=/usr/local/share/man:/usr/share/man:/usr/share/gcc-data/x86_64-pc-linux-gnu/4.9.4/man:/usr/share/binutils-data/x86_64-pc-linux-gnu/2.25.1/man
XDG_SESSION_ID=XX
TERM=xterm-256color
SHELL=/bin/bash
MAKEFLAGS=
KONSOLE_DBUS_SERVICE=:X.YZ
KONSOLE_PROFILE_NAME=New Profile
GS_LIB=/home/XX/.fonts
WINDOWID=XXXXXXXX
SHELL_SESSION_ID=XXXXXXXXXXXXXXXXXX
GTK_MODULES=canberra-gtk-module
QSG_RENDER_LOOP=
KDE_FULL_SESSION=true
XDG_SESSION_CLASS=user
USER=XX
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.cfg=00;32:*.conf=00;32:*.diff=00;32:*.doc=00;32:*.ini=00;32:*.log=00;32:*.patch=00;32:*.pdf=00;32:*.ps=00;32:*.tex=00;32:*.txt=00;32:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:
GUILE_LOAD_PATH=/usr/share/guile/1.8
XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session1
MAKE_TERMOUT=true
XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0
MULTIOSDIRS=../lib64:../lib32
QT_AUTO_SCREEN_SCALE_FACTOR=0
MAKELEVEL=1
SESSION_MANAGER=local/jay:@/tmp/.ICE-unix/636,unix/jay:/tmp/.ICE-unix/636
PAGER=/usr/bin/less
CONFIG_PROTECT_MASK=/etc/gentoo-release /etc/sandbox.d /etc/terminfo /etc/ca-certificates.conf
MFLAGS=
MAIL=/var/spool/mail/XX
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/4.9.4
DESKTOP_SESSION=/usr/share/xsessions/plasma
PWD=/
XDG_SESSION_TYPE=x11
EDITOR=/bin/nano
KONSOLE_DBUS_WINDOW=/Windows/1
KDE_SESSION_UID=XXXX
LANG=en_US.UTF-8
KONSOLE_DBUS_SESSION=/Sessions/1
COLORFGBG=15;0
SHLVL=5
XDG_SEAT=seat0
HOME=/root
MANPAGER=manpager
LANGUAGE=
KDE_SESSION_VERSION=5
XCURSOR_THEME=breeze_cursors
LESS=-R -M --shift 5
LOGNAME=XX
XDG_SESSION_DESKTOP=KDE
MAKE_TERMERR=true
GCC_SPECS=
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/XXXX/bus
XDG_DATA_DIRS=/usr/share:/usr/share:/usr/local/share
LESSOPEN=|lesspipe %s
INFOPATH=/usr/share/info:/usr/share/gcc-data/x86_64-pc-linux-gnu/4.9.4/info:/usr/share/binutils-data/x86_64-pc-linux-gnu/2.25.1/info
DISPLAY=:0
PROFILEHOME=
XDG_RUNTIME_DIR=/run/user/XXXX
XDG_CURRENT_DESKTOP=KDE
container=lxc
CONFIG_PROTECT=/usr/share/gnupg/qualified.txt
COLORTERM=truecolor
QMLSCENE_DEVICE=
XAUTHORITY=/home/XX/.Xauthority
_=/usr/bin/env

edit

checking the environment variables did the trick. found the following variables and when they will be unset inside the chroot then building ctags through makefile works fine.

unset MAKEFLAGS
unset MAKELEVEL
unset MAKE_TERMOUT
unset MAKE_TERMERR

don't know exactly which one did it but now I don't understand the magic behind. Could someone solve?

0

There are 0 answers