Makefile 7.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
#    conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
#    of conditions and the following disclaimer in the documentation and/or other materials
#    provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
#    to endorse or promote products derived from this software without specific prior written
#    permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

ARCH = arm
C
Caoruihong 已提交
31 32 33 34 35 36
ifneq ($(GCC),)
TARGET =
CROSS_COMPILE = $(GCC:%gcc=%)
CC = $(GCC) $(ARCH_CFLAGS)
MULTILIB = $(patsubst %.,%,$(shell $(CC) -print-multi-directory))
else
M
maweiye 已提交
37
TARGET = $(ARCH)-liteos-ohos
38
CLANG ?= clang
C
Caoruihong 已提交
39
CROSS_COMPILE = $(CLANG:%clang=%llvm-)
40
CC = $(CLANG) --target=$(TARGET) $(ARCH_CFLAGS)
C
Caoruihong 已提交
41 42 43
MULTILIB = $(patsubst $(dir $(shell $(filter-out $(ARCH_CFLAGS),$(CC)) -print-libgcc-file-name))%,/%,$(dir $(shell $(CC) -print-libgcc-file-name)))
endif
MUSLBUILDDIR = build_$(or $(TARGET),$(ARCH))$(subst /,_,$(MULTILIB:%/=%))
44
HIDE = @
45
BUILD_DEBUG = false
46
SED_ARGS = -e '/install-libs:/s/if/and/g'
47 48 49 50 51 52 53

TOPDIR = $(shell pwd)/../../../..
MUSLDIR = $(TOPDIR)/third_party/musl
LINUXKERNELDIR = $(TOPDIR)/third_party/Linux_Kernel
OPTRTDIR = $(TOPDIR)/third_party/optimized-routines
NUTTXDIR = $(TOPDIR)/third_party/NuttX
SYSROOTDIR = $(TOPDIR)/prebuilts/lite/sysroot
54
LITEOSADIR = $(TOPDIR)/kernel/liteos_a
C
Caoruihong 已提交
55
LINUXDIR = $(TOPDIR)/kernel/linux/linux-4.19
56
LINUXHDRDIR = $(PREBUILTLINUXHDRDIR)
57

58
TARGETS = $(if $(wildcard $(LITEOSADIR)),liteos_a_user,)
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
TARGETS += $(if $(wildcard $(LINUXDIR)),linux_user,)

define LINUX_TYPES_H
/* Auto generated file at $(shell date), do NOT edit! */
#ifndef _LINUX_TYPES_H
#define _LINUX_TYPES_H
#include <stdint.h>
typedef uint32_t __u32, __le32;
#endif
endef
export LINUX_TYPES_H

ifeq ($(ARCH),arm)
ARCH_CFLAGS = -mfloat-abi=softfp -mcpu=cortex-a7 -mfpu=neon-vfpv4
else
$(warning *** warning: ARCH $(ARCH) has not been tested yet, use with cautions!)
ARCH_CFLAGS =
endif

CFLAGS = -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now,-z,noexecstack -Wl,--build-id=sha1

.PHONY: $(TARGETS:%=musl_copy_for_%)
.PHONY: $(TARGETS:%=musl_patch_for_%)
.PHONY: $(TARGETS:%=musl_install_for_%)
.PHONY: $(TARGETS:%=linux_header_install_for_%)
.PHONY: $(TARGETS:%=nuttx_header_install_for_%)
.PHONY: $(TARGETS:%=optimized_routines_install_for_%)
.PHONY: all clean distclean

88
all: $(TARGETS:%=musl_install_for_%)
89 90 91 92 93 94 95 96 97 98 99 100 101

$(TARGETS:%=musl_copy_for_%):
	$(HIDE) mkdir -p $@
	$(HIDE) cp -rfu $(MUSLDIR)/[^p]* $@

