support objdir != srcdir
authorMathieu Lacage <mathieu.lacage@inria.fr>
Wed, 18 May 2011 00:02:42 +0200
changeset 45532107bb1271
parent 42 31a9a363c2d3
child 46 e24d020aa31d
support objdir != srcdir
Makefile
Makefile.print
generate-autoconf.py
     1.1 --- a/Makefile	Tue Feb 01 13:31:43 2011 +0100
     1.2 +++ b/Makefile	Wed May 18 00:02:42 2011 +0200
     1.3 @@ -1,7 +1,9 @@
     1.4 -INSTALL_DIR=objdir
     1.5 +SRCDIR=$(dir $(firstword $(MAKEFILE_LIST)))
     1.6 +INSTALL_DIR=/usr
     1.7 +KCONFIG_CONFIG?=config
     1.8 +VPATH=$(SRCDIR)
     1.9  KERNEL_DIR=net-next-2.6
    1.10  KERNEL_VERSION=fed66381d65a35198639f564365e61a7f256bf79
    1.11 -KERNEL_DOWNLOAD=git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6.git
    1.12  
    1.13  SIM_SRC=\
    1.14  fs.c random.c sim.c softirq.c time.c \
    1.15 @@ -23,16 +25,16 @@
    1.16  SIM_OBJ=$(addprefix sim/,$(addsuffix .o,$(basename $(SIM_SRC))))
    1.17  CFLAGS+= \
    1.18   $(opt_$(OPT)) -g3 -D__KERNEL__ -Wall -Wstrict-prototypes -Wno-trigraphs \
    1.19 - -fno-inline -iwithprefix $(KERNEL_DIR)/include -DKBUILD_BASENAME=\"clnt\" \
    1.20 + -fno-inline -iwithprefix $(SRCDIR)$(KERNEL_DIR)/include -DKBUILD_BASENAME=\"clnt\" \
    1.21   -fno-strict-aliasing -fno-common -fno-delete-null-pointer-checks \
    1.22   -fno-stack-protector \
    1.23   -DKBUILD_MODNAME=\"nsc\" -DMODVERSIONS -DEXPORT_SYMTAB \
    1.24 - -include sim/include/generated/autoconf.h \
    1.25 + -include autoconf.h \
    1.26   -U__FreeBSD__ -D__linux__=1 -Dlinux=1 -D__linux=1 \
    1.27 - -Isim/include -I$(KERNEL_DIR)/include \
    1.28 - $(PIC_CFLAGS) -D_DEBUG
    1.29 + -I$(SRCDIR)sim/include -I$(SRCDIR)$(KERNEL_DIR)/include \
    1.30 + $(PIC_CFLAGS) -D_DEBUG -I$(PWD)
    1.31  
    1.32 -include processor.mk
    1.33 +include $(SRCDIR)processor.mk
    1.34  
    1.35  ifeq ($(PROCESSOR_SIZE),64)
    1.36  CFLAGS+= -DCONFIG_64BIT
    1.37 @@ -43,11 +45,11 @@
    1.38  modules:=
    1.39  all-obj-for-clean:=
    1.40  
    1.41 -all: install
    1.42 +all: library modules
    1.43  
    1.44  -include objs.mk
    1.45  
    1.46 -AUTOCONF=sim/include/generated/autoconf.h
    1.47 +AUTOCONF=autoconf.h
    1.48  # note: the directory order below matters to ensure that we match the kernel order
    1.49  dirs=kernel mm crypto lib drivers/base drivers/net net
    1.50  empty:=
    1.51 @@ -66,17 +68,20 @@
    1.52  rwsem-spinlock.o scatterlist.o ratelimit.o hexdump.o dec_and_lock.o \
    1.53  div64.o
    1.54  
    1.55 -objs.mk: Makefile.print $(KERNEL_DIR)/kernel/timeconst.h .download.ts
    1.56 +objs.mk: Makefile.print timeconst.h
    1.57  	-for i in 1; do \
    1.58  	$(foreach d,$(dirs), \
    1.59 -           $(MAKE) -s -f Makefile.print srcdir=$(KERNEL_DIR)/$(d) \
    1.60 -            config=$(KERNEL_DIR)/.config to_keep=$(subst $(space),$(colon),$($(d)_to_keep)) print;) \
    1.61 +           $(MAKE) -s -f $< srcdir=$(SRCDIR)$(KERNEL_DIR)/$(d) \
    1.62 +	    objdir=$(KERNEL_DIR)/$(d) \
    1.63 +            config=$(PWD)/$(KCONFIG_CONFIG) \
    1.64 +	    to_keep=$(subst $(space),$(colon),$($(d)_to_keep)) print;) \
    1.65  	done > $@
    1.66 --include $(KERNEL_DIR)/.config
    1.67 -$(AUTOCONF): ./generate-autoconf.py $(KERNEL_DIR)/.config
    1.68 -	cat $(KERNEL_DIR)/.config | ./generate-autoconf.py > $@
    1.69 -$(KERNEL_DIR)/kernel/timeconst.h: $(KERNEL_DIR)/.config
    1.70 -	perl $(KERNEL_DIR)/kernel/timeconst.pl $(CONFIG_HZ) > $@
    1.71 +$(KCONFIG_CONFIG):
    1.72 +	make -C $(SRCDIR)$(KERNEL_DIR) ARCH=sim KCONFIG_CONFIG=$(PWD)/$(KCONFIG_CONFIG) defconfig 
    1.73 +$(AUTOCONF): generate-autoconf.py $(KCONFIG_CONFIG)
    1.74 +	$^ > $@
    1.75 +timeconst.h: $(KCONFIG_CONFIG)
    1.76 +	perl $(SRCDIR)$(KERNEL_DIR)/kernel/timeconst.pl $(shell grep CONFIG_HZ= $(KCONFIG_CONFIG) | sed -e 's/CONFIG_HZ=\(\w\)/\1/g') > $@
    1.77  linker.lds: ./generate-linker-script.py
    1.78  	ld -shared --verbose | ./$^ > $@
    1.79  
    1.80 @@ -84,37 +89,41 @@
    1.81  OBJS=$(SIM_OBJ) $(foreach builtin,$(KERNEL_BUILTIN),$(if $($(builtin)),$($(builtin))))
    1.82  
    1.83  %/builtin.o:
    1.84 -	if test "$($@)"; then for f in $($@); do $(AR) Tcru $@ $$f; done; else $(AR) Tcru $@; fi
    1.85 +	mkdir -p $(dir $@); if test -n "$($@)"; then for f in $($@); do $(AR) Tcru $@ $$f; done; else $(AR) Tcru $@; fi
    1.86  %.ko:%.o
    1.87  	$(CC) -shared -o $@ -nostdlib $^
    1.88 +%.o:%.c
    1.89 +	mkdir -p $(dir $@)
    1.90 +	$(CC) $(CFLAGS) -c $^ -o $@
    1.91  
    1.92  library: $(KERNEL_LIB)
    1.93  modules: $(modules) 
    1.94  
    1.95 -install: library modules
    1.96 +install: modules library
    1.97  	mkdir -p $(INSTALL_DIR)
    1.98 -	cp $(KERNEL_LIB) $(INSTALL_DIR)
    1.99 +	mkdir -p $(INSTALL_DIR)/lib
   1.100 +	mkdir -p $(INSTALL_DIR)/include
   1.101 +	mkdir -p $(INSTALL_DIR)/include/sim
   1.102 +	mkdir -p $(INSTALL_DIR)/lib/$(KERNEL_DIR)
   1.103 +	cp $(KERNEL_LIB) $(INSTALL_DIR)/lib
   1.104  	for mod in $(modules); do \
   1.105  	  TMP=`dirname $$mod |sed -e 's;^[^/]\+/;;'`; \
   1.106 -	  mkdir -p $(INSTALL_DIR)/$$TMP; \
   1.107 -	  cp $$mod $(INSTALL_DIR)/$$TMP/`basename $$mod`; \
   1.108 +	  mkdir -p $(INSTALL_DIR)/lib/$(KERNEL_DIR)/$$TMP; \
   1.109 +	  cp $$mod $(INSTALL_DIR)/lib/$(KERNEL_DIR)/$$TMP/`basename $$mod`; \
   1.110  	done
   1.111  	for h in sim-init.h sim-types.h sim.h; do \
   1.112 -	  cp sim/include/$$h $(INSTALL_DIR)/$$h; \
   1.113 +	  cp sim/include/$$h $(INSTALL_DIR)/include/sim/$$h; \
   1.114  	done
   1.115  
   1.116  install-dir:
   1.117  
   1.118 -setup: .download.ts .patch.ts $(KERNEL_DIR)/arch/sim
   1.119 +setup: .patch.ts $(KERNEL_DIR)/arch/sim
   1.120  $(KERNEL_DIR)/arch/sim:
   1.121  	if test ! -L $@; then ln -s $(PWD)/sim $(KERNEL_DIR)/arch/sim; fi
   1.122  .patch.ts: kernel.patch
   1.123  	CWD=`pwd` && cd $(KERNEL_DIR) && patch -p1 < $$CWD/kernel.patch && cd $$CWD && touch .patch.ts
   1.124  unpatch: 
   1.125  	CWD=`pwd` && cd $(KERNEL_DIR) && git reset --hard $(KERNEL_VERSION) && cd $$CWD && rm -f .patch.ts
   1.126 -.download.ts:
   1.127 -	git clone $(KERNEL_DOWNLOAD) $(KERNEL_DIR) && pushd $(KERNEL_DIR) && git reset --hard \
   1.128 -	$(KERNEL_VERSION) && popd && touch .download.ts
   1.129  ALL_OBJS=$(OBJS) $(KERNEL_LIB) $(modules) $(all-obj-for-clean)
   1.130  clean:
   1.131  	@for f in $(foreach m,$(modules),$($(m))); do rm -f $$f; done
     2.1 --- a/Makefile.print	Tue Feb 01 13:31:43 2011 +0100
     2.2 +++ b/Makefile.print	Wed May 18 00:02:42 2011 +0200
     2.3 @@ -1,4 +1,4 @@
     2.4 -# inherit $(srcdir) $(config) $(to_keep) from command-line
     2.5 +# inherit $(objdir) $(config) $(srcdir) $(to_keep) from command-line
     2.6  
     2.7  include $(config)
     2.8  include $(srcdir)/Makefile
     2.9 @@ -20,15 +20,15 @@
    2.10  
    2.11  print: $(final-obj-m) $(subdirs)
    2.12  	@if test $(if $(final-obj-y),1); then \
    2.13 -	  echo -n $(srcdir)/builtin.o; echo -n "="; echo $(addprefix $(srcdir)/,$(final-obj-y)); \
    2.14 -	  echo -n $(srcdir)/builtin.o; echo -n ": "; echo $(addprefix $(srcdir)/,$(final-obj-y)); \
    2.15 -	  echo -n "all-obj-for-clean+="; echo $(addprefix $(srcdir)/,$(final-obj-y)) $(srcdir)/builtin.o; \
    2.16 +	  echo -n $(objdir)/builtin.o; echo -n "="; echo $(addprefix $(objdir)/,$(final-obj-y)); \
    2.17 +	  echo -n $(objdir)/builtin.o; echo -n ": "; echo $(addprefix $(objdir)/,$(final-obj-y)); \
    2.18 +	  echo -n "all-obj-for-clean+="; echo $(addprefix $(objdir)/,$(final-obj-y)) $(objdir)/builtin.o; \
    2.19  	fi
    2.20  $(final-obj-m):
    2.21 -	@echo -n "modules+="; echo $(addprefix $(srcdir)/,$(@:.o=.ko))
    2.22 -	@echo -n $(addprefix $(srcdir)/,$(@:.o=.ko)); echo -n ": "
    2.23 -	@echo $(addprefix $(srcdir)/,$(if $($(@:.o=-objs)),$($(@:.o=-objs)),$@))
    2.24 -	@echo -n $(addprefix $(srcdir)/,$(@:.o=.ko)); echo -n "="
    2.25 -	@echo $(addprefix $(srcdir)/,$(if $($(@:.o=-objs)),$($(@:.o=-objs)),$@))
    2.26 +	@echo -n "modules+="; echo $(addprefix $(objdir)/,$(@:.o=.ko))
    2.27 +	@echo -n $(addprefix $(objdir)/,$(@:.o=.ko)); echo -n ": "
    2.28 +	@echo $(addprefix $(objdir)/,$(if $($(@:.o=-objs)),$($(@:.o=-objs)),$@))
    2.29 +	@echo -n $(addprefix $(objdir)/,$(@:.o=.ko)); echo -n "="
    2.30 +	@echo $(addprefix $(objdir)/,$(if $($(@:.o=-objs)),$($(@:.o=-objs)),$@))
    2.31  $(subdirs):
    2.32 -	@$(MAKE) -s -f Makefile.print srcdir=$(srcdir)/$@ config=$(config) to_keep=$(to_keep) print 2>/dev/null
    2.33 +	@$(MAKE) -s -f $(firstword $(MAKEFILE_LIST)) objdir=$(objdir)/$@ config=$(config) srcdir=$(srcdir)/$@ to_keep=$(to_keep) print 2>/dev/null
     3.1 --- a/generate-autoconf.py	Tue Feb 01 13:31:43 2011 +0100
     3.2 +++ b/generate-autoconf.py	Wed May 18 00:02:42 2011 +0200
     3.3 @@ -18,4 +18,6 @@
     3.4              writing.write('#define ' + left + ' ' + right + '\n')
     3.5  
     3.6  import sys
     3.7 -autoconf_header (sys.stdin, sys.stdout)
     3.8 +f = open(sys.argv[1], 'r')
     3.9 +autoconf_header (f, sys.stdout)
    3.10 +f.close()