-
-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathMakefile
120 lines (99 loc) · 3.16 KB
/
Makefile
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
.DEFAULT_GOAL := cli
null :=
SPACE := $(null) $(null)
CURRENT_DIR := $(subst $(SPACE),"\\ ",$(CURDIR))
ifeq ($(BUILT_PRODUCTS_DIR),)
BUILD_DIR :="${CURRENT_DIR}/build"
else
BUILD_DIR :=${BUILT_PRODUCTS_DIR}
endif
ifeq ($(ONLY_ACTIVE_ARCH),)
ONLY_ACTIVE_ARCH=NO
endif
CFLAGS_x86_64 := -target x86_64-apple-macos10.15
CFLAGS_arm64 := -target arm64-apple-macos11
LDFLAGS_x86_64 := -target x86_64-apple-macos10.15
LDFLAGS_arm64 := -target arm64-apple-macos11
bold := $(shell tput bold 2> /dev/null)
normal := $(shell tput sgr0 2> /dev/null)
ifeq ($(CONFIGURATION),Debug)
CFLAGS_x86_64 += -g
CFLAGS_arm64 += -g
DEBUG=1
else
CFLAGS_x86_64 += -DNDEBUG
CFLAGS_arm64 += -DNDEBUG
endif
ifndef NATIVE_ARCH
NATIVE_ARCH := $(shell uname -m)
# $(error NATIVE_ARCH is not set)
endif
VALID_ARCHS:=x86_64 arm64
dos2unix_cli :=
ifeq ($(NATIVE_ARCH),x86_64)
dos2unix_cli += ${BUILD_DIR}/dos2unix-x86_64
else
dos2unix_cli += ${BUILD_DIR}/dos2unix-arm64
endif
ifeq ($(ONLY_ACTIVE_ARCH),NO)
ifeq ($(NATIVE_ARCH),x86_64)
# build arm code
dos2unix_cli += ${BUILD_DIR}/dos2unix-arm64
else
# build intel code
dos2unix_cli += ${BUILD_DIR}/dos2unix-x86_64
endif
endif
check_arch:
# @echo NATIVE_ARCH IS $(NATIVE_ARCH)
ifeq ($(filter $(NATIVE_ARCH),$(VALID_ARCHS)),)
$(error "Current arch ${NATIVE_ARCH} is not supported! Valid archs are: ${VALID_ARCHS}.")
endif
ifeq ($(ONLY_ACTIVE_ARCH),NO)
@echo "${bold}Building universal binary...${normal}"
else
@echo "${bold}Building $(NATIVE_ARCH) architecture...${normal}"
endif
@echo ""
#dos2unix_arm: ${BUILD_DIR}/arm/dos2unix
#dos2unix_intel: ${BUILD_DIR}/intel/dos2unix
cli: ${BUILD_DIR}/dos2unix
install: ${BUILD_DIR}/dos2unix
clean_dos2unix:
@echo "${bold}Cleaning dos2unix...${normal}"
${MAKE} -e "Makefile" clean
@echo ""
${BUILD_DIR}/dos2unix-arm64: | $(BUILD_DIR)
@echo "${bold}Building dos2unix for arm64 platform...${normal}"
@#${MAKE} -e "Makefile" clean
${MAKE} BUILD_DIR="build-arm-$(CONFIGURATION)" ENABLE_NLS= CC="gcc -std=gnu99 -target arm64-apple-macos11" CFLAGS="$(CFLAGS_arm64)" LDFLAGS="$(LDFLAGS_arm64)" -f "$(CURRENT_DIR)/build.makefile"
cp "build-arm-$(CONFIGURATION)/dos2unix" $@
@echo "${bold}... OK${normal}"
@echo ""
${BUILD_DIR}/dos2unix-x86_64: | $(BUILD_DIR)
@echo "${bold}Building dos2unix for intel platform...${normal}"
@#${MAKE} -e "Makefile" clean
${MAKE} BUILD_DIR="build-intel-$(CONFIGURATION)" ENABLE_NLS= CFLAGS="$(CFLAGS_x86_64)" LDFLAGS="$(LDFLAGS_x86_64)" -f "$(CURRENT_DIR)/build.makefile"
cp "build-intel-$(CONFIGURATION)/dos2unix" $@
@echo "${bold}... OK${normal}"
@echo ""
${BUILD_DIR}/dos2unix: $(BUILD_DIR) ${dos2unix_cli}
ifeq ($(ONLY_ACTIVE_ARCH),NO)
@#echo $(dos2unix_cli)
@echo "${bold}Creating universal dos2unix...${normal}"
lipo -create -output $@ "${BUILD_DIR}/dos2unix-x86_64" "${BUILD_DIR}/dos2unix-arm64"
else
@echo "${bold}Creating dos2unix for ${NATIVE_ARCH}...${normal}"
@rm -f $@ > /dev/null
ifeq ($(NATIVE_ARCH),x86_64)
ln -f "${BUILD_DIR}/dos2unix-x86_64" $@
else
ln -f "${BUILD_DIR}/dos2unix-arm64" $@
endif
endif
@echo "${bold}... OK${normal}"
$(BUILD_DIR):
@echo "Current dir: $(CURRENT_DIR)."
@echo "Creating build dir $(BUILD_DIR) ..."
mkdir -p $(BUILD_DIR)
@echo ""