11.27.2012

Make and Makefiles

Make and Makefiles



The compiler is one of the most important parts of the C programming environment. I can write Java until I'm blue in the fingers without ever having to actually USE the java compiler. Sure, it is being used in the background all the time with eclipse, but IDEs make me stupid. I don't actually learn what is happening when I click the pretty little 'run' button, I just see the output.

GNU Make is a tool that you will use constantly. It is used to generate executables and other non-source files from your source code. It does this using rules you set up in a makefile. Using the makefile, you'll be able to build and install the program you have written. So lets take a look at make files.

To set up a fairly simple example of a make file we can use the hello.c file for our C 'program.' What better example to use than Hello World.

I also included a very simple Makefile along with hello.c.
You should be able to use the commands
make hello
to build the executeable
make clean
to clean the files up

When you run make clean, it actually runs the 'clean:' target of the Makefile, which  removes the 'hello' executable.

Makefile

hello.c

That's a very simple introduction on how to make a basic Makefile. Soon, I'll write another blog post describing some of the more in depth pieces of Makefiles.

9.16.2012

Learn C the Hard Way :: Excercise 1

Learn C The Hard Way : Excercise 0



The idea behind exercise one is to get your C development environment set up. Since I use Archlinux, my notes here will mainly focus on a Linux setup for C programming. An OSx setup could be fairly similar, but a windows one would probably differ a significant amount.

Zed Shaw, the author of the book talks about how using an Integrated Development Environment makes you a lazy programmer. Is exact quote is that "An IDE, or "Integrated Development Environment" will turn you stupid." I couldn't agree more.  While it is difficult to begin learning a new language, let alone learning to program from scratch, using an IDE will give you lazy habits. To me, the difference between using an IDE against using command line tools manually is like installing Linux via the Ubuntu installer or installing an Archlinux system from the command line. It is daunting and much more difficult to do it the manual way, but you will have a greater understanding and appreciation for what goes on beneath the surface in the future.

If you're just starting out programming on Linux, it might be a good idea to use a text editor like Gedit instead of a more difficult Vim or Emacs. Personally I love Vim. Mostly it's because I'm lazy and don't want to move my hands away from the keyboard.

As for your development tools, generally any text editor should work. The great thing about Linux is it basically IS your development environment. Since Linux uses C heavily (the  kernel is written almost entirely in C) it contains all the tools your really need to start hacking some  C code.


Useful links::
vim wiki on changing vim color schemes
http://vim.wikia.com/wiki/Switch_color_schemes

some vim plugins
http://spf13.com/post/the-15-best-vim-plugins/

download some vim plugins
http://vim.sourceforge.net/index.php

9.12.2012

55 Lessons of C

Fellow hackers, I am embarking on a read through of Zed Shaw's Learn C the Hard Way. While I'm working through the book (and it's 55 exercises) I will be tracking my progress through the book. Starting with the first exercise.

A little background on my programming experience and why I want to learn C. I was a computer science major in college and learned C++ in school. I've dabbled with different languages from time to time and mainly use Java now due to my job as a Software Engineer. Java is a powerful language, but I find myself not really knowing what is going on behind the scenes. That coupled with a desire to get into Linux Kernel programming has lead me to a decision of learning C the hard way - by getting my hands dirty with Vim and the command line.

8.27.2012

Kernel Race

Popcorn Kernel Like a lot of programmers, I run off of two different machines. I have both a desktop and a laptop. My desktop was one built for gaming about two and a half years ago. At the time I thought it was the speediest of machines, which wasn't entirely true. It's still a fairly beefy machine though. My laptop has fairly "similar" specs and has been a pretty decent dev machine as well. The interesting part is that for my Desktop I went AMD, and for my laptop I went Intel.

It's kind of difficult to compare the two processors I am going to pit against each other. AMD has always had more processing power, but less cache. Intel has always had less processing power, a little bit more cache and hyperthreading. This should be an interesting comparison.

System Maker Proc Model Clock Speed Num Cores (Physical/Virtual) Memory
Custom Desktop AMD Phenom II x4 955 BE 3.2 GHz 4/4 8 Gb
Lenovo T420 Intel Core i5 2520M 2.5 (3.2) GHz 2/4 8 Gb

Operating System Specs

System Linux Distro
Custom Desktop Ubuntu 12.04 Standard install
Lenovo T420 ArchLinux with DWM

Let's see how they compare! For my test I compiled the linux kernel version 3.6.0 using the default config that came with my Ubuntu 12.04 install on my desktop.

Interestingly, after the first test the kernel compile times were relatively similar. I thought that the desktop would waste my laptop, but the times were very close.


LENOVO T420 :: Core i5 2520M
=-=-=-=-=-=-=-=-=-=-=
real 29m7.789s
user 101m37.572s
sys 7m35.954s

DESKTOP :: PHENOM II x4 955 BE
=-=-=-=-=-=-=-=-=-=
real 28m26.318s
user 74m27.363s
sys 7m1.530s

Review :: Linux Mint Debian Edition 201204 with MATE

I had been using Ubuntu Linux for several years when they released the Unity interface, and like many Linux enthusiasts I was put off by the "mobile" centric view Ubuntu had adopted. After being finding myself without a distro, home I settled into the comfortable familiarity of Linux Mint. It is build off of Ubuntu so it was a logical next step after giving up Ubuntu. I used Mint for a while and eventually made it to ArchLinux and now I have found myself wandering back to Linux Mint, but with a pleasantly surprising twist of Debian.  

Linux Mint, an Old Familiar Friend

Linux Mint Debian edition has almost everything I am looking for in a distro. The familiarity of debian commands from my Ubuntu days, the rolling distribution updates of Debian (and ArchLinux) plus my the nostalgic window manager that I never could give up - MATE (a Gnome 2 fork) . After having two weeks of using LMDE as my primary distribution on my Lenovo T420, I have been very pleasantly surprised. MATE has the stability and programs that Gnome 2 had, although it takes a bit of getting used to since the applications have different names.

Performance

Overall I have been very impressed by the performance of LMDE and MATE. Compared to the latest version of Ubuntu and Gnome 3 in general, the memory usage of LMDE is lower. My setup which I use as my my development station rarely uses more than 1.5 GB of RAM and usually hovers around 675 MB when I'm doing normal internet browsing. The availability of graphics drivers isn't quite as nice as Ubuntu or other version of Linux Mint which will display a notification if proprietary drivers are available. The same drivers are available for LMDE, you just have to install them yourself through the command line or synaptic package manager. For those of you who have a hybrid graphics card like Nvidia Optimus, LMDE works surprisingly well with bumlebee to run everyday programs through the Intel integrated graphics and switch to the Nvidia chip for more power.

MATE

Mate is the desktop manager of LMDE. After Gnome stopped supporting Gnome 2, the MATE project picked up where Gnome left off and began forking the existing Desktop Manager and application suite that came with it. They tweaked it into something called MATE. Besides the names of applications, you won't notice much of a difference between MATE and Gnome 2, which is absolutely fantastic. I grew up on Gnome 2 and haven't been the same sine I was forced off of it. The developers on the MATE project have done a great job bringing the useability back to the desktop. If you happen to have the opposite opinion that I do, LMDE comes with Linux Mint's Cinnamon desktop installed as well. It is as simple as selecting a different session from the login menu to add a bit of spice (pun intented) into your mint.

Battery Life

The length of your battery life depends greatly on the version of the kernel you are running (to find this run the command uname -r). LMDE currently has kernel version 3.2 which has brought some great improvements since early kernel versions. Out of several distros I have had installed on my laptop recently, LMDE has the longest battery life by at least an hour. If you are running a debian based system and want to take advantage of the latest and greatest kernel, take a look at my tutorial and compiling the kernel on Debian based systems.

Applications

LMDE comes with Linux Mints standard applications and philosophy on a distribution. The Linux Mint creators believe that a distribution should just work, which means they include almost everything you need out of the box.  The main applications are:
  • Firefox for web browsing
  • Pidgin for instant messaging
  • Xchat for IRC
  • The LibreOffice suite for documents
  • Pluma (a gedit continuation) for text edititing
  • Banshee for music
And much much more. One of the best things about Linux Mint is that if you are missing some application you would like to install, the Software Manager is only a few clicks away on the start menu.

Updating

Yes, updating the system has its very own section. My absolute favorite thing about LMDE is the Debian-based rolling release. This means that unlike Ubuntu where you have to upgrade EVERYTHING in your system to get the next version, you simply roll everything together. Basically once you install LMDE, you won't have to upgrade to another version again just to get the latest and greatest updates. This is a fantastic approach to software updates. It remains painless and easy to upgrade.

Summary

If you are just getting into linux, Linux Mint Debian Edition may not be the best choice for you. It takes more command fu in the console and knowledge of linux in general than running the standard version of Linux Mint. If you are more experienced LMDE is a fantastic desktop that brings the performance and stability of the Gnome 2 desktop back from the grave. The rolling release update style keeps takes the headache of major release upgrades away and replaces it with simple and normal updates. LMDE comes out of the box ready with flash and other codecs for listening to music and has a great repository of applications should you need anything else. I still haven't decided which distro is the right one for me, but Linux Mint Debian Edition has passed my stress test and checklist for my main Operating System. Thanks for reading and happy hacking!

3.10.2012

Fixing minecraft with DWM and Arch Linux

In DWM minecraft doesn't work correctly, due to Java not recognizing DWM as a window manager, minecraft will appear something like this.


The fix is quite easy. Install the wname package using pacman and set the window manager name to something java will recognize.

# pacman -S wmname

# wmname LG3D

This is not a permanent change, so it is a good idea to add it to your .xinitrc file in your home directory

Geek Code

What is the geek code?

The geek code gives geeks a way to tell other geeks where their experiences and interests are. It's basically a programmatic way to sum yourself up by code. It is worth checking out.

For those of you who have never heard of the geek code, here is a link: http://www.geekcode.com/geek.html

My geek code.

For those of you who wish to see what my geek code looks like.

------BEGIN GEEK CODE BLOCK------
Version: 3.1
GCS/M/MU d- s++:-- a-- C+++(++++)$ UL+++ P+ L+++>$ E--- W++ N? o? K- w++ !O !M V? PS+++ PE+ Y+ PGP> t 5 x+ R+ tv+ b++ DI+ D++ G++ e++> h r+++ y+++
------END GEEK CODE BLOCK------