From 3a6f4c4376eba5d20038331a1a8f147cee8d9d2a Mon Sep 17 00:00:00 2001 From: midipix Date: Jan 10 2019 03:43:14 +0000 Subject: project: added rules for install-headers, simplified include path scheme. --- diff --git a/config.project b/config.project index b9e01d6..19b5902 100644 --- a/config.project +++ b/config.project @@ -1,7 +1,7 @@ # project mb_package=c mb_require_out_of_tree=no -mb_custom_install_headers=no +mb_custom_install_headers=yes mb_avoid_version=no # config @@ -34,13 +34,9 @@ mb_default_cflags_common="-std=c99 -pipe -D_XOPEN_SOURCE=700" mb_default_cflags_common="$mb_default_cflags_common -ffreestanding -nostdinc" mb_default_cflags_common="$mb_default_cflags_common -fomit-frame-pointer" mb_default_cflags_common="$mb_default_cflags_common -Ibuild/include" -mb_default_cflags_common="$mb_default_cflags_common -I\$(SOURCE_DIR)/arch/\$(ARCH)" -mb_default_cflags_common="$mb_default_cflags_common -I\$(PROJECT_DIR)/arch/\$(ARCH)" -mb_default_cflags_common="$mb_default_cflags_common -I\$(SOURCE_DIR)/arch/\$(ARCH)/generic" -mb_default_cflags_common="$mb_default_cflags_common -Iobj/src/internal" +mb_default_cflags_common="$mb_default_cflags_common -I\$(PORT_DIR)/arch/\$(ARCH)" mb_default_cflags_common="$mb_default_cflags_common -I\$(SOURCE_DIR)/src/include" mb_default_cflags_common="$mb_default_cflags_common -I\$(SOURCE_DIR)/src/internal" -mb_default_cflags_common="$mb_default_cflags_common -Iobj/include" mb_default_cflags_common="$mb_default_cflags_common -I\$(SOURCE_DIR)/include" mb_default_cflags_common="$mb_default_cflags_common -Ibuild" diff --git a/project/headers.mk b/project/headers.mk index ea8bea4..d254dc0 100644 --- a/project/headers.mk +++ b/project/headers.mk @@ -1,4 +1,7 @@ # alltypes.h, syscall.h +build/include/bits/: + mkdir -p $@ + ALLTYPES_H = build/include/bits/alltypes.h SYSCALL_H = build/include/bits/syscall.h @@ -9,15 +12,17 @@ ALLTYPES_DEPS = \ $(SOURCE_DIR)/include/alltypes.h.in \ $(SOURCE_DIR)/tools/mkalltypes.sed -$(ALLTYPES_H): build/headers.tag $(ALLTYPES_DEPS) +$(ALLTYPES_H): $(ALLTYPES_DEPS) build/include/bits/ sed -f $(SOURCE_DIR)/tools/mkalltypes.sed \ $(PORT_DIR)/arch/$(ARCH)/bits/alltypes.h.in \ $(SOURCE_DIR)/include/alltypes.h.in > $@ -syscall-copy: $(PORT_DIR)/arch/$(ARCH)/bits/syscall.h build/headers.tag +syscall-copy: | build/include/bits/ +syscall-copy: $(PORT_DIR)/arch/$(ARCH)/bits/syscall.h cp $< $(SYSCALL_H) -syscall-gen: $(PORT_DIR)/arch/$(ARCH)/bits/syscall.h.in build/headers.tag +syscall-gen: | build/include/bits/ +syscall-gen: $(PORT_DIR)/arch/$(ARCH)/bits/syscall.h.in cp $< $(SYSCALL_H).tmp sed -n -e 's/__NR_/SYS_/p' < $< >> $(SYSCALL_H).tmp mv $(SYSCALL_H).tmp $(SYSCALL_H) @@ -25,15 +30,68 @@ syscall-gen: $(PORT_DIR)/arch/$(ARCH)/bits/syscall.h.in build/headers.tag $(SYSCALL_H): syscall-arch +# arch headers +libc_bits_h = $(sort $(wildcard $(SOURCE_DIR)/arch/generic/bits/*.h)) +port_bits_h = $(sort $(wildcard $(PORT_DIR)/arch/$(ARCH)/bits/*.h)) +port_substs_h = $(subst $(PORT_DIR)/arch/$(ARCH)/, \ + $(SOURCE_DIR)/arch/generic/,\ + $(port_bits_h)) + +ARCH_HEADERS = $(port_bits_h) $(filter-out $(port_substs_h), $(libc_bits_h)) + +src_bits_h = $(ARCH_GEN_H) +src_bits_h += $(subst $(SOURCE_DIR)/arch/generic/,build/include/,\ + $(subst $(PORT_DIR)/arch/$(ARCH)/,build/include/, \ + $(ARCH_HEADERS))) + +dst_bits_h = $(src_bits_h:build/include/%=$(DESTDIR)$(INCLUDEDIR)/%) + + +# libc headers +src_header_dirs = $(filter %/,$(wildcard $(SOURCE_DIR)/include/*/)) +dst_header_dirs = $(src_header_dirs:$(SOURCE_DIR)/include/%=$(DESTDIR)$(INCLUDEDIR)/%) + +src_c_headers = $(sort $(wildcard $(SOURCE_DIR)/include/*.h)) +src_c_headers += $(sort $(wildcard $(SOURCE_DIR)/include/*/*.h)) + +dst_c_headers = $(subst $(SOURCE_DIR)/include/, \ + $(DESTDIR)$(INCLUDEDIR)/, \ + $(src_c_headers)) + +$(dst_header_dirs): + mkdir -p $@ + +build/include/bits/%.h: build/headers.tag + +$(DESTDIR)$(INCLUDEDIR)/bits/: + mkdir -p $@ + +$(DESTDIR)$(INCLUDEDIR)/bits/%.h: build/include/bits/%.h $(DESTDIR)$(INCLUDEDIR)/bits/ + cp $< $@.tmp + chmod 0644 $@.tmp + mv $@.tmp $@ + +$(DESTDIR)$(INCLUDEDIR)/%.h: | $(dst_header_dirs) +$(DESTDIR)$(INCLUDEDIR)/%.h: $(SOURCE_DIR)/include/%.h + cp -p $< $@.tmp + chmod 0644 $@.tmp + mv $@.tmp $@ + +install-arch-headers: build/headers.tag $(src_bits_h) $(dst_bits_h) + +install-libc-headers: $(dst_header_dirs) $(dst_c_headers) + +install-headers: install-arch-headers install-libc-headers + # build/include -build/headers.tag: - mkdir -p build/include - mkdir -p build/include/bits - touch $@ +build/headers.tag: | build/include/bits/ +build/headers.tag: $(ARCH_HEADERS) + cp $(ARCH_HEADERS) build/include/bits/ + touch $@ clean-headers: - rm -f $(ARCH_GEN_H) + rm -f $(src_bits_h) rm -f $(SYSCALL_H).tmp rmdir build/include/bits 2>/dev/null || true rmdir build/include 2>/dev/null || true