Wednesday, March 13, 2013

Makefile in Linux

                         -----------------------MAKEFILE-----------------------------

A Makefile basically consists of :

1) Definitions of variables and functions,
   example: myshell=bash
2) Commensts:
   e.g. # converting postscript to pdf or what ever
3) Includes:
   e.g.- include Makefile.local
4) Rules:
   e.g. - %.pdf: %.ps; -@ps2pdf $<

-------------------------

**)Mind the tab key (<tab>) prefacing the commands past the fist line.

**)Use a semicolon to stuff muiltiple commands into one single lin, or a backslash to join split lines. (Refer Makefile1)

NOTE::
I. The at-sign (@) in front of the commnad prevents make from announcing the commands it's going to do.
II. If you don't tell make a target, it will simply do the first rule.
III. If you tell make multiple targets, it will do them all in order.

------------------------------------------------------------------
We can Combine multiple makefiles:

command in makefile(-include m/Makefile-l)

When make encounters an include-command, it will stop processing the current Makefile, read the included Makefile and then continue where it left off.

-----------------------------------------------------------
If we define a target socks twice it will give the warning mesage
Example:
socks: ; @echo get into left sock
socks: ; @echo get inot right sock
***While make it will give the warning messages z`       
***For remove the warning message we have to duplicate the colon:

socks:: ; @echo get into left sock
socks:: ; @echo get inot right sock
*** Now When we make this it will not give the error
Imp Note:

CXXSOURCES = basic_sample.cpp       # list of source files
CXXOBJECTS = $(CXXSOURCES:.cpp=.o)  # expands to list of object files


-----------------------------------Built-in fuctions------------------------------
1) $(subst from,to,text)     Replace from with to in text.
2) $(patsubst pattern,replacement,text)  Replace words matching pattern with replacement in text.
3) $(strip string) Remove excess whitespace characters from string.
4) $(findstring find,text)     Locate find in text.
5) $(filter pattern...,text)     Select words in text that match one of the pattern words.
6) $(filter-out pattern...,text)     Select words in text that do not match any of the pattern words.
7) $(sort list)     Sort the words in list lexicographically, removing duplicates.
8) $(dir names...)     Extract the directory part of each file name.
9) $(notdir names...)     Extract the non-directory part of each file name.
10) $(suffix names...)     Extract the suffix (the last dot and following characters) of each file name.
11) $(basename names...)     Extract the base name (name without suffix) of each file name.
12) $(addsuffix suffix,names...)     Append suffix to each word in names.
13) $(addprefix prefix,names...)     Prepend prefix to each word in names.
14) $(join list1,list2)     Join two parallel lists of words.
15) $(word n,text)     Extract the nth word (one-origin) of text.
16) $(words text)     Count the number of words in text.
17) $(wordlist s,e,text)     Returns the list of words in text from s to e.
18) $(firstword names...)     Extract the first word of names.
19) $(wildcard pattern...)     Find file names matching a shell file name pattern (not a `%' pattern).
20) $(error text...)     When this function is evaluated, make generates a fatal error with the message text.
21) $(warning text...)     When this function is evaluated, make generates a warning with the message text.
22) $(shell command)     Execute a shell command and return its output.
23) $(origin variable)     Return a string describing how the make variable variable was defined.
24) $(foreach var,words,text)     Evaluate text with var bound to each word in words, and concatenate the results.
25) $(call var,param,...)     Evaluate the variable var replacing any references to $(1),$(2) with the first, second, etc. param values.


-----------------------------------Automatic Variable----------------------------------

$@     The name of the target.
$%     The target member name, when the target is an archive member.
$<     The name of the first (or only) prerequisite.
$?     The names of all the prerequisites that are newer than the target, with spaces between them.

$^ $+   The names of all the prerequisites, with spaces between them. The value of $^ omits duplicate prerequisites, while $+ retains them and preserves their order.
$*     The stem with which an implicit rule matches.
$(@D)
$(@F)     The directory part and the file-within-directory part of $@

$(*D)
$(*F)     The directory part and the file-within-directory part of $*

$(%D)
$(%F)     The directory part and the file-within-directory part of $%

$(<D)
$(<F)     The directory part and the file-within-directory part of $<

$(^D)
$(^F)     The directory part and the file-within-directory part of $^

$(+D)
$(+F)     The directory part and the file-within-directory part of $+

$(?D)
$(?F)     The directory part and the file-within-directory part of $?















Monday, February 11, 2013

Malloc, calloc, and Realloc

                              Calloc, malloc, free, realloc
                               -------------------------------------------
void *calloc(size_t nmemb, size_t size);
Calloc allocates memory for an array of nmemb elements of size bytes each and returns a pointer to the allocated memory. The memory is set to zero. if nmemb or size is 0, then calloc() returns either NULL, or a unique pointer value that can later be successfully passed to free().
** the memory is initialized to zeros.

void *malloc(size_t size);
allocates size bytes and returns a pointer to the allocated memory (BLOCK). The memory is neot cleared. If size is 0, then malloc() returns either NULL or a unique pointer value that can later be successfully passed to free().
** The memory is uninitialized.

