Blame project/headers.mk

79e62f
# build/version.h
79e62f
build/version.h:$(SOURCE_DIR)/VERSION $(SOURCE_DIR)/.git/index
79e62f
		mkdir -p build
79e62f
		printf '#define VERSION "%s"\n' \
79e62f
		       "$$(cd $(SOURCE_DIR); $(SHELL) ./tools/version.sh)" > $@
79e62f
dd6f0e
# alltypes.h, syscall.h
3a6f4c
build/include/bits/:
3a6f4c
		mkdir -p $@
3a6f4c
dd6f0e
ALLTYPES_H      = build/include/bits/alltypes.h
dd6f0e
SYSCALL_H       = build/include/bits/syscall.h
3ae283
dd6f0e
ARCH_GEN_H      = $(ALLTYPES_H) $(SYSCALL_H)
3ae283
dd6f0e
ALLTYPES_DEPS   = \
dd6f0e
		$(PORT_DIR)/arch/$(ARCH)/bits/alltypes.h.in \
dd6f0e
		$(SOURCE_DIR)/include/alltypes.h.in \
dd6f0e
		$(SOURCE_DIR)/tools/mkalltypes.sed
dd6f0e
3a6f4c
$(ALLTYPES_H):	$(ALLTYPES_DEPS) build/include/bits/
dd6f0e
		sed -f $(SOURCE_DIR)/tools/mkalltypes.sed \
dd6f0e
			$(PORT_DIR)/arch/$(ARCH)/bits/alltypes.h.in \
dd6f0e
			$(SOURCE_DIR)/include/alltypes.h.in > $@
dd6f0e
155000
build/syscall_h.tag:
155000
		touch $@
155000
		touch $(SYSCALL_H)
155000
155000
build/syscall-copy.tag: $(PORT_DIR)/arch/$(ARCH)/bits/syscall.h
155000
		mkdir -p build/include/bits/
dd6f0e
		cp $< $(SYSCALL_H)
155000
		touch $@
dd6f0e
155000
build/syscall-gen.tag: $(PORT_DIR)/arch/$(ARCH)/bits/syscall.h.in
155000
		mkdir -p build/include/bits/
dd6f0e
		cp $< $(SYSCALL_H).tmp
dd6f0e
		sed -n -e 's/__NR_/SYS_/p' < $< >> $(SYSCALL_H).tmp
dd6f0e
		mv $(SYSCALL_H).tmp $(SYSCALL_H)
155000
		touch $@
dd6f0e
155000
$(SYSCALL_H):	build/syscall_h.tag
dd6f0e
dd6f0e
3a6f4c
# arch headers
3a6f4c
libc_bits_h     = $(sort $(wildcard $(SOURCE_DIR)/arch/generic/bits/*.h))
3a6f4c
port_bits_h     = $(sort $(wildcard $(PORT_DIR)/arch/$(ARCH)/bits/*.h))
3a6f4c
port_substs_h   = $(subst $(PORT_DIR)/arch/$(ARCH)/, \
3a6f4c
		          $(SOURCE_DIR)/arch/generic/,\
3a6f4c
		   $(port_bits_h))
3a6f4c
3a6f4c
ARCH_HEADERS    = $(port_bits_h) $(filter-out $(port_substs_h), $(libc_bits_h))
3a6f4c
3a6f4c
src_bits_h      = $(ARCH_GEN_H)
3a6f4c
src_bits_h     += $(subst $(SOURCE_DIR)/arch/generic/,build/include/,\
3a6f4c
		    $(subst $(PORT_DIR)/arch/$(ARCH)/,build/include/, \
3a6f4c
		      $(ARCH_HEADERS)))
3a6f4c
3a6f4c
dst_bits_h      = $(src_bits_h:build/include/%=$(DESTDIR)$(INCLUDEDIR)/%)
3a6f4c
3a6f4c
3a6f4c
# libc headers
3a6f4c
src_header_dirs = $(filter %/,$(wildcard $(SOURCE_DIR)/include/*/))
3a6f4c
dst_header_dirs = $(src_header_dirs:$(SOURCE_DIR)/include/%=$(DESTDIR)$(INCLUDEDIR)/%)
3a6f4c
3a6f4c
src_c_headers   = $(sort $(wildcard $(SOURCE_DIR)/include/*.h))
3a6f4c
src_c_headers  += $(sort $(wildcard $(SOURCE_DIR)/include/*/*.h))
3a6f4c
3a6f4c
dst_c_headers   = $(subst $(SOURCE_DIR)/include/,  \
3a6f4c
		          $(DESTDIR)$(INCLUDEDIR)/, \
3a6f4c
		    $(src_c_headers))
3a6f4c
3a6f4c
$(dst_header_dirs):
3a6f4c
			mkdir -p $@
3a6f4c
3a6f4c
build/include/bits/%.h:	build/headers.tag
3a6f4c
3a6f4c
$(DESTDIR)$(INCLUDEDIR)/bits/:
3a6f4c
			mkdir -p $@
3a6f4c
3a6f4c
$(DESTDIR)$(INCLUDEDIR)/bits/%.h: build/include/bits/%.h $(DESTDIR)$(INCLUDEDIR)/bits/
3a6f4c
			cp $< $@.tmp
3a6f4c
			chmod 0644 $@.tmp
3a6f4c
			mv $@.tmp $@
3a6f4c
3a6f4c
$(DESTDIR)$(INCLUDEDIR)/%.h: | $(dst_header_dirs)
3a6f4c
$(DESTDIR)$(INCLUDEDIR)/%.h: $(SOURCE_DIR)/include/%.h
3a6f4c
			cp -p $< $@.tmp
3a6f4c
			chmod 0644 $@.tmp
3a6f4c
			mv $@.tmp $@
3a6f4c
155000
install-arch-headers:	headers.tag $(src_bits_h) $(dst_bits_h)
3a6f4c
155000
install-libc-headers:	headers.tag $(dst_header_dirs) $(dst_c_headers)
3a6f4c
3a6f4c
install-headers:	install-arch-headers install-libc-headers
3a6f4c
dd6f0e
dd6f0e
# build/include
3a6f4c
build/headers.tag:	| build/include/bits/
3a6f4c
build/headers.tag:	$(ARCH_HEADERS)
3a6f4c
			cp $(ARCH_HEADERS) build/include/bits/
3a6f4c
			touch $@
dd6f0e
155000
headers.tag:		build/headers.tag $(ARCH_GEN_H)
155000
			touch $@
155000
dd6f0e
clean-headers:
3a6f4c
		rm -f $(src_bits_h)
dd6f0e
		rm -f $(SYSCALL_H).tmp
79e62f
		rm -f build/version.h
dd6f0e
		rmdir build/include/bits 2>/dev/null || true
dd6f0e
		rmdir build/include      2>/dev/null || true
dd6f0e
		rm -f build/headers.tag
155000
		rm -f build/syscall-copy.tag
155000
		rm -f build/syscall-gen.tag
155000
		rm -f build/syscall_h.tag
155000
		rm -f headers.tag
dd6f0e
dd6f0e
clean:		clean-headers
dd6f0e
dd6f0e
.PHONY:		syscall-arch
dd6f0e
.PHONY:		syscall-copy
dd6f0e
.PHONY:		syscall-gen
dd6f0e
.PHONY:		clean-headers