LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 01-09-2018, 04:32 PM   #1
qwxy
LQ Newbie
 
Registered: Jan 2018
Posts: 1

Rep: Reputation: Disabled
How to set SLACKBUILD CFLAGS / CXXFLAGS / QMAKE C/CXX flags globally?


Hello everyone.

I guess this is an odd first question and an odd first thread here.
I apologize if this question has been asked before, but almost everything I've found are age old threads, and I think, when it comes to the compilation flags the SLACKBUILD format has probably changed since then?

Anyway, what I wanted to ask was can you and if yes how do you set CFLAGS or CXXFLAGS (C++ flags), QMAKE C/CXX FLAGS (QMAKE_CFLAGS_RELEASE and QMAKE_CXXFLAGS_RELEASE) globally? (so, any of them)

I'm most interested if you can set CFLAGS and CXXFLAGS globally to overwrite those default ones in slackbuilds, so that I don't have to edit each slackbuild manually for every package.

I'm asking this since I've used Arch Linux for a long time and I'm used to specifying compilation flags for AUR scripts/PKGBUILDs and the like. I would like to specify them at least for some packages and recompile packages to optimize them for Atom cpu in my laptop (I've installed the 32bit version of Slackware. So, I'd use sse up to sse4.2 and -mfpmath=sse and some other optimizations). Also, the MAKEOPTS="-j3" come to mind
I want to compile packages with options that are enabled by -march=native, so I'd create packages which run only on my/this specific Atom cpu and favour it's capabilities.
Also, Slackware is probably the most responsive Linux distro I've tried on this laptop.

Cheers and thanks for reading , I know it's long

Last edited by qwxy; 01-09-2018 at 04:44 PM.
 
Old 01-09-2018, 05:40 PM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
I think /etc/profile.d is the place to set environment variables globaly (eg for all users)
There, any script with .sh extension and that has executable permission will be sourced (if you use bourne type shell or .csh for c shells)
 
Old 01-09-2018, 09:11 PM   #3
55020
Senior Member
 
Registered: Sep 2009
Location: Yorks. W.R. 167397
Distribution: Slackware
Posts: 1,307
Blog Entries: 4

Rep: Reputation: Disabled
Hi, and welcome to LQ (and to Slackware).

Short answer, you can't.

Each SlackBuild script is inherently standalone and unique, but almost none of the SlackBuild scripts from Slackware itself or SlackBuilds.org will pay any attention if you set any compiler flags externally via environment variables. A few SlackBuilds have carefully chosen hardcoded options, but most are hardcoded with '-O2 -march=i486 -mtune=i686' on 32 bit.

This question has come up occasionally in the past, but nobody has ever made a case with proper benchmarks that diddling compiler flags would make a worthwhile difference beyond placebo. You'll get far more gain from going 64 bit than by trying to rice 32 bits with -march=native, and I'm not sure if the fancier sse stuff is even compatible with -m32. 32 bit support in Slackware will probably be around for many years to come, but I doubt anybody will be bothered changing anything at this time to optimise it even if you showed a small benefit.

MAKEOPTS is a different matter. It is a Gentoo specific environment variable. *Nothing* other than Gentoo's tools recognises it. The standard name is MAKEFLAGS, and you can use MAKEFLAGS with the vast majority of SlackBuilds.org scripts. I'd recommend using '-l' in addition to '-j', for example export MAKEFLAGS='-j6 -l3'
 
4 members found this post helpful.
Old 01-09-2018, 09:17 PM   #4
orbea
Senior Member
 
Registered: Feb 2015
Distribution: Slackware64-current
Posts: 1,950

Rep: Reputation: Disabled
While I agree with 55020 that there is not much benefit if I was going to attempt this I would make a wrapper script that would copy a slackbuild, sed the appropriate $SLKCFLAGS variable (Not all scripts use this variable) and then executes the new edited script.
 
Old 01-09-2018, 10:06 PM   #5
abga
Senior Member
 
Registered: Jul 2017
Location: EU
Distribution: Slackware
Posts: 1,634

