1 |
On Thu, 2010-07-29 at 13:15 -0400, Tanstaafl wrote: |
2 |
[...] |
3 |
> Wow, Albert, this looks very, very cool. I have heard of using 'make' |
4 |
> and creating your own make files to do things like this, but after a few |
5 |
> minutes of perusing these files I realize this is just way over my head, |
6 |
> at least without some kind of tutorial (I'm just a lowly user whose |
7 |
> (lack of) bash skills would make most of you guys laugh). |
8 |
> |
9 |
Charles, |
10 |
|
11 |
Well, looks like you are looking for a make tutorial. There are a few |
12 |
make tutorials on the internet (a simple Google search should return |
13 |
something). I am by no means an expert on make or Makefiles, but for my |
14 |
makefile specifically: |
15 |
|
16 |
The first part is simply assigning variables, much like bash. The rest |
17 |
are "recipes" for creating targets (files usually). |
18 |
|
19 |
So we can look at the 2nd recipe which is probably the simplest. I'll |
20 |
past it here and replace the variables with actual values for clarity: |
21 |
|
22 |
base.img: |
23 |
qemu-img create -f raw base.img 60G |
24 |
|
25 |
So our "target" here is the file called "base.img". This recipe has no |
26 |
dependencies (after the colon is where you list dependencies). The |
27 |
TABed in line(s) are the instructions, so to create the base.img file we |
28 |
simply execute that qemu-img command. |
29 |
|
30 |
In the makefile the "default" target is the first one, so the default is |
31 |
"all" in my case. "all" requires "image" and has no instructions. The |
32 |
"image" target requires the RAW_IMAGE we saw above, and a few other |
33 |
dependencies. So the make command will try to satisfy those |
34 |
dependencies before it runs the recipe for "image" |
35 |
|
36 |
> Do you know of any generic tutorials on using creating/using your own |
37 |
> make files to do repetitive tasks (not necessarily like building an |
38 |
> entire system as you are doing here (but if there is something like that |
39 |
> even better)? |
40 |
> |
41 |
Makefiles may not be what you need if you are wanting to do "repetitive |
42 |
tasks", but it depends on what you want to do. For example, the virtual |
43 |
appliance makefile isn't really doing "repetitive" tasks, but a series |
44 |
of tasks that need to be run in a certain order (a recipe). |
45 |
|
46 |
Someone asked me why I chose to use a Makefile instead of just writing a |
47 |
script. The reason is that Makefiles can do "checkpointing" and it makes |
48 |
it much easier to debug the appliance creation process. For example, if |
49 |
your script did the chroot and unpacking but then it failed on "emerge |
50 |
world", well if you fix that and run your script again then it will |
51 |
start from the beginning, which takes a long time. But with Makefiles |
52 |
make will see that the first parts are "up to date" and continue from |
53 |
where it failed. It also lets you test certain parts (targets) without |
54 |
having to run the entire thing. |
55 |
|
56 |
But if you really want a script all you need to do is |
57 |
|
58 |
# make -n > script.sh |
59 |
|
60 |
|
61 |
> If not, no worries. |
62 |
|
63 |
http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=makefile |
64 |
+tutorial |
65 |
|
66 |
|
67 |
> Anyway, thanks for sharing what you've done here... |
68 |
|
69 |
NP. I will be committing a fix soon that will use the default portage |
70 |
directories instead of my funny ones. Oh, and I confirmed that you can |
71 |
create virtual appliances inside a virtual appliance, which is safer. |
72 |
So I will be adding a virtual appliance creating virtual appliance soon. |
73 |
|
74 |
-a |