├── README ├── SDI_compiler.h ├── SDI_hook.h ├── SDI_interrupt.h ├── SDI_lib.h ├── SDI_misc.h ├── SDI_stdarg.h └── examples ├── hooks ├── example_hookuse.c ├── makefile.mos ├── makefile.os3 └── makefile.os4 ├── libraries ├── example_lib.c ├── makefile.mos ├── makefile.os3 └── makefile.os4 ├── misc ├── example_miscuse.c ├── makefile.mos ├── makefile.os3 └── makefile.os4 └── varargs ├── example_varargs.c ├── makefile.mos ├── makefile.os3 └── makefile.os4 /README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adtools/SDI/4a7f5f694a211210811810d6ac452080b80527d7/README -------------------------------------------------------------------------------- /SDI_compiler.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adtools/SDI/4a7f5f694a211210811810d6ac452080b80527d7/SDI_compiler.h -------------------------------------------------------------------------------- /SDI_hook.h: -------------------------------------------------------------------------------- 1 | #ifndef SDI_HOOK_H 2 | #define SDI_HOOK_H 3 | 4 | /* Includeheader 5 | 6 | Name: SDI_hook.h 7 | Versionstring: $VER: SDI_hook.h 1.27 (04.04.2015) 8 | Authors: Dirk Stoecker, Jens Maus 9 | Distribution: PD 10 | Project page: https://github.com/adtools/SDI 11 | Description: defines to hide compiler specific hook stuff 12 | 13 | 1.0 21.06.02 : based on the work made for freeciv and YAM with 14 | additional texts partly taken from YAM_hook.h changes made 15 | by Jens Langner, largely reworked the mechanism 16 | 1.1 07.10.02 : added HOOKPROTONP and HOOKPROTONONP requested by Jens 17 | 1.2 18.10.02 : reverted to old MorphOS-method for GCC 18 | 1.3 08.02.04 : modified to get it compatible to AmigaOS4 19 | 1.4 17.02.04 : modified to get compatible to latest SDI_compiler.h changes 20 | 1.5 02.03.04 : added UNUSED define to OS4 hook specification so that the 21 | compiler can ignore some warnings. 22 | 1.6 02.03.04 : added (APTR) casts to MorphOS prototype definition to 23 | reduce compiler warnings. 24 | 1.7 04.07.04 : removed static from all DISPATCHERPROTO definitions as there 25 | may be dispatchers that are of course non static. 26 | 1.8 07.04.05 : added MakeHookWithData (Sebastian Bauer) 27 | 1.9 08.04.05 : changed MorphOS hooks to use HookEntry (Ilkka Lehtoranta) 28 | 1.10 16.05.05 : simplified and fixed for vbcc/MorphOS (Frank Wille) 29 | 1.11 17.05.05 : changed cast in DISPATCHERPROTO from (void(*)()) to APTR 30 | cause SDI version of the EmulLibEntry uses APTR for easy 31 | usage. 32 | Added #ifndef SDI_TRAP_LIB to avoid double defines when 33 | combining with SDI_interrupt.h or SDI_misc.h (Guido 34 | Mersmann) 35 | 1.12 18.05.05 : DISPATCHERPROTO wasn't working, because of the missing REG_Ax 36 | definitions. Added include (Guido Mersmann) 37 | 1.13 11.12.05 : fixed a minor typo in the PPC HOOKPROTONP macro. 38 | (Jens Langner) 39 | 1.14 20.04.06 : unified static of MorphOs with non-MorphOS vesion 40 | 1.15 30.04.06 : modified to get it compatible to AROS. (Guido Mersmann) 41 | 1.16 06.10.06 : added new DISPATCHER() macro and separated it from the 42 | DISPATCHERPROTO() definition. Now the DISPATCHERPROTO() should 43 | only be used to get the correct prototype and the plain 44 | DISPATCHER() for defining the dispatcher itself. 45 | 1.17 14.07.08 : added "_" to all UNUSED variable specifications to make sure 46 | a user does not use those definition on accident. 47 | 1.18 20.03.09 : modified macros to be somewhat more compatible for an AROS 48 | usage (Pavel Fedin) 49 | 1.19 25.03.09 : fixed the DISPATCHERPROTO() macros for x86_64 AROS. 50 | 1.20 26.03.09 : fixed m68k define checks. 51 | 1.21 19.05.09 : added SDISPATCHER() to generate a static dispatcher. 52 | 1.22 24.06.10 : fixed AROS macros (Matthias Rustler). 53 | 1.23 12.08.10 : added missing proto/alib.h include for AROS 54 | 1.24 03.03.11 : fixed AROS macros for m68k (Jason McMullan) 55 | 1.25 18.07.12 : added crosscall macros for functions with 1 and 2 parameters. 56 | These macros are to be used in case i.e. PPC code is to be called 57 | from m68k code. The function pointer must be passed with ENTRY(). 58 | 1.26 17.10.12 : added crosscall macros for functions with 1 and 2 parameters but 59 | no return value. 60 | 1.27 04.04.15 : fixed HOOKPROTO for vbcc (Fredrik Wikstrom) 61 | 1.28 12.07.16 : fixed HOOKPROTO for vbcc (O. Sezer) 62 | 63 | */ 64 | 65 | /* 66 | ** This is PD (Public Domain). This means you can do with it whatever you want 67 | ** without any restrictions. I only ask you to tell me improvements, so I may 68 | ** fix the main line of this files as well. 69 | ** 70 | ** To keep confusion level low: When changing this file, please note it in 71 | ** above history list and indicate that the change was not made by myself 72 | ** (e.g. add your name or nick name). 73 | ** 74 | ** Find the latest version of this file at: 75 | ** https://github.com/adtools/SDI 76 | ** 77 | ** Jens Maus 78 | ** Dirk Stoecker 79 | */ 80 | 81 | #include "SDI_compiler.h" 82 | 83 | /* 84 | ** Hook macros to handle the creation of Hooks/Dispatchers for different 85 | ** Operating System versions. 86 | ** Currently AmigaOS, AROS, and MorphOS are supported. 87 | ** 88 | ** For more information about hooks see include file or 89 | ** the relevant descriptions in utility.library autodocs. 90 | ** 91 | ** Example: 92 | ** 93 | ** Creates a hook with the name "TestHook" that calls a corresponding 94 | ** function "TestFunc" that will be called with a pointer "text" 95 | ** (in register A1) and returns a long. 96 | ** 97 | ** HOOKPROTONHNO(TestFunc, LONG, STRPTR text) 98 | ** { 99 | ** Printf(text); 100 | ** return 0; 101 | ** } 102 | ** MakeHook(TestHook, TestFunc); 103 | ** 104 | ** Every function that is created with HOOKPROTO* must have a MakeHook() or 105 | ** MakeStaticHook() to create the corresponding hook. Best is to call this 106 | ** directly after the hook function. This is required by the GCC macros. 107 | ** 108 | ** The naming convention for the Hook Prototype macros is as followed: 109 | ** 110 | ** HOOKPROTO[NH][NO][NP] 111 | ** ^^ ^^ ^^ 112 | ** NoHook | NoParameter 113 | ** NoObject 114 | ** 115 | ** So a plain HOOKPROTO() creates you a Hook function that requires 116 | ** 4 parameters, the "name" of the hookfunction, the "obj" in REG_A2, 117 | ** the "param" in REG_A1 and a "hook" in REG_A0. Usually you will always 118 | ** use NH, as the hook structure itself is nearly never required. 119 | ** 120 | ** The DISPATCHERPROTO macro is for MUI dispatcher functions. It gets the 121 | ** functionname as argument. To supply this function for use by MUI, use 122 | ** The ENTRY macro, which also gets the function name as argument. 123 | */ 124 | 125 | #if !defined(__AROS__) && (defined(_M68000) || defined(__M68000) || defined(__mc68000) || defined(__M68K__)) 126 | #define HOOKPROTO(name, ret, obj, param) static SAVEDS ASM ret \ 127 | name(REG(a0, struct Hook *hook), REG(a2, obj), REG(a1, param)) 128 | #define HOOKPROTONO(name, ret, param) static SAVEDS ASM ret \ 129 | name(REG(a0, struct Hook *hook), REG(a1, param)) 130 | #define HOOKPROTONP(name, ret, obj) static SAVEDS ASM ret \ 131 | name(REG(a0, struct Hook *hook), REG(a2, obj)) 132 | #define HOOKPROTONONP(name, ret) static SAVEDS ASM ret \ 133 | name(REG(a0, struct Hook *hook)) 134 | #define HOOKPROTONH(name, ret, obj, param) static SAVEDS ASM ret \ 135 | name(REG(a2, obj), REG(a1, param)) 136 | #define HOOKPROTONHNO(name, ret, param) static SAVEDS ASM ret \ 137 | name(REG(a1, param)) 138 | #define HOOKPROTONHNP(name, ret, obj) static SAVEDS ASM ret \ 139 | name(REG(a2, obj)) 140 | #define HOOKPROTONHNONP(name, ret) static SAVEDS ret name(void) 141 | #else 142 | /* NOTE: This is fine for AROS, since HookEntry will handle stack params 143 | */ 144 | #define HOOKPROTO(name, ret, obj, param) static SAVEDS ret \ 145 | name(struct Hook *hook, obj, param) 146 | #define HOOKPROTONO(name, ret, param) static SAVEDS ret \ 147 | name(struct Hook *hook, UNUSED APTR _obj, param) 148 | #define HOOKPROTONP(name, ret, obj) static SAVEDS ret \ 149 | name(struct Hook *hook, obj, UNUSED APTR _param) 150 | #define HOOKPROTONONP(name, ret) static SAVEDS ret \ 151 | name(struct Hook *hook, UNUSED APTR _obj, UNUSED APTR _param) 152 | #define HOOKPROTONH(name, ret, obj, param) static SAVEDS ret \ 153 | name(UNUSED struct Hook *_hook, obj, param) 154 | #define HOOKPROTONHNO(name, ret, param) static SAVEDS ret \ 155 | name(UNUSED struct Hook *_hook, UNUSED APTR _obj, param) 156 | #define HOOKPROTONHNP(name, ret, obj) static SAVEDS ret \ 157 | name(UNUSED struct Hook *_hook, obj, UNUSED APTR _param) 158 | #define HOOKPROTONHNONP(name, ret) static SAVEDS ret name(void) 159 | #endif 160 | 161 | #ifdef __MORPHOS__ 162 | 163 | #ifndef SDI_TRAP_LIB /* avoid defining this twice */ 164 | #include 165 | #include 166 | 167 | #define SDI_TRAP_LIB 0xFF00 /* SDI prefix to reduce conflicts */ 168 | 169 | struct SDI_EmulLibEntry 170 | { 171 | UWORD Trap; 172 | UWORD pad; 173 | APTR Func; 174 | }; 175 | #endif 176 | 177 | #define MakeHook(hookname, funcname) struct Hook hookname = {{NULL, NULL}, \ 178 | (HOOKFUNC)HookEntry, (HOOKFUNC)funcname, NULL} 179 | #define MakeHookWithData(hookname, funcname, data) struct Hook hookname = \ 180 | {{NULL, NULL}, (HOOKFUNC)HookEntry, (HOOKFUNC)funcname, (APTR)data} 181 | #define MakeStaticHook(hookname, funcname) static struct Hook hookname = \ 182 | {{NULL, NULL}, (HOOKFUNC)HookEntry, (HOOKFUNC)funcname, NULL} 183 | #define DISPATCHERPROTO(name) ULONG name(struct IClass * cl, Object * obj, \ 184 | Msg msg); \ 185 | extern const struct SDI_EmulLibEntry Gate_##name 186 | #define DISPATCHER(name) \ 187 | struct IClass; \ 188 | ULONG name(struct IClass * cl, Object * obj, Msg msg); \ 189 | static ULONG Trampoline_##name(void) {return name((struct IClass *) \ 190 | REG_A0, (Object *) REG_A2, (Msg) REG_A1);} \ 191 | const struct SDI_EmulLibEntry Gate_##name = {SDI_TRAP_LIB, 0, \ 192 | (APTR) Trampoline_##name}; \ 193 | ULONG name(struct IClass * cl, Object * obj, Msg msg) 194 | #define SDISPATCHER(name) \ 195 | struct IClass; \ 196 | static ULONG name(struct IClass * cl, Object * obj, Msg msg); \ 197 | static ULONG Trampoline_##name(void) {return name((struct IClass *) \ 198 | REG_A0, (Object *) REG_A2, (Msg) REG_A1);} \ 199 | static const struct SDI_EmulLibEntry Gate_##name = {SDI_TRAP_LIB, 0, \ 200 | (APTR) Trampoline_##name}; \ 201 | static ULONG name(struct IClass * cl, Object * obj, Msg msg) 202 | #define CROSSCALL1(name, ret, type1, param1) \ 203 | static STDARGS SAVEDS ret name(type1 param1); \ 204 | static ret Trampoline_##name(void) \ 205 | { \ 206 | ULONG *stk = (ULONG *)REG_A7; \ 207 | type1 param1 = (type1)stk[1]; \ 208 | return name(param1); \ 209 | } \ 210 | static const struct SDI_EmulLibEntry Gate_##name = {SDI_TRAP_LIB, 0, \ 211 | (APTR) Trampoline_##name}; \ 212 | static STDARGS SAVEDS ret name(type1 param1, type2 param2) 213 | #define CROSSCALL1NR(name, type1, param1) \ 214 | static STDARGS SAVEDS void name(type1 param1); \ 215 | static void Trampoline_##name(void) \ 216 | { \ 217 | ULONG *stk = (ULONG *)REG_A7; \ 218 | type1 param1 = (type1)stk[1]; \ 219 | name(param1); \ 220 | } \ 221 | static const struct SDI_EmulLibEntry Gate_##name = {SDI_TRAP_LIB, 0, \ 222 | (APTR) Trampoline_##name}; \ 223 | static STDARGS SAVEDS void name(type1 param1) 224 | #define CROSSCALL2(name, ret, type1, param1, type2, param2) \ 225 | static STDARGS SAVEDS ret name(type1 param1, type2 param2); \ 226 | static ret Trampoline_##name(void) \ 227 | { \ 228 | ULONG *stk = (ULONG *)REG_A7; \ 229 | type1 param1 = (type1)stk[1]; \ 230 | type2 param2 = (type2)stk[2]; \ 231 | return name(param1, param2); \ 232 | } \ 233 | static const struct SDI_EmulLibEntry Gate_##name = {SDI_TRAP_LIB, 0, \ 234 | (APTR) Trampoline_##name}; \ 235 | static STDARGS SAVEDS ret name(type1 param1, type2 param2) 236 | #define CROSSCALL2NR(name, type1, param1, type2, param2) \ 237 | static STDARGS SAVEDS void name(type1 param1, type2 param2); \ 238 | static void Trampoline_##name(void) \ 239 | { \ 240 | ULONG *stk = (ULONG *)REG_A7; \ 241 | type1 param1 = (type1)stk[1]; \ 242 | type2 param2 = (type2)stk[2]; \ 243 | name(param1, param2); \ 244 | } \ 245 | static const struct SDI_EmulLibEntry Gate_##name = {SDI_TRAP_LIB, 0, \ 246 | (APTR) Trampoline_##name}; \ 247 | static STDARGS SAVEDS void name(type1 param1, type2 param2) 248 | #define ENTRY(func) (APTR)&Gate_##func 249 | 250 | #elif defined(__AROS__) 251 | #include 252 | 253 | #define MakeHook(hookname, funcname) struct Hook hookname = {{NULL, NULL}, \ 254 | (HOOKFUNC)HookEntry, (HOOKFUNC)funcname, NULL} 255 | #define MakeHookWithData(hookname, funcname, data) struct Hook hookname = \ 256 | {{NULL, NULL}, (HOOKFUNC)HookEntry, (HOOKFUNC)funcname, (APTR)data} 257 | #define MakeStaticHook(hookname, funcname) static struct Hook hookname = \ 258 | {{NULL, NULL}, (HOOKFUNC)HookEntry, (HOOKFUNC)funcname, NULL} 259 | #define DISPATCHERPROTO(name) \ 260 | IPTR name(struct IClass * cl, Object * obj, Msg msg); \ 261 | AROS_UFP3(IPTR, Gate_##name, \ 262 | AROS_UFPA(struct IClass *, cl, A0), \ 263 | AROS_UFPA(Object *, obj, A2), \ 264 | AROS_UFPA(Msg, msg, A1)) 265 | #define DISPATCHERx(x,name) \ 266 | x IPTR name(struct IClass * cl, Object * obj, Msg msg); \ 267 | x AROS_UFH3(IPTR, Gate_##name, \ 268 | AROS_UFHA(struct IClass *, cl, A0), \ 269 | AROS_UFHA(Object *, obj, A2), \ 270 | AROS_UFHA(Msg, msg, A1)) \ 271 | { AROS_USERFUNC_INIT \ 272 | return name(cl, obj, msg); \ 273 | AROS_USERFUNC_EXIT \ 274 | } \ 275 | x IPTR name(struct IClass * cl, Object * obj, Msg msg) 276 | #define DISPATCHER(name) DISPATCHERx(,name) 277 | #define SDISPATCHER(name) DISPATCHERx(static,name) 278 | #define CROSSCALL1(name, ret, type1, param1) \ 279 | static STDARGS SAVEDS ret Gate_##name(type1 param1) 280 | #define CROSSCALL1NR(name, type1, param1) \ 281 | static STDARGS SAVEDS void Gate_##name(type1 param1) 282 | #define CROSSCALL2(name, ret, type1, param1, type2, param2) \ 283 | static STDARGS SAVEDS ret Gate_##name(type1 param1, type2 param2) 284 | #define CROSSCALL2NR(name, type1, param1, type2, param2) \ 285 | static STDARGS SAVEDS void Gate_##name(type1 param1, type2 param2) 286 | #define ENTRY(func) (APTR)Gate_##func 287 | 288 | #else /* !__MORPHOS__ && !__AROS__*/ 289 | 290 | #define MakeHook(hookname, funcname) struct Hook hookname = {{NULL, NULL}, \ 291 | (HOOKFUNC)funcname, NULL, NULL} 292 | #define MakeHookWithData(hookname, funcname, data) struct Hook hookname = \ 293 | {{NULL, NULL}, (HOOKFUNC)funcname, NULL, (APTR)data} 294 | #define MakeStaticHook(hookname, funcname) static struct Hook hookname = \ 295 | {{NULL, NULL}, (HOOKFUNC)funcname, NULL, NULL} 296 | #define DISPATCHERPROTO(name) SAVEDS ASM IPTR name(REG(a0, \ 297 | struct IClass * cl), REG(a2, Object * obj), REG(a1, Msg msg)) 298 | #define DISPATCHER(name) DISPATCHERPROTO(name) 299 | #define SDISPATCHER(name) static DISPATCHERPROTO(name) 300 | #define CROSSCALL1(name, ret, type1, param1) \ 301 | static STDARGS SAVEDS ret name(type1 param1) 302 | #define CROSSCALL1NR(name, type1, param1) \ 303 | static STDARGS SAVEDS void name(type1 param1) 304 | #define CROSSCALL2(name, ret, type1, param1, type2, param2) \ 305 | static STDARGS SAVEDS ret name(type1 param1, type2 param2) 306 | #define CROSSCALL2NR(name, type1, param1, type2, param2) \ 307 | static STDARGS SAVEDS void name(type1 param1, type2 param2) 308 | #define ENTRY(func) (APTR)func 309 | 310 | #endif 311 | 312 | #define InitHook(hook, orighook, data) ((hook)->h_Entry = (orighook).h_Entry,\ 313 | (hook)->h_SubEntry = (orighook).h_SubEntry,(hook)->h_Data = (APTR)(data)) 314 | 315 | #endif /* SDI_HOOK_H */ 316 | -------------------------------------------------------------------------------- /SDI_interrupt.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adtools/SDI/4a7f5f694a211210811810d6ac452080b80527d7/SDI_interrupt.h -------------------------------------------------------------------------------- /SDI_lib.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adtools/SDI/4a7f5f694a211210811810d6ac452080b80527d7/SDI_lib.h -------------------------------------------------------------------------------- /SDI_misc.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adtools/SDI/4a7f5f694a211210811810d6ac452080b80527d7/SDI_misc.h -------------------------------------------------------------------------------- /SDI_stdarg.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adtools/SDI/4a7f5f694a211210811810d6ac452080b80527d7/SDI_stdarg.h -------------------------------------------------------------------------------- /examples/hooks/example_hookuse.c: -------------------------------------------------------------------------------- 1 | /* Example source 2 | 3 | Name: example_hookuse.c 4 | Versionstring: $VER: example_hookuse.c 1.0 (06.10.2004) 5 | Author: Jens Langner 6 | Distribution: PD 7 | Description: shows how the SDI_hook.h header include are used 8 | 9 | 1.0 06.10.04 : initial version showing how the SDI_hook.h header have to be 10 | used if one wants to keep the sources platform independent 11 | throughout all common AmigaOS compatible platforms like OS3, 12 | OS4 and MorphOS. 13 | 14 | 15 | Please note that this example is just for educational purposes and wasn't 16 | checked for complete correctness. However, it should compile and probably also 17 | work as expected. But please note that its purpose is to show how the hook 18 | macros make it very easy to deal with hooks and also keep the sources simple 19 | and platform independent through OS3, OS4 and MorphOS. 20 | 21 | Feel free to comment and submit any suggestions directly to 22 | Jens.Langner@light-speed.de 23 | 24 | */ 25 | 26 | #include 27 | #include 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #include "SDI_hook.h" 34 | 35 | /******************************************************************************/ 36 | /* Own hook definitions */ 37 | /******************************************************************************/ 38 | 39 | // The following hook is just an example hook where we use the object 40 | // for printing out some minor text. Do you see how easy it is to use hooks and 41 | // how great it is to use SDI_hook.h to automatically keep your sources compatible 42 | // to all common AmigaOS platforms? 43 | HOOKPROTONHNP(HelloFunc, LONG, char *txt) 44 | { 45 | printf("'%s' which returns ", txt); 46 | 47 | return -10; 48 | } 49 | MakeStaticHook(HelloHook, HelloFunc); 50 | 51 | /******************************************************************************/ 52 | /* The main entry point to just illustrate how the hook is called */ 53 | /******************************************************************************/ 54 | 55 | struct Library *UtilityBase; 56 | #if defined(__amigaos4__) 57 | struct UtilityIFace *IUtility; 58 | #define GETINTERFACE(iface, base) (iface = (APTR)GetInterface((struct Library *)(base), "main", 1L, NULL)) 59 | #define DROPINTERFACE(iface) { DropInterface((APTR)(iface)); iface = NULL; } 60 | #else 61 | #define GETINTERFACE(iface, base) TRUE 62 | #define DROPINTERFACE(iface) 63 | #endif 64 | 65 | int main(void) 66 | { 67 | LONG ret = 0; 68 | 69 | if((UtilityBase = OpenLibrary("utility.library", 37))) 70 | { 71 | if(GETINTERFACE(IUtility, UtilityBase)) 72 | { 73 | printf("Hello! I am a "); 74 | 75 | ret = CallHook(&HelloHook, "portable Hook"); 76 | 77 | printf("%ld\n", ret); 78 | 79 | DROPINTERFACE(IUtility); 80 | } 81 | 82 | CloseLibrary(UtilityBase); 83 | } 84 | 85 | return 0; 86 | } 87 | -------------------------------------------------------------------------------- /examples/hooks/makefile.mos: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: makefile.mos,v 1.2 2005/06/08 06:54:25 damato Exp $ 3 | # 4 | # :ts=4 5 | # 6 | 7 | CC = ppc-morphos-gcc 8 | 9 | .c.o: 10 | @echo "Compiling $<" 11 | @$(CC) -c $(CFLAGS) -o $*.o $< 12 | 13 | ########################################################################### 14 | 15 | NAME = hellohook 16 | VERSION = 51 17 | 18 | ########################################################################### 19 | 20 | WARNINGS = \ 21 | -Wall -W -Wshadow -Wpointer-arith -Wsign-compare -Wmissing-prototypes \ 22 | -Wundef -Wbad-function-cast -Wmissing-declarations 23 | 24 | CPU = -mcpu=604e -mmultiple 25 | OPTIONS = -DNDEBUG -D__USE_INLINE__ 26 | OPTIMIZE = -O3 -fomit-frame-pointer -fstrength-reduce -finline-functions 27 | DEBUG = -g 28 | 29 | ########################################################################### 30 | 31 | CFLAGS = -noixemul $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(CPU) $(OPTIONS) -I. \ 32 | -I../../includes 33 | LFLAGS = -L. 34 | 35 | ########################################################################### 36 | 37 | OBJS = \ 38 | example_hookuse.o \ 39 | 40 | LIBS = 41 | 42 | ########################################################################### 43 | 44 | all: $(NAME) 45 | 46 | $(NAME): $(OBJS) 47 | @echo "Linking $@" 48 | @$(CC) -o $@.debug $(CFLAGS) $(LFLAGS) $(OBJS) $(LIBS) 49 | @ppc-morphos-strip -R.comment -o $@ $@.debug 50 | 51 | ########################################################################### 52 | 53 | example_hookuse.o : example_hookuse.c 54 | 55 | ########################################################################### 56 | 57 | clean: 58 | -rm *.o *.debug $(NAME) 59 | -------------------------------------------------------------------------------- /examples/hooks/makefile.os3: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: makefile.os3,v 1.2 2005/06/08 06:54:25 damato Exp $ 3 | # 4 | # :ts=4 5 | # 6 | 7 | CC = m68k-amigaos-gcc 8 | 9 | .c.o: 10 | @echo "Compiling $<" 11 | @$(CC) -c $(CFLAGS) -o $*.o $< 12 | 13 | ########################################################################### 14 | 15 | NAME = hellohook 16 | VERSION = 51 17 | 18 | ########################################################################### 19 | 20 | WARNINGS = \ 21 | -Wall -W -Wshadow -Wpointer-arith -Wsign-compare -Wmissing-prototypes \ 22 | -Wundef -Wbad-function-cast -Wmissing-declarations 23 | 24 | CPU = -m68020-60 -msoft-float 25 | OPTIONS = -DNDEBUG -D__USE_INLINE__ 26 | OPTIMIZE = -O3 -fomit-frame-pointer -fstrength-reduce -finline-functions 27 | DEBUG = -g 28 | 29 | ########################################################################### 30 | 31 | CFLAGS = -noixemul $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(CPU) $(OPTIONS) -I. \ 32 | -I../../includes 33 | LFLAGS = -L. 34 | 35 | ########################################################################### 36 | 37 | OBJS = \ 38 | example_hookuse.o \ 39 | 40 | LIBS = \ 41 | -lc 42 | 43 | ########################################################################### 44 | 45 | all: $(NAME) 46 | 47 | $(NAME): $(OBJS) 48 | @echo "Linking $@" 49 | @$(CC) -o $@.debug $(CFLAGS) $(LFLAGS) $(OBJS) $(LIBS) 50 | @m68k-amigaos-strip -R.comment -o $@ $@.debug 51 | 52 | ########################################################################### 53 | 54 | example_hookuse.o : example_hookuse.c 55 | 56 | ########################################################################### 57 | 58 | clean: 59 | -rm *.o *.debug $(NAME) 60 | -------------------------------------------------------------------------------- /examples/hooks/makefile.os4: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: makefile.os4,v 1.2 2005/06/08 06:54:25 damato Exp $ 3 | # 4 | # :ts=4 5 | # 6 | 7 | CC = ppc-amigaos-gcc 8 | 9 | .c.o: 10 | @echo "Compiling $<" 11 | @$(CC) -c $(CFLAGS) -o $*.o $< 12 | 13 | ########################################################################### 14 | 15 | NAME = hellohook 16 | VERSION = 51 17 | 18 | ########################################################################### 19 | 20 | WARNINGS = \ 21 | -Wall -W -Wshadow -Wpointer-arith -Wsign-compare -Wmissing-prototypes \ 22 | -Wundef -Wbad-function-cast -Wmissing-declarations 23 | 24 | CPU = -mcpu=604e -mmultiple 25 | OPTIONS = -DNDEBUG -D__USE_INLINE__ 26 | OPTIMIZE = -O3 -fomit-frame-pointer -fstrength-reduce -finline-functions 27 | DEBUG = -g 28 | 29 | ########################################################################### 30 | 31 | CFLAGS = $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(CPU) $(OPTIONS) -I. \ 32 | -I../../includes 33 | LFLAGS = -L. 34 | 35 | ########################################################################### 36 | 37 | OBJS = \ 38 | example_hookuse.o \ 39 | 40 | LIBS = \ 41 | -lc -lm 42 | 43 | ########################################################################### 44 | 45 | all: $(NAME) 46 | 47 | $(NAME): $(OBJS) 48 | @echo "Linking $@" 49 | @$(CC) -o $@.debug $(CFLAGS) $(LFLAGS) $(OBJS) $(LIBS) 50 | @ppc-amigaos-strip -R.comment -o $@ $@.debug 51 | 52 | ########################################################################### 53 | 54 | example_hookuse.o : example_hookuse.c 55 | 56 | ########################################################################### 57 | 58 | clean: 59 | -rm *.o *.debug $(NAME) 60 | -------------------------------------------------------------------------------- /examples/libraries/example_lib.c: -------------------------------------------------------------------------------- 1 | /* Example source 2 | 3 | Name: example_lib.c 4 | Versionstring: $VER: example_lib.c 1.2 (21.06.2007) 5 | Author: Jens Langner 6 | Distribution: PD 7 | Description: shows how the SDI_lib.h header include can be used 8 | 9 | 1.0 05.10.04 : initial version showing how the SDI_lib.h headers can help 10 | when used for maintaining AmigaOS compatible shared library 11 | interfaces upon compatible operating systems like AmigaOS3, 12 | AmigaOS4 and MorphOS. 13 | 14 | 1.1 20.06.07 : moved LIBFUNC to be first in line acording to changes in 15 | SDI_lib.h. (Guido Mersmann) 16 | 17 | 1.2 21.06.07 : added missing libvector to MorphOS/AmigaOS3 libvectors[] 18 | (Guido Mersmann) 19 | 20 | Please note that this example is just for educational purposes and wasn't 21 | checked for complete correctness. However, it should compile and probably also 22 | work as expected. But please note that its purpose is to show how a shared 23 | library can held platform independent over all different available AmigaOS 24 | platforms like OS3, OS4 and MorphOS. 25 | 26 | Feel free to comment and submit any suggestions directly to 27 | Jens.Langner@light-speed.de 28 | 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include 37 | 38 | #ifdef __amigaos4__ 39 | #include 40 | #endif 41 | 42 | #include 43 | #include 44 | #include 45 | 46 | #include 47 | #include 48 | 49 | #define VERSION 1 50 | #define REVISION 3 51 | #define DATE "01.04.2014" 52 | #define VERS "example.library 1.3" 53 | #define VSTRING "example.library 1.3 01.04.2014)\r\n" 54 | #define VERSTAG "\0$VER: example.library 1.3 01.04.2014)" 55 | 56 | static const char UserLibName[] = "example.library"; 57 | static const char UserLibID[] = "\0$VER: example.library 1.3 01.04.2014)"; 58 | 59 | #if defined(__MORPHOS__) 60 | struct ExecBase *SysBase; 61 | #endif 62 | 63 | /******************************************************************************/ 64 | /* >> User defineable library functions start here << */ 65 | /* The following section should illustrate how the SDI_lib.h macros make it */ 66 | /* possible to easily maintain a typical Amiga shared library interface if */ 67 | /* compatibility over all common (OS3/OS4, MorphOS) is required */ 68 | /******************************************************************************/ 69 | 70 | /******************************************************************************/ 71 | /* Local Structures & Prototypes */ 72 | /******************************************************************************/ 73 | 74 | struct LibraryHeader 75 | { 76 | struct Library libBase; 77 | struct Library *sysBase; 78 | ULONG segList; 79 | }; 80 | 81 | #if defined(__amigaos4__) 82 | #define __BASE_OR_IFACE_TYPE struct ExampleIFace * 83 | #define __BASE_OR_IFACE_VAR IExample 84 | #else 85 | #define __BASE_OR_IFACE_TYPE struct LibraryHeader * 86 | #define __BASE_OR_IFACE_VAR ExampleBase 87 | #endif 88 | #define __BASE_OR_IFACE __BASE_OR_IFACE_TYPE __BASE_OR_IFACE_VAR 89 | 90 | // first the prototypes of all our public library functions 91 | LIBPROTO(SayHelloOS4, char *, REG(a6, UNUSED __BASE_OR_IFACE)); 92 | LIBPROTO(SayHelloOS3, char *, REG(a6, UNUSED __BASE_OR_IFACE)); 93 | LIBPROTO(SayHelloMOS, char *, REG(a6, UNUSED __BASE_OR_IFACE)); 94 | LIBPROTO(Uppercase, char *, REG(a6, UNUSED __BASE_OR_IFACE), REG(a0, char *txt)); 95 | LIBPROTO(SPrintfA, char *, REG(a6, UNUSED __BASE_OR_IFACE), REG(a0, char *buf), REG(a1, char *format), REG(a2, APTR args)); 96 | LIBPROTOVA(SPrintf, char *, REG(a6, UNUSED __BASE_OR_IFACE), REG(a0, char *buf), REG(a1, char *format), ...); 97 | 98 | // let us now create the libvector. 99 | // Please note that the start of the vectors has to be always the "LFUNC_FAS" 100 | // macro 101 | #define libvector LFUNC_FAS(SayHelloOS4) \ 102 | LFUNC_FA_(SayHelloOS3) \ 103 | LFUNC_FA_(SayHelloMOS) \ 104 | LFUNC_FA_(Uppercase) \ 105 | LFUNC_FA_(SPrintfA) \ 106 | LFUNC_VA_(SPrintf) 107 | 108 | // Now the real implementations of the library functions above like in 109 | // a normal AmigaOS shared library follow 110 | LIBPROTO(SayHelloOS4, char *, REG(a6, UNUSED __BASE_OR_IFACE)) 111 | { 112 | return "Hello AmigaOS4!!!"; 113 | } 114 | 115 | LIBPROTO(SayHelloOS3, char *, REG(a6, UNUSED __BASE_OR_IFACE)) 116 | { 117 | return "Hello AmigaOS3!!!"; 118 | } 119 | 120 | LIBPROTO(SayHelloMOS, char *, REG(a6, UNUSED __BASE_OR_IFACE)) 121 | { 122 | return "Hello MorphOS!!!"; 123 | } 124 | 125 | LIBPROTO(Uppercase, char *, REG(a6, UNUSED __BASE_OR_IFACE), REG(a0, char *txt)) 126 | { 127 | char *p = txt; 128 | 129 | while(p) 130 | { 131 | *p = toupper(*p); 132 | p++; 133 | } 134 | 135 | return txt; 136 | } 137 | 138 | LIBPROTO(SPrintfA, char *, REG(a6, UNUSED __BASE_OR_IFACE), REG(a0, char *buf), REG(a1, char *format), REG(a2, APTR args)) 139 | { 140 | RawDoFmt(fmt, args, NULL, buf); 141 | 142 | return(buf); 143 | } 144 | 145 | #if defined(__amigaos4__) 146 | // for AmigaOS4 varargs functions are separate entries in the interface structure and 147 | // hence must be defined as separate functions 148 | LIBPROTOVA(SPrintf, char *, REG(a6, UNUSED __BASE_OR_IFACE), REG(a0, char *buf), REG(a1, char *format), ...) 149 | { 150 | char *ret; 151 | VA_LIST args; 152 | 153 | VA_START(args, format); 154 | // the SPrintf function will be call via the interface 155 | ret = SPrintfA(buf, format, VA_ARG(args, ULONG)); 156 | VA_END(args); 157 | 158 | return(ret); 159 | } 160 | #elif defined(__MORPHOS__) 161 | // define stub functions for all functions in the jump table which take the 162 | // parameters from the emulated 68k registers. The parameters don't need to 163 | // be specified again, because these are really functions taking no direct 164 | // parameters. Only the type of the returned value is required. 165 | LIBSTUB(SayHelloOS4, char *) 166 | { 167 | __BASE_OR_IFACE = (__BASE_OR_IFACE_TYPE)REG_A6; 168 | return CALL_LFUNC_NP(SayHelloOS4); 169 | } 170 | 171 | LIBSTUB(SayHelloOS3, char *) 172 | { 173 | __BASE_OR_IFACE = (__BASE_OR_IFACE_TYPE)REG_A6; 174 | return CALL_LFUNC_NP(SayHelloOS3); 175 | } 176 | 177 | LIBSTUB(SayHelloMOS, char *) 178 | { 179 | __BASE_OR_IFACE = (__BASE_OR_IFACE_TYPE)REG_A6; 180 | return CALL_LFUNC_NP(SayHelloMOS); 181 | } 182 | 183 | LIBSTUB(Uppercase, char *) 184 | { 185 | __BASE_OR_IFACE = (__BASE_OR_IFACE_TYPE)REG_A6; 186 | return CALL_LFUNC(Uppercase, (char *)REG_A0); 187 | } 188 | 189 | LIBSTUB(SPrintfA, char *) 190 | { 191 | __BASE_OR_IFACE = (__BASE_OR_IFACE_TYPE)REG_A6; 192 | return CALL_LFUNC(SprintfA, (char)REG_A0, (char *)REG_A1, (APTR)REG_A2); 193 | } 194 | #endif 195 | 196 | /******************************************************************************/ 197 | /* Starting from here starts the "standard" Amiga library initialization. */ 198 | /* All the above should have illustrated enough how "easy" it is to use the */ 199 | /* SDI_lib.h header file and how it can help in developing a shared library */ 200 | /* for multiple AmigaOS compatible platforms. */ 201 | /******************************************************************************/ 202 | 203 | #if defined(__amigaos4__) 204 | 205 | LIBFUNC static struct LibraryHeader * LibInit (struct LibraryHeader *base, BPTR librarySegment, struct ExecIFace *pIExec); 206 | LIBFUNC static BPTR LibExpunge (struct LibraryManagerInterface *Self); 207 | LIBFUNC static struct LibraryHeader * LibOpen (struct LibraryManagerInterface *Self, ULONG version); 208 | LIBFUNC static BPTR LibClose (struct LibraryManagerInterface *Self); 209 | 210 | #elif defined(__MORPHOS__) 211 | 212 | LIBFUNC static struct LibraryHeader * LibInit (struct LibraryHeader *base, BPTR librarySegment, struct ExecBase *sb); 213 | LIBFUNC static BPTR LibExpunge(void); 214 | LIBFUNC static struct LibraryHeader * LibOpen (void); 215 | LIBFUNC static BPTR LibClose (void); 216 | LIBFUNC static LONG LibNull (void); 217 | 218 | #else 219 | 220 | LIBFUNC static struct LibraryHeader * LibInit (REG(a0, BPTR Segment), REG(d0, struct LibraryHeader *lh), REG(a6, struct ExecBase *sb)); 221 | LIBFUNC static BPTR LibExpunge (REG(a6, struct LibraryHeader *base)); 222 | LIBFUNC static struct LibraryHeader * LibOpen (REG(a6, struct LibraryHeader *base)); 223 | LIBFUNC static BPTR LibClose (REG(a6, struct LibraryHeader *base)); 224 | LIBFUNC static LONG LibNull (void); 225 | 226 | #endif 227 | 228 | /******************************************************************************/ 229 | /* Dummy entry point and LibNull() function all in one */ 230 | /******************************************************************************/ 231 | 232 | #if defined(__amigaos4__) 233 | int _start(void) 234 | #else 235 | int Main(void) 236 | #endif 237 | { 238 | return RETURN_FAIL; 239 | } 240 | 241 | #if !defined(__amigaos4__) 242 | LIBFUNC static LONG LibNull(VOID) 243 | { 244 | return(0); 245 | } 246 | #endif 247 | 248 | /******************************************************************************/ 249 | /* Local data structures */ 250 | /******************************************************************************/ 251 | 252 | #if defined(__amigaos4__) 253 | /* ------------------- OS4 Manager Interface ------------------------ */ 254 | STATIC ULONG LibObtain(struct LibraryManagerInterface *Self) 255 | { 256 | return(Self->Data.RefCount++); 257 | } 258 | 259 | STATIC ULONG LibRelease(struct LibraryManagerInterface *Self) 260 | { 261 | return(Self->Data.RefCount--); 262 | } 263 | 264 | STATIC CONST APTR LibManagerVectors[] = 265 | { 266 | (APTR)LibObtain, 267 | (APTR)LibRelease, 268 | (APTR)NULL, 269 | (APTR)NULL, 270 | (APTR)LibOpen, 271 | (APTR)LibClose, 272 | (APTR)LibExpunge, 273 | (APTR)NULL, 274 | (APTR)-1 275 | }; 276 | 277 | STATIC CONST struct TagItem LibManagerTags[] = 278 | { 279 | {MIT_Name, (ULONG)"__library"}, 280 | {MIT_VectorTable, (ULONG)LibManagerVectors}, 281 | {MIT_Version, 1}, 282 | {TAG_DONE, 0} 283 | }; 284 | 285 | /* ------------------- Library Interface(s) ------------------------ */ 286 | 287 | STATIC CONST APTR LibVectors[] = 288 | { 289 | (APTR)LibObtain, 290 | (APTR)LibRelease, 291 | (APTR)NULL, 292 | (APTR)NULL, 293 | (APTR)libvector, 294 | (APTR)-1 295 | }; 296 | 297 | STATIC CONST struct TagItem MainTags[] = 298 | { 299 | {MIT_Name, (ULONG)"main"}, 300 | {MIT_VectorTable, (ULONG)LibVectors}, 301 | {MIT_Version, 1}, 302 | {TAG_DONE, 0} 303 | }; 304 | 305 | 306 | STATIC CONST ULONG LibInterfaces[] = 307 | { 308 | (ULONG)LibManagerTags, 309 | (ULONG)MainTags, 310 | (ULONG)0 311 | }; 312 | 313 | /* --------------------- m68k Library stubs ------------------------ */ 314 | 315 | STATIC ULONG stub_OpenPPC(ULONG *regarray) 316 | { 317 | struct Library *Base = (struct Library *) regarray[REG68K_A6/4]; 318 | struct ExtendedLibrary *ExtLib = (struct ExtendedLibrary *) ((ULONG)Base + Base->lib_PosSize); 319 | struct LibraryManagerInterface *Self = (struct LibraryManagerInterface *) ExtLib->ILibrary; 320 | 321 | return (ULONG) Self->Open(0); 322 | } 323 | struct EmuTrap stub_Open = { TRAPINST, TRAPTYPE, stub_OpenPPC }; 324 | 325 | STATIC ULONG stub_ClosePPC(ULONG *regarray) 326 | { 327 | struct Library *Base = (struct Library *) regarray[REG68K_A6/4]; 328 | struct ExtendedLibrary *ExtLib = (struct ExtendedLibrary *) ((ULONG)Base + Base->lib_PosSize); 329 | struct LibraryManagerInterface *Self = (struct LibraryManagerInterface *) ExtLib->ILibrary; 330 | 331 | return (ULONG) Self->Close(); 332 | } 333 | struct EmuTrap stub_Close = { TRAPINST, TRAPTYPE, stub_ClosePPC }; 334 | 335 | STATIC ULONG stub_ExpungePPC(ULONG *regarray) 336 | { 337 | return 0UL; 338 | } 339 | struct EmuTrap stub_Expunge = { TRAPINST, TRAPTYPE, stub_ExpungePPC }; 340 | 341 | STATIC ULONG stub_ReservedPPC(ULONG *regarray) 342 | { 343 | return 0UL; 344 | } 345 | struct EmuTrap stub_Reserved = { TRAPINST, TRAPTYPE, stub_ReservedPPC }; 346 | 347 | STATIC ULONG stub_SayHelloOS4PPC(ULONG *regarray) 348 | { 349 | struct Library *Base = (struct Library *) regarray[REG68K_A6/4]; 350 | struct ExtendedLibrary *ExtLib = (struct ExtendedLibrary *) ((ULONG)Base + Base->lib_PosSize); 351 | struct LibraryManagerInterface *Self = (struct LibraryManagerInterface *) ExtLib->ILibrary; 352 | 353 | return (char *)Self->SayHelloOS4(); 354 | } 355 | struct EmuTrap stub_SayHelloOS4 = { TRAPINST, TRAPTYPE, stub_SayHelloOS4PPC }; 356 | 357 | STATIC ULONG stub_SayHelloOS3PPC(ULONG *regarray) 358 | { 359 | struct Library *Base = (struct Library *) regarray[REG68K_A6/4]; 360 | struct ExtendedLibrary *ExtLib = (struct ExtendedLibrary *) ((ULONG)Base + Base->lib_PosSize); 361 | struct LibraryManagerInterface *Self = (struct LibraryManagerInterface *) ExtLib->ILibrary; 362 | 363 | return (char *)Self->SayHelloOS3(); 364 | } 365 | struct EmuTrap stub_SayHelloOS3 = { TRAPINST, TRAPTYPE, stub_SayHelloOS3PPC }; 366 | 367 | STATIC ULONG stub_SayHelloMOSPPC(ULONG *regarray) 368 | { 369 | struct Library *Base = (struct Library *) regarray[REG68K_A6/4]; 370 | struct ExtendedLibrary *ExtLib = (struct ExtendedLibrary *) ((ULONG)Base + Base->lib_PosSize); 371 | struct LibraryManagerInterface *Self = (struct LibraryManagerInterface *) ExtLib->ILibrary; 372 | 373 | return (char *)Self->SayHelloMOS(); 374 | } 375 | struct EmuTrap stub_SayHelloMOS = { TRAPINST, TRAPTYPE, stub_SayHelloMOSPPC }; 376 | 377 | STATIC ULONG stub_UppercasePPC(ULONG *regarray) 378 | { 379 | struct Library *Base = (struct Library *) regarray[REG68K_A6/4]; 380 | struct ExtendedLibrary *ExtLib = (struct ExtendedLibrary *) ((ULONG)Base + Base->lib_PosSize); 381 | struct LibraryManagerInterface *Self = (struct LibraryManagerInterface *) ExtLib->ILibrary; 382 | 383 | return (char *)Self->Uppercase( 384 | (char *)regarray[8] 385 | ); 386 | } 387 | struct EmuTrap stub_Uppercase = { TRAPINST, TRAPTYPE, stub_UppercasePPC }; 388 | 389 | STATIC ULONG stub_SPrintfAPPC(ULONG *regarray) 390 | { 391 | struct Library *Base = (struct Library *) regarray[REG68K_A6/4]; 392 | struct ExtendedLibrary *ExtLib = (struct ExtendedLibrary *) ((ULONG)Base + Base->lib_PosSize); 393 | struct LibraryManagerInterface *Self = (struct LibraryManagerInterface *) ExtLib->ILibrary; 394 | 395 | return (char *)Self->SPrintfA( 396 | (char *)regarray[8], 397 | (char *)regarray[9], 398 | (APTR)regarray[10] 399 | ); 400 | } 401 | struct EmuTrap stub_SPrintfA = { TRAPINST, TRAPTYPE, stub_SPrintfAPPC }; 402 | 403 | STATIC ULONG VecTable68K[] = 404 | { 405 | (ULONG)&stub_Open, 406 | (ULONG)&stub_Close, 407 | (ULONG)&stub_Expunge, 408 | (ULONG)&stub_Reserved, 409 | (ULONG)&stub_SayHelloOS4, 410 | (ULONG)&stub_SayHelloOS3, 411 | (ULONG)&stub_SayHelloMOS, 412 | (ULONG)&stub_Uppercase, 413 | (ULONG)&stub_SprintfA, 414 | (ULONG)-1 415 | }; 416 | 417 | /* ----------------------- LibCreate Tags -------------------------- */ 418 | 419 | STATIC CONST struct TagItem LibCreateTags[] = 420 | { 421 | {CLT_DataSize, (ULONG)(sizeof(struct LibraryHeader))}, 422 | {CLT_InitFunc, (ULONG)LibInit}, 423 | {CLT_Interfaces, (ULONG)LibInterfaces}, 424 | {CLT_Vector68K, (ULONG)VecTable68K}, 425 | {TAG_DONE, 0} 426 | }; 427 | 428 | #else 429 | 430 | STATIC CONST APTR LibVectors[] = 431 | { 432 | #ifdef __MORPHOS__ 433 | (APTR)FUNCARRAY_32BIT_NATIVE, 434 | #endif 435 | (APTR)LibOpen, 436 | (APTR)LibClose, 437 | (APTR)LibExpunge, 438 | (APTR)LibNull, 439 | (APTR)libvector, 440 | (APTR)-1 441 | }; 442 | 443 | STATIC CONST ULONG LibInitTab[] = 444 | { 445 | sizeof(struct LibraryHeader), 446 | (ULONG)LibVectors, 447 | (ULONG)NULL, 448 | (ULONG)LibInit 449 | }; 450 | 451 | #endif 452 | 453 | /* ------------------- ROM Tag ------------------------ */ 454 | static const USED_VAR struct Resident ROMTag = 455 | { 456 | RTC_MATCHWORD, 457 | (struct Resident *)&ROMTag, 458 | (struct Resident *)&ROMTag + 1, 459 | #if defined(__amigaos4__) 460 | RTF_AUTOINIT|RTF_NATIVE, // The Library should be set up according to the given table. 461 | #elif defined(__MORPHOS__) 462 | RTF_AUTOINIT|RTF_PPC, 463 | #else 464 | RTF_AUTOINIT, 465 | #endif 466 | VERSION, 467 | NT_LIBRARY, 468 | 0, 469 | (APTR)UserLibName, 470 | VSTRING, 471 | #if defined(__amigaos4__) 472 | (APTR)LibCreateTags // This table is for initializing the Library. 473 | #else 474 | (APTR)LibInitTab 475 | #endif 476 | }; 477 | 478 | #if defined(__MORPHOS__) 479 | /* 480 | * To tell the loader that this is a new emulppc elf and not 481 | * one for the ppc.library. 482 | * ** IMPORTANT ** 483 | */ 484 | ULONG USED_VAR __amigappc__=1; 485 | ULONG USED_VAR __abox__=1; 486 | 487 | #endif /* __MORPHOS */ 488 | 489 | /******************************************************************************/ 490 | /* Standard Library Functions, all of them are called in Forbid() state. */ 491 | /******************************************************************************/ 492 | 493 | #ifndef __amigaos4__ 494 | #define DeleteLibrary(LIB) \ 495 | FreeMem((STRPTR)(LIB)-(LIB)->lib_NegSize, (ULONG)((LIB)->lib_NegSize+(LIB)->lib_PosSize)) 496 | #endif 497 | 498 | #if defined(__amigaos4__) 499 | static struct LibraryHeader * LibInit(struct LibraryHeader *base, BPTR librarySegment, struct ExecIFace *pIExec) 500 | { 501 | struct ExecBase *sb = (struct ExecBase *)pIExec->Data.LibBase; 502 | IExec = pIExec; 503 | #elif defined(__MORPHOS__) 504 | static struct LibraryHeader * LibInit(struct LibraryHeader *base, BPTR librarySegment, struct ExecBase *sb) 505 | { 506 | #else 507 | LIBFUNC static struct LibraryHeader * LibInit(REG(a0, BPTR librarySegment), REG(d0, struct LibraryHeader *base), REG(a6, struct ExecBase *sb)) 508 | { 509 | #endif 510 | 511 | SysBase = (APTR)sb; 512 | 513 | base->libBase.lib_Node.ln_Type = NT_LIBRARY; 514 | base->libBase.lib_Node.ln_Pri = 0; 515 | base->libBase.lib_Node.ln_Name = (char *)UserLibName; 516 | base->libBase.lib_Flags = LIBF_CHANGED | LIBF_SUMUSED; 517 | base->libBase.lib_Version = VERSION; 518 | base->libBase.lib_Revision = REVISION; 519 | base->libBase.lib_IdString = (char *)UserLibID; 520 | 521 | base->segList = librarySegment; 522 | base->sysBase = (APTR)SysBase; 523 | 524 | return(base); 525 | } 526 | 527 | #if defined(__amigaos4__) 528 | static BPTR LibExpunge(struct LibraryManagerInterface *Self) 529 | { 530 | struct LibraryHeader *base = (struct LibraryHeader *)Self->Data.LibBase; 531 | #elif defined(__MORPHOS__) 532 | static BPTR LibExpunge(void) 533 | { 534 | struct LibraryHeader *base = (struct LibraryHeader*)REG_A6; 535 | #else 536 | LIBFUNC static BPTR LibExpunge(REG(a6, struct LibraryHeader *base)) 537 | { 538 | #endif 539 | BPTR rc; 540 | 541 | if(base->libBase.lib_OpenCnt > 0) 542 | { 543 | base->libBase.lib_Flags |= LIBF_DELEXP; 544 | return(0); 545 | } 546 | 547 | SysBase = (APTR)base->sysBase; 548 | rc = base->segList; 549 | 550 | Remove((struct Node *)base); 551 | DeleteLibrary(&base->libBase); 552 | 553 | return(rc); 554 | } 555 | 556 | #if defined(__amigaos4__) 557 | static struct LibraryHeader *LibOpen(struct LibraryManagerInterface *Self, ULONG version) 558 | { 559 | struct LibraryHeader *base = (struct LibraryHeader *)Self->Data.LibBase; 560 | #elif defined(__MORPHOS__) 561 | static struct LibraryHeader *LibOpen(void) 562 | { 563 | struct LibraryHeader *base = (struct LibraryHeader*)REG_A6; 564 | #else 565 | LIBFUNC static struct LibraryHeader * LibOpen(REG(a6, struct LibraryHeader *base)) 566 | { 567 | #endif 568 | 569 | base->libBase.lib_Flags &= ~LIBF_DELEXP; 570 | base->libBase.lib_OpenCnt++; 571 | 572 | return base; 573 | } 574 | 575 | #if defined(__amigaos4__) 576 | static BPTR LibClose(struct LibraryManagerInterface *Self) 577 | { 578 | struct LibraryHeader *base = (struct LibraryHeader *)Self->Data.LibBase; 579 | #elif defined(__MORPHOS__) 580 | static BPTR LibClose(void) 581 | { 582 | struct LibraryHeader *base = (struct LibraryHeader *)REG_A6; 583 | #else 584 | LIBFUNC static BPTR LibClose(REG(a6, struct LibraryHeader *base)) 585 | { 586 | #endif 587 | 588 | if(base->libBase.lib_OpenCnt > 0 && 589 | --base->libBase.lib_OpenCnt == 0) 590 | { 591 | if(base->libBase.lib_Flags & LIBF_DELEXP) 592 | { 593 | #if defined(__amigaos4__) 594 | return LibExpunge(Self); 595 | #elif defined(__MORPHOS__) 596 | return LibExpunge(); 597 | #else 598 | return LibExpunge(base); 599 | #endif 600 | } 601 | } 602 | 603 | return 0; 604 | } 605 | -------------------------------------------------------------------------------- /examples/libraries/makefile.mos: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: makefile.mos,v 1.2 2005/06/08 06:54:25 damato Exp $ 3 | # 4 | # :ts=4 5 | # 6 | 7 | CC = ppc-morphos-gcc 8 | 9 | .c.o: 10 | @echo "Compiling $<" 11 | @$(CC) -c $(CFLAGS) -o $*.o $< 12 | 13 | ########################################################################### 14 | 15 | NAME = example.library 16 | VERSION = 51 17 | 18 | ########################################################################### 19 | 20 | WARNINGS = \ 21 | -Wall -W -Wshadow -Wpointer-arith -Wsign-compare -Wmissing-prototypes \ 22 | -Wundef -Wbad-function-cast -Wmissing-declarations 23 | 24 | CPU = -mcpu=604e -mmultiple 25 | OPTIONS = -DNDEBUG -D__USE_INLINE__ 26 | OPTIMIZE = -O3 -fomit-frame-pointer -fstrength-reduce -finline-functions 27 | DEBUG = -g 28 | 29 | ########################################################################### 30 | 31 | CFLAGS = $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(CPU) $(OPTIONS) -I. \ 32 | -I../../includes 33 | LFLAGS = -L. 34 | 35 | ########################################################################### 36 | 37 | OBJS = \ 38 | example_lib.o \ 39 | 40 | LIBS = -lstring 41 | 42 | ########################################################################### 43 | 44 | all: $(NAME) 45 | 46 | $(NAME): $(OBJS) 47 | @echo "Linking $@" 48 | @$(CC) -o $@.debug $(CFLAGS) $(LFLAGS) -nostdlib -nostartfiles $(OBJS) $(LIBS) 49 | @ppc-morphos-strip -R.comment -o $@ $@.debug 50 | 51 | ########################################################################### 52 | 53 | example_lib.o : example_lib.c 54 | 55 | ########################################################################### 56 | 57 | clean: 58 | -rm *.o *.debug *.library 59 | -------------------------------------------------------------------------------- /examples/libraries/makefile.os3: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: makefile.os3,v 1.2 2005/06/08 06:54:25 damato Exp $ 3 | # 4 | # :ts=4 5 | # 6 | 7 | CC = m68k-amigaos-gcc 8 | 9 | .c.o: 10 | @echo "Compiling $<" 11 | @$(CC) -c $(CFLAGS) -o $*.o $< 12 | 13 | ########################################################################### 14 | 15 | NAME = example.library 16 | VERSION = 51 17 | 18 | ########################################################################### 19 | 20 | WARNINGS = \ 21 | -Wall -W -Wshadow -Wpointer-arith -Wsign-compare -Wmissing-prototypes \ 22 | -Wundef -Wbad-function-cast -Wmissing-declarations 23 | 24 | CPU = -m68020-60 -msoft-float 25 | OPTIONS = -DNDEBUG -D__USE_INLINE__ 26 | OPTIMIZE = -O3 -fomit-frame-pointer -fstrength-reduce -finline-functions 27 | DEBUG = -g 28 | 29 | ########################################################################### 30 | 31 | CFLAGS = $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(CPU) $(OPTIONS) -I. \ 32 | -I../../includes 33 | LFLAGS = -L. 34 | 35 | ########################################################################### 36 | 37 | OBJS = \ 38 | example_lib.o \ 39 | 40 | LIBS = \ 41 | -lc 42 | 43 | ########################################################################### 44 | 45 | all: $(NAME) 46 | 47 | $(NAME): $(OBJS) 48 | @echo "Linking $@" 49 | @$(CC) -o $@.debug $(CFLAGS) $(LFLAGS) -nostdlib -nostartfiles $(OBJS) $(LIBS) 50 | @m68k-amigaos-strip -R.comment -o $@ $@.debug 51 | 52 | ########################################################################### 53 | 54 | example_lib.o : example_lib.c 55 | 56 | ########################################################################### 57 | 58 | clean: 59 | -rm *.o *.debug *.library 60 | -------------------------------------------------------------------------------- /examples/libraries/makefile.os4: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: makefile.os4,v 1.2 2005/06/08 06:54:25 damato Exp $ 3 | # 4 | # :ts=4 5 | # 6 | 7 | CC = ppc-amigaos-gcc 8 | 9 | .c.o: 10 | @echo "Compiling $<" 11 | @$(CC) -c $(CFLAGS) -o $*.o $< 12 | 13 | ########################################################################### 14 | 15 | NAME = example.library 16 | VERSION = 51 17 | 18 | ########################################################################### 19 | 20 | WARNINGS = \ 21 | -Wall -W -Wshadow -Wpointer-arith -Wsign-compare -Wmissing-prototypes \ 22 | -Wundef -Wbad-function-cast -Wmissing-declarations 23 | 24 | CPU = -mcpu=604e -mmultiple 25 | OPTIONS = -DNDEBUG -D__USE_INLINE__ 26 | OPTIMIZE = -O3 -fomit-frame-pointer -fstrength-reduce -finline-functions 27 | DEBUG = -g 28 | 29 | ########################################################################### 30 | 31 | CFLAGS = $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(CPU) $(OPTIONS) -I. \ 32 | -I../../includes 33 | LFLAGS = -L. 34 | 35 | ########################################################################### 36 | 37 | OBJS = \ 38 | example_lib.o \ 39 | 40 | LIBS = \ 41 | -lc 42 | 43 | ########################################################################### 44 | 45 | all: $(NAME) 46 | 47 | $(NAME): $(OBJS) 48 | @echo "Linking $@" 49 | @$(CC) -o $@.debug $(CFLAGS) $(LFLAGS) -nostdlib -nostartfiles $(OBJS) $(LIBS) 50 | @ppc-amigaos-strip -R.comment -o $@ $@.debug 51 | 52 | ########################################################################### 53 | 54 | example_lib.o : example_lib.c 55 | 56 | ########################################################################### 57 | 58 | clean: 59 | -rm *.o *.debug *.library 60 | -------------------------------------------------------------------------------- /examples/misc/example_miscuse.c: -------------------------------------------------------------------------------- 1 | /* Example source 2 | 3 | Name: example_miscuse.c 4 | Versionstring: $VER: example_miscuse.c 1.0 (17.05.2005) 5 | Author: Guido Mersmann 6 | Distribution: PD 7 | Description: shows how the SDI_misc.h header includes are used 8 | 9 | 1.0 17.05.04 : initial version showing how the SDI_misc.h header have to be 10 | used if one wants to keep the sources platform independent 11 | throughout all common AmigaOS compatible platforms like OS3, 12 | OS4 and MorphOS. 13 | 14 | 15 | Please note that this example is just for educational purposes and wasn't 16 | checked for complete correctness. However, it should compile and probably also 17 | work as expected. But please note that its purpose is to show how the misc 18 | macros make it very easy to deal with those functions and also keep the 19 | sources simple and platform independent through OS3, OS4 and MorphOS. 20 | 21 | Feel free to comment and submit any suggestions directly to 22 | Guido Mersmann 23 | 24 | */ 25 | 26 | #include 27 | #include 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #include "SDI_misc.h" 34 | 35 | 36 | /* 37 | ** 38 | **This structure keeps our internal sprintf vars during RawDoFmt() 39 | ** 40 | */ 41 | 42 | struct SPrintfStream 43 | { 44 | char *Target; 45 | ULONG TargetSize; /* Obsolete in this example, but useful when 46 | dealing with size limited streams */ 47 | }; 48 | 49 | /* 50 | ** SPrintf_DoChar 51 | ** 52 | ** The following function is just an example where we use the object 53 | ** for composing some minor text. Do you see how easy it is to use and 54 | ** how great it is to use SDI_misc.h to automatically keep your sources 55 | ** compatible to all common AmigaOS platforms? 56 | ** 57 | */ 58 | 59 | PUTCHARPROTO( SPrintf_DoChar, char c, struct SPrintfStream *s ) 60 | { 61 | *(s->Target++) = c; 62 | } 63 | 64 | /* 65 | ** 66 | ** SPrintf 67 | ** 68 | ** Here you can see how the function is used by the ENTRY() function. 69 | ** 70 | */ 71 | 72 | ULONG SPrintf( char *format, char *target, ULONG *args ); 73 | ULONG SPrintf( char *format, char *target, ULONG *args ) 74 | { 75 | struct SPrintfStream s; 76 | 77 | s.Target = target; 78 | 79 | RawDoFmt( format, args, ENTRY( SPrintf_DoChar ), &s); 80 | 81 | return( s.Target - target ); 82 | } 83 | 84 | /* 85 | ** 86 | ** The main entry point 87 | ** 88 | */ 89 | 90 | int main(void) 91 | { 92 | char buf[0x80]; /* storage for keeping the SPrintf result string */ 93 | ULONG args[2]; /* storage for keeping the SPrintf arguments */ 94 | 95 | args[0] = (ULONG) "result"; 96 | args[1] = (ULONG) "PUTCHARPROTO macro"; 97 | 98 | SPrintf("I am the %s of using SPrintf() with the new %s!", buf, args); 99 | 100 | printf("%s\n", buf); /* just a simple printf to output and add the \n */ 101 | 102 | return( 0); 103 | } 104 | 105 | 106 | -------------------------------------------------------------------------------- /examples/misc/makefile.mos: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: makefile.mos,v 1.1 2005/06/08 06:54:25 damato Exp $ 3 | # 4 | # :ts=4 5 | # 6 | 7 | CC = ppc-morphos-gcc 8 | 9 | .c.o: 10 | @echo "Compiling $<" 11 | @$(CC) -c $(CFLAGS) -o $*.o $< 12 | 13 | ########################################################################### 14 | 15 | NAME = hellomisc 16 | VERSION = 51 17 | 18 | ########################################################################### 19 | 20 | WARNINGS = \ 21 | -Wall -W -Wshadow -Wpointer-arith -Wsign-compare -Wmissing-prototypes \ 22 | -Wundef -Wbad-function-cast -Wmissing-declarations 23 | 24 | CPU = -mcpu=604e -mmultiple 25 | OPTIONS = -DNDEBUG -D__USE_INLINE__ 26 | OPTIMIZE = -O3 -fomit-frame-pointer -fstrength-reduce -finline-functions 27 | DEBUG = -g 28 | 29 | ########################################################################### 30 | 31 | CFLAGS = -noixemul $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(CPU) $(OPTIONS) -I. \ 32 | -I../../includes 33 | LFLAGS = -L. 34 | 35 | ########################################################################### 36 | 37 | OBJS = \ 38 | example_miscuse.o \ 39 | 40 | LIBS = 41 | 42 | ########################################################################### 43 | 44 | all: $(NAME) 45 | 46 | $(NAME): $(OBJS) 47 | @echo "Linking $@" 48 | @$(CC) -o $@.debug $(CFLAGS) $(LFLAGS) $(OBJS) $(LIBS) 49 | @ppc-morphos-strip -R.comment -o $@ $@.debug 50 | 51 | ########################################################################### 52 | 53 | example_miscuse.o : example_miscuse.c 54 | 55 | ########################################################################### 56 | 57 | clean: 58 | -rm *.o *.debug $(NAME) 59 | -------------------------------------------------------------------------------- /examples/misc/makefile.os3: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: makefile.os3,v 1.1 2005/06/08 06:54:25 damato Exp $ 3 | # 4 | # :ts=4 5 | # 6 | 7 | CC = m68k-amigaos-gcc 8 | 9 | .c.o: 10 | @echo "Compiling $<" 11 | @$(CC) -c $(CFLAGS) -o $*.o $< 12 | 13 | ########################################################################### 14 | 15 | NAME = hellomisc 16 | VERSION = 51 17 | 18 | ########################################################################### 19 | 20 | WARNINGS = \ 21 | -Wall -W -Wshadow -Wpointer-arith -Wsign-compare -Wmissing-prototypes \ 22 | -Wundef -Wbad-function-cast -Wmissing-declarations 23 | 24 | CPU = -m68020-60 -msoft-float 25 | OPTIONS = -DNDEBUG -D__USE_INLINE__ 26 | OPTIMIZE = -O3 -fomit-frame-pointer -fstrength-reduce -finline-functions 27 | DEBUG = -g 28 | 29 | ########################################################################### 30 | 31 | CFLAGS = -noixemul $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(CPU) $(OPTIONS) -I. \ 32 | -I../../includes 33 | LFLAGS = -L. 34 | 35 | ########################################################################### 36 | 37 | OBJS = \ 38 | example_miscuse.o \ 39 | 40 | LIBS = \ 41 | -lc 42 | 43 | ########################################################################### 44 | 45 | all: $(NAME) 46 | 47 | $(NAME): $(OBJS) 48 | @echo "Linking $@" 49 | @$(CC) -o $@.debug $(CFLAGS) $(LFLAGS) $(OBJS) $(LIBS) 50 | @m68k-amigaos-strip -R.comment -o $@ $@.debug 51 | 52 | ########################################################################### 53 | 54 | example_miscuse.o : example_miscuse.c 55 | 56 | ########################################################################### 57 | 58 | clean: 59 | -rm *.o *.debug $(NAME) 60 | -------------------------------------------------------------------------------- /examples/misc/makefile.os4: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: makefile.os4,v 1.1 2005/06/08 06:54:25 damato Exp $ 3 | # 4 | # :ts=4 5 | # 6 | 7 | CC = ppc-amigaos-gcc 8 | 9 | .c.o: 10 | @echo "Compiling $<" 11 | @$(CC) -c $(CFLAGS) -o $*.o $< 12 | 13 | ########################################################################### 14 | 15 | NAME = hellomisc 16 | VERSION = 51 17 | 18 | ########################################################################### 19 | 20 | WARNINGS = \ 21 | -Wall -W -Wshadow -Wpointer-arith -Wsign-compare -Wmissing-prototypes \ 22 | -Wundef -Wbad-function-cast -Wmissing-declarations 23 | 24 | CPU = -mcpu=604e -mmultiple 25 | OPTIONS = -DNDEBUG -D__USE_INLINE__ 26 | OPTIMIZE = -O3 -fomit-frame-pointer -fstrength-reduce -finline-functions 27 | DEBUG = -g 28 | 29 | ########################################################################### 30 | 31 | CFLAGS = $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(CPU) $(OPTIONS) -I. \ 32 | -I../../includes 33 | LFLAGS = -L. 34 | 35 | ########################################################################### 36 | 37 | OBJS = \ 38 | example_miscuse.o \ 39 | 40 | LIBS = \ 41 | -lc -lm 42 | 43 | ########################################################################### 44 | 45 | all: $(NAME) 46 | 47 | $(NAME): $(OBJS) 48 | @echo "Linking $@" 49 | @$(CC) -o $@.debug $(CFLAGS) $(LFLAGS) $(OBJS) $(LIBS) 50 | @ppc-amigaos-strip -R.comment -o $@ $@.debug 51 | 52 | ########################################################################### 53 | 54 | example_miscuse.o : example_miscuse.c 55 | 56 | ########################################################################### 57 | 58 | clean: 59 | -rm *.o *.debug $(NAME) 60 | -------------------------------------------------------------------------------- /examples/varargs/example_varargs.c: -------------------------------------------------------------------------------- 1 | /* Example source 2 | 3 | Name: example_varargs.c 4 | Versionstring: $VER: example_varargs.c 1.0 (06.10.2004) 5 | Author: Jens Langner 6 | Distribution: PD 7 | Description: shows how the SDI_stdarg.h header include are used 8 | 9 | 1.0 06.10.04 : initial version showing how the SDI_stdarg.h header have to be 10 | used if one wants to keep the sources platform independent 11 | throughout all common AmigaOS compatible platforms like OS3, 12 | OS4 and MorphOS, because all of those systems have a slightly 13 | different way to deal with variable argument functions. 14 | 15 | 16 | Please note that this example is just for educational purposes and wasn't 17 | checked for complete correctness. However, it should compile and probably also 18 | work as expected. But please note that its purpose is to show how the varargs 19 | macros make it very easy to deal with variable argument based functions and also 20 | keep the sources simple and platform independent through OS3, OS4 and MorphOS. 21 | 22 | Feel free to comment and submit any suggestions directly to 23 | Jens.Langner@light-speed.de 24 | 25 | */ 26 | 27 | #include 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #include "SDI_stdarg.h" 34 | 35 | /******************************************************************************/ 36 | /* Example of a variable argument based function which is automatically */ 37 | /* compatible to varargs definitions of AmigaOS3, AmigaOS4 and MorphOS... */ 38 | /******************************************************************************/ 39 | 40 | static int STDARGS VARARGS68K MySPrintf(char *buf, char *fmt, ...) 41 | { 42 | VA_LIST args; 43 | 44 | VA_START(args, fmt); 45 | RawDoFmt(fmt, VA_ARG(args, void *), NULL, buf); 46 | VA_END(args); 47 | 48 | return(strlen(buf)); 49 | } 50 | 51 | /******************************************************************************/ 52 | /* The main entry point to just illustrate how the varargs function is called */ 53 | /******************************************************************************/ 54 | 55 | int main(void) 56 | { 57 | char buf[256]; 58 | char *type = "portable varargs"; 59 | LONG ret; 60 | 61 | ret = MySPrintf(buf, "This is a '%s' function", type); 62 | 63 | printf("%s returning %d\n", buf, ret); 64 | 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /examples/varargs/makefile.mos: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: makefile.mos,v 1.2 2005/06/08 06:54:25 damato Exp $ 3 | # 4 | # :ts=4 5 | # 6 | 7 | CC = ppc-morphos-gcc 8 | 9 | .c.o: 10 | @echo "Compiling $<" 11 | @$(CC) -c $(CFLAGS) -o $*.o $< 12 | 13 | ########################################################################### 14 | 15 | NAME = hello_varargs 16 | VERSION = 51 17 | 18 | ########################################################################### 19 | 20 | WARNINGS = \ 21 | -Wall -W -Wshadow -Wpointer-arith -Wsign-compare -Wmissing-prototypes \ 22 | -Wundef -Wbad-function-cast -Wmissing-declarations 23 | 24 | CPU = -mcpu=604e -mmultiple 25 | OPTIONS = -DNDEBUG -D__USE_INLINE__ 26 | OPTIMIZE = -O3 -fomit-frame-pointer -fstrength-reduce -finline-functions 27 | DEBUG = -g 28 | 29 | ########################################################################### 30 | 31 | CFLAGS = -noixemul $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(CPU) $(OPTIONS) -I. \ 32 | -I../../includes 33 | LFLAGS = -L. 34 | 35 | ########################################################################### 36 | 37 | OBJS = \ 38 | example_varargs.o \ 39 | 40 | LIBS = \ 41 | -lstring 42 | 43 | ########################################################################### 44 | 45 | all: $(NAME) 46 | 47 | $(NAME): $(OBJS) 48 | @echo "Linking $@" 49 | @$(CC) -o $@.debug $(CFLAGS) $(LFLAGS) $(OBJS) $(LIBS) 50 | @ppc-morphos-strip -R.comment -o $@ $@.debug 51 | 52 | ########################################################################### 53 | 54 | example_varargs.o : example_varargs.c 55 | 56 | ########################################################################### 57 | 58 | clean: 59 | -rm *.o *.debug $(NAME) 60 | -------------------------------------------------------------------------------- /examples/varargs/makefile.os3: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: makefile.os3,v 1.2 2005/06/08 06:54:25 damato Exp $ 3 | # 4 | # :ts=4 5 | # 6 | 7 | CC = m68k-amigaos-gcc 8 | 9 | .c.o: 10 | @echo "Compiling $<" 11 | @$(CC) -c $(CFLAGS) -o $*.o $< 12 | 13 | ########################################################################### 14 | 15 | NAME = hello_varargs 16 | VERSION = 51 17 | 18 | ########################################################################### 19 | 20 | WARNINGS = \ 21 | -Wall -W -Wshadow -Wpointer-arith -Wsign-compare -Wmissing-prototypes \ 22 | -Wundef -Wbad-function-cast -Wmissing-declarations 23 | 24 | CPU = -m68020-60 -msoft-float 25 | OPTIONS = -DNDEBUG -D__USE_INLINE__ 26 | OPTIMIZE = -O3 -fomit-frame-pointer -fstrength-reduce -finline-functions 27 | DEBUG = -g 28 | 29 | ########################################################################### 30 | 31 | CFLAGS = -noixemul $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(CPU) $(OPTIONS) -I. \ 32 | -I../../includes 33 | LFLAGS = -L. 34 | 35 | ########################################################################### 36 | 37 | OBJS = \ 38 | example_varargs.o \ 39 | 40 | LIBS = \ 41 | -lc 42 | 43 | ########################################################################### 44 | 45 | all: $(NAME) 46 | 47 | $(NAME): $(OBJS) 48 | @echo "Linking $@" 49 | @$(CC) -o $@.debug $(CFLAGS) $(LFLAGS) $(OBJS) $(LIBS) 50 | @m68k-amigaos-strip -R.comment -o $@ $@.debug 51 | 52 | ########################################################################### 53 | 54 | example_varargs.o : example_varargs.c 55 | 56 | ########################################################################### 57 | 58 | clean: 59 | -rm *.o *.debug $(NAME) 60 | -------------------------------------------------------------------------------- /examples/varargs/makefile.os4: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: makefile.os4,v 1.2 2005/06/08 06:54:25 damato Exp $ 3 | # 4 | # :ts=4 5 | # 6 | 7 | CC = ppc-amigaos-gcc 8 | 9 | .c.o: 10 | @echo "Compiling $<" 11 | @$(CC) -c $(CFLAGS) -o $*.o $< 12 | 13 | ########################################################################### 14 | 15 | NAME = hello_varargs 16 | VERSION = 51 17 | 18 | ########################################################################### 19 | 20 | WARNINGS = \ 21 | -Wall -W -Wshadow -Wpointer-arith -Wsign-compare -Wmissing-prototypes \ 22 | -Wundef -Wbad-function-cast -Wmissing-declarations 23 | 24 | CPU = -mcpu=604e -mmultiple 25 | OPTIONS = -DNDEBUG -D__USE_INLINE__ 26 | OPTIMIZE = -O3 -fomit-frame-pointer -fstrength-reduce -finline-functions 27 | DEBUG = -g 28 | 29 | ########################################################################### 30 | 31 | CFLAGS = $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(CPU) $(OPTIONS) -I. \ 32 | -I../../includes 33 | LFLAGS = -L. 34 | 35 | ########################################################################### 36 | 37 | OBJS = \ 38 | example_varargs.o \ 39 | 40 | LIBS = \ 41 | -lc -lm 42 | 43 | ########################################################################### 44 | 45 | all: $(NAME) 46 | 47 | $(NAME): $(OBJS) 48 | @echo "Linking $@" 49 | @$(CC) -o $@.debug $(CFLAGS) $(LFLAGS) $(OBJS) $(LIBS) 50 | @ppc-amigaos-strip -R.comment -o $@ $@.debug 51 | 52 | ########################################################################### 53 | 54 | example_varargs.o : example_varargs.c 55 | 56 | ########################################################################### 57 | 58 | clean: 59 | -rm *.o *.debug $(NAME) 60 | --------------------------------------------------------------------------------