gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

Makefile (3064B)


      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 
     17 ARCH			:= avx avx2 sse
     18 TMP_DIR			:= output
     19 OUT_DIR			:= internal/native
     20 SRC_FILE		:= native/native.c
     21 
     22 CPU_avx			:= amd64
     23 CPU_avx2		:= amd64
     24 CPU_sse  		:= amd64
     25 
     26 TMPL_avx		:= fastint_amd64_test fastfloat_amd64_test native_amd64_test native_export_amd64
     27 TMPL_avx2		:= fastint_amd64_test fastfloat_amd64_test native_amd64_test native_export_amd64
     28 TMPL_sse 		:= fastint_amd64_test fastfloat_amd64_test native_amd64_test native_export_amd64
     29 
     30 CFLAGS_avx		:= -msse -mno-sse4 -mavx -mpclmul -mno-avx2 -DUSE_AVX=1 -DUSE_AVX2=0
     31 CFLAGS_avx2		:= -msse -mno-sse4 -mavx -mpclmul -mavx2    -DUSE_AVX=1 -DUSE_AVX2=1 
     32 CFLAGS_sse		:= -msse -mno-sse4 -mno-avx -mno-avx2 -mpclmul
     33 
     34 CC_amd64		:= clang
     35 ASM2ASM_amd64	:= tools/asm2asm/asm2asm.py
     36 
     37 CFLAGS			:= -mno-red-zone
     38 CFLAGS			+= -target x86_64-apple-macos11
     39 CFLAGS			+= -fno-asynchronous-unwind-tables
     40 CFLAGS			+= -fno-builtin
     41 CFLAGS			+= -fno-exceptions
     42 CFLAGS			+= -fno-rtti
     43 CFLAGS			+= -fno-stack-protector
     44 CFLAGS			+= -nostdlib
     45 CFLAGS			+= -O3
     46 CFLAGS			+= -Wall -Werror
     47 
     48 NATIVE_SRC		:= $(wildcard native/*.h)
     49 NATIVE_SRC		+= $(wildcard native/*.c)
     50 
     51 .PHONY: all clean ${ARCH}
     52 
     53 define 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}
     63 endef
     64 
     65 define 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_${@cpu}.s)
     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}} ${@asmout} ${TMP_DIR}/$(1)/native.s
     79 	asmfmt -w ${@asmout}
     80 
     81 $(eval $(call 	\
     82 	build_tmpl,	\
     83 	$(1),		\
     84 	${@stubin},	\
     85 	${@stubout}	\
     86 ))
     87 
     88 $(foreach 							\
     89 	tmpl,							\
     90 	$(value TMPL_$(1)),				\
     91 	$(eval $(call 					\
     92 		build_tmpl,					\
     93 		$(1),						\
     94 		${OUT_DIR}/${tmpl}.tmpl,	\
     95 		${OUT_DIR}/$(1)/${tmpl}.go	\
     96 	))								\
     97 )
     98 endef
     99 
    100 all: ${ARCH}
    101 
    102 clean:
    103 	for arch in ${ARCH}; do \
    104 		rm -vfr ${TMP_DIR}/$${arch}; \
    105 		rm -vfr ${OUT_DIR}/$${arch}; \
    106 	done
    107 
    108 $(foreach 								\
    109 	arch,								\
    110 	${ARCH},							\
    111 	$(eval $(call build_arch,${arch}))	\
    112 )