3 ms·
Why is the business with CFLAGS and LDFLAGS a big deal? Because if you follow the standard ways, your program is easier to package in a distro. CFLAGS, LDFLAGS
by kazinator 3y ago
Why is the business with CFLAGS and LDFLAGS a big deal?
Because if you follow the standard ways, your program is easier to package in a distro.
CFLAGS, LDFLAGS and LDLIBS are set by a distro build. They specify system-wide settings that the distro wants. Anything from special ways of linking the program, to tuning optimization for a particular CPU and whatnot.
The more your Makefile sticks to standards, the less they have to do.
Make sure you support "make DESTDIR=<directory>" to install into a temporary directory of the caller's choice. E.g. if your prefix (another thing to support) is /usr/bin then "make DESTDIR=tmp-dir" installs into tmp-dir/usr/bin. The software is configured to run in /usr/bin though and won't necessarily execute properly out of there; that tmp-dir is just for packaging.
However you do compiler selection, make sure that the default is to use $(CC).
Regarding the OUR_CFLAGS thing in my above post: the reason some Makefiles clobber CFLAGS is that they can then use built-in recipes. The built-in recipe for compiling a .c to a .o only knows about CC and CFLAGS. It's worth it to replace the built-in recipes with your own though in order not to disturb the standard variables.