Rep: Reputation: 929Reputation: 929Reputation: 929Reputation: 929Reputation: 929Reputation: 929Reputation: 929Reputation: 929
@qwxy

AFAIK, there are only some ways you could achieve what you're looking after when using SlackBuilds and all these imply some manual checking and editing work.

1. Manually edit the SlackBuild script and add what you want to the $SLKCFLAGS variable. If there are other FLAGS that are not covered in the SlackBuild and the package configure script supports (manually check with configure --help), you can define them as environmental variables either before running the SlackBuild script or within the script itself, just before the section where the script executes the package configure script, with (for example):
export C_INCLUDE_PATH=
LDFLAGS=""
2. Put a break in the SlackBuild script just after it executes the package configure script (and before issuing make) and manually edit the resulted Makefile. For example, look in the Makefile for the field "CFLAGS =" and edit add/remove your flags. This works well when the source package has only one central Makefile, if there are Makefiles in every (sub)directory of the source base of the package - then you have a lot of work - editing each one individually. Finally, once you're done editing, resume the SlackBuild script execution and enjoy your "platform optimized" package.
 
Old 01-10-2018, 04:11 AM   #6
abga
Senior Member
 
Registered: Jul 2017
Location: EU
Distribution: Slackware
Posts: 1,634

Rep: Reputation: 929Reputation: 929Reputation: 929Reputation: 929Reputation: 929Reputation: 929Reputation: 929Reputation: 929
@qwxy
The previous hints were for a non-invasive surgery. If you believe that you're skilled enough / have plenty of time, you could recompile gcc and change the default compiler flags, then you'll get your desired global effect.
To check the actual ones, run:
Code:
gcc -march=native -E -v - </dev/null 2>&1 | grep cc1
You might also want to tune&recompile the kernel:
https://www.linux.com/news/linux-41-...ntel-atom-socs
 
Old 01-10-2018, 05:30 AM   #7
a4z
Senior Member
 
Registered: Feb 2009
Posts: 1,727

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
as mentioned above, each SlackBuild script is inherently standalone and unique
but
usually slack build files contain boilerplate like
and some places make it even a requirement to do so, like SBO who will reject your build if it does not use the standard build template.
Code:
if [ -z "$ARCH" ]; then
  case "$( uname -m )" in
    i?86) ARCH=i486 ;;
    arm*) ARCH=arm ;;
       *) ARCH=$( uname -m ) ;;
  esac
fi
and than

Code:
if [ "$ARCH" = "i486" ]; then
  SLKCFLAGS="-O2 -march=i486 -mtune=i686"
  LIBDIRSUFFIX=""
elif [ "$ARCH" = "i686" ]; then
  SLKCFLAGS="-O2 -march=i686 -mtune=i686"
  LIBDIRSUFFIX=""
elif [ "$ARCH" = "x86_64" ]; then
  SLKCFLAGS="-O2 -fPIC"
  LIBDIRSUFFIX="64"
else
  SLKCFLAGS="-O2"
  LIBDIRSUFFIX=""
fi
and than

Code:
CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
followed buy configure, cmake whatever

you see what happens?
you can set whatever global build flags ever, they will be ignored and overwritten by the usual and standard slack builds
it is in the else case of the second code block, otherwise your special ARCH could fix this
this means, whatever you do , your flags will be kindly ignored, one of the reasons why I had my own builds for many packages over many years but this became to time intensive.

all this redundant boilerplate in each Slackbuild file is there to give you exactly no options :-)
sorry for mention this reality.

and this is Slackware, things to not change that easy, not even if something is so suboptimal like this, missing multilib compiler and packages, or PAM support.
So the old information you found is very probably still valid.

Eric did, when I remember correct, some years ago, a proposal for a more flexible way of getting global compiler flags, through including a global spec file, but this idea never seen the light. (sorry when I remember false Eric, pls correct if so)

I think Salix has an alternative, and more arch way, of building slack packages, and once I have seen something, I think from ivaldi, that looked also arch like.
 
Old 01-10-2018, 05:50 AM   #8
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,057

