tech-pkg archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: mk.conf option to build and install with -g?



Emmanuel Dreyfus schrieb:
> On Mon, Mar 23, 2009 at 05:14:41PM +0000, Adrian Portelli wrote:
>> CFLAGS+=             -g
>> INSTALL_UNSTRIPPED=  yes
> 
> Great. Is there any way to have this set for a single package?
> Something like this:
> foo.CFLAGS+=  -g
> foo.INSTALL_UNSTRIPPED= yes

The best way is to query the PKGPATH variable, which is provided
specifically for that purpose. See "make help topic=mk.conf".

.if ${PKGPATH} == "category/package"
...
.endif

I have some infrastructure changes that build all packages with
debugging symbols and install the source code, too. This is similar to
the *-debuginfo packages in SuSE and Redhat Linux.

The source code of each package is installed into
$LOCALBASE/share/debuginfo/$PKGNAME, but these files are not recorded in
the PLIST.

Roland
Index: mk/compiler/gcc.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/compiler/gcc.mk,v
retrieving revision 1.96
diff -u -p -r1.96 gcc.mk
--- mk/compiler/gcc.mk  17 Mar 2009 21:28:10 -0000      1.96
+++ mk/compiler/gcc.mk  23 Mar 2009 22:59:49 -0000
@@ -8,6 +8,22 @@
 #      When set to "yes", the native gcc is used, no matter which
 #      compiler version a package requires.
 #
+# GCC_PREPEND_CFLAGS
+#      These flags are prepended to the final gcc and g++ command line,
+#      both when compiling and when linking files.
+#
+# GCC_APPEND_CFLAGS
+#      These flags are appended to the final gcc and g++ command line,
+#      both when compiling and when linking files.
+#
+# GCC_PREPEND_LDFLAGS
+#      These flags are prepended to the final gcc and g++ command line,
+#      but only when linking.
+#
+# GCC_APPEND_LDFLAGS
+#      These flags are appended to the final gcc and g++ command line,
+#      but only when linking.
+#
 # Package-settable variables:
 #
 # GCC_REQD
@@ -50,7 +66,7 @@ _DEF_VARS.gcc=        \
        _GCC_PKGBASE _GCC_PKGSRCDIR _GCC_PKG_SATISFIES_DEP \
        _GCC_PREFIX _GCC_REQD _GCC_STRICTEST_REQD _GCC_SUBPREFIX \
        _GCC_TEST_DEPENDS _GCC_USE_F2C _GCC_VARS _GCC_VERSION \
-       _GCC_VERSION_STRING \
+       _GCC_VERSION_STRING _GCC_VERSION_STRING_CMD \
        _IGNORE_GCC _IGNORE_GCC3CXX _IGNORE_GCC3F77 _IGNORE_GCC3OBJC \
        _IS_BUILTIN_GCC \
        _LANGUAGES.gcc \
@@ -101,8 +117,9 @@ MAKEFLAGS+= _CC=${_CC:Q}
 .endif
 
 .if !defined(_GCC_VERSION)
-_GCC_VERSION_STRING!=  \
+_GCC_VERSION_STRING_CMD:=      \
        ( ${SETENV} ${ALL_ENV} ${_CC} -v 2>&1 | ${GREP} 'gcc version' ) 
2>/dev/null || ${ECHO} 0
+_GCC_VERSION_STRING!=${_GCC_VERSION_STRING_CMD}
 .  if !empty(_GCC_VERSION_STRING:Megcs*)
 _GCC_VERSION=  2.8.1           # egcs is considered to be gcc-2.8.1.
 .  elif !empty(_GCC_VERSION_STRING:Mgcc*)
