-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
71 lines (54 loc) · 2.51 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
# CTNG_VERSION=crosstool-ng-1.24.0
CTNG_VERSION=a9f8a8e67509547a53b9b4781734e2b482b75b4e
CTNG_URL=https://github.com/crosstool-ng/crosstool-ng/archive/$(CTNG_VERSION).tar.gz
TARGET=x86_64-generic
COMMON_DIR=$(shell pwd)/common
PACKAGES_DIR=$(shell pwd)/packages
TARBALLS_DIR=$(shell pwd)/cache
TARGET_DIR=$(shell pwd)/targets/$(TARGET)
BUILD_DIR=$(shell pwd)/build/$(TARGET)
DIST_DIR=$(shell pwd)/dist/$(TARGET)
include $(TARGET_DIR)/config.mk
CTNG_DIR=$(BUILD_DIR)/ct-ng
CTNG=$(CTNG_DIR)/bin/ct-ng
TOOLCHAIN_DIR=$(BUILD_DIR)/toolchain
TOOLCHAIN_CC_DIR=$(TOOLCHAIN_DIR)/bin
TOOLCHAIN_CC_PREFIX=$(TOOLCHAIN_CC_DIR)/$(HOST)-
export ARCH
export HOST
export CROSS_COMPILE=$(TOOLCHAIN_CC_PREFIX)
export PATH:=$(TOOLCHAIN_CC_DIR):$(PATH)
VPATH=$(BUILD_DIR)
all: $(DIST_DIR)
$(TARBALLS_DIR):
mkdir -p $@
$(TARBALLS_DIR)/$(CTNG_VERSION).tar.gz: $(TARBALLS_DIR)
wget $(CTNG_URL) -N -P $(TARBALLS_DIR)
$(BUILD_DIR)/crosstool-ng-$(CTNG_VERSION): $(TARBALLS_DIR)/$(CTNG_VERSION).tar.gz
mkdir -p $(BUILD_DIR)
tar -xf $^ -C $(BUILD_DIR)
$(CTNG): $(BUILD_DIR)/crosstool-ng-$(CTNG_VERSION) $(COMMON_DIR)/crosstool-ng.patch
mkdir -p $(CTNG_DIR)
if ! [ -z $${LIBRARY_PATH+dummy} ]; then echo "LIBRARY_PATH is set; crosstool-ng build won't work."; false; fi
if ! [ -z $${LD_LIBRARY_PATH+dummy} ]; then echo "LD_LIBRARY_PATH is set; crosstool-ng build won't work."; false; fi
(cd $(BUILD_DIR)/crosstool-ng-$(CTNG_VERSION) ; ./bootstrap)
(cd $(BUILD_DIR)/crosstool-ng-$(CTNG_VERSION) ; ./configure --prefix="$(CTNG_DIR)")
patch -p0 -d $(BUILD_DIR)/crosstool-ng-$(CTNG_VERSION) -N < $(COMMON_DIR)/crosstool-ng.patch; true
$(MAKE) -C $(BUILD_DIR)/crosstool-ng-$(CTNG_VERSION)
$(MAKE) -C $(BUILD_DIR)/crosstool-ng-$(CTNG_VERSION) install
$(TOOLCHAIN_CC_DIR): $(TARBALLS_DIR) $(CTNG) $(TARGET_DIR)/crosstool-ng.config
mkdir -p $(TOOLCHAIN_DIR)
cp $(TARGET_DIR)/crosstool-ng.config $(BUILD_DIR)/.config
sed -i -r "s:(CT_LOCAL_TARBALLS_DIR).+:\1=$(TARBALLS_DIR):" $(BUILD_DIR)/.config
sed -i -r "s:(CT_PREFIX_DIR).+:\1=$(TOOLCHAIN_DIR):" $(BUILD_DIR)/.config
(cd $(BUILD_DIR) ; $(CTNG) build)
$(BUILD_DIR)/%.tar.gz: $(PACKAGES_DIR)/% $(TOOLCHAIN_CC_DIR)
@echo "Building package $@"
$(MAKE) -C $< TARBALLS_DIR=$(TARBALLS_DIR) BUILD_DIR=$(BUILD_DIR) DIST_DIR=$(BUILD_DIR)/$(notdir $(basename $@)) INSTALL_PREFIX=$(BUILD_DIR)
$(DIST_DIR): $(foreach PACKAGE,$(PACKAGES),$(BUILD_DIR)/$(PACKAGE).tar.gz)
mkdir -p $(DIST_DIR)/fs
for package in $^; do tar -xf $$package -C $(DIST_DIR)/fs; done
clean:
rm -rf $(BUILD_DIR); true
rm -rf $(DIST_DIR); true
.PHONY: clean