Makefile conditional compilation giving error


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Makefile conditional compilation giving error
# 1  
Old 02-27-2009
Makefile conditional compilation giving error

Hi ,
Please answer my query:
I want to create a common make file for one of mylibrary such that it should work on both Sun as well as Linux on 32 and 64 bit system.
The flow is sth like this:

..............
..............
if$(OS) == solaris
BINDIR= ../../lib/solaris/64
else
BINDIR= ../../lib/solaris/32
endif
.................
.................

But the above line throwing an error in line 3 as "Makefile, line 18: Unexpected end of line seen"
I tried hard but to no avail.
Please guide me where i am incorrect.
Moreover i will extend this conditional compilation to sth like this:
if$(OS) == solaris and machine== 64
BINDIR= ../../lib/solaris/64
elseif $(OS) == solaris and machine== 32
BINDIR= ../../lib/solaris/32
if$(OS) == linux and machine== 64
BINDIR= ../../lib/linux/64
elseif $(OS) == linux and machine== 32
BINDIR= ../../lib/linux/32
endif

Waiting for someone reply !!

/regards,
Suraj
# 2  
Old 02-28-2009
Hi.

GNU make can handle Makefiles like:
Code:
# Sat Feb 28 17:09:10 CST 2009

main: sub
        @echo " BINDIR is $(BINDIR)"

sub:
ifndef OS
        @echo " Error, OS not defined."
        @exit 1
endif

ifeq "$(OS)" "solaris"
BINDIR := ../../lib/solaris/64
else
BINDIR := ../../lib/solaris/32
endif

# if$(OS) == solaris
# BINDIR= ../../lib/solaris/64
# else
# BINDIR= ../../lib/solaris/32
# endif

When make is used as in this script:
Code:
#!/usr/bin/env bash

# @(#) s1       Demonstrate GNU make test features.

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
echo " OS not defined:"
make

echo
echo " OS set to solaris:"
make OS=solaris

echo
echo " OS set to linux:"
make OS=linux

exit 0

produces:
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

 OS not defined:
 Error, OS not defined.
make: *** [sub] Error 1

 OS set to solaris:
 BINDIR is ../../lib/solaris/64

 OS set to linux:
 BINDIR is ../../lib/solaris/32

I tried this on Solaris 10, without much hope, and I got the same error message you did.

In order to process this kind of Makefile on Solaris, you would need GNU make.

The topic of make and makefiles is complex, so perhaps the guidance below will be of some value.

Best wishes ... cheers, drl
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: Google "linux tutorial make makefile"
Comments: Conflicting opinions amazon.com; 3.5 stars, 12 reviews, 2009.02.
Comments: see also cons, scons
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Compilation Error

I am getting the below given errors for the following program though all the variables have been declared and used appropriately. Please Help. The environment is AIX. Error: ------ "gbsizeprofile.c", line 67.4: 1506-275 (S) Unexpected text 'void' encountered. "gbsizeprofile.c", line 67.10:... (2 Replies)
Discussion started by: yschd
2 Replies

2. Programming

Conditional Compilation based on Environmental Variable in Unix

I want to be able to access an environment variable to control how a program is compiled. So: export MY_VERSN=9 Then ideally, within my C++ code, I would have #if MY_VERSN = 9 iret = FRED9() #else iret = FRED() #endif The way I thought I could do it is that in the script that... (2 Replies)
Discussion started by: BrighterLater
2 Replies

3. Programming

Compilation error : Please help

state_field state_abvr = { "AL","ALABAMA", "AK","ALASKA", "AZ","ARIZONA", "AR","ARKANSAS", "CA","CALIFORNIA", "CO","COLORADO", "CT","CONNECTICUT", "DE","DELAWARE", "DC","DISTRICT-OF-COLUMBIA", "FL","FLORIDA", "GA","GEORGIA", "HI","HAWAII", "ID","IDAHO", "IL","ILLINOIS",... (1 Reply)
Discussion started by: jagan_kalluri
1 Replies

4. UNIX for Dummies Questions & Answers

Warning message while makefile compilation

Hi all, I am trying to create an executable, but when the .pc file converting to .c file I am getting lots of warning message like of these 3 lines. Any idea why I am getting these lines? Any configuration issues? What exactly needs to be done to solve these warning messages? ... (0 Replies)
Discussion started by: nsurendiran
0 Replies

5. UNIX for Dummies Questions & Answers

Issue with makefile compilation

All, I am facing problem with one makefile compilation. The following is the error I am getting, Before proceeding to this I want to let you know all, only last week onwards I started working in solaris10, the same code is working in solaris 9. I dont know any link has to be created, or any path... (3 Replies)
Discussion started by: nsurendiran
3 Replies

6. Programming

Issue with Makefile compilation

All, I am facing problem with one makefile compilation. The following is the error I am getting <Code> /applns/ora10/rdbms/bin/proc sqlcheck=semantics userid=/ CHAR_MAP=VARCHAR2 DBMS=V7 DEFINE=UNIX DEFINE=SUN_SRC_COMPAT iname=mm5900.pc sh: /applns/ora10/rdbms/bin/proc: not found *** Error... (1 Reply)
Discussion started by: nsurendiran
1 Replies

7. Programming

Compilation error

I am compiling a software xchm on solaris 10. First i run './configure' There is no error. But when i start compiling using 'gmake' following error shown /usr/local/include/wx-2.6/wx/x11/brush.h: In copy constructor `wxBrush::wxBrush(const wxBrush&)':... (3 Replies)
Discussion started by: mansoorulhaq
3 Replies

8. Programming

question on conditional compilation

Hey, can I #define something outside the source file ? I have a C program which uses #ifdef.. #ifdef ABC ... do this.. #else ... that ... #endif The usual way that I know of defining ABC is in the source/header file #define ABC But is there any other way to do that ? Maybe as... (2 Replies)
Discussion started by: the_learner
2 Replies

9. Programming

Makefile compilation Error -Unable to create executable

Hi , While trying to compile a PRO*C code on unix using makefile i get the following errors. i am now working on a 10g migration (from 8i) ... these makefile perfectly work in previous version. ld: fatal: file... (7 Replies)
Discussion started by: sivalives
7 Replies

10. Programming

compilation error

Hi, While trying compile a C++ file in UNIX with gcc whose make rule involves the usage of /usr/ccs/bin/as, I get the following error: /usr/ccs/bin/as: No such file or directory /usr/ccs/bin/as: error: write error on output file "<filename>.o" *** Error code 1 clearmake: Error: Build... (2 Replies)
Discussion started by: smanu
2 Replies
Login or Register to Ask a Question