make files and linking: empty objs

Hello there! I'm writting a make file to create a static lib.a then an upper level make file links together all the static libs. The project is structured in several folders. Each static lib should be created in one of these folders, then moved to the global lib folder. So I have a make file in each one of this folders. It is in this make file where I have the problem, for clarity i will call it here sub-makefile. Problem being that the first time I run one of these sub-make files, which are all identical, just one per folder, the wildcard that expands all the objs produced, is empty, and then, the output static lib is 8bytes size (is actually empty). If I run the make file again, without changing anything, then everything goes ok. I will post down here one of this sub-make files:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#===== aliases =====
#--- compiler
CC=g++
CFLAGS=-g -Wall -ansi
LIBNAME:=kmath

#--- folders
MAINPATH:=../..
OBJDIR:= $(MAINPATH)/obj
LIBDIR:= $(MAINPATH)/lib
INCLUDES:= -I ../include -I ../kStd -I ../kRTLib

#--- aliases
LOCALOBJS:=$(wildcard *.o)

#--- directives
vpath %.h ../include

#--- 
.PHONY: all
all: $(LIBNAME).a

#--- build lib
$(LIBNAME).a: *.cpp
	@+echo
	@echo "---creating $(LIBNAME) lib---"
	$(CC) $(INCLUDES) $(CFLAGS) -c $?; \
	ar rcs lib$(LIBNAME).a $(LOCALOBJS); \
	ranlib lib$(LIBNAME).a; \
	mv $(LOCALOBJS) $(OBJDIR); \
	cp -p lib$(LIBNAME).a $(LIBDIR)
Last edited on
Bump.
Topic archived. No new replies allowed.