more gdc fixes
[k8jam.git] / defaults / Jambase.profile
blob223dc27a68aee88549d78fcb1c841835d8ad4319
1 # This program is free software: you can redistribute it and/or modify
2 # it under the terms of the GNU General Public License as published by
3 # the Free Software Foundation, either version 3 of the License, or
4 # (at your option) any later version.
6 # This program is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9 # GNU General Public License for more details.
11 # You should have received a copy of the GNU General Public License
12 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
14 ###############################################################################
15 # special values
16 ###############################################################################
17 DIET_BIN ?= diet ;
19 GDC_INLINE_FLAGS ?= -finline-small-functions -finline-functions ;
21 OPTIM_SPEED ?= -O3 -fwrapv -march=native -mtune=native -mfpmath=sse  ;
22 LINKFLAGS_SPEED ?= -s ;
24 OPTIM_SIZE ?= -Os -fwrapv -march=native -mtune=native ;
25 LINKFLAGS_SIZE ?= -s ;
27 OPTIM_STANDARD ?= -O2 -fwrapv -march=native -mtune=native ;
28 LINKFLAGS_STANDARD ?= -s ;
30 OPTIM_NOOPT ?= -O0 ;
31 LINKFLAGS_NOOPT ?= -s ;
33 OPTIM_DEBUG ?= -O0 -g ;
34 LINKFLAGS_DEBUG ?= -g ;
36 OPTIM_NOALIAS ?= -fno-strict-aliasing ;
39 # current profile will be saved to OPT_PROFILE
40 # empty OPT_PROFILE means 'default'
43 ## K8JAM-KNOWN-PROFILES =
44 ##   none default  # don't change
45 ##   empty         # remove optimisation flags
46 ##   speed         # optimise for speed
47 ##   size          # optimise for size
48 ##   debug         # don't optimize, add debug info
49 ##   standard      # -O2
50 ## ;
53 rule --k8jam-set-standards-- {
54   if ! $(CC.standard) { CC.standard = -std=gnu11 ; }
55   if ! $(C++.standard) { C++.standard = -std=gnu++98 ; }
59 rule --k8jam-profile-default-- {
60   OPT_PROFILE = ;
64 rule --k8jam-profile-empty-- {
65   LINKFLAGS.all += -s ;
66   --k8jam-set-standards-- ;
70 rule --k8jam-profile-noopt-- {
71   CFLAGS.all += $(OPTIM_NOOPT) ;
72   GDCFLAGS.all += $(OPTIM_NOOPT) ;
73   LINKFLAGS.all += $(LINKFLAGS_NOOPT) ;
74   --k8jam-set-standards-- ;
78 rule --k8jam-profile-speed-- {
79   CFLAGS.all += $(OPTIM_SPEED) ;
80   GDCFLAGS.all += $(OPTIM_SPEED) ;
81   LINKFLAGS.all += $(LINKFLAGS_SPEED) ;
82   --k8jam-set-standards-- ;
85 rule --k8jam-profile-size-- {
86   CFLAGS.all += $(OPTIM_SIZE) ;
87   GDCFLAGS.all += $(OPTIM_SIZE) ;
88   LINKFLAGS.all += $(LINKFLAGS_SIZE) ;
89   --k8jam-set-standards-- ;
92 rule --k8jam-profile-debug-- {
93   CFLAGS.all += $(OPTIM_DEBUG) ;
94   GDCFLAGS.all += $(OPTIM_DEBUG) ;
95   LINKFLAGS.all += $(LINKFLAGS_DEBUG) ;
96   --k8jam-set-standards-- ;
99 rule --k8jam-profile-standard-- {
100   CFLAGS.all += $(OPTIM_STANDARD) ;
101   GDCFLAGS.all += $(OPTIM_STANDARD) ;
102   LINKFLAGS.all += $(LINKFLAGS_STANDARD) ;
103   --k8jam-set-standards-- ;
107 # profile 'name' ;
108 # set compile flags for profile; works only for gcc/g++
109 # available profiles:
110 #  none, default: don't change
111 #  empty: remove optimisation flags
112 #  speed: optimise for speed and pIII
113 #  size: optimise for size
114 #  debug: don't optimize, add debug info
115 #  standard: -O2
116 rule profile {
117   local pnn = $(1) ;
118   if ! $(pnn) { pnn = 'standard' ; }
119   if [ HaveRule --k8jam-profile-$(pnn)-- ] {
120     # --fuck-idiotic-caret-- ;
121     remove-opt-flags-for-all-compilers ;
122     LINKFLAGS -= '-g' '-s' ;
123     C++LINKFLAGS -= '-g' '-s' ;
124     OBJCLINKFLAGS -= '-g' '-s' ;
125     LINKFLAGS.all -= '-g' '-s' ;
126     if ! $(JAM_OPTION_MAKE_UPDATES_SILENT) {
127       Echo "MSG: '$(pnn)' profile" ;
128     }
129     OPT_PROFILE = $(pnn) ;
130     --k8jam-profile-$(OPT_PROFILE)-- ;
131   } else {
132     Exit 'FATAL: invalid profile:' "$(pnn)" ;
133   }
137 # process various profile targets:
138 #   speed
139 #   size
140 #   debug
141 rule profile-targets {
142   local prf = ;
143   local rel = ;
144   local ut = ;
145   local ntarg = ;
146   for local targ in $(JAM_TARGETS) {
147     if $(targ) = 'speed' || $(targ) = 'size' || $(targ) = 'debug' {
148       if ! $(PROFILE) {
149         if $(prf) { Exit "FATAL: duplicate profile target; " $(prf) "and" $(targ) ; }
150         prf = $(targ) ;
151       }
152     } else if $(targ) = 'release' {
153       if $(rel) { Exit "FATAL: duplicate profile target; " $(prf) "and" $(targ) ; }
154       rel = tan ;
155     } else if $(targ) = 'unittest' {
156       if $(ut) { Exit "FATAL: duplicate profile target; " $(prf) "and" $(targ) ; }
157       ut = tan ;
158     } else {
159       ntarg += $(targ) ;
160     }
161   }
162   if $(prf) { PROFILE = $(prf) ; }
163   if $(rel) { RELEASE = tan ; }
164   if $(ut) { UNITTEST = tan ; }
165   if ! $(ntarg) { ntarg = 'all' ; }
166   JAM_TARGETS = $(ntarg) ;
170 # selects profile
171 # if $(flags) contains 'no-targets' -- disallow 'profile targets'
172 rule set-profile flags {
173   local profname ndb dbg ;
175   if ! 'no-targets' in $(flags) { profile-targets ; }
177   dbg = ;
178   profname = $(PROFILE) ;
179   if ! $(profname) {
180     if $(DEBUG) { profname = 'debug' ; } else { profname = 'standard' ; }
181   } else {
182     if $(profname) != 'debug' && $(DEBUG) { dbg = 'tan' ; }
183   }
185   if $(profname) = 'debug' && ! $(DEBUG) { DEBUG = tan ; }
187   if $(USE_CLANG) {
188     CC = clang ;
189     LINK = clang ;
190     C++ = clang++ ;
191     C++LINK = clang++ ;
192   }
194   if $(DIET) && $(DIET_BIN) {
195     CC = $(DIET_BIN) $(CC) ;
196     LINK = $(DIET_BIN) $(LINK) ;
197     C++ = $(DIET_BIN) $(C++) ;
198     C++LINK = $(DIET_BIN) $(C++LINK) ;
199   }
201   if $(DBG) || $(DEBUG) { ndb = ; } else { ndb = NDEBUG ; }
203   profile $(profname) ;
205   if $(VALGRIND) || $(dbg) || $(DEBUG) {
206     CFLAGS.all -= '-g' '-s' ;
207     GDCFLAGS.all -= '-g' '-s' ;
208     LINKFLAGS.all -= '-g' '-s' ;
209     CFLAGS.all += -g ;
210     GDCFLAGS.all += -g ;
211     LINKFLAGS.all += -g ;
212   }
213   if ! $(NO_WARNINGS) { CFLAGS.all += -Wall ; GDCFLAGS.all += -Wall ; }
214   if $(NO_NATIVE) { CFLAGS.all -= '-march=native' '-mtune=native' ; GDCFLAGS.all -= '-march=native' '-mtune=native' ; }
215   if $(NO_FWRAP) { CFLAGS.all -= '-fwrapv' ; GDCFLAGS.all -= '-fwrapv' ; }
217   if $(ndb) { DEFINES += $(ndb) ; }
219   if $(MAEMO47) { CFLAGS.all += -fgnu89-inline ; }
220   if $(MAEMO47) && $(USE_THUMB) { CFLAGS.all += -mthumb ; }
221   if $(MAEMO47) && $(THUMB_WRELOC) { CFLAGS.all += -mword-relocations ; }
222   if $(MAEMO47) && $(Fpic) { CFLAGS.all += -fpic ; }
223   if $(MAEMO47) && $(FPIC) { CFLAGS.all += -fPIC ; }
225   # d
226   if $(UNITTEST) {
227     GDCFLAGS.all += -funittest ;
228   }
229   if $(RELEASE) {
230     GDCFLAGS.all += -frelease ;
231     GDCFLAGS.all += -fno-assert ;
232     GDCFLAGS.all += -fno-debug ;
233     GDCFLAGS.all += -fno-in ;
234     GDCFLAGS.all += -fno-out ;
235     GDCFLAGS.all += -fno-invariants ;
236     GDCFLAGS.all += -fno-bounds-check ;
237   } else {
238     if ! $(D_MAXSPEED) {
239       if ! $(NODEBUG) && ! $(NO_DEBUG) && ! $(D_NO_DEBUG) { GDCFLAGS.all += -fdebug ; }
240       if ! $(D_NO_ASSERT) { GDCFLAGS.all += -fassert ; } else { GDCFLAGS.all += -fno-assert ; }
241       if ! $(D_NO_IN) { GDCFLAGS.all += -fin ; } else { GDCFLAGS.all += -fno-in ; }
242       if ! $(D_NO_OUT) { GDCFLAGS.all += -fout ; } else { GDCFLAGS.all += -fno-out ; }
243       if ! $(D_NO_INVARIANTS) { GDCFLAGS.all += -finvariants ; } else { GDCFLAGS.all += -fno-invariants ; }
244       if ! $(D_NO_BOUNDS) { GDCFLAGS.all += -fbounds-check ; } else { GDCFLAGS.all += -fno-bounds-check ; }
245     } else {
246       GDCFLAGS.all += -fno-assert ;
247       GDCFLAGS.all += -fno-debug ;
248       GDCFLAGS.all += -fno-in ;
249       GDCFLAGS.all += -fno-out ;
250       GDCFLAGS.all += -fno-invariants ;
251       GDCFLAGS.all += -fno-bounds-check ;
252     }
253   }
255   if ! $(USE_DMD) && $(PHOBOS_STATIC) {
256     #GDCFLAGS.all += -static-libphobos ;
257     GDCLINKFLAGS.all += -static-libphobos ;
258   } else {
259     GDCFLAGS.all += -fPIC ;
260     #LINKFLAGS.all += -fPIC ;
261   }
263   gcc-suggest-attrs ;