Skip to main content

Sponsors

Running Dual-Core using Makefile

Posted in

Problem: Given a set of .mp3 files. I like to convert these files into .ogg files. In addition, I like the processing takes advantage of the dual-core processor, i.e. two simultaneous processing at a time.

Solution:

Make (Make is a Unix utility widely used to manage program compilations. It is used to compile only updated source files to create target files. Hence, the overall compilation time can be reduced significantly, especially during software development) provides some concurrency facility, that it allows multiple targets to be created simultaneously.

Makefile:

.SUFFIXES:
.SUFFIXES: .mp3 .ogg

all: $T

.mp3.ogg:
        echo "Encoding: $<"
        lame --decode $< ${<:.mp3=.wav}
        oggenc ${<:.mp3=.wav}

Now, with the .mp3 files in the current directory, assign the .ogg files to be created in environment variable T.

$ T=
$ for i in *.mp3; do T="$T ${i%.*}.ogg"; done

Then, run "make" with certain number of simultaneous creations say 2.

$ make -j 2 T=$T

In overall, for each .ogg found in T, "make" will try to create its .wav then the .ogg from a .mp3 file. COOL ;)

Post new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.