Ex1:
int *ptr;
ptr=(int*) malloc(sizeof(int));

Ex2.
struct employee *ptr;
ptr=(struct employee *ptr)malloc (sizeof(struct employee));

void free( void *ptr);
free() frees the memory space pointed to by ptr, which must have been returned by a prevoious call to malloc(), caloc() or realloc(). otherwise, or if free(ptr) has already been called before, undefined behaviour occurs. If ptr is NULL, no operation is performed.

void *realloc ( void *ptr, size_t size)
realloc() changes the size of the memory block pointed to by ptr to size bytes. The contents will be unchanged to the minimum of the old and new sizes; newly alllocated memory will be uninitialized. If ptr is NULL, then the call is equivalent to malloc(size), for all values of size; if size is equal to sero, and pt is not NULL, then the call is equivalent ot free(ptr). Unless ptr is NULL, it must have been returned by an earlier call to malloc(), calloc or realloc(). If the area pointed to was moved, a freeptr) is done.
------------------------------------------------------------------------------------------------------------------------

Thursday, February 7, 2013

How to use GDB debugger

                                 -------------------GDB-----------------------------

1. gcc -g program.c
2. gdb ./a.out
3. break main
4. run
5. list ( show the all line of the program.c)
6. list 5,10 ( show the line form 5 to 10 )
7. bt ( back trace )
8. whatis variable_name (it will give the datatype of variable)
9. bt n ( print only the innermost n frames)
10. bt -n ( print only the outermost n frames)
11. fn ( select frame number n)
12. f addr ( select the frame at address addr)
13. up n ( move n frames up the stack )
14. down n ( move n frames down the stack )
15. info f ( print info about the frame )
    info b ( to list the number of breakpoints )   
16. break function ( Set a breakpoin at entry to function)
17. break -offset, break +offset ( set a break point some number of lines forward or backward to the position)
18. break linenum ( set the breakpoint at particular linenumber)
19. break filename:linenum ( set a breakpoin at line linenum in sourece file filename)
20. delete <breakpoint_number>
    clear <function>
21. Enable/Disable breakpoints
    a) enable <breakpoint_number>
    b) disable <breakpoint_number>
