gcc: limit postinst and postrm only with INCLUDE_STATIC_LINK_SPEC
[feed/packages.git] / devel / gcc / Makefile
1 #
2 # Copyright (C) 2002-2003 Erik Andersen <andersen@uclibc.org>
3 # Copyright (C) 2004 Manuel Novoa III <mjn3@uclibc.org>
4 # Copyright (C) 2005-2006 Felix Fietkau <nbd@nbd.name>
5 # Copyright (C) 2006-2014 OpenWrt.org
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
21 include $(TOPDIR)/rules.mk
22
23 PKG_NAME:=gcc
24 GCC_VERSION:=$(call qstrip,$(CONFIG_GCC_VERSION))
25 PKG_VERSION:=$(firstword $(subst +, ,$(GCC_VERSION)))
26 PKG_RELEASE:=5
27 GCC_DIR:=$(PKG_NAME)-$(PKG_VERSION)
28
29 PKG_SOURCE_URL:=@GNU/gcc/gcc-$(PKG_VERSION)
30 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
31 PKG_INSTALL:=1
32 PKG_FIXUP:=libtool
33 PKG_BUILD_PARALLEL:=1
34
35 PKG_CPE_ID:=cpe:/a:gnu:gcc
36
37 ifeq ($(PKG_VERSION),8.4.0)
38 PKG_HASH:=e30a6e52d10e1f27ed55104ad233c30bd1e99cfb5ff98ab022dc941edd1b2dd4
39 endif
40
41 ifeq ($(PKG_VERSION),10.3.0)
42 PKG_HASH:=64f404c1a650f27fc33da242e1f2df54952e3963a49e06e73f6940f3223ac344
43 endif
44
45 ifeq ($(PKG_VERSION),11.3.0)
46 PKG_HASH:=b47cf2818691f5b1e21df2bb38c795fac2cfbd640ede2d0a5e1c89e338a3ac39
47 endif
48
49 ifeq ($(PKG_VERSION),12.2.0)
50 PKG_HASH:=e549cf9cf3594a00e27b6589d4322d70e0720cdd213f39beb4181e06926230ff
51 endif
52
53 PATCH_DIR=./patches/$(GCC_VERSION)
54
55 include $(INCLUDE_DIR)/package.mk
56
57 define Package/gcc
58 SECTION:=devel
59 CATEGORY:=Development
60 TITLE:=gcc
61 MAINTAINER:=W. Michael Petullo <mike@flyn.org>
62 DEPENDS:= +binutils +libstdcpp +libzstd @!arc
63 MENU:=1
64 endef
65
66 define Package/gcc/config
67 source "$(SOURCE)/Config.in"
68 endef
69
70 ifeq ($(CONFIG_INCLUDE_STATIC_LIBC),y)
71 COPY_STATIC_LIBC=cp -a $(TOOLCHAIN_DIR)/lib/libc.a $(1)/usr/lib/$(PKG_NAME)/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION)
72 endif
73
74 ifeq ($(CONFIG_INCLUDE_STATIC_LIBPTHREAD),y)
75 COPY_STATIC_LIBPTHREAD=cp -a $(TOOLCHAIN_DIR)/lib/libpthread.a $(1)/usr/lib/$(PKG_NAME)/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION)
76 endif
77
78 ifeq ($(CONFIG_INCLUDE_STATIC_LIBSTDC),y)
79 COPY_STATIC_LIBSTDC=cp -a $(TOOLCHAIN_DIR)/lib/libstdc++.a $(1)/usr/lib/$(PKG_NAME)/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION)
80 endif
81
82 ifeq ($(CONFIG_INCLUDE_STATIC_LINK_SPEC),y)
83 INSTALL_STATIC_SPEC=g++ -dumpspecs |sed s/--start-group}\ %G\ %L\ /--start-group}\ %G\ %L\ -lstdc++\ -lgcc_pic\ / >/usr/lib/$(PKG_NAME)/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION)/specs
84 REMOVE_STATIC_SPEC=rm /usr/lib/$(PKG_NAME)/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION)/specs
85 endif
86
87 TARGET_LANGUAGES:="c,c++"
88 BUGURL=https://dev.openwrt.org/
89 PKGVERSION=OpenWrt GCC $(PKG_VERSION)
90 TARGET_CPPFLAGS += -D_GLIBCXX_INCLUDE_NEXT_C_HEADERS
91
92 # not using sstrip here as this messes up the .so's somehow
93 STRIP:=$(TOOLCHAIN_DIR)/bin/$(TARGET_CROSS)strip
94 RSTRIP:= \
95 NM="$(TOOLCHAIN_DIR)/bin/$(TARGET_CROSS)nm" \
96 STRIP="$(STRIP)" \
97 STRIP_KMOD="$(STRIP) --strip-debug" \
98 $(SCRIPT_DIR)/rstrip.sh
99
100 ifneq ($(CONFIG_SOFT_FLOAT),y)
101 ifeq ($(CONFIG_arm),y)
102 ARM_FLOAT_OPTION:= --with-float=hard
103 endif
104 endif
105
106 GMPSRC=gmp-6.1.0
107
108 define Download/gmp
109 URL:=ftp://gcc.gnu.org/pub/gcc/infrastructure/
110 FILE:=$(GMPSRC).tar.bz2
111 HASH:=498449a994efeba527885c10405993427995d3f86b8768d8cdf8d9dd7c6b73e8
112 endef
113 $(eval $(call Download,gmp))
114
115 MPCSRC=mpc-1.0.3
116
117 define Download/mpc
118 URL:=ftp://gcc.gnu.org/pub/gcc/infrastructure/
119 FILE:=$(MPCSRC).tar.gz
120 HASH:=617decc6ea09889fb08ede330917a00b16809b8db88c29c31bfbb49cbf88ecc3
121 endef
122 $(eval $(call Download,mpc))
123
124 MPFRSRC=mpfr-3.1.4
125
126 define Download/mpfr
127 URL:=ftp://gcc.gnu.org/pub/gcc/infrastructure/
128 FILE:=$(MPFRSRC).tar.bz2
129 HASH:=d3103a80cdad2407ed581f3618c4bed04e0c92d1cf771a65ead662cc397f7775
130 endef
131 $(eval $(call Download,mpfr))
132
133 define Build/Prepare
134 $(PKG_UNPACK)
135 # we have to download and unpack additional stuff before patching
136 tar -C $(PKG_BUILD_DIR) -xvjf $(DL_DIR)/$(GMPSRC).tar.bz2
137 ln -sf $(PKG_BUILD_DIR)/$(GMPSRC) $(PKG_BUILD_DIR)/gmp
138 tar -C $(PKG_BUILD_DIR) -xvzf $(DL_DIR)/$(MPCSRC).tar.gz
139 ln -sf $(PKG_BUILD_DIR)/$(MPCSRC) $(PKG_BUILD_DIR)/mpc
140 tar -C $(PKG_BUILD_DIR) -xvjf $(DL_DIR)/$(MPFRSRC).tar.bz2
141 ln -sf $(PKG_BUILD_DIR)/$(MPFRSRC) $(PKG_BUILD_DIR)/mpfr
142 $(Build/Patch)
143 # poor man's fix for `none-openwrt-linux' not recognized when building with musl
144 cp $(PKG_BUILD_DIR)/config.sub $(PKG_BUILD_DIR)/mpfr/
145 cp $(PKG_BUILD_DIR)/config.sub $(PKG_BUILD_DIR)/gmp/
146 chmod u+w $(PKG_BUILD_DIR)/mpc/config.sub
147 cp $(PKG_BUILD_DIR)/config.sub $(PKG_BUILD_DIR)/mpc/
148 endef
149
150 CONFIGURE_ARGS += CXXFLAGS_FOR_TARGET="-g -O2 -D_GLIBCXX_INCLUDE_NEXT_C_HEADERS"
151
152 define Build/Configure
153 (cd $(PKG_BUILD_DIR); rm -f config.cache; \
154 SHELL="$(BASH)" \
155 $(TARGET_CONFIGURE_OPTS) \
156 $(PKG_BUILD_DIR)/configure \
157 $(CONFIGURE_ARGS) \
158 --build=$(GNU_HOST_NAME) \
159 --host=$(REAL_GNU_TARGET_NAME) \
160 --target=$(REAL_GNU_TARGET_NAME) \
161 --enable-languages=$(TARGET_LANGUAGES) \
162 --with-bugurl=$(BUGURL) \
163 --with-pkgversion="$(PKGVERSION)" \
164 --enable-shared \
165 $(if $(CONFIG_LIBC_USE_GLIBC),--enable,--disable)-__cxa_atexit \
166 --with-default-libstdcxx-abi=gcc4-compatible \
167 --enable-target-optspace \
168 --with-gnu-ld \
169 --disable-nls \
170 --disable-libsanitizer \
171 --disable-libvtv \
172 --disable-libcilkrts \
173 --disable-libmudflap \
174 --disable-libmpx \
175 --disable-multilib \
176 --disable-libgomp \
177 --disable-libquadmath \
178 --disable-libssp \
179 --disable-decimal-float \
180 --disable-libstdcxx-pch \
181 --with-host-libstdcxx=-lstdc++ \
182 --prefix=/usr \
183 --libexecdir=/usr/lib \
184 --with-local-prefix=/usr \
185 --with-stage1-ldflags=-lstdc++ \
186 $(ARM_FLOAT_OPTION) \
187 $(SOFT_FLOAT_CONFIG_OPTION) \
188 $(call qstrip,$(CONFIG_EXTRA_GCC_CONFIG_OPTIONS)) \
189 );
190 endef
191
192 define Build/Compile
193 export SHELL="$(BASH)"; $(MAKE_VARS) $(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR) \
194 DESTDIR="$(PKG_INSTALL_DIR)" $(MAKE_ARGS) all
195 export SHELL="$(BASH)"; $(MAKE_VARS) $(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR) \
196 DESTDIR="$(PKG_INSTALL_DIR)" $(MAKE_ARGS) install
197 endef
198
199 ENVCFLAGS:="$(TARGET_OPTIMIZATION) $(EXTRA_OPTIMIZATION)
200 ifeq ($(CONFIG_SOFT_FLOAT),y)
201 ifeq ($(CONFIG_arm),y)
202 ENVCFLAGS+= -mfloat-abi=soft
203 else
204 ENVCFLAGS+= -msoft-float
205 endif
206 endif
207 ENVCFLAGS+="
208
209 ENVLDFLAGS:="-Wl,-rpath=/usr/lib -Wl,--dynamic-linker=/usr/lib/$(DYNLINKER) -L/usr/lib, -lstdc++"
210
211 define Package/gcc/install
212 $(INSTALL_DIR) $(1)/usr/bin $(1)/usr/lib $(1)/usr/lib/$(PKG_NAME)/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION)
213 cp -ar $(PKG_INSTALL_DIR)/usr/include $(1)/usr
214 cp -a $(PKG_INSTALL_DIR)/usr/bin/{$(REAL_GNU_TARGET_NAME)-{g++,gcc},cpp,gcov} $(1)/usr/bin
215 ln -s $(REAL_GNU_TARGET_NAME)-g++ $(1)/usr/bin/c++
216 ln -s $(REAL_GNU_TARGET_NAME)-g++ $(1)/usr/bin/g++
217 ln -s $(REAL_GNU_TARGET_NAME)-g++ $(1)/usr/bin/$(REAL_GNU_TARGET_NAME)-c++
218 ln -s $(REAL_GNU_TARGET_NAME)-gcc $(1)/usr/bin/gcc
219 ln -s $(REAL_GNU_TARGET_NAME)-gcc $(1)/usr/bin/cc
220 ln -s $(REAL_GNU_TARGET_NAME)-gcc $(1)/usr/bin/$(REAL_GNU_TARGET_NAME)-gcc-$(PKG_VERSION)
221 cp -ar $(PKG_INSTALL_DIR)/usr/lib/gcc $(1)/usr/lib
222 cp -ar $(TOOLCHAIN_DIR)/include $(1)/usr
223 cp -a $(TOOLCHAIN_DIR)/lib/*.{o,so*} $(1)/usr/lib/$(PKG_NAME)/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION)
224 cp -a $(TOOLCHAIN_DIR)/lib/*nonshared*.a $(1)/usr/lib/$(PKG_NAME)/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION)
225 cp -a $(TOOLCHAIN_DIR)/lib/libm.a $(1)/usr/lib/$(PKG_NAME)/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION)
226 $(COPY_STATIC_LIBC)
227 $(COPY_STATIC_LIBPTHREAD)
228 $(COPY_STATIC_LIBSTDC)
229 rm -f $(1)/usr/lib/$(PKG_NAME)/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION)/libgo*
230 rm -f $(1)/usr/lib/$(PKG_NAME)/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION)/libcc1*
231 echo '#!/bin/sh' > $(1)/usr/bin/gcc_env.sh
232 echo 'export LDFLAGS=$(ENVLDFLAGS)' >> $(1)/usr/bin/gcc_env.sh
233 echo 'export CFLAGS=$(ENVCFLAGS)' >> $(1)/usr/bin/gcc_env.sh
234 chmod +x $(1)/usr/bin/gcc_env.sh
235 endef
236
237 ifeq ($(CONFIG_INCLUDE_STATIC_LINK_SPEC),y)
238 define Package/gcc/postinst
239 #!/bin/sh
240
241 $(INSTALL_STATIC_SPEC)
242 endef
243
244 define Package/gcc/postrm
245 #!/bin/sh
246
247 $(REMOVE_STATIC_SPEC)
248 endef
249 endif
250
251 $(eval $(call BuildPackage,gcc))