Skip to content

Commit

Permalink
build: Enhance shadow build for package install
Browse files Browse the repository at this point in the history
This patch is to allow better shadow build similar to uftrace.
Most of the code are copied from uftrace build system.

Signed-off-by: Honggyu Kim <[email protected]>
  • Loading branch information
honggyukim authored and Bojun-Seo committed Dec 3, 2022
1 parent f3eaee8 commit f33b43c
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 13 deletions.
34 changes: 22 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
# Copyright (c) 2022 LG Electronics Inc.
# SPDX-License-Identifier: GPL-2.0
ifneq ($(wildcard .config),)
include .config
prefix ?= /usr/local
bindir = $(prefix)/bin
libdir = $(prefix)/lib

srcdir = $(CURDIR)
# set objdir to $(O) by default (if any)
ifeq ($(objdir),)
ifneq ($(O),)
objdir = $(O)
else
objdir = $(CURDIR)
endif
endif

prefix ?= /usr
DESTDIR := $(prefix)
ifneq ($(wildcard $(objdir)/.config),)
include $(objdir)/.config
endif

srcdir ?= $(CURDIR)
objdir ?= $(CURDIR)
export CC CXX LD srcdir objdir LDFLAGS

ifdef CROSS_COMPILE
CC := $(CROSS_COMPILE)gcc
Expand Down Expand Up @@ -67,14 +77,14 @@ libheaptrace.so: $(LIB_OBJS)
$(QUIET_LINK)$(CXX) -shared -o $(objdir)/$@ $^ $(LIB_LDFLAGS)

install: all
mkdir -p $(DESTDIR)/bin $(DESTDIR)/lib
install -m 755 heaptrace $(DESTDIR)/bin/heaptrace
install -m 755 libheaptrace.so $(DESTDIR)/lib/libheaptrace.so
mkdir -p $(DESTDIR)$(bindir) $(DESTDIR)$(libdir)
install -m 755 $(objdir)/heaptrace $(DESTDIR)$(bindir)/heaptrace
install -m 755 $(objdir)/libheaptrace.so $(DESTDIR)$(libdir)/libheaptrace.so

uninstall:
rm -f $(DESTDIR)/bin/heaptrace
rm -f $(DESTDIR)/lib/libheaptrace.so
rm -f $(DESTDIR)$(bindir)/heaptrace
rm -f $(DESTDIR)$(libdir)/libheaptrace.so

clean:
rm -f heaptrace libheaptrace.so $(LIB_OBJS) $(HEAPTRACE_OBJS)
rm -f $(objdir)/heaptrace $(objdir)/libheaptrace.so $(LIB_OBJS) $(HEAPTRACE_OBJS)
$(MAKE) -C samples clean
57 changes: 56 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,67 @@
# Copyright (c) 2022 LG Electronics Inc.
# SPDX-License-Identifier: GPL-2.0

prefix=/usr/local

srcdir=$(readlink -f $(dirname $0))
objdir=$(readlink -f ${objdir:-${PWD}})
output=${output:-${objdir}/.config}

usage() {
echo "Usage: $0 [<options>]
--help print this message
--prefix=<DIR> set install root dir as <DIR> (default: /usr/local)
--bindir=<DIR> set executable install dir as <DIR> (default: \${prefix}/bin)
--libdir=<DIR> set library install dir as <DIR> (default: \${prefix}/lib)
--objdir=<DIR> set build dir as <DIR> (default: \${PWD})
"
exit 1
}

while getopts ":ho:-:p" opt; do
case "$opt" in
-)
# process --long-options
case "$OPTARG" in
help) usage ;;
*=*) opt=${OPTARG%%=*}; val=${OPTARG#*=}
eval "${opt/-/_}='$val'" ;;
*) ;;
esac
;;
o) output=$OPTARG ;;
*) usage ;;
esac
done
shift $((OPTIND - 1))

bindir=${bindir:-${prefix}/bin}
libdir=${libdir:-${prefix}/lib}

# objdir can be changed, reset output
objdir=$(readlink -f ${objdir})
output=${output:-${objdir}/.config}

cat >$output <<EOF
# this file is generated automatically
override prefix := $prefix
override bindir := $bindir
override libdir := $libdir
EOF

cat >$output <<EOF
override CC := $CC
override CXX := $CXX
override LD := $LD
override CFLAGS = $CFLAGS
override CXXLAGS = $CXXLAGS
override LDFLAGS = $LDFLAGS
override srcdir := $srcdir
override objdir := $objdir
EOF

if [ "$srcdir" != "$objdir" ]; then
cat > $objdir/Makefile <<EOF
Expand All @@ -27,7 +82,7 @@ clean:
install:
@\$(MAKE) -C \$(srcdir) install
.PHONY: all clean tinstall
.PHONY: all clean install
EOF
if [ $(id -u) -eq 0 ]; then
chmod 666 $objdir/Makefile
Expand Down

0 comments on commit f33b43c

Please sign in to comment.