Make to install dependencies in multiple projects Makefile - makefile

I have a Makefile with multiple subprojects and set its build dependencies.
Now I want to be able to selectively make install some of those subprojects but include the dependencies in the installation.
How can I do this?
Suppose a Makefile like this:
lib1:
lib2:
proj1: lib1
proj2: lib2
proj3: lib1 lib2
install_%: $*
make -C $* install
install: $(addprefix install_,$(SUBDIRS) )
And I'd like to be able to do, from command line, things like:
make install SUBDIRS=proj1
or
make install SUBDIRS=proj3
My rules will try to build and install "proj3", but:
Will fail if any lib is not built.
Even if it finds the needed libs, those will not be installed along the program.
Any help is welcome.

In the makefile for dependent projects and include the makefiles for dependencies and write rules to express the dependency:
proj3/Makefile:
include ../lib1/Makefile
include ../lib2/Makefile
proj3: lib1 lib2
$(CC) ....
install: proj3 install_lib1 install_lib2
cp ...
lib1/Makefile:
lib1: # ....
$(CC) ....
install_lib1: # ....
cp ...

Related

ninja appends its default installation path to my DESTDIR [duplicate]

I'm using to building code with CMake; but I'm now faced with using meson to build a certain repository. With CMake and make, if I use something like:
cmake -DCMAKE_INSTALL_PREFIX=/some/where` build_dir
make -C build_dir
make -C build_dir install
then instead of the files going under /usr/local by default, they will go under /some/where, e.g. /some/where/bin for executables, /some/where/lib, for libraries etc.
What's the meson equivalent of doing this?
Inspired by: What is CMake equivalent of 'configure --prefix=DIR && make all install '?
It's actually similar to the autotools convention in terms of the switch:
meson setup --prefix=/path/of/installation/destination build_dir
ninja -C build_dir
ninja -C build_dir install
(you could drop the first ninja command; ninja install will build before it installs.)

GNU make - enforcing target order

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.

Libtool: Makefile.am call a Makefile in some other directory

Deal All,
I have a library that is built with libtool. I have an additional module that has been built using a Makefile but not using libtool. I want to be able to use this library object along with the ones that libtool builds. Since I do not want to integrate the additional module with libtool, I just want to expand the Makefile generated from libtool on the lines of:
all: all-am
(instead:)
all: new-module all-am
new-module:
-cd new-module-src && $(MAKE)
Thanks
How can I do this in the Makefile.am?

Can GNU make have targets that depend on the completion of targets from other makefiles?

I have several directories representing subparts of a project, each with its own Makefile.
I want to create a master Makefile with targets for each of those subparts, each target satisfying the following:
depend on a certain target from that subproject's Makefile.
This is the tricky part.
copy some resulting library/executable build by the subproject into a central directory (kind of like "make install"-ing it).
This I can already achieve using simple commands.
I could only find information about the include directive of GNU make, but that doesn't help me much as it seems not to encapsulate the rules (and execution) of the included makefile in its own directory, but instead just #includes them C-style (rather that thinking of them as packages with separate scopes).
INSTALLDIR := build
SRCDIR := src
TARGETS := projA projB
.PHONY: $(TARGETS)
TARGETS_PATH := $(addprefix $(SRCDIR)/, $(TARGETS))
MAKEFILES := $(addsuffix /osx.mak, $(TARGETS_PATH))
# include them somehow?
For such a setup as defined above, I now want each of $(TARGETS) to depend on the release target of its corresponding Makefile (something like projA: $(SRCDIR)/projA/osx.mak # release for projA, in my own language meaning that target projA depends on the successful execution of the release target in that specific Makefile).
Is there any way to achieve this?
You can suggest other tools apart from GNU make, but the subproject makefiles are already written as makefiles.
Have a look at recursive make.
You could do something like,
SRCDIR := src
TARGETS := projA projB
.PHONY: $(TARGETS)
$(TARGETS):
cd $(SRCDIR)/$#; $(MAKE) release

multi package makefile example for go

I'm trying to setup a multi package go project something like
./main.go
./subpackage1/sub1_1.go
./subpackage1/sub1_2.go
./subpackage2/sub2_1.go
./subpackage2/sub2_2.go
where main.go imports both subpackage1 and subpackage2. And subpackage2 imports subpackage1.
Ive been looking around for go makefile examples but I can't find anything that supports this kind of set-up. Any idea?
Install godag then run:
gd -o myapp
It will automatically build a Directed Acyclic Graph (DAG) of all the dependencies in your src/ directory, then compile and link each package in the proper order.
Much easier than manually maintaining a Makefile, especially since $(GOROOT)/src/Make.* has changed in recent versions of Go (there is no longer a Make.$(GOARCH)). Also useful:
gd clean removes object files.
gd -test runs your automated tests (see testing package).
gd -dot=myapp.dot generates a graph of your package imports you can visualize using GraphViz.
Something like this should work
# Makefile
include $(GOROOT)/src/Make.$(GOARCH)
all:main
main:main.$O
$(LD) -Lsubpackage1/_obj -Lsubpackage2/_obj -o $# $^
%.$O:%.go subpackage1 subpackage2
$(GC) -Isubpackage1/_obj -Isubpackage2/_obj -o $# $^
subpackage1:
$(MAKE) -C subpackage1
subpackage2:
$(MAKE) -C subpackage2
.PHONY:subpackage1 subpackage2
# subpackage1/Makefile
TARG=subpackage1
GOFILES=sub1_1.go sub1_2.go
include $(GOROOT)/src/Make.$(GOARCH)
include $(GOROOT)/src/Make.pkg
# subpackage2/Makefile
TARG=subpackage2
GOFILES=sub2_1.go sub2_2.go
include $(GOROOT)/src/Make.$(GOARCH)
include $(GOROOT)/src/Make.pkg
GC+=-I../subpackage1/_obj
LD+=-L../subpackage1/_obj
sub2_1.$O sub2_2.$O:subpackage1
subpackage1:
$(MAKE) -C ../subpackage1
.PHONY:subpackage1
If you don't install the subpackages you need to explicitly set the include path. The supplied makefile Make.pkg is mainly to build packages, which is why it's only included in the subpackage makefile.
hello world with a Makefile and a test (Googles Groupes : golang-nuts)
Check out https://github.com/banthar/Go-SDL which is an actively maintained multi-package go project using Makefiles.
I notice some of these the answers use the obsolete Make.$(GOARCH) include. So hopefully the above link will be stabler than trying to stay on top of Google's changing API in an answer here.

Resources