[Solved] makefile conditions


 
Thread Tools Search this Thread
Top Forums Programming [Solved] makefile conditions
# 1  
Old 12-01-2010
[Solved] makefile conditions

Hi Everyone,

I'm trying to write a makefile that has two options. 1. A make all that shall believe it or not make everything :P and 2. a make without option.

I need to setup a few arrays differently, depending on the option choosen i.e. all or without.

My first try consisted of me creating a file "without"

e.g.

without:
touch without
make

then testing for that file using wildcard. I could not get this to work and it didnt even look like it was falling into the else condition.

So, attempt number two. I was thinking of creating a function similar to that of a shell script but from what i have read, this is not possible and i saw reference to something like this:-

without = \
@echo -e "Making Airsurf [Without PIF]"
VPATH = $(APP_C):$(IMS_C):$(COM_C)
CCP = g++ -Wall -O2 -DMENU -DCPU=I80386 -Wno-deprecated -Wno-write-strings -Wno-non-virtual-dtor -DUSEMYSQL -DUSESDL

then inside the actual rule:-

without:
$(call, without)

This also did not work, and variables never seemed to get set, or i would end up in an infinite loop.


Can anyone explain where i maybe going wrong or throw some ideas of what else may work my way? In theory this is a simple problem

if running make 1: set these variables else set variables to this instead.

Hope this post makes some sense Smilie

Thanks In Advance Smilie
# 2  
Old 12-01-2010
The first rule a makefile encounters is the default rule. So have the first rule require everything, or require things which require everything.

I usually set up like this:
Code:
TARGETS=a bc def

all:$(TARGETS)

a:a.o

bc:b.o c.o

def:d.o e.o f.o

The all:$(TARGETS) rule forces it to build a bc def, which require all the fiddly little .o files, making it build everything.

A makefile which builds nothing by default would just have a do-nothing rule at the top I think:
Code:
TARGETS=a bc def

nothing:

all:$(TARGETS)

a:a.o

bc:b.o c.o

def:d.o e.o f.o

And you can choose the default rule at runtime, by the way! Anything the makefile's capable of making can be used. You could do anything from 'make nothing' to 'make all' to 'make c.o'. Don't think there's much need to make different makefiles for the purpose, just call make in different ways.
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 12-03-2010
Helped me out alot Smilie

thanks,

Rob.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

GNU & BSD Makefile Directives & Conditions Compatibility

Firstly, I would like to apologize if this is not the appropriate sub-forum to post about GNU/BSD makefile scripting. Though my code is in C++, because I am focusing on the makefile I thought it would go better in shell scripting. Please correct me if I am wrong. Secondly, I am not interested in... (0 Replies)
Discussion started by: AntumDeluge
0 Replies

2. Shell Programming and Scripting

Conditions in if

I'm using the below one.. #!/bin/ksh File=$3 if ; then echo "Script" elif ] ;then echo "Passed k or f option" else "Please check the Input passed" fi Command line argument is "k" or -f and file is exist then... (3 Replies)
Discussion started by: Roozo
3 Replies

3. Shell Programming and Scripting

[Solved] Command execution in Makefile

Linux Gurus, I have a query regarding the execution of a complex command in the makefile of the current system. I am currently using shell command in the makefile to execute the command. However my command fails as it is a combination of a many commands and execution collects a huge data...... (4 Replies)
Discussion started by: satishkumar432
4 Replies

4. Shell Programming and Scripting

Errors in if conditions with to many OR conditions

Hi ALL I have a script where in i need to check for several values in if conditons but when i execute the script it throws error such as "TOO MANY ARGUMENTS" if then msg="BM VAR Issue :: bmaRequestVAR=$bmaRequestVAR , nltBMVAR=$nltBMVAR , bmaResponseVAR=$bmaResponseVAR ,... (10 Replies)
Discussion started by: nikhil jain
10 Replies

5. Shell Programming and Scripting

If conditions need

Dear Expert, Below code is for to take the backup of database by daily time stamp. I need vital help to make my script automatic sending me email if it sucess or fail. echo on @REM Seamonkey's quick date batch (MMDDYYYY format) @REM Setups %date variable @REM First parses month, day, and... (6 Replies)
Discussion started by: Alone
6 Replies

6. 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

7. Shell Programming and Scripting

IF OR with two conditions

I have this IF working fine, testing if a char is a digit: if ; then _VALUE=$_VALUE$_CHAR else _ISDIGIT="false" fi Then I add a second condition to test if the char is either a digit or a * if ]; then _VALUE=$_VALUE$_CHAR ... (11 Replies)
Discussion started by: Flavius
11 Replies

8. Shell Programming and Scripting

[solved] merging two files and writing to another file- solved

i have two files as file1: 1 2 3 file2: a b c and the output should be: file3: 1~a 2~b 3~c (1 Reply)
Discussion started by: mlpathir
1 Replies

9. 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

10. 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
Login or Register to Ask a Question