diff --git a/Makefile b/Makefile index 6ae9ef7..4be18aa 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 diff --git a/configure b/configure index c5477ec..8df7478 100755 --- a/configure +++ b/configure @@ -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 [] + + --help print this message + --prefix= set install root dir as (default: /usr/local) + --bindir= set executable install dir as (default: \${prefix}/bin) + --libdir= set library install dir as (default: \${prefix}/lib) + --objdir= set build dir as (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 <$output < $objdir/Makefile <