[klibc] kbuild: make install

Sam Ravnborg sam at ravnborg.org
Sun Aug 7 00:53:08 PDT 2005


kbuild: make install

Added infrastructure for make install and start usign it.
The file scripts/Kbuild.install contains both logic for descending
subdirectories and the final install steps.
For a normal binary just use:
install-y := binary

For special requirements use:
install-rule:
	commands to execute

Only user of install-rule for now is klibc/Kbuild

To test the install do:
make INSTALLROOT=~/tmp/test install

To better support make install a new Kbuild file is created in
top-level directory, and some functionality thus moved from
./Makefile to ./Kbuild

Signed-off-by: Sam Ravnborg <sam at ravnborg.org>

---
commit f0b0bb120b3104e4b7493f533e096e33cc1737cf
tree 97844eb82116ba6718fe24ed9567021571508014
parent d621115d41d24f209588b9896fcc95729cd9008f
author Sam Ravnborg <sam at mars.(none)> Sun, 07 Aug 2005 09:18:34 +0200
committer Sam Ravnborg <sam at mars.(none)> Sun, 07 Aug 2005 09:18:34 +0200

 Kbuild                 |   16 ++++++
 Makefile               |   41 +++-------------
 ash/Kbuild             |    6 +-
 gzip/Kbuild            |    5 +-
 klibc/Kbuild           |   18 ++++++-
 scripts/Kbuild.include |    3 +
 scripts/Kbuild.install |  122 ++++++++++++++++++++++++++++++++++++++++++++++++
 utils/Kbuild           |    7 +--
 8 files changed, 172 insertions(+), 46 deletions(-)

diff --git a/Kbuild b/Kbuild
new file mode 100644
--- /dev/null
+++ b/Kbuild
@@ -0,0 +1,16 @@
+#
+# Kbuild file for klibc
+#
+.PHONY: $(obj)/all
+always := all
+
+$(obj)/all:
+	$(Q)$(MAKE) $(klibc)=scripts/basic
+	$(Q)$(MAKE) $(klibc)=klibc
+	$(Q)$(MAKE) $(klibc)=ash
+	$(Q)$(MAKE) $(klibc)=utils
+	$(Q)$(MAKE) $(klibc)=gzip
+
+
+# Directories to visit during clean and install
+subdir- := klibc ash utils gzip
diff --git a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -25,6 +25,7 @@ export bindir      = $(prefix)/bin
 export libdir      = $(prefix)/lib
 export mandir      = $(prefix)/man
 export INSTALLDIR  = $(prefix)/lib/klibc
+export INSTALLROOT =
 
 # Create a fake .config as present in the kernel tree
 # But if it exists leave it alone
@@ -67,8 +68,8 @@ MAKEFLAGS += --no-print-directory
 klibc := -f $(srctree)/scripts/Kbuild.klibc obj
 
 # Very first target
-.PHONY: klcc
-all: klcc
+.PHONY: all klcc klibc
+all: klcc klibc
 
 rpmbuild = $(shell which rpmbuild 2>/dev/null || which rpm)
 
@@ -83,15 +84,9 @@ rpm: klibc.spec
 klcc:
 	$(Q)$(MAKE) $(klibc)=klcc
 
-%: local-%
-	$(Q)$(MAKE) $(klibc)=scripts/basic
-	$(Q)$(MAKE) $(klibc)=klibc
-	$(Q)$(MAKE) $(klibc)=ash
-	$(Q)$(MAKE) $(klibc)=utils
-	$(Q)$(MAKE) $(klibc)=gzip
-	@set -e; for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done
-
-local-all: $(CROSS)klcc
+klibc:
+	$(Q)$(MAKE) $(klibc)=.
+#$(Q)set -e; for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done
 
 local-clean:
 	rm -f klibc.config klcc
@@ -99,30 +94,10 @@ local-clean:
 local-spotless: local-clean
 	rm -f klibc.spec *~ tags
 
