domingo, 13 de mayo de 2012

Make

Because compiling projects can be such a complicated and repetitive process, a good IDE provides a means to abstract, simplify, and even automate software builds. Unix and its descendents accomplish this process with a Makefile, a prescribed recipe in a standard format for generating executable files from source and object files, taking account of changes to only rebuild 
what’s necessary to prevent costly recompilation.

Anatomy of a Makefile

The general pattern of a Makefile is a list of variables and a list of targets, and the sources and/or objects used to provide them. Targets may not necessarily be linked binaries; they could also constitute actions to perform using the generated files, such as install to instate built files into the system, and clean to remove built files from the source tree.

It’s this flexibility of targets that enables make to automate any sort of task relevant to assembling a production build of software; not just the typical parsing, preprocessing, compiling proper and linking steps performed by the compiler, but also running tests (make test), compiling documentation source files into one or more appropriate formats, or automating deployment of code into production systems, for example, uploading to a website via a git push or similar content-tracking method.

An example Makefile for a simple software project might look something like the below:




CC=gcc

#The basic makefile is composed of:
#target: dependencies
#[tab] system command


hello.o: hello.c
        $(CC)  hello.c -o hello.o

install: hello.o
        cp hello.o /bin

If you run

make
 
this program will look for a file named makefile in your directory, and then execute it.

If you have several makefiles, then you can execute them with the command:

make -f MyMakefile


http://mrbook.org/tutorials/make/

 

 

 

 

sábado, 12 de mayo de 2012

GCC G++

GCC is a very mature GPL-licensed collection of compilers, perhaps best-known for working with C and C++ programs. Its free software license and near ubiquity on free Unix-like systems like Linux and BSD has made it enduringly popular for these purposes, though more modern alternatives are available in compilers using the LLVM infrastructure, such as Clang.




"The GNU Compiler Collection includes front ends for C, C++, Objective-C, Fortran, Java, Ada, and Go, as well as libraries for these languages (libstdc++, libgcj,...). GCC was originally written as the compiler for the GNU operating system. The GNU system was developed to be 100% free software, free in the sense that it respects the user's freedom."


To install the gcc and g++ compilers, you will need the build-essential package. This will also install GNU make.


  • dpkg-dev (>= 1.13.5)
    Debian package development tools
  • g++ (>= 4:4.4.3)
    GNU C++ compiler
  • gcc (>= 4:4.4.3)
    GNU C compiler
  • libc6-dev
    Embedded GNU C Library: Development Libraries and Header Files
    or libc-dev
    virtual package provided by libc6-dev
  • make
    An utility for Directing compilation.

viernes, 11 de mayo de 2012

a.out

 Steps in Developing a Program in C

 $ touch       hello.c

#include <stdio.h>

main()
{
printf("Hello, world!\n");
return 0;
}


 $ gcc hello.c

  a.out -- > file create

--------------------------------------------
Steps in Developing a Program in C++


  $ touch       hello.cpp



#include<iostream>
 using namespace std;

int main()
{
    cout << "First c++ program!";
    return 0;
}


  $ g++ hello.cpp

  a.out -- > file create




a.out remains the default output file name for executables created by certain compilers/linkers when no output name is specified, even though these executables are no longer in the a.out format.


These files can be found here

https://www.dropbox.com/sh/5ubehsnaufd8d0w/mJsOKVg4Th/code%20files

http://en.wikipedia.org/wiki/A.out_%28file_format%29




jueves, 10 de mayo de 2012

kernel [vmlinuz] and initrd image [initrd.img]

  • vmlinuz- is the "linux kernel"

  • initrd is the "initial ramdisk"
It is enough files stored in a ramdisk to store needed drivers . You need the drivers so that the kernel can mount / and kick off init.


Remove old linux kernel entries from GRUB2 


 GRUB 2 has three main parts:
  •     /etc/default/grub - the file containing GRUB 2 menu settings.
  •     /etc/grub.d/ - the directory containing GRUB 2 menu creating scripts.
  •     /boot/grub/grub.cfg - the GRUB 2 configuration file, not editable.

Steps 


1. /etc/grub.d/10_linux Identifies kernels on the root device for the operating system in use and creates menu entries.


Note: All kernels residing in the boot folder are included in this section. If you don't want all your old kernels to appear in the menu, remove the kernels from the /boot folder. 


