Perl Script to Generate Makefile

Download here. createmakefile.pdf
#!/usr/bin/perl
# File name: writemake.pl
# Author: A.G.Raja
# Website: agraja.wordpress.com
# License: GPL
use strict; use warnings; open(FH,">Makefile") or die "Cannot create Makefile"; print FH ("all: buildnn"); print FH ("build: " . $ARGV[0] .".onn"); print FH ("shared: " . $ARGV[0] . ".sonn"); print FH ("clean: n"); print FH ("trm ".$ARGV[0].".*o nn"); print FH ($ARGV[0].".o: ".$ARGV[0].".cn"); print FH ("tgcc -o ".$ARGV[0].".o ".$ARGV[0].".cnn"); print FH ($ARGV[0].".so: ".$ARGV[0].".cn"); print FH ("tgcc -fPIC -shared -o ".$ARGV[0].".so ".$ARGV[0].".cn"); close FH;
# Usage:
# chmod +x writemake.pl
# writenake.pl hello
Below is the Makefile generated:
all: build build: hello.o shared: hello.so clean: rm hello.*o hello.o: hello.c gcc -o hello.o hello.c hello.so: hello.c gcc -fPIC -shared -o hello.so hello.c
Download here. createmakefile.pdf
Advertisements

GCC Include Files Path

GCC looks in several different places for headers.

On a normal Unix system, if you do not instruct it otherwise, it will look for headers requested with #include <file> in:

/usr/local/include
libdir/gcc/target/version/include
/usr/target/include
/usr/include
You can add to this list with the -Idir command line option.

Below is a small demo

///////////     defines.c   ////////
#include <stdio.h>
#include <defines.h>
int main()
begin
    printf("hellon");
    return 0;
end

This requires the folowing header file

///////     headers/defines.h   ///////////
#define begin {
#define end }
//////  save this file in directory named headers

Compile defines.c as below

[raja@AGRAJA ~] gcc defines.c -Iheaders