summaryrefslogtreecommitdiff
path: root/mk/lib.mk
diff options
context:
space:
mode:
Diffstat (limited to 'mk/lib.mk')
-rw-r--r--mk/lib.mk46
1 files changed, 46 insertions, 0 deletions
diff --git a/mk/lib.mk b/mk/lib.mk
new file mode 100644
index 0000000..87cf579
--- /dev/null
+++ b/mk/lib.mk
@@ -0,0 +1,46 @@
+# Input
+#
+# libname tells the name of the lib and
+# libdir tells directory of lib which also is used as input to
+# mk/subdir.mk
+# conf-file [optional] if set, all objects will depend on $(conf-file)
+#
+# Output
+#
+# updated cleanfiles and
+# updated libfiles, libdirs, libnames and libdeps
+
+
+subdirs = $(libdir)
+include mk/subdir.mk
+include mk/compile.mk
+
+lib-libfile = $(out-dir)/$(base-prefix)$(libdir)/lib$(libname).a
+cleanfiles := $(cleanfiles) $(lib-libfile)
+libfiles := $(lib-libfile) $(libfiles)
+libdirs := $(out-dir)/$(base-prefix)$(libdir) $(libdirs)
+libnames := $(libname) $(libnames)
+libdeps := $(lib-libfile) $(libdeps)
+
+define process-lib
+ifeq ($(lib-use-ld), y)
+$(lib-libfile): $(objs)
+ @echo ' LD $$@'
+ @mkdir -p $$(dir $$@)
+ $$(q)$$(LD$(sm)) $(lib-ldflags) -o $$@ $$^
+else
+$(lib-libfile): $(objs)
+ @$(cmd-echo-silent) ' AR $$@'
+ @mkdir -p $$(dir $$@)
+ $$(q)rm -f $$@ && $$(AR$(sm)) rcs $$@ $$^
+endif
+endef #process-lib
+
+$(eval $(call process-lib))
+
+$(objs): $(conf-file)
+
+# Clean residues from processing
+objs :=
+libname :=
+lib-use-ld :=