How to add a shared library (let it be libXYZ.so) as a dependency for a LOCAL_MODULE target, when libXYZ.so does not link to the target directly.
How to make sure build system first builds the dependency(libXYZ.so) and then execute commands for LOCAL_MODULE from a Android.mk
This is required because in my build, the dependency (libXYZ.so) it self is not used but a symlink with different name is used. (libABC.so -> libXYZ.so). The symlink is generated after the shared library is created, as part of LOCAL_POST_INSTALL_CMD.
You can add the library to the prerequisite list:
LOCAL_MODULE: libXYZ.so
but then you must trust the rule that builds the library also builds the symlink. It would be safer to make the symlink itself a target, make the symlink a prereq of the module, and make the library a prereq of the symlink.
Related
I have an external out-of-tree linux kernel module, say foo. Therein, I have a directory include/uapi/ that should, I assume, contain Kbuild file defining inclusion rules and/or headers to export. The directory include/uapi/ on its turn contains one more directory linux having the target user-API headers in, say three files foo.h bar.h baz.h
Ok, I have defined this Kbuild file inside include/uapi and it contains:
header-y += linux/
Then, inside include/uapi/linux directory I've defined one more KBuild and it has the content:
header-y += foo.h bar.h baz.h
Now I am expecting that upon running the command
make -C /lib/modules/5.4.48-dannftk/build M=/home/dannftk/foo INSTALL_HDR_PATH=/home/dannftk/my_exported_headers/ headers_install
I will get the headers installed in the /home/dannftk/my_exported_headers/ directory, instead, I am getting the error saying:
make: *** No rule to make target 'headers_install'. Stop.
/home/dannftk/foo - the path the out-of-tree module discussed is located by
/lib/modules/5.4.48-dannftk/build - the build directory of the kernel, it points to /usr/src/linux-5.4.48 containing the source code of the kernel, actually, I am on Gentoo Linux
May someone give me a hint what I am doing wrongly? Am I incorrectly setting rules for Kbuild? Or maybe I am locating them in unexpected for the kernel build system directories?
Thank you in advance
I personally consider this issue as a bad Kbuild error message. It's too confusing.
The answer is in linux documentation:
--- 2.3 Targets
When building an external module, only a subset of the "make"
targets are available.
make -C $KDIR M=$PWD [target]
The default will build the module(s) located in the current
directory, so a target does not need to be specified. All
output files will also be generated in this directory. No
attempts are made to update the kernel source, and it is a
precondition that a successful "make" has been executed for the
kernel.
modules
The default target for external modules. It has the
same functionality as if no target was specified. See
description above.
modules_install
Install the external module(s). The default location is
/lib/modules/<kernel_release>/extra/, but a prefix may
be added with INSTALL_MOD_PATH (discussed in section 5).
clean
Remove all generated files in the module directory only.
help
List the available targets for external modules.
There were some hacks available in older kernel versions, as adding header-y += ... into Kbuild file, but, as you see, it's not the official approach.
Looks like developers of out-of-tree modules should take care of headers installation manually, without reusing of linux kernel make rules.
I want to automatically create Makefile dependency files in a hidden folder but I can't find an example of how to create dependency files automatically. Everything concerning makefile is gcc, but I am using not for gcc and I am not too familiar with gcc.
I have a makefile like this.
importf = .mkfiles/import
import: $(importf)
$(importf):
#$(call make_function,0,import)
Could you please help me what I am missing in the makefile.
Could someone please tell me if there is a way to enforce sequential execution of specific Makefile targets. For example, I have a Makefile that builds Libraries and Executables. Now, Executables depend on Libraries, so they must be built after the Libraries are built and staged. This is what I currently have in a single Makefile:
.PHONY: all
all: all_lib all_bin
.PHONY: all_lib
all_lib: $(dep_lib)
.PHONY: all_bin
all_bin: $(dep_bin)
I have two targets all_lib and all_bin, one builds all libraries and the other builds all binary executables. When I pass -j to make to run parallel jobs, I get build failures, because all targets run in parallel and binaries can't find shared library objects and staged header files.
I tried changing it to this to try and force some dependency order:
.PHONY: all
all: all_bin
.PHONY: all_lib
all_lib: $(dep_lib)
.PHONY: all_bin
all_bin: all_lib $(dep_bin)
But for some reason all targets still run in parallel I still get the same build failures. Any ideas?
Make is entirely built around the concept of dependencies. You are simply not using it that way.
If an executable depends on a library, then you should list that library in the prerequisites list of the executable. I can't give you a relevant example because you don't provide any details about the contents of dep_lib or dep_bin above, but for example:
exe1 : exe1.o liblib1.a liblib2.a
etc. Now, exe1 won't attempt to be linked until after the liblib1.a and liblib2.a targets have been created.
Is it possible to use install(TARGETS ...) with targets that are defined in directories added with add_subdirectory?
My use case is, that I want to build e.gg an rpm for gtest. the gtest project happens to have a CMakeLists.txt without any install statements. I want to build the package without adding those statements to the CMakeLists.txt of gtest.
I have this resulting directory structure:
+ gtest-1.5.0/...
+ CMakeLists.txt
The CMakeLists of gtest-1.5.0 defines libraries like this:
cxx_static_library(gtest "${cxx_strict}" src/gtest-all.cc)
cxx_static_library(gtest_main "${cxx_strict}" src/gtest_main.cc)
target_link_libraries(gtest_main gtest)
now i want to add something like this to my CMakeLists.txt:
add_subdirectory(gtest-1.5.0)
install(TARGETS gtest gtest_main ARCHIVE DESTINATION lib)
but cmake correctly states:
CMake Error at CMakeLists.txt:10 (install):
install TARGETS given target "gtest" which does not exist in this
directory.
Is there a way to do this without patching gtest-1.5.0?
You could try using file install rather than install targets. The downside is that you will have to handle shared and static builds.
install(FILES gtest-1.5.0/gtest_main.so DESTINATION lib)
I'm using CMake-2.8 on winxp with Visual Studio 2005 generator.
lets say I've a dll created (A.dll) from some cxx files and a static library static.lib
So I call Link_Directories to specify the directory where the static library is located.
Now A.dll is built fine.
Now I want B.dll built from some cxx sources, A.lib (the import lib of A.dll)
Now when I say Target_Link_Libraries for (B A), the project file is created with static.lib also as a dependency.
Now B has two dependencies A and static.lib. But I'm not adding the directory of static.lib to Link_Directories for B and my build fails.
I do not think B needs to know about static.lib
Any Ideas how to avoid this ?
Thanks in advance,
Surya
From the CMake docs:
Library dependencies are transitive by default. When this target is linked into another target then the libraries linked to this target will appear on the link line for the other target too. See the LINK_INTERFACE_LIBRARIES target property to override the set of transitive link dependencies for a target.
Hence, this should solve your problem:
TARGET_LINK_LIBRARIES(B LINK_INTERFACE_LIBRARIES A)