optimized_routines_install_for_liteos_a_user: musl_copy_for_liteos_a_user
ifneq ($(ARCH),)
	$(HIDE) cp -rfp $(OPTRTDIR)/string/$(ARCH)/* $</src/string/$(ARCH)/
	$(HIDE) cp -rfp $(OPTRTDIR)/string/asmdefs.h $</src/string/asmdefs.h
ifeq ($(ARCH),arm)
	$(HIDE) rm -f $</src/string/arm/memcpy.c
	$(HIDE) rm -f $</src/string/arm/memcpy_le.S
	$(HIDE) rm -f $</src/string/arm/memset.S
102
	$(HIDE) rm -f $</src/string/arm/strcpy.c
C
Caoruihong 已提交
103
	$(HIDE) true >> $</src/string/arm/strlen.S
104 105 106 107 108 109 110 111

CFLAGS += \
	-D__strlen_armv6t2=strlen \
	-D__strcpy_arm=strcpy \
	-D__strcmp_arm=strcmp \
	-D__memcpy_arm=memcpy \
	-D__memchr_arm=memchr

112 113 114 115 116 117 118
endif
endif

nuttx_header_install_for_liteos_a_user: musl_copy_for_liteos_a_user
	$(HIDE) sed '/^#include/d' $(NUTTXDIR)/include/nuttx/video/fb.h | sed 's,FAR ,,g' | sed 's,LosVmMapRegion,void,g' > $</include/fb.h

linux_header_install_for_liteos_a_user: musl_copy_for_liteos_a_user
119 120
	$(HIDE) make -sj headers_install ARCH=$(ARCH) O=$(shell pwd)/$@ -C $(LINUXKERNELDIR)
	$(HIDE) install -p -m 644 -D $@/usr/include/linux/capability.h $</include/linux/capability.h
121 122 123 124 125 126 127 128
	$(HIDE) echo "$$LINUX_TYPES_H" > $</include/linux/types.h

musl_patch_for_liteos_a_user: nuttx_header_install_for_liteos_a_user
musl_patch_for_liteos_a_user: linux_header_install_for_liteos_a_user
musl_patch_for_liteos_a_user: optimized_routines_install_for_liteos_a_user
musl_patch_for_liteos_a_user: musl_copy_for_liteos_a_user
	$(HIDE) cp -rfp $(MUSLDIR)/porting/liteos_a/user/* $</

129 130 131 132 133
musl_patch_for_liteos_a_user_debug: musl_patch_for_liteos_a_user
musl_patch_for_liteos_a_user_debug: musl_copy_for_liteos_a_user
	$(HIDE) cp -rfp $(MUSLDIR)/porting/liteos_a/user_debug/* $</

ifeq ($(BUILD_DEBUG),true)
C
Caoruihong 已提交
134 135
ifeq ($(GCC),)
musl_install_for_liteos_a_user: LDFLAGS = $(shell $(CC) -print-file-name=libunwind.a) -Wl,--no-dependent-libraries
136
musl_install_for_liteos_a_user: SED_ARGS += -e 's,$$(AR) rc $$@ $$(AOBJS)$$,cp $$(shell $$(CC) -print-file-name=libunwind.a) $$@ \&\& &,g'
C
Caoruihong 已提交
137
endif
138 139
musl_install_for_liteos_a_user: SED_ARGS += -e 's,CFLAGS_ALL += -DCRT$$,& -fno-unwind-tables -fno-asynchronous-unwind-tables,g'
musl_install_for_liteos_a_user: CFLAGS += -funwind-tables -fasynchronous-unwind-tables -rdynamic -I $(shell $(CC) "-print-file-name=include")
140 141 142 143 144
musl_install_for_liteos_a_user: musl_patch_for_liteos_a_user_debug
endif

musl_install_for_liteos_a_user: musl_patch_for_liteos_a_user
	$(HIDE) cd musl_copy_for_liteos_a_user && mkdir -p $(MUSLBUILDDIR) && cd $(MUSLBUILDDIR) && \
C
Caoruihong 已提交
145 146 147
	../configure --prefix=$(SYSROOTDIR)/usr --target=$(TARGET) \
		--includedir=$(SYSROOTDIR)/usr/include/$(TARGET) \
		--libdir=$(SYSROOTDIR)/usr/lib/$(TARGET)/$(MULTILIB) \
148
		$(if $(LDFLAGS),LDFLAGS="$(LDFLAGS)",) \
C
Caoruihong 已提交
149
		CC="$(CC)" CROSS_COMPILE="$(CROSS_COMPILE)" CFLAGS="$(CFLAGS)" >/dev/null && \
C
Caoruihong 已提交
150
	sed $(SED_ARGS) Makefile | make -f- -sj install
151

152
ifeq ($(wildcard $(LINUXHDRDIR)),)
153
LINUXHDRDIR = $(shell pwd)/linux_header_install_for_linux_user/usr/include
154
linux_header_install_for_linux_user:
155
	$(HIDE) make -sj headers_install ARCH=$(ARCH) O=$(shell pwd)/$@ -C $(LINUXDIR)
156 157 158 159 160 161
musl_patch_for_linux_user: linux_header_install_for_linux_user
endif

musl_patch_for_linux_user: musl_copy_for_linux_user
	$(HIDE) cp -rfp $(MUSLDIR)/porting/linux/user/* $</

162
musl_install_for_linux_user: CFLAGS += -I $(LINUXHDRDIR)
C
Caoruihong 已提交
163
ifeq ($(GCC),)
M
maweiye 已提交
164
musl_install_for_linux_user: TARGET = $(ARCH)-linux-ohos
C
Caoruihong 已提交
165
endif
166 167
musl_install_for_linux_user: musl_patch_for_linux_user
	$(HIDE) cd musl_copy_for_linux_user && mkdir -p $(MUSLBUILDDIR) && cd $(MUSLBUILDDIR) && \
C
Caoruihong 已提交
168 169 170
	../configure --prefix=$(SYSROOTDIR)/usr --target=$(TARGET) \
		--includedir=$(SYSROOTDIR)/usr/include/$(TARGET) \
		--libdir=$(SYSROOTDIR)/usr/lib/$(TARGET)/$(MULTILIB) \
171
		CC="$(CC)" CROSS_COMPILE="$(CROSS_COMPILE)" CFLAGS="$(CFLAGS)" >/dev/null && \
C
Caoruihong 已提交
172
	sed $(SED_ARGS) Makefile | make -f- -sj install
173
	$(HIDE) cp -rfp $(LINUXHDRDIR)/* $(SYSROOTDIR)/usr/include/$(TARGET)
174
	$(HIDE) if [ -d $(LINUXHDRDIR)/asm-$(ARCH)/asm ]; then ln -snf asm-$(ARCH)/asm $(SYSROOTDIR)/usr/include/$(TARGET)/; fi
175 176

clean:
177
	$(HIDE) rm -rf musl_copy_for_* linux_header_install_for_*
178 179 180

distclean: clean
	$(HIDE) rm -rf $(SYSROOTDIR)/lib $(SYSROOTDIR)/usr