Error in thrid-party Makefile made with Cygwin - c++

I am trying to compile a third-party c++ project that says it is intended for 64 bit Ubuntu with cygwin on my windows pc and am encountering the following error when making the project:
BuildPrefix.mak:212: *** Invalid configuration Unable to determine compiler version.. Stop.
I'm pretty sure it's the makefile that is throwing this error but I'm not sure exactly why or how to fix it. The makefile is pretty large but here is the lines that are throwing the errors:
# Validate we built the same as we received. Anything else is invalid.
ifneq ($(ACTIV_BUILD_OPTIONS),$(__ACTIV_BUILD_OPTIONS_VALIDATION))
$(error Invalid configuration $(CFG))
endif
which comes after it doing a bunch of stuff that I'm not sure whats going on:
# Optional options field?
ifeq ($(CFG_LIST_LENGTH),5)
ACTIV_BUILD_OPTIONS := $(call word,4,$(CFG_LIST))
ACTIV_CONFIGURATION_TYPE := $(call word,5,$(CFG_LIST))
# C++11?
ifneq ($(call findstring,cxx11,$(ACTIV_BUILD_OPTIONS)),)
ACTIV_CXX11 := 1
__ACTIV_BUILD_OPTIONS_VALIDATION := $(call merge,-,$(__ACTIV_BUILD_OPTIONS_VALIDATION) cxx11)
endif
# STLport?
ifneq ($(call findstring,stlport,$(ACTIV_BUILD_OPTIONS)),)
IS_STLPORT := 1
__ACTIV_BUILD_OPTIONS_VALIDATION := $(call merge,-,$(__ACTIV_BUILD_OPTIONS_VALIDATION) stlport)
endif
# vstring?
ifneq ($(call findstring,vstring,$(ACTIV_BUILD_OPTIONS)),)
ACTIV_STRING_IMPLEMENTATION := vstring
__ACTIV_BUILD_OPTIONS_VALIDATION := $(call merge,-,$(__ACTIV_BUILD_OPTIONS_VALIDATION) $(ACTIV_STRING_IMPLEMENTATION))
endif
# libc++?
ifneq ($(call findstring,libcxx,$(ACTIV_BUILD_OPTIONS)),)
__ACTIV_BUILD_OPTIONS_VALIDATION := $(call merge,-,$(__ACTIV_BUILD_OPTIONS_VALIDATION) libcxx)
ACTIV_LIBCXX := 1
endif
# Boost string?
ifneq ($(call findstring,bstring,$(ACTIV_BUILD_OPTIONS)),)
ACTIV_STRING_IMPLEMENTATION := bstring
__ACTIV_BUILD_OPTIONS_VALIDATION := $(call merge,-,$(__ACTIV_BUILD_OPTIONS_VALIDATION) $(ACTIV_STRING_IMPLEMENTATION))
endif
Theres a lot more to the file so let me know if I should post more, any hints/clues/possible courses of action would be greatly appreciated.

Related

How to include libxml2 library on GNUMakefile

I recently try to include libxml2 on my OpenDDS c++ project.
But, I don't know the way how to include this library on GNUMakefile.
How can I include libxml2 on this GNUmake file?
Also, I have tried to add command on GNUMakefile like this.
LIB = /usr/local/xml/lib
But, still doesn't work.
My GNUMakefile is Here:
MAKEFILE = GNUmakefile.DDS_Messenger_Publisher
DEPENDENCY_FILE = .depend.DDS_Messenger_Publisher
BIN_UNCHECKED = publisher
LIB_PREFIX ?= lib
TAO_ROOT ?= $(ACE_ROOT)/TAO
FILES = \
publisher.cpp \
Writer.cpp
LIBPATHS := . "$(ACE_ROOT)/lib" "../../../lib"
#----------------------------------------------------------------------------
# Include macros and targets
#----------------------------------------------------------------------------
LDLIBS = -lDDS_Messenger_Idl -lOpenDDS_Shmem -lOpenDDS_Rtps_Udp -lOpenDDS_Rtps -lOpenDDS_Multicast -lOpenDDS_Udp -lOpenDDS_Tcp -lOpenDDS_InfoRepoDiscovery -lOpenDDS_Dcps -lTAO_BiDirGIOP -lTAO_PI -lTAO_CodecFactory -lTAO_PortableServer -lTAO_AnyTypeCode -lTAO -lACE
TAO_IDL = $(ACE_ROOT)/bin/tao_idl
TAO_IDL_DEP = $(ACE_ROOT)/bin/tao_idl$(EXEEXT)
TAO_IDLFLAGS = -Wb,pre_include=ace/pre.h -Wb,post_include=ace/post.h -I$(TAO_ROOT)$(if $(ARCH), -g $(call ADD_QUOTE,$(call ADD_ARCH,$(ACE_ROOT)/bin/ace_gperf)))
PRJ_TYPE = rtp
ifeq ($(INSBIN),.)
ifeq ($(CURDIR),)
ifeq ($(PWD),)
PWD=$(shell pwd)
endif
else
PWD=$(CURDIR)
endif
INSBIN = $(PWD)
endif
OUTPUT_DIRECTORY = $(if $(ARCH),./$(ARCH))
include $(ACE_ROOT)/include/makeinclude/wrapper_macros.GNU
include $(DDS_ROOT)/rules.dds.GNU
include $(TAO_ROOT)/rules.tao.GNU
...
...
I finally solved this problem.
just added
LIBXML_ROOT ?= /usr/local/xml
LDLIBS = -lDDS_Messenger_Idl -lOpenDDS_Shmem ... -L$(LIBXML_ROOT)/lib -lxml2
...
CPPFLAGS += -I$(ACE_ROOT) -I$(TAO_ROOT) -I../../.. -I$(LIBXML_ROOT)/include/libxml2

How to pass arguments to boilermake

Apologies if this is not the place to post this. I'm not really sure where is.
I'm new to make and after a lot of research I stumbled across boilermake and have implemented it successfully on my project.
I build a release version of my project by default. I would like to know how to build a debug version of my project by supplying a command line argument such as debug. E.g.
make debug
which changes some of the compiler options set in CXXFLAGS in my top-level makefile.
However, I've not been able to get this to work.
Here is my makefile, which is included by the top-level makefile of boilermake.
INCDIRS := \
../component1/include \
../component2/include \
../component3/include
CXXFLAGS := O2 -pipe -std=c++11 -Wall -Wextra -Wold-style-cast -pedantic \
-isystem boost
SUBMAKEFILES := \
../component1/build/component1.mk \
../component2/build/component3.mk \
../component3/build/component4.mk
TARGET := my-project
TGT_LDFLAGS := -L. -L${TARGET_DIR}
TGT_LDLIBS := -lcomponent1 -lcomponent2 -lcomponent3 \
libboost_date_time-mt-sd.a \
libboost_filesystem-mt-sd.a
libcrypto.a \
libssl.a \
-lz \
-ldl \
-lpthread
TGT_PREREQS := \
libcomponent1.a \
libcomponent2.a \
libcomponent3.a
SOURCES := \
main.cpp
Here is the boilermake makefile.
# boilermake: A reusable, but flexible, boilerplate Makefile.
#
# Copyright 2008, 2009, 2010 Dan Moulding, Alan T. DeKok
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Caution: Don't edit this Makefile! Create your own main.mk and other
# submakefiles, which will be included by this Makefile.
# Only edit this if you need to modify boilermake's behavior (fix
# bugs, add features, etc).
# Note: Parameterized "functions" in this makefile that are marked with
# "USE WITH EVAL" are only useful in conjuction with eval. This is
# because those functions result in a block of Makefile syntax that must
# be evaluated after expansion. Since they must be used with eval, most
# instances of "$" within them need to be escaped with a second "$" to
# accomodate the double expansion that occurs when eval is invoked.
# ADD_CLEAN_RULE - Parameterized "function" that adds a new rule and phony
# target for cleaning the specified target (removing its build-generated
# files).
#
# USE WITH EVAL
#
define ADD_CLEAN_RULE
clean: clean_${1}
.PHONY: clean_${1}
clean_${1}:
$$(strip rm -f ${TARGET_DIR}/${1} $${${1}_OBJS:%.o=%.[do]})
$${${1}_POSTCLEAN}
endef
# ADD_OBJECT_RULE - Parameterized "function" that adds a pattern rule for
# building object files from source files with the filename extension
# specified in the second argument. The first argument must be the name of the
# base directory where the object files should reside (such that the portion
# of the path after the base directory will match the path to corresponding
# source files). The third argument must contain the rules used to compile the
# source files into object code form.
#
# USE WITH EVAL
#
define ADD_OBJECT_RULE
${1}/%.o: ${2}
${3}
endef
# ADD_TARGET_RULE - Parameterized "function" that adds a new target to the
# Makefile. The target may be an executable or a library. The two allowable
# types of targets are distinguished based on the name: library targets must
# end with the traditional ".a" extension.
#
# USE WITH EVAL
#
define ADD_TARGET_RULE
ifeq "$$(suffix ${1})" ".a"
# Add a target for creating a static library.
$${TARGET_DIR}/${1}: $${${1}_OBJS}
#mkdir -p $$(dir $$#)
$$(strip $${AR} $${ARFLAGS} $$# $${${1}_OBJS})
$${${1}_POSTMAKE}
else
# Add a target for linking an executable. First, attempt to select the
# appropriate front-end to use for linking. This might not choose the
# right one (e.g. if linking with a C++ static library, but all other
# sources are C sources), so the user makefile is allowed to specify a
# linker to be used for each target.
ifeq "$$(strip $${${1}_LINKER})" ""
# No linker was explicitly specified to be used for this target. If
# there are any C++ sources for this target, use the C++ compiler.
# For all other targets, default to using the C compiler.
ifneq "$$(strip $$(filter $${CXX_SRC_EXTS},$${${1}_SOURCES}))" ""
${1}_LINKER = $${CXX}
else
${1}_LINKER = $${CC}
endif
endif
$${TARGET_DIR}/${1}: $${${1}_OBJS} $${${1}_PREREQS}
#mkdir -p $$(dir $$#)
$$(strip $${${1}_LINKER} -o $$# $${LDFLAGS} $${${1}_LDFLAGS} \
$${${1}_OBJS} $${LDLIBS} $${${1}_LDLIBS})
$${${1}_POSTMAKE}
endif
endef
# CANONICAL_PATH - Given one or more paths, converts the paths to the canonical
# form. The canonical form is the path, relative to the project's top-level
# directory (the directory from which "make" is run), and without
# any "./" or "../" sequences. For paths that are not located below the
# top-level directory, the canonical form is the absolute path (i.e. from
# the root of the filesystem) also without "./" or "../" sequences.
define CANONICAL_PATH
$(patsubst ${CURDIR}/%,%,$(abspath ${1}))
endef
# COMPILE_C_CMDS - Commands for compiling C source code.
define COMPILE_C_CMDS
#mkdir -p $(dir $#)
$(strip ${CC} -o $# -c -MP -MD ${CFLAGS} ${SRC_CFLAGS} ${INCDIRS} \
${SRC_INCDIRS} ${SRC_DEFS} ${DEFS} $<)
endef
# COMPILE_CXX_CMDS - Commands for compiling C++ source code.
define COMPILE_CXX_CMDS
#mkdir -p $(dir $#)
$(strip ${CXX} -o $# -c -MP -MD ${CXXFLAGS} ${SRC_CXXFLAGS} ${INCDIRS} \
${SRC_INCDIRS} ${SRC_DEFS} ${DEFS} $<)
endef
# INCLUDE_SUBMAKEFILE - Parameterized "function" that includes a new
# "submakefile" fragment into the overall Makefile. It also recursively
# includes all submakefiles of the specified submakefile fragment.
#
# USE WITH EVAL
#
define INCLUDE_SUBMAKEFILE
# Initialize all variables that can be defined by a makefile fragment, then
# include the specified makefile fragment.
TARGET :=
TGT_CFLAGS :=
TGT_CXXFLAGS :=
TGT_DEFS :=
TGT_INCDIRS :=
TGT_LDFLAGS :=
TGT_LDLIBS :=
TGT_LINKER :=
TGT_POSTCLEAN :=
TGT_POSTMAKE :=
TGT_PREREQS :=
SOURCES :=
SRC_CFLAGS :=
SRC_CXXFLAGS :=
SRC_DEFS :=
SRC_INCDIRS :=
SUBMAKEFILES :=
# A directory stack is maintained so that the correct paths are used as we
# recursively include all submakefiles. Get the makefile's directory and
# push it onto the stack.
DIR := $(call CANONICAL_PATH,$(dir ${1}))
DIR_STACK := $$(call PUSH,$${DIR_STACK},$${DIR})
include ${1}
# Initialize internal local variables.
OBJS :=
# Ensure that valid values are set for BUILD_DIR and TARGET_DIR.
ifeq "$$(strip $${BUILD_DIR})" ""
BUILD_DIR := build
endif
ifeq "$$(strip $${TARGET_DIR})" ""
TARGET_DIR := .
endif
# Determine which target this makefile's variables apply to. A stack is
# used to keep track of which target is the "current" target as we
# recursively include other submakefiles.
ifneq "$$(strip $${TARGET})" ""
# This makefile defined a new target. Target variables defined by this
# makefile apply to this new target. Initialize the target's variables.
TGT := $$(strip $${TARGET})
ALL_TGTS += $${TGT}
$${TGT}_CFLAGS := $${TGT_CFLAGS}
$${TGT}_CXXFLAGS := $${TGT_CXXFLAGS}
$${TGT}_DEFS := $${TGT_DEFS}
$${TGT}_DEPS :=
TGT_INCDIRS := $$(call QUALIFY_PATH,$${DIR},$${TGT_INCDIRS})
TGT_INCDIRS := $$(call CANONICAL_PATH,$${TGT_INCDIRS})
$${TGT}_INCDIRS := $${TGT_INCDIRS}
$${TGT}_LDFLAGS := $${TGT_LDFLAGS}
$${TGT}_LDLIBS := $${TGT_LDLIBS}
$${TGT}_LINKER := $${TGT_LINKER}
$${TGT}_OBJS :=
$${TGT}_POSTCLEAN := $${TGT_POSTCLEAN}
$${TGT}_POSTMAKE := $${TGT_POSTMAKE}
$${TGT}_PREREQS := $$(addprefix $${TARGET_DIR}/,$${TGT_PREREQS})
$${TGT}_SOURCES :=
else
# The values defined by this makefile apply to the the "current" target
# as determined by which target is at the top of the stack.
TGT := $$(strip $$(call PEEK,$${TGT_STACK}))
$${TGT}_CFLAGS += $${TGT_CFLAGS}
$${TGT}_CXXFLAGS += $${TGT_CXXFLAGS}
$${TGT}_DEFS += $${TGT_DEFS}
TGT_INCDIRS := $$(call QUALIFY_PATH,$${DIR},$${TGT_INCDIRS})
TGT_INCDIRS := $$(call CANONICAL_PATH,$${TGT_INCDIRS})
$${TGT}_INCDIRS += $${TGT_INCDIRS}
$${TGT}_LDFLAGS += $${TGT_LDFLAGS}
$${TGT}_LDLIBS += $${TGT_LDLIBS}
$${TGT}_POSTCLEAN += $${TGT_POSTCLEAN}
$${TGT}_POSTMAKE += $${TGT_POSTMAKE}
$${TGT}_PREREQS += $${TGT_PREREQS}
endif
# Push the current target onto the target stack.
TGT_STACK := $$(call PUSH,$${TGT_STACK},$${TGT})
ifneq "$$(strip $${SOURCES})" ""
# This makefile builds one or more objects from source. Validate the
# specified sources against the supported source file types.
BAD_SRCS := $$(strip $$(filter-out $${ALL_SRC_EXTS},$${SOURCES}))
ifneq "$${BAD_SRCS}" ""
$$(error Unsupported source file(s) found in ${1} [$${BAD_SRCS}])
endif
# Qualify and canonicalize paths.
SOURCES := $$(call QUALIFY_PATH,$${DIR},$${SOURCES})
SOURCES := $$(call CANONICAL_PATH,$${SOURCES})
SRC_INCDIRS := $$(call QUALIFY_PATH,$${DIR},$${SRC_INCDIRS})
SRC_INCDIRS := $$(call CANONICAL_PATH,$${SRC_INCDIRS})
# Save the list of source files for this target.
$${TGT}_SOURCES += $${SOURCES}
# Convert the source file names to their corresponding object file
# names.
OBJS := $$(addprefix $${BUILD_DIR}/$$(call CANONICAL_PATH,$${TGT})/,\
$$(addsuffix .o,$$(basename $${SOURCES})))
# Add the objects to the current target's list of objects, and create
# target-specific variables for the objects based on any source
# variables that were defined.
$${TGT}_OBJS += $${OBJS}
$${TGT}_DEPS += $${OBJS:%.o=%.d}
$${OBJS}: SRC_CFLAGS := $${$${TGT}_CFLAGS} $${SRC_CFLAGS}
$${OBJS}: SRC_CXXFLAGS := $${$${TGT}_CXXFLAGS} $${SRC_CXXFLAGS}
$${OBJS}: SRC_DEFS := $$(addprefix -D,$${$${TGT}_DEFS} $${SRC_DEFS})
$${OBJS}: SRC_INCDIRS := $$(addprefix -I,\
$${$${TGT}_INCDIRS} $${SRC_INCDIRS})
endif
ifneq "$$(strip $${SUBMAKEFILES})" ""
# This makefile has submakefiles. Recursively include them.
$$(foreach MK,$${SUBMAKEFILES},\
$$(eval $$(call INCLUDE_SUBMAKEFILE,\
$$(call CANONICAL_PATH,\
$$(call QUALIFY_PATH,$${DIR},$${MK})))))
endif
# Reset the "current" target to it's previous value.
TGT_STACK := $$(call POP,$${TGT_STACK})
TGT := $$(call PEEK,$${TGT_STACK})
# Reset the "current" directory to it's previous value.
DIR_STACK := $$(call POP,$${DIR_STACK})
DIR := $$(call PEEK,$${DIR_STACK})
endef
# MIN - Parameterized "function" that results in the minimum lexical value of
# the two values given.
define MIN
$(firstword $(sort ${1} ${2}))
endef
# PEEK - Parameterized "function" that results in the value at the top of the
# specified colon-delimited stack.
define PEEK
$(lastword $(subst :, ,${1}))
endef
# POP - Parameterized "function" that pops the top value off of the specified
# colon-delimited stack, and results in the new value of the stack. Note that
# the popped value cannot be obtained using this function; use peek for that.
define POP
${1:%:$(lastword $(subst :, ,${1}))=%}
endef
# PUSH - Parameterized "function" that pushes a value onto the specified colon-
# delimited stack, and results in the new value of the stack.
define PUSH
${2:%=${1}:%}
endef
# QUALIFY_PATH - Given a "root" directory and one or more paths, qualifies the
# paths using the "root" directory (i.e. appends the root directory name to
# the paths) except for paths that are absolute.
define QUALIFY_PATH
$(addprefix ${1}/,$(filter-out /%,${2})) $(filter /%,${2})
endef
###############################################################################
#
# Start of Makefile Evaluation
#
###############################################################################
# Older versions of GNU Make lack capabilities needed by boilermake.
# With older versions, "make" may simply output "nothing to do", likely leading
# to confusion. To avoid this, check the version of GNU make up-front and
# inform the user if their version of make doesn't meet the minimum required.
MIN_MAKE_VERSION := 3.81
MIN_MAKE_VER_MSG := boilermake requires GNU Make ${MIN_MAKE_VERSION} or greater
ifeq "${MAKE_VERSION}" ""
$(info GNU Make not detected)
$(error ${MIN_MAKE_VER_MSG})
endif
ifneq "${MIN_MAKE_VERSION}" "$(call MIN,${MIN_MAKE_VERSION},${MAKE_VERSION})"
$(info This is GNU Make version ${MAKE_VERSION})
$(error ${MIN_MAKE_VER_MSG})
endif
# Define the source file extensions that we know how to handle.
C_SRC_EXTS := %.c
CXX_SRC_EXTS := %.C %.cc %.cp %.cpp %.CPP %.cxx %.c++
ALL_SRC_EXTS := ${C_SRC_EXTS} ${CXX_SRC_EXTS}
# Initialize global variables.
ALL_TGTS :=
DEFS :=
DIR_STACK :=
INCDIRS :=
TGT_STACK :=
# Include the main user-supplied submakefile. This also recursively includes
# all other user-supplied submakefiles.
$(eval $(call INCLUDE_SUBMAKEFILE,main.mk))
# Perform post-processing on global variables as needed.
DEFS := $(addprefix -D,${DEFS})
INCDIRS := $(addprefix -I,$(call CANONICAL_PATH,${INCDIRS}))
# Define the "all" target (which simply builds all user-defined targets) as the
# default goal.
.PHONY: all
all: $(addprefix ${TARGET_DIR}/,${ALL_TGTS})
# Add a new target rule for each user-defined target.
$(foreach TGT,${ALL_TGTS},\
$(eval $(call ADD_TARGET_RULE,${TGT})))
# Add pattern rule(s) for creating compiled object code from C source.
$(foreach TGT,${ALL_TGTS},\
$(foreach EXT,${C_SRC_EXTS},\
$(eval $(call ADD_OBJECT_RULE,${BUILD_DIR}/$(call CANONICAL_PATH,${TGT}),\
${EXT},$${COMPILE_C_CMDS}))))
# Add pattern rule(s) for creating compiled object code from C++ source.
$(foreach TGT,${ALL_TGTS},\
$(foreach EXT,${CXX_SRC_EXTS},\
$(eval $(call ADD_OBJECT_RULE,${BUILD_DIR}/$(call CANONICAL_PATH,${TGT}),\
${EXT},$${COMPILE_CXX_CMDS}))))
# Add "clean" rules to remove all build-generated files.
.PHONY: clean
$(foreach TGT,${ALL_TGTS},\
$(eval $(call ADD_CLEAN_RULE,${TGT})))
# Include generated rules that define additional (header) dependencies.
$(foreach TGT,${ALL_TGTS},\
$(eval -include ${${TGT}_DEPS}))
If you make the command as:
make debug=true
Then in one of your makefiles:
ifeq (debug,true)
CXXFLAGS += -DDEBUG
else
CXXFLAGS += -DNDEBUG
endif

String replacements in files while performing a MAKE

I have a existing project I am working on, currently there is a line in the make file
VERSION := $(shell ${GIT} describe --tags --always)
It ends up storing a string similar to v2.3-9-gcdf3820 in to the VERSION variable. That variable is eventually used to name the file during a package process.
What I would like to do is have make write out a Example.version file which would have the following format.
{
"NAME":"Examle",
"VERSION":
{
"MAJOR":2,
"MINOR":3,
"PATCH":0,
"BUILD":0
}
}
So it takes in the version numbers up to the first - then fills the rest with 0's. The result from describe could have 1 to 4 version numbers in it so I wanted to be flexible.
The problem is I am now stuck on how I should proceed next. I made a Example.version.template file
{
"NAME":"Examle",
"VERSION":
{
"MAJOR":{MAJOR},
"MINOR":{MINOR},
"PATCH":{PATCH},
"BUILD":{BUILD}
}
}
I know how to read in the file and write out the file from inside the makefile, and I know how to replace the text once I have each of my variables. What I don't know how to do is how to I turn v2.3-9-gcdf3820 in to the equivalent of
MAJOR := 2
MINOR := 3
PATCH := 0
BUILD := 0
How do I split my string up and strip of that leading v from within make?
While I completely agree with #MadScientist that make isn't the most suited to this task and that a small shell script is likely a better option it is possible (given assumptions about input values) to do this manipulation using make itself.
$ cat desc.mk
define p
$(info $1:$($(1)):)
endef
raw := v2.3-9-gcdf3820
$(call p,raw)
split := $(subst -, ,$(raw))
$(call p,split)
ver := $(subst v,,$(word 1,$(split)))
$(call p,ver)
versplit := $(subst ., ,$(ver))
$(call p,versplit)
MAJOR := $(or $(word 1,$(versplit)),0)
$(call p,MAJOR)
MINOR := $(or $(word 2,$(versplit)),0)
$(call p,MINOR)
PATCH := $(or $(word 3,$(versplit)),0)
$(call p,PATCH)
BUILD := $(or $(word 4,$(versplit)),0)
$(call p,BUILD)
all: ;
$ make -qf desc.mk
raw:v2.3-9-gcdf3820:
split:v2.3 9 gcdf3820:
ver:2.3:
versplit:2 3:
MAJOR:2:
MINOR:3:
PATCH:0:
BUILD:0:
It might also make sense to use git describe --tags --always --abbrev=0 to have git drop the -9-gcdf3820 (or whatever) for you from the start (at least for this usage) since that eliminates a good amount of the work needed.
Edit: A little cleverness from #laune gets a cleaned up last few lines:
versplit := $(subst ., ,$(ver)) 0 0 0 0
MAJOR := $(word 1,$(versplit))
$(call p,MAJOR)
MINOR := $(word 2,$(versplit))
$(call p,MINOR)
PATCH := $(word 3,$(versplit))
$(call p,PATCH)
BUILD := $(word 4,$(versplit))
$(call p,BUILD)

Android NDK -Linker errors to shared libraries.

I'm trying to figure out why I keep getting undefined references to functions that are declared in shared libraries that come with android.
My application.mk and root android.mk
APP_MODULES := adhoc
APP_STL := gnustl_shared
NDK_TOOLCHAIN_VERSION=clang3.1
APP_OPTIM := debug
CUR_PATH := $(call my-dir)
LOCAL_CPPFLAGS += -std-c++11 -Wwrite-strings
include $(CUR_PATH)/native/adhoc/Android.mk
adhoc Android.mk
LOCAL_PATH := $(call my-dir)
updater_src_files := \
install.cpp\
sha1.cpp\
addhoc_lib.cpp
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(updater_src_files)
inc_path = $(NDK_ROOT)/../AndroidSource/system/core/include \
$(NDK_ROOT)/../AndroidSource/hardware/libhardware_legacy/include
LOCAL_C_INCLUDES += $(inc_path)
LOCAL_CFLAGS := -DINTERNAL_SHA1 -DCONFIG_CRYPTO_INTERNAL -DCONFIG_NO_T_PRF -DCONFIG_NO_TLS_PRF -std=c++11 -Wc++11-extensions -Wno-deprecated-writable-strings
LOCAL_STATIC_LIBRARIES := libedify
LOCAL_SHARED_LIBRARIES := libcutils\
libhardware_legacy\
libc\
libnetutils\
libsysutils
LOCAL_MODULE := adhoc
include $(BUILD_SHARED_LIBRARY)
$(call import-add-path, $(LOCAL_PATH))
$(call import-module, edify)
and adhoc/edify/android.mk
LOCAL_PATH := $(call my-dir)
edify_src_files := \
lexer.l \
parser.y \
expr.c
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(edify_src_files)
LOCAL_CFLAGS := $(edify_cflags)
LOCAL_MODULE := edify
include $(BUILD_STATIC_LIBRARY)
I get output from ndk-build -B V=1 like:
SharedLibrary : libadhoc.so
/home/corey/Android_Dev/android-ndk-r8d/toolchains/llvm-3.1/prebuilt/linux-x86/bin/clang++ -Wl,-soname,libadhoc.so -shared --sysroot=/home/corey/Android_Dev/android-ndk-r8d/platforms/android-14/arch-arm ./obj/local/armeabi/objs-debug/adhoc/install.o ./obj/local/armeabi/objs-debug/adhoc/sha1.o ./obj/local/armeabi/objs-debug/adhoc/addhoc_lib.o ./obj/local/armeabi/libedify.a ./obj/local/armeabi/libgnustl_shared.so -gcc-toolchain /home/corey/Android_Dev/android-ndk-r8d/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86 -no-canonical-prefixes -target armv5te-none-linux-androideabi -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now /home/corey/Android_Dev/android-ndk-r8d/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/libsupc++.a -lc -lm -o ./obj/local/armeabi/libadhoc.so
/home/corey/Android_Dev/android-ndk-r8d/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs-debug/adhoc/install.o: in function GetPropFn(char const*, State*, int, Expr**):jni/native/adhoc/install.cpp:463: error: undefined reference to 'property_get'
If you are using C++ code, then add C PLUS PLUS flag.
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
Also take a look at the following post.
android ndk undefined reference to a method

In a makefile, how to get the relative path from one absolute path to another?

An example to illustrate my question:
Top level makefile
rootdir = $(realpath .)
export includedir = $(rootdir)/include
default:
#$(MAKE) --directory=$(rootdir)/src/libs/libfoo
Makefile for src/libfoo
currentdir = $(realpath .)
includedir = $(function or magic to make a relative path
from $(currentdir) to $(includedir),
which in this example would be ../../../include)
Another example:
current dir = /home/username/projects/app/trunk/src/libs/libfoo/
destination = /home/username/projects/app/build/libfoo/
relative = ../../../../build/libfoo
How can this be done, while trying to be as portable as possible?
You can use the shell function, and use realpath(1) (which is part of coreutils) and the --relative-to flag.
Here is an example:
RELATIVE_FILE1_FILE2:=$(shell realpath --relative-to $(FILE1) $(FILE2))
You can even process a whole list of files with one invocation of realpath(1) since it knows how to process many file names.
Here is an example:
RELATIVES:=$(shell realpath --relative-to $(RELATIVE) $(FILES))
Doing what you want does not look easy. It may be possible using a lot of combined $(if in the makefile but not portable (gmake only) and cumbersome.
IMHO, you are trying to solve a problem that you create yourself. Why don't you send the correct value of includedir as a relative path from the Top-level Makefile? It can be done very easily as follows:
rootdir = $(realpath .)
default:
#$(MAKE) --directory=$(rootdir)/src/libs/libfoo includedir=../../../include
Then you can use $(includedir) in the sub-makefiles. It is already defined as relative.
Python is portable! So, I would suggest you this simple example in your submakefile
With current_dir and destination_dir paths os.path.relpath() does the job for you so you do not have to re-invent the wheel.
submakefile.mk
current_dir=$(CURDIR)
makefile_target:
(echo "import os"; echo "print(os.path.relpath('$(destination_dir)', '$(current_dir)'))" )| python
Robust drop-in solution with pure Make:
override define \s :=
$() $()
endef
ifndef $(\s)
override $(\s) :=
else
$(error Defined special variable '$(\s)': reserved for internal use)
endif
override define dirname
$(patsubst %/,%,$(dir $(patsubst %/,%,$1)))
endef
override define prefix_1
$(if $(or $\
$(patsubst $(abspath $3)%,,$(abspath $1)),$\
$(patsubst $(abspath $3)%,,$(abspath $2))),$\
$(strip $(call prefix_1,$1,$2,$(call dirname,$3))),$\
$(strip $(abspath $3)))
endef
override define prefix
$(call prefix_1,$1,$2,$1)
endef
override define relpath_1
$(patsubst /%,%,$(subst $(\s),/,$(patsubst %,..,$(subst /,$(\s),$\
$(patsubst $3%,%,$(abspath $2)))))$\
$(patsubst $3%,%,$(abspath $1)))
endef
override define relpath
$(call relpath_1,$1,$2,$(call prefix,$1,$2))
endef
Test cases:
$(info $(call prefix,/home/user,/home/user))
$(info $(call prefix,/home/user,/home/user/))
$(info $(call prefix,/home/user/,/home/user))
$(info $(call prefix,/home/user/,/home/user/))
$(info $(call relpath,/home/user,/home/user))
$(info $(call relpath,/home/user,/home/user/))
$(info $(call relpath,/home/user/,/home/user))
$(info $(call relpath,/home/user/,/home/user/))
$(info ----------------------------------------------------------------------)
$(info $(call prefix,/home/user,/home/user/.local/share))
$(info $(call prefix,/home/user,/home/user/.local/share/))
$(info $(call prefix,/home/user/,/home/user/.local/share))
$(info $(call prefix,/home/user/,/home/user/.local/share/))
$(info $(call relpath,/home/user,/home/user/.local/share))
$(info $(call relpath,/home/user,/home/user/.local/share/))
$(info $(call relpath,/home/user/,/home/user/.local/share))
$(info $(call relpath,/home/user/,/home/user/.local/share/))
$(info ----------------------------------------------------------------------)
$(info $(call prefix,/home/user/.config,/home/user/.local/share))
$(info $(call prefix,/home/user/.config,/home/user/.local/share/))
$(info $(call prefix,/home/user/.config/,/home/user/.local/share))
$(info $(call prefix,/home/user/.config/,/home/user/.local/share/))
$(info $(call relpath,/home/user/.config,/home/user/.local/share))
$(info $(call relpath,/home/user/.config,/home/user/.local/share/))
$(info $(call relpath,/home/user/.config/,/home/user/.local/share))
$(info $(call relpath,/home/user/.config/,/home/user/.local/share/))
$(info ----------------------------------------------------------------------)
$(info $(call prefix,/home/user/.local/share,/home/user))
$(info $(call prefix,/home/user/.local/share,/home/user/))
$(info $(call prefix,/home/user/.local/share/,/home/user))
$(info $(call prefix,/home/user/.local/share/,/home/user/))
$(info $(call relpath,/home/user/.local/share,/home/user))
$(info $(call relpath,/home/user/.local/share,/home/user/))
$(info $(call relpath,/home/user/.local/share/,/home/user))
$(info $(call relpath,/home/user/.local/share/,/home/user/))
$(info ----------------------------------------------------------------------)
$(info $(call prefix,/home/user/.local/share,/home/user/.config))
$(info $(call prefix,/home/user/.local/share,/home/user/.config/))
$(info $(call prefix,/home/user/.local/share/,/home/user/.config))
$(info $(call prefix,/home/user/.local/share/,/home/user/.config/))
$(info $(call relpath,/home/user/.local/share,/home/user/.config))
$(info $(call relpath,/home/user/.local/share,/home/user/.config/))
$(info $(call relpath,/home/user/.local/share/,/home/user/.config))
$(info $(call relpath,/home/user/.local/share/,/home/user/.config/))
$(info ----------------------------------------------------------------------)
$(info $(call prefix,/root,/home/user))
$(info $(call prefix,/root,/home/user/))
$(info $(call prefix,/root/,/home/user))
$(info $(call prefix,/root/,/home/user/))
$(info $(call relpath,/root,/home/user))
$(info $(call relpath,/root,/home/user/))
$(info $(call relpath,/root/,/home/user))
$(info $(call relpath,/root/,/home/user/))
Expected results:
/home/user
/home/user
/home/user
/home/user
----------------------------------------------------------------------
/home/user
/home/user
/home/user
/home/user
../..
../..
../..
../..
----------------------------------------------------------------------
/home/user
/home/user
/home/user
/home/user
../../.config
../../.config
../../.config
../../.config
----------------------------------------------------------------------
/home/user
/home/user
/home/user
/home/user
.local/share
.local/share
.local/share
.local/share
----------------------------------------------------------------------
/home/user
/home/user
/home/user
/home/user
../.local/share
../.local/share
../.local/share
../.local/share
----------------------------------------------------------------------
../../root
../../root
../../root
../../root
Didier's answer is the best one, but the following might give you some ideas:
includedir=/a/b/c/d
currentdir=/a/b/e/f/g
up=; while ! expr $includedir : $currentdir >/dev/null; do up=../$up; currentdir=`dirname $currentdir`; done; relative=$up`expr $includedir : $currentdir'/*\(.*\)'`
echo "up=$up currentdir=$currentdir, relative=$relative"
Sorted!
(no-one said it had to be pretty...)
Here's a solution that only uses GNU make functions. Even though it's recursive, it ought to be more efficient than calling an external program. The idea is pretty straight forward: the relative path will be zero or more .. to go up to the most common ancestor, then a suffix to go down to the 2nd directory. The hard part is finding the longest common prefix in both paths.
# DOES not work if path has spaces
OneDirectoryUp=$(patsubst %/$(lastword $(subst /, ,$(1))),%,$(1))
# FindParentDir2(dir0, dir1, prefix) returns prefix if dir0 and dir1
# start with prefix, otherwise returns
# FindParentDir2(dir0, dir1, OneDirectoryUp(prefix))
FindParentDir2=
$(if
$(or
$(patsubst $(3)/%,,$(1)),
$(patsubst $(3)/%,,$(2))
),
$(call FindParentDir2,$(1),$(2),$(call OneDirectoryUp,$(3))),
$(3)
)
FindParentDir=$(call FindParentDir2,$(1),$(2),$(1))
# how to make a variable with a space, courtesy of John Graham-Cumming
# http://blog.jgc.org/2007/06/escaping-comma-and-space-in-gnu-make.html
space:=
space+=
# dir1 relative to dir2 (dir1 and dir2 must be absolute paths)
RelativePath=$(subst
$(space),
,
$(patsubst
%,
../,
$(subst
/,
,
$(patsubst
$(call FindParentDir,$(1),$(2))/%,
%,
$(2)
)
)
)
)
$(patsubst
$(call FindParentDir,$(1),$(2))/%,
%,
$(1)
)
# example of how to use (will give ..)
$(call RelativePath,/home/yale,/home/yale/workspace)
I recently translated a large set of recursive makefiles into a whole project make as it's well known that recursive make is bad due to not exposing the entire dependence graph (http://aegis.sourceforge.net/auug97.pdf). All source code and library paths are defined relative to the current makefile directory. Instead of defining a fixed number of generic % build rules, I create a set of rules for every (source code directory, output directory) pair, which avoids the ambiguity of using vpath. When creating the build rules, I need a canonical path for each source code directory. Although the absolute path can be used, it's usually too long and less portable (I happened to be using Cygwin GNU make where absolute paths have a /cygdrive prefix and aren't recognized by Windows programs). Therefore, I use this function heavily for generating canonical paths.
Perl is portable! Here's a solution using the abs2rel function from the core Perl module File::Spec (resp. File::Spec::Functions):
current_dir= /home/username/projects/app/trunk/src/libs/libfoo/
destination= /home/username/projects/app/build/libfoo/
relative= $(shell perl -MFile::Spec::Functions=abs2rel -E 'say abs2rel(shift, shift)' $(destination) $(current_dir))
makefile_target:
#echo "Use now $(relative)"
This is my solution based on the Norman Gray's idea:
define relative
CURDIR=$(1); UP=; while ! expr $(2) : $${CURDIR} > /dev/null; do UP=../$${UP}; CURDIR=$$(dirname $${CURDIR}); done; echo $${UP}$$(expr $(2) : $${CURDIR}'/*\(.*\)')
endef
includedir1=/a/b/c/d
includedir2=/a/b/e/f/g/h/j
currentdir=/a/b/e/f/g
relative1:=$(shell $(call relative,$(currentdir),$(includedir1)))
makefile_target:
#echo "Relative1: $(relative1)"
#echo "Relative2: $(shell $(call relative,$(currentdir),$(includedir2)))"