Add switch to every gcc/g++ call


Results 1 to 5 of 5

Thread: Add switch to every gcc/g++ call

  1. #1
    Join Date
    May 2001
    Location
    Uh, I'm somewhere where I don't know where I am.
    Posts
    1,228

    Add switch to every gcc/g++ call

    I was wondering if there was a way to add a switch to a gcc/g++ call everytime. I have a few libraries that I need to compile for different processors. Each has a makefile which calls gcc to compile. Here is the best option I could come up with so far:

    Include a Makefile and define CC as gcc -mcpu=xxx.

    Are there any others/better?
    if (i_forgot && this_is_about_code)
    language = c++;

  2. #2
    Join Date
    Sep 1999
    Posts
    3,202
    alias gcc="/usr/bin/gcc -mcpu=foo"

  3. #3
    Join Date
    May 2001
    Location
    Uh, I'm somewhere where I don't know where I am.
    Posts
    1,228
    Sweet, that's what I was looking for, thanks!
    if (i_forgot && this_is_about_code)
    language = c++;

  4. #4
    Join Date
    Sep 1999
    Posts
    3,202
    You'll probably want to put this in your ~/.bash_profile or ~/.bashrc so it "sticks" between logins. If you want it system wide for everyone, then /etc/profile or /etc/bashrc

  5. #5
    Join Date
    Apr 2001
    Location
    SF Bay Area, CA
    Posts
    14,936
    make CC="/usr/bin/gcc -mcpu=xxxx"

    should also work, assuming your makefiles are sane. Setting CC this way (as opposed to setting it in the environment) will override whatever the Makefile has it set to. (The Makefile can set it to anything it likes, but it won't take effect.) Any sane Makefile lets you override the compiler this way, and always calls the compiler like:

    $(CC) [other options] [file]

    (i.e. no quotes around $(CC)), so the space that you add will actually work.

    (You could also do a wrapper script, but that's overkill if you can just override the compiler.)

    CFLAGS is another variable that you can sometimes use to add options to the compiler invocation in Makefiles, but they often set their own CFLAGS, so you have to figure out how to specify all of them rather than just the one flag you want to add.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •