+if MODULES
+if LDISKFS
+modulefs_DATA = ldiskfs2$(KMODEXT)
+endif
+endif
+
+ldiskfs2_linux_headers := $(addprefix linux/,$(subst ext3,ldiskfs2,$(notdir $(linux_headers))))
+
+$(filter %.c,$(ldiskfs2_patched_sources)): sources $(ldiskfs2_linux_headers) $(filter %.h,$(ldiskfs2_patched_sources))
+
+ldiskfs2_sed_flags = \
+ -e "s/dx_hash_info/ext3_dx_hash_info/g" \
+ -e "s/dir_private_info/ext3_dir_private_info/g" \
+ -e "s/DX_HASH/EXT3_DX_HASH/g" \
+ -e "s/reserve_window/ext3_reserve_window/g" \
+ -e "s/rsv_window_add/ext3_rsv_window_add/g" \
+ -e "s/EXT3/LDISKFS2/g" -e "s/ext3/ldiskfs2/g"
+
+%.c: linux-stage/fs/ext3/%.c
+ sed $(strip $(ldiskfs2_sed_flags)) $< > $@
+
+%.h: linux-stage/fs/ext3/%.h
+ sed $(strip $(ldiskfs2_sed_flags)) $< > $@
+
+linux/ldiskfs2%.h: linux-stage/include/linux/ext3%.h
+ sed $(strip $(ldiskfs2_sed_flags)) $< > $@
+
+#
+# FIXME: we need to grab the series in configure somehow
+# (see bug 1679)
+#
+series := @top_srcdir@/lustre/kernel_patches/series/ldiskfs2-$(LDISKFS_SERIES)
+patches := @top_srcdir@/lustre/kernel_patches/patches
+
+sources: $(ext3_sources) $(ext3_headers) $(linux_headers) $(series)
+ rm -rf linux-stage linux sources $(ldiskfs2_SOURCES)
+ mkdir -p linux-stage/fs/ext3 linux-stage/include/linux
+ cp $(ext3_sources) $(ext3_headers) $(ext3_extra) linux-stage/fs/ext3
+ cp $(linux_headers) linux-stage/include/linux
+if USE_QUILT
+ ln -s ../$(patches) linux-stage/patches
+ ln -s ../$(series) linux-stage/series
+ cd linux-stage && quilt push -a -q
+else
+ @echo -n "Applying ext3 patches:"
+ @cd linux-stage && for i in $$(<../$(series)) ; do \
+ echo -n " $$i" ; \
+ patch -s -p1 < ../$(patches)/$$i || exit 1 ; \
+ done
+ @echo
+endif
+ mkdir linux
+ @echo -n "Replacing 'ext3' with 'ldiskfs2':"
+ @for i in $(notdir $(ext3_headers) $(ext3_sources)) $(new_sources) ; do \
+ echo -n " $$i" ; \
+ sed $(strip $(ldiskfs2_sed_flags)) \
+ linux-stage/fs/ext3/$$i > $$i ; \
+ done
+ @for i in $(subst ext3,,$(notdir $(linux_headers) $(new_headers))) ; do \
+ echo -n " ext3$$i" ; \
+ sed $(strip $(ldiskfs2_sed_flags)) \
+ linux-stage/include/linux/ext3$$i \
+ > linux/ldiskfs2$$i ; \
+ done
+ @echo
+ touch sources
+
+foo-check:
+ @echo "ldiskfs2_sources: $(ldiskfs2_sources)"
+ @echo "ldiskfs2_SOURCES: $(ldiskfs2_SOURCES)"
+ @echo "ldiskfs2_headers: $(ldiskfs2_headers)"
+ @echo "ldiskfs2_objects: $(ldiskfs2_objects)"
+ @echo "ldiskfs2_OBJECTS: $(ldiskfs2_OBJECTS)"
+ @echo "ldiskfs2_LDADD: $(ldiskfs2_LDADD)"
+
+MOSTLYCLEANFILES := @MOSTLYCLEANFILES@
+CLEANFILES = sources $(notdir $(linux_headers) $(ext3_headers) $(ext3_sources) $(new_sources) $(new_headers))
+
+clean: clean-am
+ rm -rf linux linux-stage