Build fix, include deflibdefs.h during dependencies generation.
[AROS.git] / rom / exec / makelibrary.c
blobb43bc398c15a62b125a3d7c645c3ce07887aface
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Make a library ready for use.
6 Lang: english
7 */
9 #include <exec/execbase.h>
10 #include <exec/memory.h>
11 #include <dos/dos.h>
12 #include <aros/libcall.h>
13 #include <aros/asmcall.h>
14 #include <proto/exec.h>
16 #include "exec_debug.h"
18 /*****************************************************************************
20 NAME */
22 AROS_LH5(struct Library *, MakeLibrary,
24 /* SYNOPSIS */
25 AROS_LHA(APTR, funcInit, A0),
26 AROS_LHA(APTR, structInit, A1),
27 AROS_LHA(ULONG_FUNC, libInit, A2),
28 AROS_LHA(ULONG, dataSize, D0),
29 AROS_LHA(BPTR, segList, D1),
31 /* LOCATION */
32 struct ExecBase *, SysBase, 14, Exec)
34 /* FUNCTION
35 Allocates memory for the library, builds it and calls the library's
36 init vector. Generally this function is for internal use and for
37 use by library programmers that don't want to use the automatic
38 initialization procedure.
40 INPUTS
41 funcInit - Either a pointer to an array of function offsets
42 (starts with -1, relative to funcInit) or to an array
43 of absolute function pointers.
44 structInit - Pointer to a InitStruct() data region or NULL.
45 libInit - The library's init vector or NULL.
46 The init vector is called with the library address (D0),
47 the segList (A0) and ExecBase (A6) as arguments.
48 If the init fails the init code has to free the base memory
49 and return NULL (the library address for success).
50 dataSize - Size of the library structure including system structures.
51 Must be at least sizeof(struct Library).
52 segList - BCPL pointer to the library segments. Used to free the
53 library later.
55 RESULT
56 The library base address or NULL.
58 NOTES
59 The library base is always aligned to the maximum of sizeof(LONG)
60 and double alignment restrictions.
62 EXAMPLE
64 BUGS
66 SEE ALSO
67 AddLibrary(), RemLibrary(), MakeFunctions(), InitStruct(), SumLibrary()
69 INTERNALS
71 ******************************************************************************/
73 AROS_LIBFUNC_INIT
75 struct Library *library;
76 ULONG negsize;
77 ULONG count = 0;
79 DCREATELIBRARY("MakeLibrary: functions table at 0x%p, data size is %lu", funcInit, dataSize);
81 /* Calculate the jumptable's size */
82 if (*(WORD *)funcInit==-1)
84 /* Count offsets */
85 WORD *fp=(WORD *)funcInit+1;
87 while(*fp++!=-1)
88 count++;
89 DCREATELIBRARY("Table contains %lu relative offsets", count);
91 else
93 /* Count function pointers */
94 void **fp=(void **)funcInit;
96 while(*fp++!=(void *)-1)
97 count++;
99 DCREATELIBRARY("Table contains %lu absolute pointers", count);
102 /* Align library base */
103 negsize=AROS_ALIGN(count * LIB_VECTSIZE);
105 /* Allocate memory */
106 library=(struct Library *)AllocMem(dataSize+negsize,MEMF_PUBLIC|MEMF_CLEAR);
107 DCREATELIBRARY("Allocated vector table at 0x%p, size is %lu", library, negsize);
109 /* And initilize the library */
110 if (library!=NULL)
112 /* Get real library base */
113 library=(struct Library *)((char *)library+negsize);
115 /* Build jumptable */
116 if(*(WORD *)funcInit==-1)
117 /* offsets */
118 MakeFunctions(library,(WORD *)funcInit+1,(WORD *)funcInit);
119 else
120 /* function pointers */
121 MakeFunctions(library,funcInit,NULL);
123 /* Write sizes */
124 library->lib_NegSize=negsize;
125 library->lib_PosSize=dataSize;
127 /* Create structure */
128 if(structInit!=NULL)
129 InitStruct(structInit,library,dataSize);
131 /* Call init vector */
132 if (libInit!=NULL)
134 DCREATELIBRARY("Calling init function 0x%p", libInit);
136 library=AROS_UFC3(struct Library *, libInit,
137 AROS_UFCA(struct Library *, library, D0),
138 AROS_UFCA(BPTR, segList, A0),
139 AROS_UFCA(struct ExecBase *, SysBase, A6)
144 /* All done */
145 DCREATELIBRARY("Created library 0x%p", library);
146 return library;
148 AROS_LIBFUNC_EXIT
149 } /* MakeLibrary */