Rep: Reputation: Disabled
Quote:
Originally Posted by a4z View Post
I think Salix has an alternative, and more arch way, of building slack packages, and once I have seen something
Yes. See e.g. a slkbuild package here and the source directory there. That's what I use when I have to make a new package.

After installation, read "man slkbuild" and "man SLKBUILD". Templates are stored in /etc/slkbuild, you can edit them and make your own.

PS it is recommended to use fakeroot when running slkbuild. That's also what I do when testing my SlackBuilds just to avoid nasty consequences of wrong paths on the host's main directories. Yes, I make mistakes...

Last edited by Didier Spaier; 01-10-2018 at 06:36 AM. Reason: PS added.
 
2 members found this post helpful.
Old 01-10-2018, 06:20 AM   #9
Alien Bob
Slackware Contributor
 
Registered: Sep 2005
Location: Eindhoven, The Netherlands
Distribution: Slackware
Posts: 8,559

Rep: Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106
Quote:
Originally Posted by a4z View Post
Eric did, when I remember correct, some years ago, a proposal for a more flexible way of getting global compiler flags, through including a global spec file, but this idea never seen the light. (sorry when I remember false Eric, pls correct if so)
When I worked on an hard-float ARM port for Slackware I wanted to stick to the concept of using one single source tree for all ARCH'es (the armedslack aka slackwarearm port maintained by MoZes does not use unmodified Slackware build scripts), so I proposed the following:
Code:
# You can use your own private machine.conf file to overrule machine defaults:
if [ -e $SRCDIR/machine.conf ]; then
  . $SRCDIR/machine.conf
elif [ -e /etc/slackbuild/machine.conf ]; then
  . /etc/slackbuild/machine.conf
else
  # Automatically determine the architecture we're building on:
  if [ -z "$ARCH" ]; then
    case "$(uname -m)" in
      i?86) ARCH=i586 ;;
      arm*) readelf /usr/bin/file -A | egrep -q "Tag_CPU.*[4,5]" && ARCH=arm || 
ARCH=armv7hl ;;
      # Unless $ARCH is already set, use uname -m for all other archs:
      *) ARCH=$(uname -m) ;;
    esac
    export ARCH
  fi
  # Set CFLAGS/CXXFLAGS and LIBDIRSUFFIX:
  case "$ARCH" in
    i?86)      SLKCFLAGS="-O2 -march=${ARCH} -mtune=i686"
               SLKLDFLAGS=""; LIBDIRSUFFIX=""
               ;;
    x86_64)    SLKCFLAGS="-O2 -fPIC"
               SLKLDFLAGS="-L/usr/lib64"; LIBDIRSUFFIX="64"
               ;;
    armv7hl)   SLKCFLAGS="-O2 -march=armv7-a -mfpu=vfpv3-d16"
               SLKLDFLAGS=""; LIBDIRSUFFIX=""
               ;;
    *)         SLKCFLAGS=${SLKCFLAGS:-"-O2"}
               SLKLDFLAGS=${SLKLDFLAGS:-""}; LIBDIRSUFFIX=${LIBDIRSUFFIX:-""}
               ;;
  esac
fi

case "$ARCH" in
    arm*)    TARGET=$ARCH-slackware-linux-gnueabi ;;
    *)       TARGET=$ARCH-slackware-linux ;;
esac
It was not adopted in full, unfortunately. You'll find this block of code in very few official Slackware build scripts (samba and tigervnc).
 
6 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] how do I translate the /proc/cpuinfo ( flags line) to $CFLAGS rob.rice Programming 6 04-07-2017 07:50 PM
Sbopkg : building a queue file with CFLAGS and CXXFLAGS set. Linux.tar.gz Slackware 4 03-11-2012 10:24 PM
SBOpkg honor's CFLAGS but then they're replaced with i486 arch flags? = :( Holering Slackware 8 10-11-2010 11:08 PM
[SOLVED] Set DPI Globally bassmadrigal Slackware 2 07-25-2010 03:55 PM
[SOLVED] Is this how you set CFLAGS and other Make options? agi93 Slackware 6 01-02-2010 02:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 01:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration