Makefile - If Statement?


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Makefile - If Statement?
# 1  
Makefile - If Statement?

Hey,

I'm creating a Makefile, and in one of my targets, i need an IF statement to determine if two things are equal... but, I can't get it to run. Any ideas what is wrong?

Here's a snippet of the test from makefile:

Code:
test-if
        ifeq("a", "a")
          python somefile.py
        else
          python anotherfile.py
        endif

# 2  
Hi.

It helps if you say more than: I can't get it to run, versions, etc.

So, for this script:
Code:
#!/usr/bin/env bash

# @(#) s1       Demonstrate ifeq in make, with, without parens.

echo
set +o nounset
LC_ALL=C ; LANG=C ; export LC_ALL LANG
echo "Environment: LC_ALL = $LC_ALL, LANG = $LANG"
echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version "=o" $(_eat $0 $1) make
set -o nounset
echo

FILE=${1-Makefile}

echo " Data file $FILE:"
cat $FILE

echo
echo " Results:"
make

exit 0

We get:
Code:
% ./s1

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.11-x1, i686
Distribution        : Xandros Desktop 3.0.3 Business
GNU bash 2.05b.0
GNU Make 3.80

 Data file Makefile:
# Sat Jan 24 11:25:44 CST 2009

file:
        @echo
        @echo " No parens, whitespace ignored."
  ifeq    "a"    "a"
        @echo " Strings are equal."
  else
        @echo " Strings differ."
  endif
        @echo
        @echo " With parens -- tricky comparison of whitespace."
  ifeq ( "a", "a" )
        @echo " Strings are equal."
  else
        @echo " Strings differ."
  endif

 Results:

 No parens, whitespace ignored.
 Strings are equal.

 With parens -- tricky comparison of whitespace.
 Strings differ.

You can google for examples or read GNU Make Manual - GNU Project - Free Software Foundation (FSF) or try:
Quote:
Title: Managing Projects with GNU Make
Author: R Mecklenburg
Edition: 3rd
Date: 2004
Publisher: O'Reilly
ISBN: 0-596-00610-1
Pages: 280
Categories: *nix, development, compiling, building, programming, tools
Comments: Visit O'Reilly Media | Spreading the knowledge of technology innovators to get the
Comments: corrections for a large number of errors.
Comments: GNU manual: GNU `make'
Comments: 43 page tutorial: http://www.cs.utah.edu/classes/cs563...mentsOfMake.ps
Comments: Conflicting opinions amazon.com; 4 stars, 8 reviews, 2007.05.
Comments: see also cons, scons
cheers, drl
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #482
Difficulty: Medium
in 2018, developers and programmers rarely used an Integrated Development Environment (IDE) that provided a text editor with code highlighting.
True or False?

10 More Discussions You Might Find Interesting

1. Programming

Makefile for g++

Hi All, We have moved our OS from Sun Solaris to Linux and also some of the compilers. Our old makefile used to be as below: CC=cc FLAGS=-G -KPIC -DLG_SOLARIS_OS DEFINES=-DSunOS SYSLIBS=-lc .SUFFIXES : .c .c.o : ;$(CC) -c $(FLAGS) $(DEFINES) $*.c -o $*.o ... (3 Replies)
Discussion started by: shash
3 Replies

2. Shell Programming and Scripting

Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks, I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex. I have a bunch of update statements with all columns in a file which I need to convert into insert statements. UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Discussion started by: dev123
0 Replies

3. Homework & Coursework Questions

Help with Simple Multi-Level Makefile (Extremely New at Makefile)

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Basically, the prompt is make a makefile with various sub makefiles in their respective subdirectories. All code... (1 Reply)
Discussion started by: Tatl
1 Replies

4. UNIX for Advanced & Expert Users

Makefile executing another Makefile first?

I have 2 libraries in 2 different directories that I build with Makefiles. library B depends on library A. If I modify a .cpp file in library A and run lib B's Makefile can I have B's makefile to automatically rebuild library A? I am now rebuilding A, followed by B... but I'd like B to... (0 Replies)
Discussion started by: wwuster
0 Replies

5. Programming

[Makefile] nothing to be done for 'all'

hello, I have a firts makefile who call others makefile. for this i use: $ make -f linux.mak and output his: $ make -f linux.mak all make -C DerelictAL all PLATFORM=linux make: Entering directory `/home/builder/rpmbuild/SOURCES/derelict2-20100407/DerelictAL' make: Nothing to be done for... (2 Replies)
Discussion started by: bioinfornatics
2 Replies

6. Shell Programming and Scripting

makefile

Hi, I have problem related to makefile in c in linux(ubuntu). What is the meaning of @prefix@ what this two @ symbols mean here? Thanks, Vivek (0 Replies)
Discussion started by: vivek146
0 Replies

7. UNIX for Advanced & Expert Users

Makefile problem - How to run module load in a Makefile

Hi, I'm trying to run the module load command in a Makefile and i'm getting the following error: make: module: command not found Why is this? Is there any way to run this command in a Makefile? NOTE: command - module load msjava/sunjdk/1.5.0 works fine outside of the Makefile (2 Replies)
Discussion started by: hernandinho
2 Replies

8. Shell Programming and Scripting

How is use sselect statement o/p in insert statement.

Hi All, I am using Unix ksh script. I need to insert values to a table using the o/p from a slelect statement. Can anybody Help! My script looks like tihs. ---`sqlplus -s username/password@SID << EOF set heading off set feedback off set pages 0 insert into ${TB_NAME}_D... (2 Replies)
Discussion started by: nkosaraju
2 Replies

9. Shell Programming and Scripting

If statement - How to write a null statement

In my ksh script, if the conditions of a if statement are true, then do nothing; otherwise, execute some commands. How do I write the "do nothing" statement in the following example? Example: if (( "$x"="1" && "$y"="a" && "$z"="happy" )) then do nothing else command command fi... (3 Replies)
Discussion started by: april
3 Replies

10. UNIX for Dummies Questions & Answers

makefile

I'm new to the admin world, and I'm trying to install the GNU C Compiler to work on my project. I got the source code, and was able to configure it. Most of the info I've read tells me the next step is to run a command called "make". when I run it, I get a "command not found" message. I've... (4 Replies)
Discussion started by: ECBROWN
4 Replies

Featured Tech Videos