2. Run grub-mkconfig


3. update-grub

Shell scripts


What are they ?

Shell scripts, which are text files containing shell commands.


So-called scripting languages are usually interpreted. A regular compiled program, the interpreter, reads the program, translates it into an internal form, and then executes the program

Why use a shell script ?

The advantage to scripting languages is that they often work at a higher level than compiled languages, being able to deal more easily with objects such as files and directories. The disadvantage is that they are often less efficient than compiled languages. 

Usually the tradeoff is worthwhile; it can take an hour to write a simple script that would take two days to code in C or C++, and usually the script will run fast enough that performance won't be a problem. Examples of scripting languages include awk, Perl, Python, Ruby, and the shell.

Because the shell is universal among Unix systems, and because the language is standardized by POSIX, shell scripts can be written once and, if written carefully, used across a range of systems. Thus, the reasons to use a shell script are:
  
Simplicity
The shell is a high-level language; you can express complex operations clearly and simply using it.

Portability
By using just POSIX-specified features, you have a good chance of being able to move your script, unchanged, to different kinds of systems.

Ease of development
You can often write a powerful, useful script in little time.

Classic Shell Scripting By Nelson H.F. Beebe, Arnold Robbins


  • La primera linea de un script debe comenzar con los caracteres #!, seguidos del nombre del interprete de comandos.
  • Un script, como cualquier otro archivo que se puede ejecutar, necesita tener permiso de ejecucion.
                                         $ chmod 755 / chmod +x  file.sh
  • Cuando el Unix intenta ejecutar algun archivo, lee los primeros dos caracteres , que en el caso de los scripts son #!, y al saber que el archivo es un script,el Unix continuara leyendo la linea  para encontrar el programa que  servira de interprete del script.

DKMS

Source is a wonderful thing. Merged module source in the kernel tree is even better.

The dynamic kernel module support (DKMS) framework  . The DKMS framework is basically a duplicate tree outside of the kernel tree that holds module source and compiled module binaries.

The DKMS executable takes care of building and installing the module for any kernel users may have on their systems, eliminating the kernel catch-up game.

First, using DKMS for a module requires that the module source be located on the user's system and that it be located in the directory /usr/src/(module))-((module-version))/. In addition, a dkms.conf file must exist with the appropriately formatted directives within this configuration file to tell DKMS such things as where to install the module and how to build it.






miércoles, 9 de mayo de 2012

Shell

echo $SHELL

  • Un shell es un interprete de comandos, es decir, el shell lee comandos del teclado y los ejecuta.  


  • A number of important shells have appeared over time
     




Hint: Ubuntu makes /bin/sh a symlink to /bin/dash.

Programming Languages  >> http://hyperpolyglot.org/ 

$VAR y ${VAR}

#!/bin/sh
INGREDIENTE=azucar
echo Hay pan $INGREDIENTEado
echo Hay pan ${INGREDIENTE}ado

Variables de entorno:linux

Variables de entorno

A continuacion tenemos la lista de variables reservadas por el interprete de comandos mas comunes. Todas ellas tienen un significado especial para el mismo, algunas de ellas solo se pueden leer, a otras se le asignan ciertos valores automaticamente y algunas pierden su significado si le cambiamos los valores que tienen por defecto.

http://www.linux-es.org/node/107

server2

Ubuntu 9.10 Karmic Koala



Creates patches using diff

Do.  
 
diff -u old.sh new.sh > file.patch
 
example- file.patch 
 
 
--- old.sh      2012-05-09 20:10:05.596606469 -0300
+++ new.sh      2012-05-09 20:12:24.765286827 -0300
@@ -8,4 +8,13 @@

 echo -n "Your full name is:" $nombre

+echo
+
+echo -n " Now tell me your age :"
+
+read age 
+
+
+echo -n " Your age is : " $age
+
 echo
 
 Apply the patch
 
$ patch -p1 old.sh < file.patch 
patching file old.sh

 Your comments are welcome.
 

Tutorial: Puppet 2.7 Install on Ubuntu

Puppet a configuration management tool. 





dropbox: https://www.dropbox.com/sh/5ubehsnaufd8d0w/L37GsWleDR/Tutorial_0.1.pdf


 Your comments are welcome.