22. print $bpnum ( It will give the number of break points
23. watch expr (set a watchpint for an exeression. gdb will break when    expr is written into by the program and its value changes.
23. rewatch expr ( set a watchpoint that will brea when watch expr is read by the program.
24. awatch   ---()
25. info  watchpoint

26. continue[ignore-count] ( REsume program execution, at the address where your program last stopped. The optional argument ignore-count allows you to specify a further numbe ro ftimes to ignore a breakpoint at this location.

27. step [count]
    Continue running your program until control reaches a different source line, then stop it and return control to GDB.With the optional argument, it wil continue running as in step, but do so count times.
   
28. next[count]
    Continue to the next sourece line in the current( innermost) stack frame. This is similar to STEP, but function alls that appear within the line of code are executed without stopping . An optional argument count is a repeat count.
   
29 . finish ( continue running until just after function in the selected stack frame returns. Print the returned value( if any).

30. until ( continue running until a source line past the current line, in the current stack frame, is reached. This command is used to avoid single stepping throught a loop mor than once.

31. jump linespec ( Resume execution at line linespec. Execution stops again immediately if ther is a break ping there.

32. jump *address ( Resume execution at the instruction at address .
33. info local ( Show the
34  info reg ( Show all the machine register )

************************************************************************
**) SEGMENTATION FAULT:: It is often caused by trying to access a memory location that is not in the address space of the process.
**) BUS ERROR :: It is typically caused by trying to access an object with an improperly aligned address. (Ex: tring to fetch an int from address 1)
**) ILLEGAL INSTRUCTION:: It is typically occurs when execution branches into data. This sometimes happens when the stack is overwritten.
**) Arithmetic exception :: It is typically caused by integer  division by zero.

*************************************************************************
            LAUNCHING GDBSERVER IN TARGET PLATFORM:
    
     TCP/Ip
     1. gdbserver host:port <application name >
        example gdbserver 10.102.68.51:1233 hello
     2. COM port
        gdbserver commdevice <application name >
        example gdbserver /dev/com1 telephony

    LAUNCHING GDB IN HOST PLATFORM
  
   1. gdb telephony
   2. target remote /dev/com1
        OR
   1. (gdb)target remote <targetip>2345
   (gdb) continue (don't run once again. it is already running in target machine ).

  

Monday, February 4, 2013

SED and AWK command in Linux



-------------------AWK--------------------
1) Pattern scanning and text processing language


awk one-liner Tips

Print column1, column5 and column7 of a data file or output of any columns list

$awk ‘{print $1, $5, $7}’ data_file

$cat file_name |awk ‘{print $1 $5 $7}’

$ls –al |awk ‘{print $1, $5, $7}’ -- Prints file_permissions,size and date

Syntax of running an awk program

Awk ‘program’ input file(s)


List all files names whose file size greater than zero.

$ls –al |awk ‘$5 > 0 {print $9}’


List all files whose file size equal to 512bytes.

$ls –al |awk ‘$5 == 0 {print $9}’

print all lines

$awk ‘{print }’ file_name

$awk ‘{print 0}’ file_name

Number of lines in a file

$awk ‘ END {print NR}’ file_name

Number of columns in each row of a file

$awk ‘ {print NF’} file_name

Sort the output of file and eliminate duplicate rows

$awk ‘{print $1, $5, $7}’ |sort –u

List all file names whose file size is greater than 512bytes and owner is "oracle"

$ls –al |awk ‘$3 == "oracle" && $5 > 512 {print $9}’

List all file names whose owner could be either "oracle" or "root"

$ls –al |awk ‘$3 == "oracle" || $3 == "root" {print $9}’

list all the files whose owner is not "oracle

$ls –al |awk ‘$3 != "oracle" {print $9}’

List all lines which has atlease one or more characters

$awk ‘NF > 0 {print }’ file_name

List all lines longer that 50 characters

$awk ‘length($0) > 50 ‘{print }’ file_name

List first two columns

$awk ‘{print $1, $2}’ file_name

Swap first two columns of a file and print

$awk ‘{temp = $1; $1 = $2; $2 = temp; print }’ file_name

Replace first column as "ORACLE" in a data file

$awk ‘{$1 = "ORACLE"; print }’ data_file

Remove first column values in a data file

$awk ‘{$1 =""; print }’ data_file

Calculate total size of a directory in Mb

$ls –al |awk ‘{total +=$5};END {print "Total size: " total/1024/1024 " Mb"}’

Calculate total size of a directory including sub directories in Mb

$ls –lR |awk ‘{total +=$5};END {print "Total size: " total/1024/1024 " Mb"}’

Find largest file in a directory including sub directories

$ls –lR |awk ‘{print $5 "\t" $9}’ |sort –n |tail -1

$ awk -F":" '{ print $1 $3 }' /etc/passwd

$ awk -f myscript.awk myfile.in


------------------SED---------------------
1)  Stream editor for filtering and transforming text
2) Sed works as filter, which makes it particularly useful for scripts, sed works line oriented. The most simple commands are a pattern and an action . if no pattern is given, then action is applied to all lines, otherwise it is applied only to lines matching the pattern.

EXAMPLE::
1) A sample application of sed would be to delete the first 10 lines of stdin and echo the rest to stdout:

$cat /etc/passwd| sed -e '1,10d'

2) If we wanted to print only the first ten lines, we would have deleted all the lines starting with 11:

$cat /etc/passwd| sed -e '11,$d'

3)Another way to get only the first 10 lines is to use the -n option:

$cat /etc/passwd | sed -n -e '1,10p'

4)Commands in sed programs are separated by new lines. So if we wanted to delete the lines 1 to 4 and 6 to 9, we could use:

$cat /etc/passwd | sed -e '1,4d 
6,9d'

5)If we want to put command in the script files instead of using the command line.

$sed -f program.sed

















Wednesday, January 23, 2013

Working with Pulse Audio with Alsa

After Integration/Installation of Alsa and Pulse Audio We have to follow the following steps to play and record mp3 files.

Also we have set some configuration in the default.pa file

For setting the volume using pulseaudio::
$pacmd set-sink-volume 0 65537 (volume full)

For setting the volume to the mute::
$pacmd set-sink-mute 0 0 (volume)

This command put all the error and message into the file(cfg.out)
$ ./configure --help 1> cfg.out  2>&1

This command is used for the starting the pulseaudio binary file or we can say the server.
$pulseaudio --start --log-target=syslog --exit-idle-time=-1 (for run the pulseaudio)

This command is used for the recording of the .wav file using the pulseaudio
$gst-launch pulsesrc ! audio/x-raw-int,rate=8000,channels=1,width=16 ! queue ! audioconvert ! wavenc ! filesink location=/home/root/audio/far_from_love.wav

This command is used to play the mp3 file using the alsa it is not using the pulseaudio.
$gst-launch-0.10 filesrc location=/home/root/audio/far_from_love.mp3 ! mad ! alsasink

This command is used to play the mp3 file using the pulseaudio.
$gst-launch-0.10 filesrc location=/home/root/audio/far_from_love.mp3 ! mad ! pulsesink

This command is used for the recording of .wav file using the alsa .
$arecord -vv -fdat foo.wav

This command will set the Pulse input
$export PULSE_SOURCE=alsa_input.dsnoop

This command will give the list of alsa input/output cards
$LANG=C pactl list | grep -A2 'Source #' | grep 'Name: ' | cut -d" " -f2

This command will record the .mp3 file
gst-launch-0.10 pulsesrc device=alsa_input.hw_0_0 ! lame ! filesink location=sample.mp3

Qualcomm Short Term

  113 is the SL. 1st Target by mid July.

Total Pageviews