/usr/share/doc/allegro4-doc/html/ahack.html is in allegro4-doc 2:4.4.2-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><head><title>
Allegro Hacker's Guide
</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="stylesheet" title="Default" type="text/css" href="allegro.css"></head><body bgcolor=white text=black link="#0000ee" alink="#ff0000" vlink="#551a8b">
<center><h1><b>
The Allegro Hacker's Guide
</b></h1></center>
<hr>
<i>
This is a guide to some of the internal workings of Allegro, for people who
are interested in hacking on it. This document is far from complete, and may
not always be 100% accurate. Remember that when in doubt, the sources are
always the definitive reference. Suggestions for what to include in this
document will be very welcome: there is far too much code for me to go over
it all in any kind of detail, so I want to concentrate on the things that
people find most confusing...
</i>
<p><br>
<h1><a name="Contents">Contents</a></h1>
<p>
<ul>
<li><a href="#Coding Style">Coding Style</a>
<li><a href="#Build Process">Build Process</a>
<li><a href="#Header Files">Header Files</a>
<li><a href="#Definitions">Definitions</a>
<li><a href="#Unicode Support">Unicode Support</a>
<li><a href="#Asm Routines">Asm Routines</a>
<li><a href="#Documentation">Documentation</a>
<li><a href="#Debugging helpers">Debugging helpers</a>
<li><a href="#Other Stuff">Other Stuff</a>
<li><a href="#How to contribute patches">How to contribute patches</a>
</ul>
<p><br>
<h1><a name="Coding Style">Coding Style</a></h1>
<p>
I'm not going to be a fascist about this, but it does make life easier if
all the code uses a consistent layout. If you are going to write and
maintain more than one complete source file of your own, I think you are
entitled to do that however you like, but for smaller contributions, I will
probably reformat your code to fit in with my existing style. It will
obviously save me time if you write it this way in the first place, hence
this description:
<p>
Basic Allegro style: K&R, with 3 space indentation. On disk, though, tab stops
are 8 spaces, so if for example a line was indented by 12 spaces, this would be
saved out as either 12 space characters or 1 tab and 4 spaces, not as 4 tabs.
Because this format always will lead to code display looking broken in place or
another, new patches should now always use spaces only and no longer contain
tabs. The indent.pro file included with the Allegro distribution comes close to
getting this layout right, but doesn't quite manage it, so some things still
need to be cleaned up by hand.
<p>
Preprocessor defines and structure names are UPPER_CASE. Function and
variable names are lower_case. MixedCaseNames are evil and should not be
used. That silly m_pHungarian notation is _really_ evil and should not even
be thought about.
<p>
All symbols should be declared as static unless that is absolutely not
possible, in which case they should be prefixed with an underscore.
<p>
Functions look like this:
<blockquote class="code"><pre>
/* foobar:
* Description of what it does.
*/
void foobar(int foo, int bar)
{
/* do some stuff */
}
</pre></blockquote>
Three blank lines between functions.
<p>
Conditionals look like:
<blockquote class="code"><pre>
if (foo) {
/* stuff */
}
else {
/* stuff */
}
</pre></blockquote>
The only time when something comes on the same line after a closing brace is
at the end of a do/while loop, eg:
<blockquote class="code"><pre>
do {
/* stuff */
} while (foo);
</pre></blockquote>
Case statements look like this:
<blockquote class="code"><pre>
switch (foo) {
case bar:
/* stuff */
break;
default:
/* stuff */
break;
}
</pre></blockquote>
Examples of where to put spaces:
<blockquote class="code"><pre>
char *p;
if (condition) { }
for (x=0; x<10; x++) { }
function(foo, bar);
(BITMAP *)data[id].dat;
</pre></blockquote>
All sources should begin with the standard header:
<blockquote class="code"><pre>
/* ______ ___ ___
* /\ _ \ /\_ \ /\_ \
* \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___
* \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ <tt>`\/\`'</tt>__\/ __`\
* \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \
* \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
* \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
* /\____/
* \_/__/
*
* Brief description of what this file does.
*
* By Author.
*
* Cool stuff added by Someone Else.
*
* Stupid bug fixed by a Third Person.
*
* See <a href="readme.html">readme.txt</a> for copyright information.
*/
</pre></blockquote>
Author credits should be added in chronological order, and email addresses
should not be included: those can be found in the main credits file, and if
they only exist in one place, it is easier to update them when people change
address.
<p>
People only need to be listed in the source file header if they've made a
significant contribution to it (one-line fixes don't count), but no matter
how small their addition, they must be added to the docs/thanks._tx file.
This is sorted alphabetically by name. If they are already in it, update the
text to describe the new addition, otherwise make a new entry for the new
contributor. Also, anything more than very tiny modifications should be
added to the docs/changes._tx file, which grows from the top in reverse
chronological order. This file should briefly describe both the nature of
the modification and who did it.
<p><br>
<h1><a name="Build Process">Build Process</a></h1>
<p>
[This is outdated. Now we use CMake.]
<p>
This is very different depending on whether you are using autoconf or a
fixed makefile. For most platforms, though, the fixup script (eg.
fixdjgpp.bat), will create a small makefile, which defines MAKEFILE_INC to
the make of another file (eg. makefile.dj), and then includes makefile.all.
This contains a lot of generic rules, and includes the file named in
MAKEFILE_INC to provide additional platform-specific information. The actual
source files are listed in makefile.lst.
<p>
There are three library targets: alleg (release), alld (debugging), and allp
(profiling). Objects go in obj/compiler/version/, where version is one of
alleg, alld, or allp. Libraries go in lib/compiler/. A few generated things
(asmdefs.inc, mmxtest.s, etc), go in the root of obj/compiler/. Dependencies
are generated by "make depend", and go in obj/compiler/version/makefile.dep,
which is included by makefile.all.
<p>
When you run "make clean", this only deletes harmless generated files like
the objects. "make distclean" strips you right back to the original
distribution, including getting rid of the test executables and the library
itself. For the ultimate in personal hygene, run "make veryclean", which
will wipe absolutely all generated files. After doing this, you will have to
run "make depend" before you can build the library, and also "fixdll.bat" if
you are working on a Windows platform.
<p>
To pass long commandlines to the MSVC and Watcom linkers, the program
runner.exe is compiled using gcc, so make can pass it a decent number of
arguments. This just saves the parameters into a temporary file, and then
invokes the real command using that as an argument file.
<p>
All the makefiles currently use gcc for dependency generation, because this
is easier than trying to get MSVC or Watcom to output the right info.
<p>
The symbol LIBRARY_VERSION, defined at the top of the makefile.ver, is used
for including a version number in things like the DLL filename.
<p><br>
<h1><a name="Header Files">Header Files</a></h1>
<p>
allegro.h lives in the include/ directory. It is only a placeholder which
includes other headers which live in the include/allegro/ tree. The reason
for this slightly odd approach is that allegro.h can include things like
"allegro/keyboard.h", which will work both in-situ within the build
directory, and if we copy allegro.h to the system include directory and the
other headers into system_include/allegro/. This avoids cluttering the
system directories with lots of our headers, while still allowing programs
to just #include <allegro.h>, and also makes it possible for people to
access keyboard stuff with #include <allegro/keyboard.h>.
<p>
base.h includes alconfig.h, which checks the current platform and includes
a helper header for this compiler (aldjgpp.h, almsvc.h, alwatcom.h, etc).
That helper header defines a bunch of macros describing the system, emulates
whatever things are needed to make the code compile properly, and optionally
defines ALLEGRO_EXTRA_HEADER and ALLEGRO_INTERNAL_HEADER if it is going to
need any other platform-specific includes.
<p>
After including the platform header, the rest of alconfig.h defines a lot of
generic helper macros to their default values, but only if the platform
header hasn't already overridden these to something specific.
<p>
Every module-specific header contains structure definitions and function
prototypes. At the end of the file, it may include a header from the
include/allegro/inline/ directory which defines related inline routines.
If inline asm is supported, this can include in turn asm.inl which imports
routines from one of the compiler-specific files al386gcc.h, al386vc.h and
al386wat.h; otherwise C versions are used instead. The header alinline.h
is a placeholder which includes all the headers defining inline functions.
<p>
If ALLEGRO_EXTRA_HEADER is defined, allegro.h includes this at the very end.
This is used to include one of the files aldos.h, alwin.h, etc, which define
platform-specific things like ID values for the hardware drivers. Unlike the
platform files included from the top of allegro.h, these are specific per-OS
rather than per-compiler, so the same alwin.h can be used by both MSVC and
MinGW. They describe library functions that relate to this platform, while
the earlier header described the basic language syntax.
<p>
aintern.h is like the internal.h in earlier Allegro versions, defining
routines that are shared between multiple sources, but that we don't
generally want user programs to see.
<p>
On platforms which have specific, non-portable API routines of their own,
these should go in a special header in the root of the include directory,
eg. winalleg.h. This can be included by user programs that want to access
these routines, while making it very clear to them that by including this
header, they are writing non-portable code.
<p><br>
<h1><a name="Definitions">Definitions</a></h1>
<p>
All header function prototypes should use the macro AL_FUNC(). Inline
routines use the macro AL_INLINE(). Global variables use AL_VAR() or
AL_ARRAY(). Global pointers to functions use AL_FUNCPTR(). Pointers to
functions which are passed as parameters to other routines or stored in a
structure typedef use AL_METHOD(). This may seem like something of an
overkill, but it gives us a lot of flexibility to add DLL import/export
specifiers, calling convention markers like __cdecl, and even to mangle
symbol names on some compilers. If you forget to use these macros, your code
won't work on some platforms.
<p>
This only applies to header files, though: you can write normal code in the
C sources.
<p>
The symbol ALLEGRO_SRC is defined while compiling library source files. If
you want to inline a function in one of your sources, use the INLINE macro.
To declare a zero-sized array in terminal position inside a structure, use
the ZERO_SIZE_ARRAY(type, name) macro. To use 64 bit integers, declare a
LONG_LONG variable (this won't be defined on all platforms). To do things
with filenames, check the macros ALLEGRO_LFN, OTHER_PATH_SEPARATOR, and
DEVICE_SEPARATOR. See the headers for details.
<p><br>
<h1><a name="Unicode Support">Unicode Support</a></h1>
<p>
Do not assume that strings are ASCII. They aren't. If you assume they are,
your code might work for a while as long as people are only using it with
UTF-8 data, but it will die horribly as soon as someone tries to run it with
16 bit Unicode strings, or Chinese GB-code, or some strange MIME format,
etc. Whenever you see a char * being passed around, you must be aware that
this will actually contain text in whatever format is currently selected, so
you have to be damn careful when manipulating strings. Don't ever forget and
call a regular libc routine on them!
<p>
Use the Unicode functions for all your text manipulation: see the docs for
details. When allocating a scratch string on the stack, assume that each
character will occupy at most four bytes: this will give you more than
enough space for any of the current encoding schemes.
<p>
If you want to specify a constant string, use the function
uconvert_ascii("my string", buf) to obtain a copy of "my string" in the
current encoding format. If buf is NULL, this will use an internal static
buffer, but the converted string will be overwritten by the next call to any
format conversion routines, so you shouldn't pass it down into other library
functions. Normally you should provide the conversion space yourself,
allocating buf as a temporary object on the stack.
<p>
To convert the other way (eg. before passing an Allegro string to an OS
routine that expects ASCII data), call uconvert_toascii(mystring, buf).
<p>
For any messages that may be seen by the user, you can call
get_config_text("my ascii string") instead of uconvert_ascii(). This will
return a pointer to persistent memory (so it is ok to keep the string around
indefinitely), after converting into the current text encoding format. This
function is cool because it saves you having to bother allocating space for
the converted data, and because it allows the string to be replaced by the
translations in language.dat. You should be sure to always pass a constant
string to get_config_text(), rather than any generated text or data from
other string variables: this is so that the findtext.sh script can easily
locate all the strings that need to be translated.
<p>
Hardware drivers should initialise their name and desc fields to the global
empty_string, and store an ASCII driver name in their ascii_name field. The
framework code will automatically translate and convert this value, storing
the result in both the name and desc fields. For most drivers this will be
enough, but if you want to provide a more detailed description, it is up to
your driver to set this up from their init routine, and take care of all the
required conversions.
<p><br>
<h1><a name="Asm Routines">Asm Routines</a></h1>
<p>
[We don't use hand written asm any more.]
<p>
Structure offsets are defined in asmdef.inc, which is generated by asmdef.c.
This allows the asm code to use human readable names for the structure
members, and to automatically adjust whenever new fields are added, so it
will always exactly match the layout of the C structures.
<p>
Asm code should use the macro FUNC(name) to declare the start of a routine,
and GLOBL(name) whenever it wants to refer to an external symbol (eg. a C
variable or function). This is to handle name mangling in a portable way
(COFF requires an underscore prefix, ELF does not).
<p>
You can modify %ds and %es from asm, as long as you put them back. If USE_FS
and FSEG are defined, you can also change %fs, otherwise this is not
required and you can safely use nearptr access for everything.
<p>
Don't assume that the MMX opcodes will be supported: not every assembler
version knows about these. Check the ALLEGRO_MMX macro, and be sure to give
up gracefully if these instructions are not available.
<p><br>
<h1><a name="Documentation">Documentation</a></h1>
<p>
One of the nicest features of Allegro is its excellent manual, that you can
read in several formats, ranging from plain text to compiled HTML. All API
functions of the library have to be documented in docs/src/allegro._tx in the
appropriate section. Note that, whatever you write in the file, you shouldn't
exceed a line width of 78 characters, except for lines which contain tags.
This rule is needed in order to produce correct plain text documentation that
doesn't extend beyond the standard 80 column screen/terminal. All the other
formats are less strict about line width and will probably reformat the text
anyway.
<p>
If the function you are documenting returns a value, use the @retval command
to start the chunk of text that describes the return value or how it is used.
If the function takes parameters, document if they are required to follow a
specific format (e.g. string encoding), what they are for, and their range of
values (if any). The latter is particularly important for boolean parameters,
because there's no way to tell the user that an integer must be either <tt>`true'</tt>
or <tt>`false'</tt> in the C programming language. Parameters are always referred to
between single quotes, left and right. These are tt-ized in the HTML version,
but only if there are no space characters between the left and right quote.
<p>
If it is possible to include a little fragment of code which demonstrates the
usage of the function, do it just before the @retval command if there is one,
or at the end of the block. This is very welcome for functions that don't have
example references (@eref). You don't need to include the declaration of the
variables unless you really think it can help newbies.
<p>
Usually a single line will be enough, but don't hesitate to add whatever
comments you might think of as useful for newbies. Also, if you are writing
such a one liner, try to use verbose variable names to indicate where they
come from or what they should contain. Compare the following lines, where the
second is more likely to be found in `<tt>real life</tt>' code, but should be avoided
in these little code fragments taken out of context:
<blockquote class="text"><pre>
blit(source_bitmap, destination_bitmap, source_x, source_y,
destination_x, destination_y, bitmap_width, bitmap_height);
...
blit(spr[3]->bmp, screen, x, y, s_x, s_y, spr[3]->bmp->w, spr[3]->bmp->h);
</pre></blockquote>
Whatever coding style applies to Allegro's code also applies to these examples
(e.g. 8 characters tab, 3 spaces indentation). If you are having trouble
documenting a particular function because you don't know how to approach the
task (this tends to happen when you have used the function so much that you
have learnt it by heart), here is a checklist you can follow:
<ul><li>
What is the purpose of the function? Why would the user want to call it?
<li>
Can you call it at any time or is any other function required to have
been called before (excluding install_allegro/allegro_init)?
<li>
What do the parameters mean? Do they have a precisely defined type?
Do they have a range (like boolean integers)?
<li>
If the function returns a value, what is it? What can it be used for? Is
it likely to be the input of another Allegro function? Does the return
value have a range (e.g. positive numbers mean success, negative ones
failure)?
<li>
Is this function supported across all platforms that Allegro runs on?
What does it do if it is not supported? Does it require a more thorough
explanation in the platform-specific section of the documentation?
<li>
Should the description say whether the function is reentrant or not?
Do you think users would like to use it concurrently in multithreaded
environments?
</ul>
Don't bother about existing example references (@eref). These are generated
automatically by a script. The person in charge of releasing Allegro will
most surely do this for you. If you know how to run it, you are very welcome
to update these tags though, to avoid piling extra work on the maintainer's
shoulders. Of course, all said about documenting functions applies to macros
and variables too.
<p><br>
<h1><a name="Debugging helpers">Debugging helpers</a></h1>
<p>
As a developer you are encouraged to spill as many ASSERT and TRACE macros as
you consider necessary. ASSERT macros are a very good way of enforcing
documented limitations in input parameters which should never happen during a
perfect (ie. bugless) version of your game. They are good for things like
verifying some Allegro subsystem was initialised at the entry point of a
function which depends on it, or passing NULL pointers where the documentation
explicitly says the user is not allowed to do so.
<p>
The TRACE macro is very good for things which are not very repetitive, mainly
initialisation functions. The problem with C code is that usually error
reporting to the user programmer layer is done through a simple integer or
NULL pointer, and the error description (if any) stored in allegro_error. This
is clearly insufficient for functions like set_gfx_mode() which test many
graphic drivers before bailing out.
<p>
What should be the error code in such case? How could you preserve a coherent
error message to the user in driver A when driver B later overwrites it with
some other error which may not interest the user trying to run driver A?
Developers have made plans to include better logging facilities in future
Allegro releases. In the meantime, it is good if opaque systems like drivers
use TRACE both to indicate success and failure.
<p>
For this reason there is a TRACE convention for Allegro code using this macro.
At the top of the source file you want to use TRACE define three macros:
PREFIX_I, PREFIX_W, PREFIX_E. Each of this should be a string in the format
"al-SYSTEM LEVEL: " where SYSTEM is usually the filename creating the TRACE
(but doesn't have to) and LEVEL is either INFO, WARNING or ERROR respectively.
Later you can use them like this:
<blockquote class="code"><pre>
if (some_error_in_a_deep_obscure_function) {
TRACE(PREFIX_E "Couldn't init obscure driver because %s", something);
return -1;
}
TRACE(PREFIX_I "Obscure system initialised with option %s", switch);
</pre></blockquote>
Thanks to this prefix convention a user can use the TRACE macro too and grep
Allegro's messages if there is no interest in them.
<p><br>
<h1><a name="Other Stuff">Other Stuff</a></h1>
<p>
Any portable routines that run inside a timer handler or input callback must
be sure to lock all the code and data that they touch. This is done by
placing an END_OF_FUNCTION(x) or END_OF_STATIC_FUNCTION(x) after each
function definition (this is not required if you declare the function as
INLINE, though), and then calling LOCK_FUNCTION() somewhere in your init
code. Use LOCK_VARIABLE() to lock global variables, and LOCK_DATA() to lock
allocated memory.
<p>
Any modules that have cleanup code should register their exit function by
calling _add_exit_func(). This will ensure that they are closed down
gracefully no matter whether the user calls allegro_exit(), falls off the
bottom of main(), or the program dies suddenly due to a runtime error. You
must call _remove_exit_func() from inside your shutdown routine, or you will
find yourself stuck in an endless loop.
<p><br>
<h1><a name="How to contribute patches">How to contribute patches</a></h1>
<p>
Once you are willing to contribute that beautiful hack which does what
everybody has been waiting for, the fix for that hideous bug which has been
driving you mad for several nights, the nice improved documentation you would
have liked to read in the manual for the first time, etc, you have already
done the hardest part. Now you only need a way to let the Allegro developers
merge your changes in the main distribution.
<p>
You could probably send your patch to one of the people working on Allegro,
but this is not very safe, it depends on the person you chose being available
and willing to do the work for you. The best you can do is to send your patch
to the Allegro Developers mailing list. Read the <a href="readme.html">readme.txt</a> file for
information on how to subscribe to this list. Alternatively, updated
subscription instructions should always be available at
<a href="http://alleg.sourceforge.net/maillist.html">http://alleg.sourceforge.net/maillist.html</a>.
<p>
Sending your patches to the mailing list instead of a single person is good,
because all the subscribed developers can take a look at your modifications,
suggest improvements, or find problems, which you can discuss on the same
mailing list, letting other developers join the conversation when they
consider appropriate. If the modifications are good, they will probably be
accepted and merged in the WIP version for the next release. If you aren't
lucky, or your patch still needs some work, you will be told why it's not
accepted, or what you have to do to improve it. If you aren't subscribed to
the list, remember to say this in your message as, by default, replies are
irected to the list.
<p>
You can also use SourceForge's issue web trackers, which you can find at
<a href="http://sourceforge.net/tracker/?group_id=5665">http://sourceforge.net/tracker/?group_id=5665</a>. This doesn't require you to
subscribe to any mailing list and you can verify every now and then the
status of your contribution.
<p><br>
<br><center><h2><a name="Building your patch against an existent release">Building your patch against an existent release</a></h2></center><p>
<p>
If you have obtained Allegro from an existent release, stable or unstable,
you will have all the source code contained in some archive format. You will
need it, because to create a patch you need two versions of each modified
file, the original version, and your modified version. You will also need
the diff tool, which is used to create the patches. This tool is usually
packaged as a standalone package in most GNU/Linux distributions with the
same name. For DOS, you can get a port from <a href="http://www.delorie.com/djgpp/">http://www.delorie.com/djgpp/</a>.
Just choose a mirror from <a href="http://www.delorie.com/djgpp/getting.html">http://www.delorie.com/djgpp/getting.html</a>,
enter the v2gnu directory and download the difxxb.zip package. While you are
at it, you can also get a tool named patch (patxxb.zip), which is used to
apply patches generated by diff, in case you have to apply the patches
somebody else sends to you. Install the binaries in some directory of your
path, so that you can use them from anywhere.
<p>
If you are planing to modify only one file, you will usually copy this file
to the same name in the same directory with the appended extension '.old'
before starting to work on it. After you have made your modifications to the
file, and verified that they please you, go to the directory containing the
modified and original files and type at the prompt:
<blockquote class="text"><pre>
diff -u file.c.old file.c > patch
</pre></blockquote>
This command will generate a text file which contains the differences
between both files in unified output format. Open it with your prefered
editor and verify that it contains the modifications you wanted to do: lines
you have added will be marked with a plus sign '+', lines you have removed
will be marked with a minus sign '-'. If the file is bigger than a few
kilobytes, compress it before sending to the developers mailing list, and of
course remember to add an explanation of what the patch is meant to do, why
it's needed, and any other information you consider relevant.
<p>
If the modifications you want to do are scattered through several files
and/or directories, this form of patch generation is very tiresome for both
ends (you, and the developers). So unpack a fresh copy of the Allegro source
somewhere and move it to the parent directory where your current version is,
after giving it another name of course, so as to obtain two complete sources
trees side by side. Modify the files you wish in your working
directory. Once you are finished, go back to the parent directory housing the
two source trees and type:
<blockquote class="text"><pre>
diff -ur fresh_original_directory working_directory > patch
</pre></blockquote>
The '-r' switch makes diff compare directories recursively. Again, do the
previous steps of verifying your patch, compressing and sending with correct
instructions. If your patch adds or removes files, you will have to add the
'-N' switch, because by default diff will ignore files which are only in one
of the trees. Of course, you might want to run a 'make clean' in your working
directory before running this command, or you will include lots of generated
files which have nothing to do with your patch. Or you could edit the
resulting patch, but that can be error prone.
<p><br>
<br><center><h2><a name="Building your patch against a SVN version">Building your patch against a SVN version</a></h2></center><p>
<p>
If you are working with the SVN version of Allegro which you can get from
Sourceforge (<a href="http://sourceforge.net/projects/alleg/">http://sourceforge.net/projects/alleg/</a>), you won't need
to copy any files at all. Just modify the files you want, go to the root
directory of the SVN copy and type:
<blockquote class="text"><pre>
svn diff > patch
</pre></blockquote>
Unlike the standalone diff, the <tt>svn diff</tt> command will work recursively
through the Allegro source tree, comparing each file against the Sourceforge
repository. The patch will have slightly different headers, but that's ok,
once you have it follow the previous process to send it to the developers
mailing list. Of course, check the Subversion manual for more information and
options.
<p><br>
<br><center><h2><a name="Online patch creation">Online patch creation</a></h2></center><p>
<p>
Sometimes you don't have the diff tool around, or don't have the SVN tool to
check out the bleeding edge version of Allegro, or you are too lazy to care
how to actually make the patch yourself. For any of those cases, you can use
the online Allegro patcher at <a href="http://www.allegro.cc/dev/make-diff.php">http://www.allegro.cc/dev/make-diff.php</a>.
<p>
To use it, first you have to get one of the source files of Allegro and make
your changes to it. Then, go to that URL and supply the local path on your
computer to the modified file. Then, you write the path of this file relative
to Allegro's <em>root</em>. If everything goes well, you will end up with a
patch you can send to the Allegro developers mailing list or post on
SourceForge's patch submission page.
</body>
</html>
|