I'm trying to build my project from the top directory which have the subdirectories
root
Makefile
| common/
| lib/
| app1/
| app2/
| app3/
Assumption 1: I'm at the root directory
Assumption 2: Each subdirectory has its own Makefile
Assumption 3: root's Makefile doesn't actually give any output, it only wants to execute Makefiles in the subdirectories
Assumption 4: common/ and lib/ will contain library files lib1.a and lib2.a
Now, by running make at the root, I want to first build the two libraries lib1.a and lib2.a. And then I want to build the respective apps in app1/, app2/, and app3/. The 3 apps should be linked to lib1.a and lib2.a.
I'm at the stage where I want to first build the two libraries by calling their Makefiles respectively. Here's what I have so far.
CFLAGS = -Wall -pedantic -std=c11 -ggdb
CC = gcc
MAKE = make
LIBPATH = lib/
COMMONPATH = common/
$(LIBPATH)lib1.a : $(LIBPATH)lib1.a # i know this isn't appropriate but it executes make
$(MAKE) -C $(LIBPATH)
$(COMMONPATH)lib2.a : $(COMMONPATH)lib2.a
$(MAKE) -C $(COMMONPATH)
I know there are probably better ways to write this, but the main problem for me is that this makefile only executes whatever is first. Now it will recursveily run the lib1.a's makefile but not for lib2.a. As I want to write similar lines for app1 app2 and app3 I want to resolve this.
Thanks in advance!