@@ -494,7 +511,16 @@ ${_GCC_${_var_}}:
 .    else
        ${RUN}                                  \
        (${ECHO} '#!${TOOLS_SHELL}';                                    \
-        ${ECHO} 'exec ${_GCCBINDIR}/${.TARGET:T} "$$@"';               \
+        ${ECHO} bin=${_GCCBINDIR}/${.TARGET:T}; \
+        ${ECHO} prepend_cflags=${GCC_PREPEND_CFLAGS:Q:Q}; \
+        ${ECHO} append_cflags=${GCC_APPEND_CFLAGS:Q:Q}; \
+        ${ECHO} prepend_ldflags=${GCC_PREPEND_LDFLAGS:Q:Q}; \
+        ${ECHO} append_ldflags=${GCC_APPEND_LDFLAGS:Q:Q}; \
+        ${ECHO}; \
+        ${ECHO} 'compiling=no; for arg do if [ "x$$arg" = "x-c" ]; then 
compiling=yes; fi; done'; \
+        ${ECHO}; \
+        ${ECHO} '[ $$compiling = no ] || eval "exec \$$bin $$prepend_cflags 
\"\$$@\" $$append_cflags"'; \
+        ${ECHO} 'eval "exec \$$bin $$prepend_cflags $$prepend_ldflags \"\$$@\" 
$$append_cflags $$append_ldflags"'; \
        ) > ${.TARGET}
        ${RUN}${CHMOD} +x ${.TARGET}
 .    endif
Index: mk/wrapper/arg-source
===================================================================
RCS file: /cvsroot/pkgsrc/mk/wrapper/arg-source,v
retrieving revision 1.15
diff -u -p -r1.15 arg-source
--- mk/wrapper/arg-source       19 Sep 2007 13:08:19 -0000      1.15
+++ mk/wrapper/arg-source       23 Mar 2009 22:59:49 -0000
@@ -46,8 +46,12 @@
 # the queue.
 
 # Push arguments from the command line into the argument buffer.
+prev_arg=""
+saved_arg=""
 while $test $# -gt 0; do
        arg="$1"; shift
+       prev_arg=$saved_arg
+       saved_arg=$arg
        case $arg in
        ##############################################################
        # Merge "-I /dir" into a single "-I/dir".  Same for -L, -R.
@@ -162,10 +166,55 @@ while $test $# -gt 0; do
                append_queue argbuf "$arg"
                $debug_log $wrapperlog "    (arg-source) push: $arg"
                ;;
-       ##############################################################
-       # For everything else, just queue it up.
-       ##############################################################
+
+
+       --mode=execute)
+               install_debuginfo=no
+               append_queue argbuf "$arg"
+               $debug_log $wrapperlog "    (arg-source) push: $arg"
+               ;;
+
        *)