-local-install: $(CROSS)klcc
-	mkdir -p $(INSTALLROOT)$(bindir)
-	mkdir -p $(INSTALLROOT)$(mandir)/man1
-	mkdir -p $(INSTALLROOT)$(SHLIBDIR)
-	mkdir -p $(INSTALLROOT)$(INSTALLDIR)
-	-rm -rf $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)include
-	mkdir -p $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)include
-	mkdir -p $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)lib
-	mkdir -p $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)bin
-	set -xe ; for d in linux scsi asm-$(ARCH) asm-generic $(ASMARCH); do \
-	  mkdir -p $(INSTALLROOT)$(INSTALLDIR)/$(CROSS)include/$$d ; \
-	  for r in $(KRNLSRC)/include $(KRNLOBJ)/include $(KRNLOBJ)/include2 ; do \
-	    [ ! -d $$r/$$d ] || \
-	      cp -rfL $$r/$$d/. $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)include/$$d/. ; \
-	  done ; \
-	done
-	cd $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)include && ln -sf asm-$(ARCH) asm
-	cp -rf include/. $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)include/.
-	$(INSTALL_DATA) klcc.1 $(INSTALLROOT)$(mandir)/man1/$(KCROSS)klcc.1
-	$(INSTALL_EXEC) $(KCROSS)klcc $(INSTALLROOT)$(bindir)
+install: all
+	$(Q)$(MAKE) -f $(srctree)/scripts/Kbuild.install obj=.
 
 # This does all the prep work needed to turn a freshly exported git repository
 # into a release tarball tree
 release: klibc.spec
 	rm -f maketar.sh
-
--include MCONFIG
diff --git a/ash/Kbuild b/ash/Kbuild
--- a/ash/Kbuild
+++ b/ash/Kbuild
@@ -118,8 +118,6 @@ $(obj)/arith_lex.c: $(src)/arith_lex.l
 $(obj)/arith.h: $(src)/arith.c
 	$(PERL) -ne 'print if ( /^\#\s*define\s+ARITH/ );' < $< > $@
 
-ifeq (a,b)
-install: all
-	$(INSTALL_EXEC) sh.shared $(INSTALLROOT)$(INSTALLDIR)/$(CROSS)bin/sh
 
-endif
+# Targets to install
+install-y := sh.shared
diff --git a/gzip/Kbuild b/gzip/Kbuild
--- a/gzip/Kbuild
+++ b/gzip/Kbuild
@@ -25,6 +25,5 @@ $(obj)/gzip.stripped: $(obj)/gzip
 # Cleaning
 targets := $(static-y) $(shared-y)
 
-# Old install target - TODO
-#install: all
-#	$(INSTALL_EXEC) gzip gunzip zcat $(INSTALLROOT)$(INSTALLDIR)/$(CROSS)bin
+# Targets to install
+install-y := gzip gunzip zcat
diff --git a/klibc/Kbuild b/klibc/Kbuild
--- a/klibc/Kbuild
+++ b/klibc/Kbuild
@@ -67,6 +67,8 @@ SOHASH   := $(call objectify,$(SOHASH))
 CRT0     := $(call objectify,$(CRT0))
 INTERP_O := $(call objectify,$(INTERP_O))
 
+SOLIBHASH = $(shell cat $(SOLIB).hash)
+
 targets  := arch/$(ARCH)/crt0.o
 targets  += $(libc-y) $(ARCHOBJS)
 
@@ -131,7 +133,7 @@ quiet_cmd_sohash = GEN     $@
       cmd_sohash = cat $< > $@;                                           \
                      $(KLIBCSTRIP) $(KLIBCSTRIPFLAGS) $@;                   \
                      rm -f $(obj)/klibc-???????????????????????????.so;   \
-                     ln -f $@ $(obj)/klibc-`cat $(SOLIB).hash`.so
+                     ln -f $@ $(obj)/klibc-$(SOLIBHASH).so
 $(SOHASH): $(SOLIB) $(SOLIB).hash
 	$(call cmd,sohash)
 
