...

Text file src/github.com/bytedance/sonic/Makefile

Documentation: github.com/bytedance/sonic

     1#
     2# Copyright 2021 ByteDance Inc.
     3#
     4# Licensed under the Apache License, Version 2.0 (the "License");
     5# you may not use this file except in compliance with the License.
     6# You may obtain a copy of the License at
     7#
     8#     http://www.apache.org/licenses/LICENSE-2.0
     9#
    10# Unless required by applicable law or agreed to in writing, software
    11# distributed under the License is distributed on an "AS IS" BASIS,
    12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13# See the License for the specific language governing permissions and
    14# limitations under the License.
    15#
    16
    17ARCH			:= avx avx2 sse
    18TMP_DIR			:= output
    19OUT_DIR			:= internal/native
    20SRC_FILE		:= native/native.c
    21
    22CPU_avx			:= amd64
    23CPU_avx2		:= amd64
    24CPU_sse  		:= amd64
    25
    26TMPL_avx		:= fastint_amd64_test fastfloat_amd64_test native_amd64_test recover_amd64_test
    27TMPL_avx2		:= fastint_amd64_test fastfloat_amd64_test native_amd64_test recover_amd64_test
    28TMPL_sse 		:= fastint_amd64_test fastfloat_amd64_test native_amd64_test recover_amd64_test
    29
    30CFLAGS_avx		:= -msse -mno-sse4 -mavx -mpclmul -mno-avx2 -mstack-alignment=0 -DUSE_AVX=1 -DUSE_AVX2=0
    31CFLAGS_avx2		:= -msse -mno-sse4 -mavx -mpclmul -mavx2 -mstack-alignment=0 -DUSE_AVX=1 -DUSE_AVX2=1 
    32CFLAGS_sse		:= -msse -mno-sse4 -mno-avx -mno-avx2 -mpclmul
    33
    34CC_amd64		:= clang
    35ASM2ASM_amd64	:= tools/asm2asm/asm2asm.py
    36
    37CFLAGS			:= -mno-red-zone
    38CFLAGS			+= -target x86_64-apple-macos11
    39CFLAGS			+= -fno-asynchronous-unwind-tables
    40CFLAGS			+= -fno-builtin
    41CFLAGS			+= -fno-exceptions
    42CFLAGS			+= -fno-rtti
    43CFLAGS			+= -fno-stack-protector
    44CFLAGS			+= -nostdlib
    45CFLAGS			+= -O3
    46CFLAGS			+= -Wall -Werror
    47
    48NATIVE_SRC		:= $(wildcard native/*.h)
    49NATIVE_SRC		+= $(wildcard native/*.c)
    50
    51.PHONY: all clean ${ARCH}
    52
    53define build_tmpl
    54	$(eval @arch := $(1))
    55	$(eval @tmpl := $(2))
    56	$(eval @dest := $(3))
    57
    58${@dest}: ${@tmpl}
    59	mkdir -p $(dir ${@dest})
    60	echo '// Code generated by Makefile, DO NOT EDIT.' > ${@dest}
    61	echo >> ${@dest}
    62	sed -e 's/{{PACKAGE}}/${@arch}/g' ${@tmpl} >> ${@dest}
    63endef
    64
    65define build_arch
    66	$(eval @cpu		:= $(value CPU_$(1)))
    67	$(eval @deps	:= $(foreach tmpl,$(value TMPL_$(1)),${OUT_DIR}/$(1)/${tmpl}.go))
    68	$(eval @asmin	:= ${TMP_DIR}/$(1)/native.s)
    69	$(eval @asmout	:= ${OUT_DIR}/$(1)/native_text_${@cpu}.go)
    70	$(eval @stubin	:= ${OUT_DIR}/native_${@cpu}.tmpl)
    71	$(eval @stubout	:= ${OUT_DIR}/$(1)/native_${@cpu}.go)
    72
    73$(1): ${@asmout} ${@deps}
    74
    75${@asmout}: ${@stubout} ${NATIVE_SRC}
    76	mkdir -p ${TMP_DIR}/$(1)
    77	$${CC_${@cpu}} $${CFLAGS} $${CFLAGS_$(1)} -S -o ${TMP_DIR}/$(1)/native.s ${SRC_FILE}
    78	python3 $${ASM2ASM_${@cpu}} -r ${@stubout} ${TMP_DIR}/$(1)/native.s
    79
    80$(eval $(call 	\
    81	build_tmpl,	\
    82	$(1),		\
    83	${@stubin},	\
    84	${@stubout}	\
    85))
    86
    87$(foreach 							\
    88	tmpl,							\
    89	$(value TMPL_$(1)),				\
    90	$(eval $(call 					\
    91		build_tmpl,					\
    92		$(1),						\
    93		${OUT_DIR}/${tmpl}.tmpl,	\
    94		${OUT_DIR}/$(1)/${tmpl}.go	\
    95	))								\
    96)
    97endef
    98
    99all: ${ARCH}
   100
   101clean:
   102	for arch in ${ARCH}; do \
   103		rm -vfr ${TMP_DIR}/$${arch}; \
   104		rm -vfr ${OUT_DIR}/$${arch}; \
   105	done
   106
   107$(foreach 								\
   108	arch,								\
   109	${ARCH},							\
   110	$(eval $(call build_arch,${arch}))	\
   111)

View as plain text