[Solution]Makefile where to add compile flags
Requirement: In a project, we need to add some compile flags in order to meet the security requirement or other reasons.
In my project, there are two kinds of Makefile. I will introduce them later.
First, let me introduce the basic concept.
- In most cases, we can add compile flag into CFALGS in compile stage and add compile flag into LDFLAGS in link stage.
- Add these flags to gcc command. Refer to the following($(CC) means your compiler):
- $(CC) xxx xxx $(CFLAGS) xxx xxx
- $(CC) xxx xxx $(CFLAGS) $(LDFLAGS) xxx xxx
In a quick summary: You need to find CFLAGS, LDFLAGS and compile command, then add your compile flags into CFLAGS and LDFLAGS, then add CFLAGS, LDFLAGS to compile command. Of course you can add compile flags into compile command directly.
Case 1:
Nothing special, you just have a Makefile, then you need to add your compile flags.
Step 1: Find the CFLAGS and LDFLAGS or maybe other name CCFLAGS. They are just a name. In most cases, It is CFLAGS and LDFLAGS.
Step 2: Add the compile flags you want to CFLAGS or LDFLAGS. (such as “-fstack-protector-strong” for stack protected, “-Wl,-z,relro” for Read-only relocations, “-Wl,-z,now” for Immediate binding)
- CFLAGS=”-fstack-protector-strong”
- CFLAGS+=”-fstack-protector”
- DLFLAGS=”-Wl,-z, now”
Option:
You can add your compile flags into compile command directly. Refer to the following:
$(CC) [other options] -fstack-protector -Wl,-z,relro,-z,now
Case 2:
You have an open source component and a Makefile outside of this component. Also there is a Makefile in this open source code.
Actually, It uses configure to create makefile.
Such as Monit component:
->Makefile (We write this makefile to add Monit component to our project)
->Makefile (We write this makefile to add Monit component to our project)
->Monit
->Makefile(created by configure file)
What we need to do is to modify the Makefile outside this open source code. Refer to the following:
CFG = [other options] CFLAGS=”-fstack-protector-strong”
Then,
./configure $(CFG);
NOW, I have already introduced how to add compile flag in two kinds of Makefile. Hope it is useful for you.
Note:
As for the difference between “=, :=, +=” in Makefile, please refer to this quesiton.
Reference:
https://www.keil.com/support/man/docs/armclang_ref/armclang_ref_cjh1548250046139.htm
https://wiki.ubuntu.com/ToolChain/CompilerFlags
https://stackoverflow.com/questions/39898815/makefile-where-to-add-compile-flags?noredirect=1&lq=1
Have a good day, Take care!
Pound of Weed for Sale
[…]Wonderful story, reckoned we could combine several unrelated information, nevertheless truly worth taking a search, whoa did 1 find out about Mid East has got additional problerms at the same time […]
PARROTS FOR SALE
[…]usually posts some extremely interesting stuff like this. If youre new to this site[…]
GOLDEN RETRIEVER PUPPIES FOR SALE
[…]The details talked about in the report are some of the most beneficial obtainable […]
Pinball for sale
[…]the time to read or visit the content material or websites we have linked to beneath the[…]
whole crab for sale
[…]The info mentioned within the post are a number of the ideal obtainable […]
cruis’n blast arcade
[…]just beneath, are a lot of entirely not connected internet sites to ours, however, they’re surely worth going over[…]
g spot toy
[…]we prefer to honor a lot of other web internet sites on the net, even though they arent linked to us, by linking to them. Underneath are some webpages really worth checking out[…]
rechargeable vibrator
[…]check below, are some entirely unrelated sites to ours, however, they’re most trustworthy sources that we use[…]
best p spot toy
[…]we prefer to honor numerous other net web-sites around the internet, even if they arent linked to us, by linking to them. Underneath are some webpages really worth checking out[…]
best adult sex games
[…]The information and facts talked about inside the article are a number of the most beneficial accessible […]
beginners strap on dildo
[…]Sites of interest we’ve a link to[…]
Buy Weed Online
[…]that will be the end of this report. Right here youll uncover some internet sites that we feel you will enjoy, just click the hyperlinks over[…]
Nearest Hair Salon
[…]Here are some of the sites we advise for our visitors[…]
realistic dildos
[…]check below, are some completely unrelated sites to ours, however, they’re most trustworthy sources that we use[…]
kratom powder for sale
[…]very handful of sites that occur to be comprehensive below, from our point of view are undoubtedly effectively really worth checking out[…]
vibrating butt plug
[…]Every as soon as inside a while we pick out blogs that we read. Listed below are the latest web-sites that we choose […]
sex and myths facts
[…]we came across a cool site that you may get pleasure from. Take a appear when you want[…]
suction cup dildos
[…]Here are several of the sites we recommend for our visitors[…]
Electric Motorcycle Canada
[…]The information talked about inside the write-up are a number of the most effective out there […]
cell phone glass repair near me
[…]The facts talked about in the write-up are a number of the most effective out there […]