Basic Compiling

I have created a shell script to run and compile my c++ programmes.

I'm pondering, if there are any reason to why this may be discouraged, or a bad idea?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/bin/bash

echo "Preparing compile directories, this may take a moment..."
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")"&& pwd)/"

if [ -e "${DIR}app/" ]; then
	rm -r ${DIR}app/
fi

cp -r ${DIR}src/ ${DIR}app/

for C_FILE in `find ${DIR}app/ -name "*.c"`; do
	echo "Compiling: ${C_FILE}."
	C_FILENAME=`echo ${C_FILE} | sed s/\.c$//g`
	g++ ${C_FILE} -Wall -o ${C_FILENAME}
	rm ${C_FILE}
done
Well, it's good for learning how to do this kind of work yourself.
But the linux make tools are specially designed for this job. Or you haven't heard of it before?
http://www.linuxmanpages.com/man1/make.1.php
Knowing what's being compiled and linked is an excellent idea and will serve you well. As shadow indicates, what you've done is begin to implement your own make system - nothing wrong with that, but make is ubiquitous and established and using it will still require you to know what you're compiling and what you're linking, so consider writing your own makefiles instead.
Thanks for your advice, I didn't realise that's what a make file did, although I was under the impression make files were more for linux libraries and such to ensure installing something, the intended system/OS contains the relevant files/libraries and versions.

Either way, I think I need to look in to this a little more, I've considered buying a book too.

Thanks for your help.
Topic archived. No new replies allowed.