makefile substitution help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting makefile substitution help
# 1  
Old 03-18-2008
makefile substitution help

This is driving me crazy. I'm trying to automate some things in my makefile and I'm running into a substitution issue.

I'm trying to automatically create object directories if they don't already exist based on the listed source files found in the $(SRCARM) variable.

SRCARM = dir1/file1.c \
dir2/file2.c \
dir3/file3.c \
main.c

COBJARM = $(SRCARM:%.c=$(OBJDIR)/%.o)

which results in:
COBJARM = output/dir1/file1.o \
output/dir2/file2.o \
output/dir3/file3.o \
output/main.o

These two work, giving me the source and object lists. Now to get all objects' directories so I can create them if they don't already exist.
I'd like to create the following:
COBJARMDIR = output/dir1 \
output/dir2 \
output/dir3 \
output

So I try this:
COBJARMDIRS = $(COBJARM:%/=%)

Which doesn't work. I don't know if I was expecting it to match the first or last /. I just expected it to do something. I tried escaping the slash as well. All I get is the same list of object files. It appears you have to match the entire end of the string to get the substitution to work.

For example:
COBJARMDIRS = $(COBJARM:%ain.o=%)
results in:
COBJARMDIRS = output/dir1/file1.o \
output/dir2/file2.o \
output/dir3/file3.o \
output/m.x

but this:
COBJARMDIRS = $(COBJARM:%main=%)
doesn't replace anything:
COBJARMDIRS = output/dir1/file1.o \
output/dir2/file2.o \
output/dir3/file3.o \
output/main.o

Sorry for the long winded post. I've just been working on this for 2 hours and I'm getting frustrated.

Does anyone know how to do this? Is this even possible?
Login or Register to Ask a Question

Previous Thread | Next Thread

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. UNIX for Dummies Questions & Answers

MakeFile

Hey everybody, This may be stup*d question for you, but i am new in unix and i wonder how can i make the rules for translating and linking my .c "primjer1.c", "primjer2.c" and "primjer3.c" in makefile. Thank you. (7 Replies)
Discussion started by: jskako
7 Replies

3. Homework & Coursework Questions

Makefile Help

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: I have been trying to make the program swap but i have been getting errors with the makefile such as driver.o:... (1 Reply)
Discussion started by: mgyeah
1 Replies

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

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

6. Programming

Makefile: multiple target variable substitution

Greetings! Basically, I would like to properly handle this with gnu make: alltools: my_tool mysecond_tool mythird_tool etc_tool %_tool: dir1/%_tool.vf dir2/%_tool/subdir2/%_tool.ver <tab>@echo done %.vf: <tab>RUN_VF $* %.ver: <tab>RUN_VER $* So, if I were to do something like:... (0 Replies)
Discussion started by: Harlinator
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

Difference between "Command substitution" and "Process substitution"

Hi, What is the actual difference between these two? Why the following code works for process substitution and fails for command substitution? while IFS= read -r line; do echo $line; done < <(cat file)executes successfully and display the contents of the file But, while IFS='\n' read -r... (3 Replies)
Discussion started by: royalibrahim
3 Replies

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

10. UNIX for Advanced & Expert Users

makefile

Can anyone tell me what does ?= do example VARIABLE ?= /somepath This is being used in makefile (1 Reply)
Discussion started by: raagbansal
1 Replies
Login or Register to Ask a Question