[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.

  1. In most cases, we can add compile flag into CFALGS in compile stage and add compile flag into LDFLAGS in link stage.
  2. Add these flags to gcc command. Refer to the following($(CC) means your compiler):
    1. $(CC) xxx xxx $(CFLAGS) xxx xxx
    2. $(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!

Share this article to your social media
Subscribe
Notify of
guest
213 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
trackback
Pound of Weed for Sale
2 years ago

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 […]

trackback
PARROTS FOR SALE
2 years ago

PARROTS FOR SALE

[…]usually posts some extremely interesting stuff like this. If you’re new to this site[…]

trackback
GOLDEN RETRIEVER PUPPIES FOR SALE
2 years ago

GOLDEN RETRIEVER PUPPIES FOR SALE

[…]The details talked about in the report are some of the most beneficial obtainable […]

trackback
Pinball for sale
2 years ago

Pinball for sale

[…]the time to read or visit the content material or websites we have linked to beneath the[…]

trackback
whole crab for sale
2 years ago

whole crab for sale

[…]The info mentioned within the post are a number of the ideal obtainable […]

trackback
cruis'n blast arcade
2 years ago

cruis’n blast arcade

[…]just beneath, are a lot of entirely not connected internet sites to ours, however, they’re surely worth going over[…]

trackback
g spot toy
2 years ago

g spot toy

[…]we prefer to honor a lot of other web internet sites on the net, even though they aren’t linked to us, by linking to them. Underneath are some webpages really worth checking out[…]

trackback
rechargeable vibrator
2 years ago

rechargeable vibrator

[…]check below, are some entirely unrelated sites to ours, however, they’re most trustworthy sources that we use[…]

trackback
best p spot toy
2 years ago

best p spot toy

[…]we prefer to honor numerous other net web-sites around the internet, even if they aren’t linked to us, by linking to them. Underneath are some webpages really worth checking out[…]

trackback
best adult sex games
2 years ago

best adult sex games

[…]The information and facts talked about inside the article are a number of the most beneficial accessible […]

trackback
beginners strap on dildo
2 years ago

beginners strap on dildo

[…]Sites of interest we’ve a link to[…]

trackback
Buy Weed Online
2 years ago

Buy Weed Online

[…]that will be the end of this report. Right here you’ll uncover some internet sites that we feel you will enjoy, just click the hyperlinks over[…]

trackback
Nearest Hair Salon
2 years ago

Nearest Hair Salon

[…]Here are some of the sites we advise for our visitors[…]

trackback
realistic dildos
2 years ago

realistic dildos

[…]check below, are some completely unrelated sites to ours, however, they’re most trustworthy sources that we use[…]

trackback
kratom powder for sale
2 years ago

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[…]

trackback
vibrating butt plug
2 years ago

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 […]

trackback
sex and myths facts
2 years ago

sex and myths facts

[…]we came across a cool site that you may get pleasure from. Take a appear when you want[…]

trackback
suction cup dildos
2 years ago

suction cup dildos

[…]Here are several of the sites we recommend for our visitors[…]

trackback
Electric Motorcycle Canada
2 years ago

Electric Motorcycle Canada

[…]The information talked about inside the write-up are a number of the most effective out there […]

trackback
cell phone glass repair near me
2 years ago

cell phone glass repair near me

[…]The facts talked about in the write-up are a number of the most effective out there […]