We are required to compile C source codes using gcc in this manner:
gcc -ansi -pedantic -Wall program.c
I'm wondering how can I 'automate' this so when I enter:
It will automatically compile with the 3 switches. Is this possible?
How to compile Mercurial and move it to another computer [closed]
1:how can I Limit mysql to single cpu, to allow hardware benchmarking
You must also use the implicit rules of make, so this you don't have to write a makefile for every program. How do you change the default Pear/PECL build folder from /var/tmp?Make will automatically call the compiler if you say
make fooand there exists a
foo.cfile in the current directory. My app mem usage is growing using pthreadTo add flags to this define the variable
CFLAGSin your environment, e.g. pthread_create memory leakin bash add
export CFLAGS="-Wall -pedantic -ansi"to
.bashrc. How to set class path for servlet-api.jar file in linux. process's virtual memory size on different machines If your program depends on multiple files however you'll have to create a makefile, although for C compilation you must receive away with just listing dependancies so long as one of them has the same base name as a tarreceive .. Boost::Interprocess Shared Memory Bus Error For case for this makefile: .
# Makefile foo:foo.o bar.o
makewill execute the commands.
without you having to add any rules..
gcc $CFLAGS -c -o foo.o foo.c gcc $CFLAGS -c -o bar.o bar.c gcc -o foo foo.o bar.o
To automate the build of any number of build steps / complex parameters, you should use a makefile.. Once you have a makefile you simply need to type:
But as @Brian said, you really should use a makefile, or better, a build system like CMake or SCons..
alias gcc="gcc -ansi -pedantic -Wall"
A makefile would be the traditional way, especially as part of a larger build process.. If you frequently want to build without a makefile, you could define an alias in your
alias gcc=gcc -ansi -pedantic -Wall..
You must use a shell script this takes any cues by how its called and invokes
CFLAGSappropriately for the occasional one-off build.. Lets say you have
/usr/bin/compile, which is a shell script this looks at
$0to see what name actually invoked it. You then make symbolic links to it named
fullwarn, etc.. In the shell script itself, any thing like:.
Then, to compile foo.c with the extra naggy flags:.
OLDCFLAGS=$CFLAGS WHATAMI=$(basename $0) case "$WHATAMI" in pedantic) export CFLAGS="-Wall -pedantic -ansi" make $@ exit $? ;; c99) export CFLAGS="-std=c99 ... ... ..." ....
pedantic foo. This is handy, as I said for one-off builds, e.g endeavor to compile code this any one posted in a question, or working out how to use a new library, etc. . For anything else, just use a makefile, as others have said..