@@ -143,8 +145,20 @@ targets += interp.o
 quiet_cmd_interp = BUILD   $@
       cmd_interp = $(KLIBCCC) $(klibccflags) -D__ASSEMBLY__     \
                              -DLIBDIR=\"$(SHLIBDIR)\"         \
-			     -DSOHASH=\"`cat $(SOLIB).hash`\" \
+			     -DSOHASH=\"$(SOLIBHASH)\" \
 			     -c -o $@ $<
 
 $(INTERP_O): $(obj)/interp.S $(SOLIB).hash
 	$(call if_changed,interp)
+
+#####
+# Install klibc
+install-rule:
+	@echo "  INSTALL klibc to $(INSTALLROOT)$(INSTALLDIR)/$(KLIBCCROSS)lib"
+	$(Q)$(foreach f, $(LIB) $(SOLIB) $(CRT0) $(INTERP_O), \
+	  $(shell $(install-data) $(f) \
+	          $(INSTALLROOT)$(INSTALLDIR)/$(KLIBCCROSS)lib))
+	$(Q)$(install-lib) $(obj)/klibc-$(SOLIBHASH).so \
+	                      $(INSTALLROOT)$(INSTALLDIR)/$(KLIBCCROSS)lib
+	$(Q)$(install-lib) $(obj)/klibc-$(SOLIBHASH).so \
+	                      $(INSTALLROOT)$(SHLIBDIR)
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -49,6 +49,9 @@ build := -f $(if $(KBUILD_SRC),$(srctree
 cmd = @$(if $($(quiet)cmd_$(1)),\
       echo '  $(subst ','\'',$($(quiet)cmd_$(1)))' &&) $(cmd_$(1))
 
+# Add $(obj)/ for paths that is not absolute
+objectify = $(foreach o,$(1),$(if $(filter /%,$(o)),$(o),$(obj)/$(o)))
+
 ###
 # if_changed      - execute command if any prerequisite is newer than 
 #                   target, or command line has changed
diff --git a/scripts/Kbuild.install b/scripts/Kbuild.install
new file mode 100644
--- /dev/null
+++ b/scripts/Kbuild.install
@@ -0,0 +1,122 @@
+#
+# Install klibc
+#
+# File is logically seperated in two pieces.
+# First piece is used when during a recursive descend of the klibc tree
+# and second piece is used to do the final steps in the install
+# If KLIBC_INSTALL is defined it tells us we are descending and we
+# use first piece of the file.
+
+# This indicates the location of the final version of the shared library.
+# THIS MUST BE AN ABSOLUTE PATH WITH NO FINAL SLASH.
+# Leave this empty to make it the root.
+#
+SHLIBDIR = /lib
+
+# First rule
+.PHONY: __install install-rule
+__install:
+
+# Install commands
+install-data := install -m 644
+install-lib  := install -m 755
+install-bin  := install -m 755
+
+# Install command
+quiet_cmd_install = INSTALL $(install-y)
+      cmd_install = $(install-bin) $(install-y) \
+                                   $(INSTALLROOT)$(INSTALLDIR)/$(KLIBCCROSS)bin
+
+ifeq ($(KLIBC_INSTALL),1)
+# First part - we are descending..
+
+# Reset variables (to get right type of assingment)
+subdir- :=
+
+# Include Kbuild file
+include $(srctree)/scripts/Kbuild.include
+include $(srctree)/$(obj)/Kbuild
+
+# Directories to visit
+# First find directories specified in lib-?, static-y and shared-y
+find-dir = $(patsubst %/,%,$(filter %/, $(1)))
+
+__subdir := $(call find-dir, $(lib-))
+__subdir += $(call find-dir, $(lib-y))
+
+__subdir += $(foreach e, $(static-y), $(call find-dir, $(e)))
+__subdir += $(foreach e, $(shared-y), $(call find-dir, $(e)))
+
+# Use subdir- in Kbuild file to tell kbuild to visit a specific dir
+subdir-  += $(__subdir)
+
+# Remove duplicates and add prefix
+subdir- := $(addprefix $(obj)/,$(sort $(subdir-)))
+
+# Files to install
+install-y := $(strip $(addprefix $(obj)/, $(install-y)))
+
+__install: $(subdir-) install-rule
+ifneq ($(install-y),)
+	$(call cmd,install)
+else
+	@:
+endif
+
+# Descending
+.PHONY: $(subdir-)
+$(subdir-):
+	$(Q)$(MAKE) KLIBC_INSTALL=1 \
+	            -f $(srctree)/scripts/Kbuild.install obj=$@
+
+# If quiet is set, only print short version of command
+cmd = @$(if $($(quiet)cmd_$(1)),echo '  $($(quiet)cmd_$(1))' &&) $(cmd_$(1))
+
+
+else
+##########################################################################
+# This is the first time this file is invoked, so kick off the
+# install process.
+# First we descend all sub-directories to let them do their install.
+# Second we do the final install steps.
+
+# Do actual install as a three steps approach
+# 1) Create directories, install headers and man pages
+# 2) Tell that we now install binaries
+# 3) Install binaries by descending
+.PHONY: header footer descend
+header:
+	$(Q)echo "  INSTALL headers + man pages to $(INSTALLROOT)$(INSTALLDIR)"
+	$(Q)mkdir -p $(INSTALLROOT)$(bindir)
+	$(Q)mkdir -p $(INSTALLROOT)$(mandir)/man1
+	$(Q)mkdir -p $(INSTALLROOT)$(SHLIBDIR)
+	$(Q)mkdir -p $(INSTALLROOT)$(INSTALLDIR)
+	$(Q)-rm -rf $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)include
+	$(Q)mkdir -p $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)include
+	$(Q)mkdir -p $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)lib
+	$(Q)mkdir -p $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)bin
+	$(Q)set -e ; for d in linux scsi asm-$(ARCH) asm-generic $(ASMARCH); do \
+	  mkdir -p $(INSTALLROOT)$(INSTALLDIR)/$(KLIBCCROSS)include/$$d ; \
+	  for r in $(KLIBCKERNELSRC)/include $(KLIBCKERNELOBJ)/include \
+	           $(KLIBCKERNELOBJ)/include2 ; do \
+	    [ ! -d $$r/$$d ] || \
+	      cp -rfL $$r/$$d/. \
+	          $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)include/$$d/. ; \
+	  done ; \
+	done
+	$(Q)cd $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)include && ln -sf asm-$(ARCH) asm
+	$(Q)cp -rf include/. $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)include/.
+	$(Q)$(install-data) $(srctree)/klcc/klcc.1 $(INSTALLROOT)$(mandir)/man1/$(KCROSS)klcc.1
+	$(Q)$(install-bin) $(objtree)/klcc/$(KCROSS)klcc $(INSTALLROOT)$(bindir)
+
+footer: header
+	$(Q)echo "  INSTALL binaries to $(INSTALLROOT)$(INSTALLDIR)/$(KLIBCCROSS)bin"
+
+descend: footer
+	$(Q)$(MAKE) KLIBC_INSTALL=1 \
+	            -f $(srctree)/scripts/Kbuild.install obj=$(obj)
+
+__install: descend
+	@:
+endif
+
diff --git a/utils/Kbuild b/utils/Kbuild
--- a/utils/Kbuild
+++ b/utils/Kbuild
@@ -49,9 +49,8 @@ shared/insmod-y     := insmod.o
 static/uname-y      := uname.o
 shared/uname-y      := uname.o
 
+# Clean deletes the static and shared dir
 clean-dirs := static shared
 
-ifeq (a,b)
-install: all
-	$(INSTALL_EXEC) shared/* $(INSTALLROOT)$(INSTALLDIR)/$(CROSS)bin	
-endif
+# install only install the shared binaries
+install-y := $(shared-y)



More information about the klibc mailing list