Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 705301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:02:17+00:00 2026-05-14T04:02:17+00:00

I don’t know how to execute a command stored as a variable or how

  • 0

I don’t know how to execute a command stored as a variable or how to use ifeq inside of a target, so I have a very redundant Makefile at the moment!

Ideally I’d like to have just one target (all) which would run the stored command on Mac and run it twice on Linux, once with -m32 and once with -m64.

all:
    echo PLEASE SELECT OS, e.g. make linux
    exit 1

mac:
     gcc $(SHARED_OPT) $(GENERAL_CFLAGS) $(PLATFORM_CFLAGS) -o $(BUILD_DIR)$(BUILD_NAME) $(SOURCE) $(LIBRARIES)

linux:
    gcc $(SHARED_OPT) $(GENERAL_CFLAGS) $(PLATFORM_CFLAGS) -o $(BUILD_DIR)$(BUILD_NAME64) $(SOURCE) $(LIBRARIES64) -m64
    gcc $(SHARED_OPT) $(GENERAL_CFLAGS) $(PLATFORM_CFLAGS) -o $(BUILD_DIR)$(BUILD_NAME) $(SOURCE) $(LIBRARIES) -m32

UPDATE: This is what I ended up with, after reading the various suggestsions. (Yes I know I should use autoconf . . .) Thanks everyone for your help!

ifeq($(PLATFORM), Linux)
    COMMON = -pthread -fPIC
    PLATFORM_CFLAGS = $(COMMON) -m32
    PLATFORM_CFLAGS64 = $(COMMON) -m64
endif

ifeq ($(PLATFORM), Darwin)
    PLATFORM_CFLAGS = -arch i386 -arch ppc -arch x86_64 -mmacosx-version-min=10.5 -isysroot /Developer/SDKs/MacOSX10.5.sdk
endif

all: $(PLATFORM)_all

Darwin_all:
     mkdir -p ../../../../tmp
     gcc $(SHARED_OPT) $(GENERAL_CFLAGS) $(PLATFORM_CFLAGS) -o $(BUILD_DIR)$(BUILD_NAME) $(SOURCE) $(LIBRARIES)

