Make is a utility that will take one set of commands stored in a file (either makefile or Makefile) and will run them. It is extremely convenient for compiling because you don't always have to type in the data. Many makefiles can get very large and will save a lot of time. Along with saving time, Make will check to see if you have updated the file since the last build. If you haven't, then it won't recompile that file. This can vastly cut down on compile time. Now, want to learn how to use Make? Sure you do. So keep reading. Make runs on variables. As you *hopefully* know, variables are placeholders for data that can change. Variables are set by simply typing VARNAME=data. Easy, huh? Comments in Makefiles are done by using # in front of the comment. So without further adieu, let's jump into Makefiles! FLAGS=-W -Wall -ggdb # flags to pass # passing -On (n being a number 1-6) will optimize # use this to make the final project # instead of --ggdb to debug CC=gcc # the common Linux compiler FILES=linux-helloworld.c # only one source file TARGET=helloworld # what we want to compile to demo: $(CC) $(FLAGS) $(FILES) -o $(TARGET) How do you like THAT? Spiffy, eh? You'll notice the variables I set at top to hold things such as the flags to pass, the name of the compiler, the files, and the final product name. Now, you'll notice the line "demo:" and the line full of variables. The "demo:" line tells you an argument you can pass to Make. You would call this by typing "Make demo" and then it would follow the command list that you wrote out for demo. To do this, type demo: then press return, then press Tab *once* and type the line you wish to be executed. If you'd like more commands to run, then press return and Tab and follow the pattern. When you type "Make demo", the Make utility will fill in all the variables so what the shell really sees is: gcc -W -Wall -ggdb linux-helloworld.c -o helloworld It's so easy, you'll never want to work without makefiles again. You can use makefiles for almost anything. I used it to make a .tar.gz archive of this article series because I'm too lazy to keep typing the tar command. Hey, it works. So, you wanna try out the Make utility? Type the example above into a file and name it Makefile or makefile. Make sure it's in the same directory as your source code, and then cd to that directory. Then, type Make demo. If everything worked out well, then type ./helloworld -- Woohoo! You're nearly on your way to Linux development success! Now you can compile programs, "Make" them, but...how will you distribute them? Well, we're going to use a program called tar to put the files in a .tar.gz archive. .tar.gz is somewhat of the .zip file equivalent in Windows.
|
|