+               if [ $install_debuginfo = yes ] && [ -f "$arg" ] && [ 
"x$prev_arg" != "x-o" ]; then
+                       wrkdir=${debuginfo_filelist%/*}
+
+                       case $arg in
+                       *conftest.* | *.o | *.lo | *.Tpo |\
+                       *.a | *.la | *.so | *.so.[0-9]* |\
+                       *.sh |\
+                       *.def | *.sym |\
+                       */.wrapper/bin/*)
+                               # These file types are ignored, since they
+                               # are not needed for debugging.
+                               ;;
+
+                       *.c |\
+                       *.C | *.cc | *.cxx | *.cpp |\
+                       *.s | *.S | *.asm)
+                               case $arg in
+                               /*)     ;;
+                               *)      arg=`pwd`/$arg ;;
+                               esac
+               
+                               case $arg in
+                               $wrkdir/*)      arg=${arg#$wrkdir/};;
+                               $debuginfo_dir/src/*)   
arg=${arg#$debuginfo_dir/src/};;
+                               *)      echo "ERROR: [scan] cannot compile 
files outside WRKDIR: $arg" 1>&2
+                                       exit 1 ;;
+                               esac
+
+                               echo "$arg" >> $debuginfo_filelist
+                               arg="$debuginfo_dir/src/$arg"
+                               ;;
+
+                       *)
+                               ls -l "$arg" 1>&2
+                               echo "ERROR: [arg-source] Unknown file type: 
$arg" 1>&2
+                               exit 1
+                               ;;
+                       esac
+               fi
+
                append_queue argbuf "$arg"
                $debug_log $wrapperlog "    (arg-source) push: $arg"
                ;;
Index: mk/wrapper/bsd.wrapper.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/wrapper/bsd.wrapper.mk,v
retrieving revision 1.82
diff -u -p -r1.82 bsd.wrapper.mk
--- mk/wrapper/bsd.wrapper.mk   29 Dec 2008 20:47:17 -0000      1.82
+++ mk/wrapper/bsd.wrapper.mk   23 Mar 2009 22:59:49 -0000
@@ -419,6 +419,9 @@ _WRAP_SUBST_SED.${_wrappee_}=                               
                \
        -e "s|@_WRAP_TYPE@|${_WRAP_TYPE.${_wrappee_}}|g" \
        -e "s|@WRAPPER_DEBUG@|${_WRAPPER_DEBUG}|g"                      \
        -e "s|@WRAPPER_UPDATE_CACHE@|${WRAPPER_UPDATE_CACHE}|g"         \
+       -e "s|@INSTALL_DEBUGINFO@|${INSTALL_DEBUGINFO:Dyes:Uno}|g"      \
+       -e "s|@_DEBUGINFO_FILELIST@|${_DEBUGINFO_FILELIST}|g"           \
+       -e "s|@_DEBUGINFO_DIR@|${_DEBUGINFO_DIR}|g"                     \
        ${_WRAP_SUBST_SED}
 
 _WRAP_COOKIE.${_wrappee_}=     ${WRAPPER_DIR}/.wrapper_${_wrappee_}_done
@@ -725,7 +728,7 @@ ${_COOKIE.wrapper}: real-wrapper
 .endif
 
 .PHONY: real-wrapper
-real-wrapper: wrapper-message wrapper-vars pre-wrapper do-wrapper post-wrapper 
wrapper-cookie error-check
+real-wrapper: wrapper-message wrapper-vars pre-wrapper do-wrapper post-wrapper 
_wrapper-debuginfo-symlink wrapper-cookie error-check
 
 .PHONY: wrapper-message
 wrapper-message:
@@ -748,6 +751,10 @@ post-wrapper:
        @${DO_NADA}
 .endif
 
+_wrapper-debuginfo-symlink: ${INSTALL_DEBUGINFO:Dsu-target}
+# su-_wrapper-debuginfo-symlink is defined in debuginfo.mk.
+.include "debuginfo.mk"
+
 .PHONY: wrapper-cookie
 wrapper-cookie:
        ${RUN} [ ! -f ${_COOKIE.wrapper} ]
Index: mk/wrapper/wrapper-defs.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/wrapper/wrapper-defs.mk,v
retrieving revision 1.2
diff -u -p -r1.2 wrapper-defs.mk
--- mk/wrapper/wrapper-defs.mk  10 Oct 2005 12:33:29 -0000      1.2
+++ mk/wrapper/wrapper-defs.mk  23 Mar 2009 22:59:49 -0000
@@ -43,4 +43,6 @@ WRAPPER_TMPDIR=               ${WRAPPER_DIR}/tmp
 WRAPPER_SRCDIR=                ${.CURDIR}/../../mk/wrapper
 WRAPPER_SHELL?=                ${SH}
 
+USE_TOOLS+=            ${INSTALL_DEBUGINFO:Dpax}
+
 .endif # WRAPPER_DEFS_MK
Index: mk/wrapper/wrapper.sh
===================================================================
RCS file: /cvsroot/pkgsrc/mk/wrapper/wrapper.sh,v
retrieving revision 1.19
diff -u -p -r1.19 wrapper.sh
--- mk/wrapper/wrapper.sh       19 Sep 2007 13:02:15 -0000      1.19
+++ mk/wrapper/wrapper.sh       23 Mar 2009 22:59:49 -0000
@@ -36,7 +36,7 @@
 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 # POSSIBILITY OF SUCH DAMAGE.
 
-#set -eu
+set -eu
 
 # The list of include files for the wrapper.
 arg_pp="@_WRAP_ARG_PP@"
@@ -61,6 +61,9 @@ wrapper_type="@_WRAP_TYPE@"   # one of AS,
 wrapperlog="${WRAPPER_LOG-@_WRAP_LOG@}"
 skip_transform="${WRAPPER_SKIP_TRANSFORM-@_WRAP_SKIP_TRANSFORM@}"
 debug="${WRAPPER_DEBUG-@WRAPPER_DEBUG@}"
+install_debuginfo="@INSTALL_DEBUGINFO@"
+debuginfo_filelist="@_DEBUGINFO_FILELIST@"
+debuginfo_dir="@_DEBUGINFO_DIR@"
 
 # Tools that can be used by the wrapper.
 # XXX: Why is this necessary? Isn't the wrapper only called with
--- /dev/null   2008-11-17 23:57:54.000000000 +0100
+++ mk/wrapper/debuginfo.mk     2008-10-02 10:25:31.000000000 +0200
@@ -0,0 +1,59 @@
+# $NetBSD$
+#
+# This file installs the debug information for packages, so that they
+# can be debugged using their source code.
+#
+# === User-settable variables ===
+#
+# INSTALL_DEBUGINFO
+#      "yes" to install the debugging information, undefined otherwise.
+#
+#      Default: undefined
+
+_DEBUGINFO_DIR=                ${PREFIX}/share/debuginfo/${PKGNAME}
+_DEBUGINFO_FILELIST=   ${WRKDIR}/.debuginfo-filelist
+
+# called from bsd.wrapper.mk.
+su-_wrapper-debuginfo-symlink: .PHONY
+       @${STEP_MSG} "Creating symlinks for debuginfo generation"
+       ${RUN} ${RM} -rf ${_DEBUGINFO_DIR}
+       ${RUN} ${MKDIR} ${_DEBUGINFO_DIR}
+       ${RUN} ${LN} -s ${BUILDLINK_DIR}/include ${_DEBUGINFO_DIR}/include
+       ${RUN} ${LN} -s ${WRKDIR} ${_DEBUGINFO_DIR}/src
+
+unprivileged-install-hook: _sanitize-debuginfo-filelist
+_sanitize-debuginfo-filelist: .PHONY
+       @${STEP_MSG} "Sanitizing debuginfo file list"
+       ${RUN} >> ${_DEBUGINFO_FILELIST}
+       ${RUN} ${AWK} -F/ '{\
+               ignore = 0; fname="";\
+               for (i = NF; i >= 1; i--) {\
+                       if ($$i == ".") {\
+                       } else if ($$i == "..") {\
+                               ignore++;\
+                       } else if (ignore > 0) {\
+                               ignore--;\
+                       } else {\
+                               fname = $$i "/" fname;\
+                       }\
+               }\
+               if (ignore == 0) print substr(fname, 1, length(fname) - 1);\
+       }' < ${_DEBUGINFO_FILELIST} > ${_DEBUGINFO_FILELIST}.tmp1
+       ${RUN} cd ${WRKDIR}; \
+       while read fname; do \
+               if test -f "$$fname"; then \
+                       echo "$$fname"; \
+               else \
+                       ${WARNING_MSG} "[debuginfo.mk] compiled file $$fname 
does not exist anymore."; \
+               fi; \
+       done < ${_DEBUGINFO_FILELIST}.tmp1 > ${_DEBUGINFO_FILELIST}.tmp2
+       ${RUN} ${SORT} -u < ${_DEBUGINFO_FILELIST}.tmp2 > 
${_DEBUGINFO_FILELIST}.tmp3
+       ${RUN} ${MV} -f ${_DEBUGINFO_FILELIST}.tmp3 ${_DEBUGINFO_FILELIST}
+       ${RUN} ${RM} -f ${_DEBUGINFO_FILELIST}.tmp?
+
+privileged-install-hook: _install-debuginfo
+_install-debuginfo: .PHONY
+       @${STEP_MSG} "Installing debuginfo"
+       ${RUN} ${RM} -rf ${_DEBUGINFO_DIR}
+       ${RUN} set -e; cd ${BUILDLINK_DIR}; ${PAX} -wr include ${_DEBUGINFO_DIR}
+       ${RUN} set -e; cd ${WRKDIR}; ${PAX} -wr ${_DEBUGINFO_DIR}/src < 
${_DEBUGINFO_FILELIST}
CFLAGS+=                -Os -ggdb -W -Wall
LDFLAGS+=               -ggdb
PREFER_PKGSRC=          yes
X11_TYPE=               modular

INSTALL_DEBUGINFO=      yes

ACCEPTABLE_LICENSES+=   velena-license

# TODO: das muss man noch feiner spezifizieren koennen.
# am besten mit einem externen Wrapper, der die Argumente
# neu anordnet.
GCC_PREPEND_CFLAGS=     -fdiagnostics-show-option
.if !defined(NO_STRICT)
GCC_APPEND_CFLAGS=      -Wall -W -Wno-error -ggdb -Werror=int-to-pointer-cast 
-Werror-implicit-function-declaration -Wno-unused-parameter
.endif
GCC_PREPEND_LDFLAGS=    -L${BUILDLINK_DIR}/lib -Wl,-R${LOCALBASE}/lib 
-L/usr/lib64 -Wl,-R/usr/lib64
GCC_APPEND_LDFLAGS=     # none



Home | Main Index | Thread Index | Old Index