diff --git a/Makefile b/Makefile index 69a7f61d9..e2ca3947a 100644 --- a/Makefile +++ b/Makefile @@ -126,12 +126,9 @@ ifeq ($(GCOV),1) %.o $(PROGRAM): override CFLAGS += --coverage endif -all: config pie $(VERSION_HEADER) lib +all: config pie $(VERSION_HEADER) $(CRIU-LIB) $(Q) $(MAKE) $(PROGRAM) -lib: $(VERSION_HEADER) - $(Q) $(MAKE) -C lib all - protobuf/%:: $(Q) $(MAKE) $(build)=protobuf $@ protobuf: @@ -152,6 +149,11 @@ pie: arch/$(ARCH) built-in.o: $(VERSION_HEADER) pie $(Q) $(MAKE) $(build-crtools)=. $@ +lib/%:: $(VERSION_HEADER) config built-in.o + $(Q) $(MAKE) $(build)=lib $@ +lib: $(VERSION_HEADER) config built-in.o + $(Q) $(MAKE) $(build)=lib all + PROGRAM-BUILTINS += pie/util-fd.o PROGRAM-BUILTINS += pie/util.o PROGRAM-BUILTINS += protobuf/built-in.o @@ -176,11 +178,11 @@ clean-built: $(Q) $(MAKE) $(build)=arch/$(ARCH) clean $(Q) $(MAKE) $(build)=protobuf clean $(Q) $(MAKE) $(build)=pie clean + $(Q) $(MAKE) $(build)=lib clean $(Q) $(MAKE) $(build-crtools)=. clean $(Q) $(MAKE) -C Documentation clean $(Q) $(RM) ./include/config.h $(Q) $(RM) ./$(PROGRAM) - $(Q) $(MAKE) -C lib clean rebuild: clean-built $(E) " FORCE-REBUILD" diff --git a/lib/Makefile b/lib/Makefile index 368883e9f..6d34fec80 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -1,13 +1,29 @@ -.PHONY: all clean +obj-y += criu.o -all: libcriu.so +cflags-y += -shared -fPIC -Wa,--noexecstack -fno-stack-protector +LDFLAGS += --export-dynamic +includes += -iquote $(obj)/../arch/$(ARCH)/include -iquote $(obj)/../include -iquote $(obj)/.. -libcriu.so: criu.o - $(Q) $(CC) $(CFLAGS) -shared -o $@ criu.o +.SECONDARY: -criu.o: - $(Q) $(CC) $(CFLAGS) -fPIC -c criu.c -I ../include/ +# +# We need util-fd.c to be re-compiled with +# own flags, but our build engine can't +# do such tricks yet, so write a rule +# manually for a while. +$(obj)/util-fd.o: $(obj)/../pie/util-fd.c + $(E) " CC " $@ + $(Q) $(CC) -c $(cflags-y) $(CFLAGS) $(includes) $< -o $@ -clean: - $(Q) $(RM) -f *.o - $(Q) $(RM) -f *.so +$(obj)/built-in.o: $(obj)/util-fd.o + +$(obj)/libcriu.so: $(obj)/built-in.o + $(E) " GEN " $@ + $(Q) $(CC) $(CFLAGS) -shared $^ -o $@ + +_all += $(obj)/built-in.o +cleanup-y += $(obj)/*.so + +ifneq ($(MAKECMDGOALS),clean) +incdeps := y +endif