forked from phoenix-rtos/libphoenix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
143 lines (108 loc) · 3.68 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#
# Makefile for libphoenix
#
# Copyright 2017, 2018 Phoenix Systems
#
# %LICENSE%
#
SIL ?= @
MAKEFLAGS += --no-print-directory --output-sync
TARGET ?= arm-imx6ull
#TARGET ?= armv7-stm32-l152xe
#TARGET ?= armv7-imxrt
#TARGET ?= ia32-qemu
#TARGET ?= riscv64
VERSION = 0.2
TOPDIR := $(CURDIR)
PREFIX_BUILD ?= ../_build/$(TARGET)
PREFIX_BUILD := $(abspath $(PREFIX_BUILD))
BUILD_DIR ?= $(PREFIX_BUILD)/$(notdir $(TOPDIR))
BUILD_DIR := $(abspath $(BUILD_DIR))
SUBSYSTEMS := math stdio stdlib string sys ctype time unistd errno signal termios posix err locale regex net syslog netinet
LIBNAME := libphoenix.a
LIB := $(BUILD_DIR)/$(LIBNAME)
include Makefile.targets
HEADER_DIR = $(TOPDIR)/include/
CFLAGS += -I"$(HEADER_DIR)"
CFLAGS += -DVERSION=\"$(VERSION)\"
CFLAGS += -fdata-sections -ffunction-sections
LDFLAGS += --gc-sections
ARCH = code.a
ARCHS := $(patsubst %,$(BUILD_DIR)/%/$(ARCH),$(SUBDIRS))
# compiling files from CWD
SRCS := _startc.c
OBJS := $(patsubst $(TOPDIR)/%,$(BUILD_DIR)/%,$(abspath $(SRCS:.c=.o)))
SYSROOT := $(shell $(CC) $(CFLAGS) -print-sysroot)
MULTILIB_DIR := $(shell $(CC) $(CFLAGS) -print-multi-directory)
LIBC_INSTALL_DIR := $(SYSROOT)/lib/$(MULTILIB_DIR)
LIBC_INSTALL_NAMES := libc.a libm.a crt0.o libg.a
HEADERS_INSTALL_DIR := $(SYSROOT)/usr/include/
ifeq (/,$(SYSROOT))
$(error Sysroot is not supported by Your toolchain. Use cross-toolchain to compile)
endif
HEADERS := $(patsubst $(HEADER_DIR)%,$(HEADERS_INSTALL_DIR)%,$(shell find $(HEADER_DIR) -name \*.h))
export TOPDIR PREFIX_BUILD BUILD_DIR SIL TARGET LIB CC CFLAGS AR ARFLAGS LD LDFLAGS GCCLIB OBJDUMP STRIP HEADERS_INSTALL_DIR HEADER_DIR
all: subsystems $(OBJS) $(LIB) tests
lib: $(LIB)
$(OBJS): $(filter clean,$(MAKECMDGOALS))
subsystems: $(ARCHS)
$(ARCHS): %.a: .FORCE $(filter clean,$(MAKECMDGOALS))
@mkdir -p $(@D); \
$(MAKE) -C "$(subst $(BUILD_DIR)/,,$(@D))" ARCH="$@"
.FORCE:
$(LIB): $(ARCHS) $(OBJS)
@echo "\033[1;34mLD $@\033[0m"
@(\
printf "Subsystem | text | rodata | data\n";\
printf "=========================================================\n";\
for f in $(ARCHS) $(OBJS); do\
datasz=0;\
textsz=0;\
rodatasz=0;\
file=$$f;\
for i in `$(OBJDUMP) -t $$file | grep -e " O " | grep -v ".rodata" | awk '{ print $$1 }'`; do\
datasz=`echo $$(($$datasz + 0x$$i))`;\
done;\
for i in `$(OBJDUMP) -t $$file | grep -e " O " | grep ".rodata" | awk '{ print $$1 }'`; do \
rodatasz=`echo $$(($$rodatasz + 0x$$i))`;\
done; \
for i in `$(OBJDUMP) -t $$file | grep -e " F " | awk '{ print $$5 }'`; do \
textsz=`echo $$(($$textsz + 0x$$i))`;\
done;\
n=`dirname $$f`;\
n=`basename $$n | sed "s/libphoenix/./"`;\
f=`basename $$f`;\
printf "%-26s | %-7d | %-7d | %-7d\n" $$n/$$f $$textsz $$rodatasz $$datasz;\
done;)
@rm -rf "$@"
$(SIL)$(AR) cqT -o $@ $(abspath $^) && echo "create $@\naddlib $@\nsave\nend" | $(AR) -M
@(echo "";\
echo "=> libphoenix for [$(TARGET)] has been created";\
echo "")
tests: test
test: $(LIB) .FORCE
@echo "\033[1;32mCOMPILE $@\033[0m";\
$(MAKE) -C "$@"
install: $(LIB) $(HEADERS)
@echo "Installing into: $(LIBC_INSTALL_DIR)"; \
mkdir -p "$(LIBC_INSTALL_DIR)" "$(HEADERS_INSTALL_DIR)"; \
cp -a "$<" "$(LIBC_INSTALL_DIR)"; \
for lib in $(LIBC_INSTALL_NAMES); do \
if [ ! -e "$(LIBC_INSTALL_DIR)/$$lib" ]; then \
ln -sf "$(LIBC_INSTALL_DIR)/$(LIBNAME)" "$(LIBC_INSTALL_DIR)/$$lib"; \
fi \
done; \
uninstall:
rm -rf "$(LIBC_INSTALL_DIR)/$(LIBNAME)"
@for lib in $(LIBC_INSTALL_NAMES); do \
rm -rf "$(LIBC_INSTALL_DIR)/$$lib"; \
done
@for file in $(HEADERS); do \
rm -rf $$file; \
done
clean:
@rm -rf $(BUILD_DIR)
# include after all dependencies are set
include $(TOPDIR)/Makefile.rules
.PHONY: clean install uninstall
# DO NOT DELETE