3 Copyright (C) 2009-2010 Borut Razem
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 3, or (at your option) any
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
28 #define NELEM(x) (sizeof (x) / sizeof (x)[0])
32 static enum sdld_target_e target
= TARGET_ID_UNKNOWN
;
36 *program_name (char *path
)
39 static char fname
[_MAX_FNAME
];
42 _splitpath (path
, NULL
, NULL
, fname
, NULL
);
43 /* convert it to lower case:
44 on DOS and Windows 9x the file name in argv[0] is uppercase */
45 for (p
= fname
; '\0' != *p
; ++p
)
49 return basename (path
);
59 fprintf(stderr
, "sdld_init not called!\n");
66 sdld_init (char *path
)
70 enum sdld_target_e target
;
72 { "gb", TARGET_ID_GB
, },
73 { "z80", TARGET_ID_Z80
, },
74 { "z180", TARGET_ID_Z180
, },
75 { "8051", TARGET_ID_8051
, },
76 { "6808", TARGET_ID_6808
, },
77 { "stm8", TARGET_ID_STM8
, },
78 { "pdk", TARGET_ID_PDK
, },
79 { "f8", TARGET_ID_F8
, },
83 char *progname
= program_name (path
);
84 if ((sdld
= (strncmp(progname
, "sdld", 4) == 0)) != 0)
86 /* exception: sdld is 8051 linker */
87 if (progname
[4] == '\0')
88 target
= TARGET_ID_8051
;
91 for (i
= 0; i
< NELEM (tgt
); ++i
)
93 if (strstr(progname
, tgt
[i
].str
))
95 target
= tgt
[i
].target
;
101 /* diagnostic message */
102 if (getenv ("SDLD_DIAG"))
104 printf ("sdld path: %s\n", path
);
105 printf ("is sdld: %d\n", sdld
);
107 printf ("sdld target: %s\n", (i
>= NELEM (tgt
)) ? "8051" : tgt
[i
].str
);
121 set_sdld_target(enum sdld_target_e trgt
)
128 get_sdld_target(void)
136 is_sdld_target_z80_like(void)
139 return target
== TARGET_ID_Z80
|| target
== TARGET_ID_Z180
|| target
== TARGET_ID_GB
;
144 is_sdld_target_8051_like(void)
147 return target
== TARGET_ID_8051
;