Linux_all: Darwin_all
     gcc $(SHARED_OPT) $(GENERAL_CFLAGS) $(PLATFORM_CFLAGS64) -o $(BUILD_DIR)$(BUILD_NAME64) $(SOURCE) $(LIBRARIES64)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T04:02:17+00:00Added an answer on May 14, 2026 at 4:02 am

    You make macros do most of the work, noting that you should use $(CC) rather than gcc.

    BUILD_COMMAND = $(CC) $(SHARED_OPT) $(GENERAL_CFLAGS) $(PLATFORM_CFLAGS)
    BUILD_NAME32  = $(BUILD_NAME)
    TARGET_32     = $(BUILD_DIR)$(BUILD_NAME32)
    TARGET_64     = $(BUILD_DIR)$(BUILD_NAME64)
    LIBS_32       = $(LIBRARIES)
    LIBS_64       = $(LIBRARIES64)
    OPTS_32       = -m32
    OPTS_64       = -m64
    
    # We could do some fancy stuff here...
    # Except that we will remove the commands momentarily
    all:
        echo PLEASE SELECT OS, e.g. make linux
        exit 1
    
    # Note that without a qualifier
    # - MacOS X 10.5.x will build 32-bit
    # - MacOS X 10.6.x will build 64-bit
    # But why not build both anyway?
    mac:
        $(BUILD_COMMAND) -o $(TARGET_64) $(SOURCE) $(LIBS_64) $(OPTS_64)
        $(BUILD_COMMAND) -o $(TARGET_32) $(SOURCE) $(LIBS_32) $(OPTS_32)
    
    linux:
        $(BUILD_COMMAND) -o $(TARGET_64) $(SOURCE) $(LIBS_64) $(OPTS_64)
        $(BUILD_COMMAND) -o $(TARGET_32) $(SOURCE) $(LIBS_32) $(OPTS_32)
    

    Oh, and look, the commands are the same for Linux and MacOS X now…so we can do:

    BUILD_COMMAND = $(CC) $(SHARED_OPT) $(GENERAL_CFLAGS) $(PLATFORM_CFLAGS)
    BUILD_NAME32  = $(BUILD_NAME)
    TARGET_32     = $(BUILD_DIR)$(BUILD_NAME32)
    TARGET_64     = $(BUILD_DIR)$(BUILD_NAME64)
    LIBS_32       = $(LIBRARIES)
    LIBS_64       = $(LIBRARIES64)
    OPTS_32       = -m32
    OPTS_64       = -m64
    
    all:
        $(BUILD_COMMAND) -o $(TARGET_64) $(SOURCE) $(LIBS_64) $(OPTS_64)
        $(BUILD_COMMAND) -o $(TARGET_32) $(SOURCE) $(LIBS_32) $(OPTS_32)
    

    Gosh, it is hard work writing $(XXX) instead of ${XXX} as I normally do in my makefiles.

    Basically, we apply DRY (Don’t Repeat Yourself) by making names boringly systematic. Makefiles should not be exciting.

    If you still want to have a difference between your platforms, then you can do something along the lines suggested by Ivan Andrus. GNU Make allows you to evaluate shell commands, so:

    BUILD_COMMAND = $(CC) $(SHARED_OPT) $(GENERAL_CFLAGS) $(PLATFORM_CFLAGS)
    BUILD_NAME32  = $(BUILD_NAME)
    TARGET_32     = $(BUILD_DIR)$(BUILD_NAME32)
    TARGET_64     = $(BUILD_DIR)$(BUILD_NAME64)
    LIBS_32       = $(LIBRARIES)
    LIBS_64       = $(LIBRARIES64)
    OPTS_32       = -m32
    OPTS_64       = -m64
    
    all:  $(shell uname)
    
    Linux:
        $(BUILD_COMMAND) -o $(TARGET_64) $(SOURCE) $(LIBS_64) $(OPTS_64)
        $(BUILD_COMMAND) -o $(TARGET_32) $(SOURCE) $(LIBS_32) $(OPTS_32)
    
    Darwin:
        $(BUILD_COMMAND) -o $(TARGET_32) $(SOURCE) $(LIBS_32)
    

    If you feel you can’t rely on GNU Make, then:

    BUILD_COMMAND = $(CC) $(SHARED_OPT) $(GENERAL_CFLAGS) $(PLATFORM_CFLAGS)
    BUILD_NAME32  = $(BUILD_NAME)
    TARGET_32     = $(BUILD_DIR)$(BUILD_NAME32)
    TARGET_64     = $(BUILD_DIR)$(BUILD_NAME64)
    LIBS_32       = $(LIBRARIES)
    LIBS_64       = $(LIBRARIES64)
    OPTS_32       = -m32
    OPTS_64       = -m64
    BUILD_32      = use_32_bit
    BUILD_64      = use_64_bit
    BUILD_TYPE    = $(BUILD_32) $(BUILD_64)
    
    .PHONEY: $(BUILD_32) $(BUILD_64)
    
    all:  $(BUILD_TYPE)
    
    use_64_bit:
        $(BUILD_COMMAND) -o $(TARGET_64) $(SOURCE) $(LIBS_64) $(OPTS_64)
    
    use_32_bit:
        $(BUILD_COMMAND) -o $(TARGET_32) $(SOURCE) $(LIBS_32) $(OPTS_32)
    

    By default this will compile both 32-bit and 64-bit versions.
    If you want 32-bit only or 64-bit only, run the appropriate one of these two:

    make BUILD_TYPE=use_32_bit
    make BUILD_TYPE=use_64_bit
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 369k
  • Answers 369k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It will use the identity setup on the AppPool May 14, 2026 at 6:23 pm
  • Editorial Team
    Editorial Team added an answer Like this: <form name="feedback" method="post" onsubmit="return checkform()" action="engine.php?ad=<?php echo htmlentities($_GET['page']);… May 14, 2026 at 6:23 pm
  • Editorial Team
    Editorial Team added an answer You can get rid of string literals using expressions public… May 14, 2026 at 6:23 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.