Merge pull request #117 from artlogic/patch-1
[open-ath9k-htc-firmware.git] / Makefile
1 GMP_VER=6.1.1
2 GMP_URL=https://ftp.gnu.org/gnu/gmp/gmp-$(GMP_VER).tar.bz2
3 GMP_TAR=gmp-$(GMP_VER).tar.bz2
4 GMP_DIR=gmp-$(GMP_VER)
5 GMP_SUM=a8109865f2893f1373b0a8ed5ff7429de8db696fc451b1036bd7bdf95bbeffd6
6
7 MPFR_VER=3.1.4
8 MPFR_URL=https://ftp.gnu.org/gnu/mpfr/mpfr-$(MPFR_VER).tar.bz2
9 MPFR_TAR=mpfr-$(MPFR_VER).tar.bz2
10 MPFR_DIR=mpfr-$(MPFR_VER)
11 MPFR_SUM=d3103a80cdad2407ed581f3618c4bed04e0c92d1cf771a65ead662cc397f7775
12
13 MPC_VER=1.0.3
14 MPC_URL=https://ftp.gnu.org/gnu/mpc/mpc-$(MPC_VER).tar.gz
15 MPC_TAR=mpc-$(MPC_VER).tar.gz
16 MPC_DIR=mpc-$(MPC_VER)
17 MPC_SUM=617decc6ea09889fb08ede330917a00b16809b8db88c29c31bfbb49cbf88ecc3
18
19 BINUTILS_VER=2.27
20 BINUTILS_URL=https://ftp.gnu.org/gnu/binutils/binutils-$(BINUTILS_VER).tar.bz2
21 BINUTILS_TAR=binutils-$(BINUTILS_VER).tar.bz2
22 BINUTILS_DIR=binutils-$(BINUTILS_VER)
23 BINUTILS_PATCHES=local/patches/binutils.patch local/patches/binutils-2.27_fixup.patch
24 BINUTILS_SUM=369737ce51587f92466041a97ab7d2358c6d9e1b6490b3940eb09fb0a9a6ac88
25
26 GCC_VER=6.2.0
27 GCC_URL=https://ftp.gnu.org/gnu/gcc/gcc-$(GCC_VER)/gcc-$(GCC_VER).tar.bz2
28 GCC_TAR=gcc-$(GCC_VER).tar.bz2
29 GCC_DIR=gcc-$(GCC_VER)
30 GCC_PATCHES=local/patches/gcc.patch
31 GCC_SUM=9944589fc722d3e66308c0ce5257788ebd7872982a718aa2516123940671b7c5
32
33 BASEDIR=$(shell pwd)
34 TOOLCHAIN_DIR=$(BASEDIR)/toolchain
35 TARGET=xtensa-elf
36 DL_DIR=$(TOOLCHAIN_DIR)/dl
37 BUILD_DIR=$(TOOLCHAIN_DIR)/build
38
39 all: toolchain
40
41 # 1: package name
42 # 2: configure arguments
43 # 3: make command
44 define Common/Compile
45         mkdir -p $(BUILD_DIR)/$($(1)_DIR)
46         +cd $(BUILD_DIR)/$($(1)_DIR) && \
47         $(DL_DIR)/$($(1)_DIR)/configure \
48                 --prefix=$(TOOLCHAIN_DIR)/inst \
49                 $(2) && \
50         $(3)
51 endef
52
53 define GMP/Compile
54         $(call Common/Compile,GMP, \
55                 --disable-shared --enable-static, \
56                 $(MAKE) && $(MAKE) check && $(MAKE) -j1 install \
57         )
58 endef
59
60 define MPFR/Compile
61         $(call Common/Compile,MPFR, \
62                 --disable-shared --enable-static \
63                 --with-gmp=$(TOOLCHAIN_DIR)/inst, \
64                 $(MAKE) && $(MAKE) check && $(MAKE) -j1 install \
65         )
66 endef
67
68 define MPC/Compile
69         $(call Common/Compile,MPC, \
70                 --disable-shared --enable-static \
71                 --with-gmp=$(TOOLCHAIN_DIR)/inst \
72                 --with-mpfr=$(TOOLCHAIN_DIR)/inst, \
73                 $(MAKE) && $(MAKE) check && $(MAKE) -j1 install \
74         )
75 endef
76
77 define BINUTILS/Compile
78         $(call Common/Compile,BINUTILS, \
79                 --target=$(TARGET) \
80                 --disable-werror, \
81                 $(MAKE) && $(MAKE) -j1 install \
82         )
83 endef
84
85 define GCC/Compile
86         $(call Common/Compile,GCC, \
87                 --target=$(TARGET) \
88                 --enable-languages=c \
89                 --disable-libssp \
90                 --disable-shared \
91                 --disable-libquadmath \
92                 --with-gmp=$(TOOLCHAIN_DIR)/inst \
93                 --with-mpfr=$(TOOLCHAIN_DIR)/inst \
94                 --with-mpc=$(TOOLCHAIN_DIR)/inst \
95                 --with-newlib, \
96                 $(MAKE) && $(MAKE) -j1 install \
97         )
98 endef
99
100 # 1: package name
101 # 2: dependencies on other packages
102 define Build
103 $(DL_DIR)/$($(1)_TAR):
104         mkdir -p $(DL_DIR)
105         wget -N -P $(DL_DIR) $($(1)_URL)
106         printf "%s  %s\n" $($(1)_SUM) $$@ | shasum -a 256 -c
107
108 $(DL_DIR)/$($(1)_DIR)/.prepared: $(DL_DIR)/$($(1)_TAR)
109         tar -C $(DL_DIR) -x$(if $(findstring bz2,$($(1)_TAR)),j,z)f $(DL_DIR)/$($(1)_TAR)
110         $(if $($(1)_PATCHES), \
111                 cat $($(1)_PATCHES) | \
112                 patch -p1 -d $(DL_DIR)/$($(1)_DIR))
113         touch $$@
114
115 $(1)_DEPENDS = $(foreach pkg,$(2),$(BUILD_DIR)/$($(pkg)_DIR)/.built)
116 $(BUILD_DIR)/$($(1)_DIR)/.built: $(DL_DIR)/$($(1)_DIR)/.prepared $$($(1)_DEPENDS)
117         mkdir -p $(BUILD_DIR)/$($(1)_DIR)
118         $($(1)/Compile)
119         touch $$@
120
121 clean-dl-$(1):
122         rm -rf $(DL_DIR)/$($(1)_DIR)
123
124 toolchain: $(BUILD_DIR)/$($(1)_DIR)/.built
125 clean-dl: clean-dl-$(1)
126 download: $(DL_DIR)/$($(1)_DIR)/.prepared
127
128 endef
129
130 all: toolchain firmware
131 toolchain-clean:
132         rm -rf $(TOOLCHAIN_DIR)/build $(TOOLCHAIN_DIR)/inst
133 clean-dl:
134 download:
135 toolchain:
136
137 clean:
138         $(MAKE) -C target_firmware clean
139
140 firmware: toolchain
141         +$(MAKE) -C target_firmware
142
143 .PHONY: all toolchain-clean clean clean-dl download toolchain firmware
144
145 $(eval $(call Build,GMP))
146 $(eval $(call Build,MPFR,GMP))
147 $(eval $(call Build,MPC,GMP MPFR))
148 $(eval $(call Build,BINUTILS))
149 $(eval $(call Build,GCC,MPC MPFR))