problem while replacing a directory with the variable
I want to replace a directory path(/home/cmac) insine root/c4/build/makeit where makeit it a file written in vim editor and in that script I have mentioned the path which needs to be replaced, with a variable name. I want to make the script in the root so that anywhere this /home/cmac/ is used gets replaced with the variable since /home/cmac/ is common in each path. Can you please help me out?
2 Months Ago
Related Article:Help Please with Vista 32 Music Problem
is a Hardware and Software discussion thread by pcmic that has 5 replies, was last updated 10 months ago and has been tagged with the keywords: help, please, with, vista, 32, music, problem.
Although personally; rather than using an absolute path (like /home/cmac/), I'd use a relative path (e.g. ../cmac/). Obviously your path would depend on the location of your makefile, relative to your source files.
As a quick practical example:
Say I have a main project directory (called myProject) containing two other directories (src and build).
The src directory contains several c++ files:
foo.h, foo.cpp, bar.h, bar.cpp and main.cpp
The build directory will contain the makefile and is where I want the .o files and the final binary to be placed.
So, the makefile is in /home/jason/projects/myProject/build/ and all of the source files are all in /home/jason/projects/myProject/src/
Instead of using the really long absolute paths above, I can use a relative path instead. So to get to the source files from the build directory, the relative path is ../src/. So I can use the relative path (../src/) in my makefile instead!
That's a pretty extreme example there. Several repetetive bits of code have been put into variables in the above makefile. MYFILEPATH is the variable storing the path to the source files. CC holds the name of the compiler (g++), CFLAGS stores the compiler flags we want to use when compiling, OBJECTS is the list of objects we depend upon in order to build the main executable.
So to declare a variable, you just give it a name and assign it a value. I usually name my variables in all upper-case characters, so I can easily identify them in my build scripts.
NAME = value
MYPATH = ../src/
and then to use the variable elsewhere in the makefile you enclose the variable name with $()