Guest User

MohammadAG

a guest
Dec 3rd, 2010
99
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/make -f
  2. #
  3. #export DH_VERBOSE=0
  4.  
  5.  
  6. WEEK := $(shell date +%Y%W)
  7. RELEASE := $(shell dpkg-parsechangelog | awk '/^Version: / { print $$2 }')
  8. #REVISION := $(shell echo "$(RELEASE)" | sed 's/\(.*\)-\(.*\)/\2/')
  9. #no need to update modules so often, api is quite stable between weekly releases
  10. REVISION := hostmode2
  11. EXTRAVERSION := EXTRAVERSION=-$(REVISION)
  12.  
  13. PACKAGE := kernel-hostmode
  14. FLASHER_PACKAGE := kernel-hostmode-flasher
  15. SOURCE_PACKAGE := $(PACKAGE)-source
  16. KERNEL_PACKAGE := $(PACKAGE)
  17. MODULES_PACKAGE := $(PACKAGE)-modules
  18. HEADERS_PACKAGE := $(PACKAGE)-headers
  19. KBUILD_PACKAGE := $(PACKAGE)-kbuild
  20. DEBUG_PACKAGE := $(PACKAGE)-debug
  21. DEBUG_MODULES_PACKAGE := $(PACKAGE)-modules-debug
  22. LIBC_PACKAGE := linux-kernel-headers
  23.  
  24. BUILDTMP := $(CURDIR)/debian/build
  25. KSRC := $(BUILDTMP)/$(PACKAGE)
  26.  
  27. DEFCONFIG := rx51_defconfig
  28. KVER = $(shell cat $(KSRC)/include/config/kernel.release 2> /dev/null)
  29. ARCH = $(shell dpkg-architecture -qDEB_HOST_ARCH_CPU)
  30. INCLUDE_HEADERS = acpi asm-generic asm-$(ARCH) config crypto drm Kbuild keys linux math-emu media mtd net pcmcia rdma rxrpc scsi sound video xen
  31. RM_SCRIPTS = bloat-o-meter show_delta
  32. DEBUG_MODULES = oprofile.ko
  33. MAKE += $(MAKEFLAGS)
  34.  
  35. ifneq (,$(findstring parallel,$(DEB_BUILD_OPTIONS)))
  36.     PARALLEL_JOBS := $(shell echo $(DEB_BUILD_OPTIONS) | \
  37.         sed -e 's/.*parallel=\([0-9]\+\).*/\1/')
  38.     ifeq ($(DEB_BUILD_OPTIONS),$(PARALLEL_JOBS))
  39.         PARALLEL_JOBS := $(shell if [ -f /proc/cpuinfo ]; \
  40.             then echo `cat /proc/cpuinfo | grep 'processor' | wc -l`; \
  41.             else echo 1; fi)
  42.     endif
  43.     NJOBS := -j$(PARALLEL_JOBS)
  44. endif
  45.  
  46. source-copy-stamp:
  47.     dh_testdir
  48.     $(MAKE) clean
  49.  
  50.     mkdir -p $(BUILDTMP)/$(SOURCE_PACKAGE)
  51.     tar cf - `echo * | sed -e 's/ debian//g' -e 's/\.deb//g' ` \
  52.     | (cd $(BUILDTMP)/$(SOURCE_PACKAGE) ; umask 000; tar xspf -)
  53.     touch $@
  54.  
  55. source-stamp: source-copy-stamp
  56.     cd $(BUILDTMP) && cp -a  $(SOURCE_PACKAGE) $(KSRC)
  57.     touch $@
  58.  
  59. configure-stamp: source-stamp
  60.     cd $(KSRC) && $(MAKE) $(EXTRAVERSION) $(DEFCONFIG)
  61.     cp $(CURDIR)/debian/.config $(CURDIR)/debian/build/$(PACKAGE)/.config
  62.     cp $(CURDIR)/debian/.config $(CURDIR)/
  63.     touch $@
  64.  
  65. kernel-stamp: configure-stamp
  66.     echo "compile $(PRODUCT) kernel"
  67.     cd $(KSRC) && $(MAKE) -j 6 $(EXTRAVERSION) zImage
  68.     touch $@
  69.  
  70. modules-stamp: configure-stamp
  71.     echo "compile $(PRODUCT) kernel modules"
  72.     cd $(KSRC) && $(MAKE) -j 6 $(EXTRAVERSION) modules
  73.     touch $@
  74.  
  75. modules-extra: configure-stamp
  76.     echo "compile $(PRODUCT) kernel EXTRA modules"
  77.     cd $(KSRC) && \
  78.     patch -p1 < $(CURDIR)/debian/modules-extra_config.patch && \
  79.     $(MAKE) $(EXTRAVERSION) oldconfig modules && \
  80.     patch -p1 -R < $(CURDIR)/debian/modules-extra_config.patch && \
  81.     $(MAKE) $(EXTRAVERSION) oldconfig
  82.  
  83. headers: kernel-stamp modules-stamp
  84.  
  85. kernel-source-stamp: source-copy-stamp
  86.     dh_testdir
  87.  
  88.     cd $(BUILDTMP) && \
  89.     tar --bzip2 -cf $(SOURCE_PACKAGE).tar.bz2 $(SOURCE_PACKAGE)
  90.     touch $@
  91.  
  92. clean:
  93.     dh_testdir
  94.     dh_testroot
  95.  
  96.     $(MAKE) clean
  97.     rm -f modules/modversions.h modules/ksyms.ver debian/files conf.vars scripts/cramfs/cramfsck \
  98.         scripts/cramfs/mkcramfs applied_patches debian/buildinfo stamp-* .config* \
  99.         debian/$(FLASHER_PACKAGE).postinst
  100.     rm -rf debian/tmp-*
  101.     rm -rf debian/build
  102.     rm -f *-stamp
  103.  
  104.     dh_clean
  105.  
  106. install-kernel:
  107.     dh_testdir
  108.     dh_testroot
  109.     dh_installdirs
  110.  
  111.     install -d -m 755 $(CURDIR)/debian/$(PACKAGE)/boot
  112.     fiasco-gen -o $(CURDIR)/debian/$(PACKAGE)/boot/zImage-$(RELEASE).fiasco -g \
  113.             -k $(KSRC)/arch/arm/boot/zImage -v $(RELEASE)
  114.     chmod 644 $(CURDIR)/debian/$(PACKAGE)/boot/zImage-$(RELEASE).fiasco
  115.  
  116. install-debug: install-modules
  117.     install -d -m 755 $(CURDIR)/debian/$(DEBUG_PACKAGE)/usr/lib/debug/lib/modules/$(KVER)
  118.     install $(KSRC)/vmlinux \
  119.         $(CURDIR)/debian/$(DEBUG_PACKAGE)/usr/lib/debug/vmlinux-$(KVER)
  120.     chmod a-x $(CURDIR)/debian/$(DEBUG_PACKAGE)/usr/lib/debug/vmlinux-*
  121.     mkdir -p $(CURDIR)/debian/$(DEBUG_PACKAGE)/lib/modules/$(KVER)
  122.  
  123.     for f in $$(find $(CURDIR)/debian/$(MODULES_PACKAGE) -name "*.ko"); do \
  124.         objcopy --only-keep-debug $$f $(CURDIR)/debian/$(DEBUG_PACKAGE)/usr/lib/debug/lib/modules/$(KVER)/$$(basename $$f); \
  125.         strip --remove-section=.comment --remove-section=.note --strip-unneeded  $(CURDIR)/debian/$(MODULES_PACKAGE)/lib/modules/$(KVER)/$$(basename $$f); \
  126.         objcopy --add-gnu-debuglink $(CURDIR)/debian/$(DEBUG_PACKAGE)/usr/lib/debug/lib/modules/$(KVER)/$$(basename $$f) $(CURDIR)/debian/$(MODULES_PACKAGE)/lib/modules/$(KVER)/$$(basename $$f); \
  127.     done
  128.  
  129. install-modules-debug: install-debug
  130.     install -d -m 755 $(CURDIR)/debian/$(DEBUG_MODULES_PACKAGE)/lib/modules/$(KVER)
  131.     -for f in $(DEBUG_MODULES); do \
  132.         mv $(CURDIR)/debian/$(MODULES_PACKAGE)/lib/modules/$(KVER)/$$f  \
  133.            $(CURDIR)/debian/$(DEBUG_MODULES_PACKAGE)/lib/modules/$(KVER)/$$f; \
  134.     done
  135.  
  136. install-modules:
  137.     dh_testdir
  138.     dh_testroot
  139.  
  140.     mkdir -p $(CURDIR)/debian/$(MODULES_PACKAGE)/lib/modules/$(KVER)
  141.     for f in $$(find $(KSRC) -name "*.ko"); do \
  142.         install -c -m 644 $$f $(CURDIR)/debian/$(MODULES_PACKAGE)/lib/modules/$(KVER)/$$(basename $$f); \
  143.     done
  144.     #ln -sf $(KVER) $(CURDIR)/debian/$(MODULES_PACKAGE)/lib/modules/current
  145.  
  146. install-headers:
  147.     dh_testdir
  148.     dh_testroot
  149.     dh_installdirs
  150.  
  151.     install -d -m755 $(CURDIR)/debian/$(HEADERS_PACKAGE)/usr/src/$(HEADERS_PACKAGE)/
  152.     install -p -o root -g root -m 644 $(KSRC)/.config  $(CURDIR)/debian/$(HEADERS_PACKAGE)/usr/src/$(HEADERS_PACKAGE)/
  153.     install -p -o root -g root -m 644 $(KSRC)/Makefile $(CURDIR)/debian/$(HEADERS_PACKAGE)/usr/src/$(HEADERS_PACKAGE)/
  154.     install -p -o root -g root -m 644 $(KSRC)/Module.symvers $(CURDIR)/debian/$(HEADERS_PACKAGE)/usr/src/$(HEADERS_PACKAGE)/
  155.     cd $(KSRC) && install -p -o root -g root -m 644 -D include/config/auto.conf \
  156.         $(CURDIR)/debian/$(HEADERS_PACKAGE)/usr/src/$(HEADERS_PACKAGE)/include/config/auto.conf
  157.     cd $(KSRC) && \
  158.         find arch/$(ARCH) $(foreach dir,$(INCLUDE_HEADERS),include/$(dir)) -name '*.h' \
  159.             -exec install -D -m644 {} $(CURDIR)/debian/$(HEADERS_PACKAGE)/usr/src/$(HEADERS_PACKAGE)/{} \;
  160.     cd $(KSRC) && \
  161.         find ./ \( -name Makefile -or -name Kbuild -or -name Kconfig\* \) \
  162.             -exec install -D -m644 {} $(CURDIR)/debian/$(HEADERS_PACKAGE)/usr/src/$(HEADERS_PACKAGE)/{} \;
  163.  
  164.     ln -sf asm-$(ARCH) $(CURDIR)/debian/$(HEADERS_PACKAGE)/usr/src/$(HEADERS_PACKAGE)/include/asm
  165.  
  166.     rm -rf $(CURDIR)/debian/$(HEADERS_PACKAGE)/usr/src/$(HEADERS_PACKAGE)/scripts
  167.     ln -sf ../$(KBUILD_PACKAGE)/scripts $(CURDIR)/debian/$(HEADERS_PACKAGE)/usr/src/$(HEADERS_PACKAGE)
  168.  
  169. #   cp -a $(KSRC)/include/asm-$(ARCH)/arch \
  170. #       $(CURDIR)/debian/$(HEADERS_PACKAGE)/usr/src/$(HEADERS_PACKAGE)/include/asm-$(ARCH)
  171.  
  172.     cp $(KSRC)/arch/$(ARCH)/kernel/asm-offsets.s \
  173.         $(CURDIR)/debian/$(HEADERS_PACKAGE)/usr/src/$(HEADERS_PACKAGE)/arch/$(ARCH)/kernel
  174. #install /lib/modules symlink
  175.     install -d -m 755 $(CURDIR)/debian/$(HEADERS_PACKAGE)/lib/modules/$(KVER)/
  176.     ln -sf /usr/src/$(HEADERS_PACKAGE) $(CURDIR)/debian/$(HEADERS_PACKAGE)/lib/modules/$(KVER)/build
  177. #install kbuild
  178.     install -d $(CURDIR)/debian/$(HEADERS_PACKAGE)/usr/src/$(KBUILD_PACKAGE)
  179.     cp -a $(KSRC)/scripts $(CURDIR)/debian/$(HEADERS_PACKAGE)/usr/src/$(KBUILD_PACKAGE)
  180. #kbuild fixes
  181.     cd $(CURDIR)/debian/$(HEADERS_PACKAGE)/usr/src/$(KBUILD_PACKAGE)/scripts && \
  182.         ( rm -f $(RM_SCRIPTS); chmod a-x mkcompile_h )
  183.  
  184. install-libc-headers: source-stamp
  185.     dh_testdir
  186.     dh_testroot
  187.  
  188.     cd $(KSRC) && \
  189.     $(MAKE) headers_check ARCH=$(ARCH) && \
  190.     $(MAKE) headers_install ARCH=$(ARCH) INSTALL_HDR_PATH=$(CURDIR)/debian/$(LIBC_PACKAGE)/usr
  191.  
  192.  
  193. install-modules-extra:
  194.     dh_testdir
  195.     dh_testroot
  196.  
  197.     mkdir -p $(CURDIR)/debian/kernel-modules-extra/lib/modules/$(KVER)/extra
  198.     for f in $(MODULES_EXTRA); do \
  199.         install -c -m 644 $(KSRC)/$$f \
  200.             $(CURDIR)/debian/kernel-modules-extra/lib/modules/$(KVER)/extra/$$(basename $$f); \
  201.     done
  202.  
  203. install-indep:
  204.     dh_testdir
  205.     dh_testroot
  206.  
  207.     install -p -d -o root -g root -m 755 debian/$(SOURCE_PACKAGE)/usr/src
  208.     install -m 644 $(BUILDTMP)/$(SOURCE_PACKAGE).tar.bz2 debian/$(SOURCE_PACKAGE)/usr/src
  209.  
  210. install-extra: install-modules-extra
  211.  
  212.  
  213. install-arch: build-arch install-kernel install-modules install-debug install-modules-debug install-headers install-libc-headers
  214.  
  215. ifeq ($(ARCH),arm)
  216. build-arch: kernel-stamp modules-stamp headers
  217. else
  218. build-arch:
  219. endif
  220.  
  221. build-indep: kernel-source-stamp
  222.  
  223. build: build-arch build-indep
  224.  
  225. binary-indep: install-indep
  226.     dh_testdir
  227.     dh_testroot
  228.     dh_installchangelogs -i
  229.     dh_installdocs -i
  230.     dh_installdeb -i
  231.     dh_gencontrol -i
  232.     dh_md5sums -i
  233.     dh_builddeb -i
  234.  
  235. ifeq ($(ARCH),arm)
  236. binary-arch: build-arch install-arch
  237. else
  238. binary-arch: install-libc-headers
  239. endif
  240.     sed \
  241.         -e 's,@VERSION@,$(RELEASE),g' \
  242.         -e 's,@KVER@,$(KVER),g' \
  243.         < $(CURDIR)/debian/$(FLASHER_PACKAGE).postinst.in \
  244.         > $(CURDIR)/debian/$(FLASHER_PACKAGE).postinst
  245.     dh_testdir
  246.     dh_testroot
  247.     dh_installchangelogs -s
  248.     dh_installdocs -s
  249. ifeq ($(ARCH),arm)
  250.     dh_strip -p$(HEADERS_PACKAGE)
  251. endif
  252.     dh_compress -s
  253.     dh_fixperms -s --exclude /usr/src/kernel-headers
  254.     dh_installdeb -s
  255.     dh_shlibdeps -s
  256.     dh_gencontrol -s
  257.     dh_md5sums -s
  258.     dh_builddeb -s
  259. binary: binary-indep binary-arch
  260. .PHONY: build clean binary-indep binary-arch binary install
RAW Paste Data