[d47e6f] | 1 | /**************************************** |
---|
| 2 | * Computer Algebra System SINGULAR * |
---|
| 3 | ****************************************/ |
---|
[341696] | 4 | /* $Id$ */ |
---|
[d47e6f] | 5 | /* |
---|
| 6 | * ABSTRACT: lib parsing |
---|
| 7 | */ |
---|
| 8 | |
---|
[dbd017] | 9 | #include <stdlib.h> |
---|
| 10 | #include <sys/stat.h> |
---|
| 11 | #include <sys/types.h> |
---|
| 12 | #include <fcntl.h> |
---|
| 13 | #include <unistd.h> |
---|
| 14 | |
---|
[d47e6f] | 15 | #include <regex.h> |
---|
| 16 | |
---|
| 17 | #include "modgen.h" |
---|
| 18 | #include "typmap.h" |
---|
| 19 | #include "pathnames.h" |
---|
| 20 | |
---|
[955a2b] | 21 | extern char* inst_dir; |
---|
| 22 | |
---|
[664898] | 23 | extern void mod_create_makefile(moddefv module); |
---|
| 24 | extern void build_head_section(FILE *fp, moddefv module); |
---|
| 25 | extern void build_clean_section(FILE *fp, moddefv module); |
---|
| 26 | extern void build_install_section(FILE *fp, moddefv module); |
---|
| 27 | extern void build_compile_section(FILE *fp, moddefv module); |
---|
| 28 | |
---|
[cbe9af8] | 29 | extern int do_create_srcdir; |
---|
| 30 | |
---|
[d47e6f] | 31 | static char *object_name(char *p); |
---|
[664898] | 32 | /*========================================================================*/ |
---|
| 33 | /* |
---|
| 34 | run mod_create_makefile(); |
---|
[cff7cec] | 35 | |
---|
[664898] | 36 | */ |
---|
| 37 | /*========================================================================*/ |
---|
[d47e6f] | 38 | |
---|
| 39 | |
---|
| 40 | /*========================================================================*/ |
---|
| 41 | void mod_create_makefile(moddefv module) |
---|
| 42 | { |
---|
| 43 | FILE *fp; |
---|
[b8856f] | 44 | |
---|
[5922b4] | 45 | if(module->targetname==NULL) |
---|
| 46 | { |
---|
| 47 | module->targetname = (char *)malloc(strlen(module->name)+1); |
---|
| 48 | memset(module->targetname, '\0', strlen(module->name)+1); |
---|
| 49 | memcpy(module->targetname,module->name,strlen(module->name)); |
---|
| 50 | } |
---|
[cbe9af8] | 51 | if(do_create_srcdir) mkdir(module->name, 0755); |
---|
[b8856f] | 52 | fp = fopen(build_filename(module, "Makefile", 0), "w"); |
---|
[d47e6f] | 53 | cfilesv cf = module->files; |
---|
| 54 | int i; |
---|
[cff7cec] | 55 | |
---|
[014db1] | 56 | if(trace)printf("Creating Makefile ...");fflush(stdout); |
---|
[d47e6f] | 57 | write_header(fp, module->name, "#"); |
---|
| 58 | build_head_section(fp, module); |
---|
[664898] | 59 | fprintf(fp, "SRCS\t= %s.cc", module->name); |
---|
[cff7cec] | 60 | |
---|
[d47e6f] | 61 | for(i=0; i<module->filecnt; i++) |
---|
[664898] | 62 | fprintf(fp, " %s", cf[i].filename); |
---|
[d47e6f] | 63 | |
---|
[664898] | 64 | fprintf(fp, "\nOBJS\t= %s.o", module->name); |
---|
[58933c] | 65 | for(i=0; i<module->filecnt; i++) |
---|
| 66 | fprintf(fp, " %s", object_name(cf[i].filename)); |
---|
| 67 | fprintf(fp, "\nDOBJS\t= %s.og", module->name); |
---|
[d47e6f] | 68 | for(i=0; i<module->filecnt; i++) |
---|
[664898] | 69 | fprintf(fp, " %s", object_name(cf[i].filename)); |
---|
[d47e6f] | 70 | |
---|
| 71 | fprintf(fp, "\n\n"); |
---|
| 72 | build_compile_section(fp, module); |
---|
| 73 | build_clean_section(fp, module); |
---|
| 74 | build_install_section(fp, module); |
---|
[cff7cec] | 75 | |
---|
[d47e6f] | 76 | fprintf(fp, "\n"); |
---|
| 77 | fprintf(fp, "\n"); |
---|
| 78 | |
---|
| 79 | fclose(fp); |
---|
[014db1] | 80 | if(trace)printf(" done.\n"); |
---|
[d47e6f] | 81 | } |
---|
| 82 | |
---|
| 83 | /*========================================================================*/ |
---|
| 84 | void build_head_section( |
---|
| 85 | FILE *fp, |
---|
| 86 | moddefv module |
---|
| 87 | ) |
---|
| 88 | { |
---|
| 89 | fprintf(fp, "CC\t= gcc\n"); |
---|
| 90 | fprintf(fp, "CXX\t= gcc\n"); |
---|
[2649c5] | 91 | fprintf(fp, "SINGULARROOT\t= ../..\n"); |
---|
[7e13d4] | 92 | fprintf(fp, "SINGUNAME\t= %s\n",SINGUNAME); |
---|
[c94e823] | 93 | #warning "PROBLEM: nice place for include file has to be found" |
---|
[5e7ae8] | 94 | fprintf(fp, "CFLAGS\t= -DNDEBUG -DBUILD_MODULE -I. -I${SINGULARROOT} -I${SINGULARROOT}/${SINGUNAME}/include\n"); |
---|
| 95 | fprintf(fp, "DCFLAGS\t= -DBUILD_MODULE -I. -I${SINGULARROOT} -I${SINGULARROOT}/${SINGUNAME}/include\n"); |
---|
[d47e6f] | 96 | fprintf(fp, "#LD\t=\n"); |
---|
| 97 | fprintf(fp, "\n"); |
---|
[955a2b] | 98 | fprintf(fp, "instdir = %s\n", inst_dir ); |
---|
[5e7ae8] | 99 | fprintf(fp, "MKINSTALLDIRS\t\t= ${SINGULARROOT}/dyn_modules/mkinstalldirs\n"); |
---|
[c94e823] | 100 | #warning "PROBLEM: do we also install install-sh when installing Singular?" |
---|
[2649c5] | 101 | fprintf(fp, "INSTALL\t\t= ${SINGULARROOT}/Singular/install-sh -c\n"); |
---|
[d47e6f] | 102 | fprintf(fp, "INSTALL_PROGRAM\t= ${INSTALL}\n"); |
---|
| 103 | fprintf(fp, "INSTALL_DATA\t= ${INSTALL} -m 644\n"); |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | /*========================================================================*/ |
---|
| 107 | void build_clean_section( |
---|
| 108 | FILE *fp, |
---|
| 109 | moddefv module |
---|
| 110 | ) |
---|
| 111 | { |
---|
| 112 | fprintf(fp, "clean:\n"); |
---|
[58933c] | 113 | fprintf(fp, "\trm -f *.o *.og *.lo *.so* *.sl *.la *~ core\n\n"); |
---|
[cff7cec] | 114 | |
---|
[d47e6f] | 115 | fprintf(fp, "distclean: clean\n"); |
---|
[cff7cec] | 116 | fprintf(fp, "\trm -f %s.cc %s.h Makefile *.bin *.pl\n\n", |
---|
[909887] | 117 | module->name, module->name); |
---|
[d47e6f] | 118 | } |
---|
| 119 | |
---|
| 120 | /*========================================================================*/ |
---|
| 121 | void build_install_section( |
---|
| 122 | FILE *fp, |
---|
| 123 | moddefv module |
---|
| 124 | ) |
---|
| 125 | { |
---|
[cff7cec] | 126 | fprintf(fp, "install bindist: all\n"); |
---|
[955a2b] | 127 | fprintf(fp, "\t${MKINSTALLDIRS} ${instdir}\n"); |
---|
[a71c43] | 128 | fprintf(fp, "\t${MKINSTALLDIRS} ${instdir}/MOD\n"); |
---|
| 129 | fprintf(fp, "\t${INSTALL_PROGRAM} %s.so ${instdir}/MOD/%s.so\n", |
---|
[5922b4] | 130 | module->targetname, module->targetname); |
---|
[a71c43] | 131 | fprintf(fp, "\t${INSTALL_PROGRAM} %s.bin ${instdir}/MOD/%s.bin\n", |
---|
[909887] | 132 | module->targetname, module->targetname); |
---|
[cff7cec] | 133 | fprintf(fp, "install-bindist: all\n"); |
---|
[2bd8f3] | 134 | fprintf(fp, "\t${MKINSTALLDIRS} ${install_bindir}\n"); |
---|
| 135 | fprintf(fp, "\t${INSTALL_PROGRAM} %s.so ${install_bindir}/%s.so\n", |
---|
| 136 | module->targetname, module->targetname); |
---|
| 137 | fprintf(fp, "\t${INSTALL_PROGRAM} %s.bin ${install_bindir}/%s.bin\n", |
---|
| 138 | module->targetname, module->targetname); |
---|
[d47e6f] | 139 | } |
---|
| 140 | |
---|
| 141 | /*========================================================================*/ |
---|
| 142 | static char *object_name(char *p) |
---|
| 143 | { |
---|
| 144 | char *q = (char *)strrchr(p, '.'); |
---|
| 145 | if(q==NULL) return ""; |
---|
| 146 | *q = '\0'; |
---|
| 147 | char *r = (char *)malloc(strlen(p)+4); |
---|
| 148 | sprintf(r, "%s.o", p); |
---|
[cff7cec] | 149 | |
---|
[d47e6f] | 150 | *q = '.'; |
---|
| 151 | return(r); |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | /*========================================================================*/ |
---|
| 155 | /*=== Machine depend Makefile creation ===*/ |
---|
| 156 | /*========================================================================*/ |
---|
[21e48b] | 157 | #if defined(ix86_Linux) |
---|
| 158 | #define HAVE_ELF_SYSTEM |
---|
| 159 | #endif |
---|
| 160 | |
---|
| 161 | #if defined(ix86_Linux_libc5) |
---|
| 162 | #define HAVE_ELF_SYSTEM |
---|
| 163 | #endif |
---|
| 164 | |
---|
| 165 | #if defined(ix86_freebsd) |
---|
| 166 | #define HAVE_ELF_SYSTEM |
---|
| 167 | #endif |
---|
| 168 | |
---|
| 169 | #if defined(x86_64_Linux) |
---|
| 170 | #define HAVE_ELF_SYSTEM |
---|
| 171 | #endif |
---|
| 172 | |
---|
| 173 | #if defined(IRIX_6) |
---|
| 174 | #define HAVE_ELF_SYSTEM |
---|
| 175 | #endif |
---|
| 176 | |
---|
| 177 | #if defined(sparc64_Linux) |
---|
| 178 | #define HAVE_ELF_SYSTEM |
---|
| 179 | #endif |
---|
| 180 | |
---|
| 181 | #if defined(IA64_Linux) |
---|
| 182 | #define HAVE_ELF_SYSTEM |
---|
| 183 | #endif |
---|
| 184 | |
---|
| 185 | #if defined(DecAlpha_Linux) |
---|
| 186 | #define HAVE_ELF_SYSTEM |
---|
| 187 | #endif |
---|
| 188 | |
---|
| 189 | #if defined(ppc_Linux) |
---|
| 190 | #define HAVE_ELF_SYSTEM |
---|
| 191 | #endif |
---|
| 192 | |
---|
| 193 | #if defined(HAVE_ELF_SYSTEM) |
---|
[d47e6f] | 194 | void build_compile_section( |
---|
| 195 | FILE *fp, |
---|
| 196 | moddefv module |
---|
| 197 | ) |
---|
| 198 | { |
---|
[5922b4] | 199 | fprintf(fp, "all:\t%s.so %s_g.so \n", module->targetname, module->targetname); |
---|
[d47e6f] | 200 | fprintf(fp, "\n"); |
---|
| 201 | fprintf(fp, "%%.o: %%.cc Makefile\n"); |
---|
| 202 | fprintf(fp, "\t${CC} ${CFLAGS} -c -fPIC -DPIC $< -o $*.o\n"); |
---|
| 203 | fprintf(fp, "\n"); |
---|
[58933c] | 204 | fprintf(fp, "%%.og: %%.cc Makefile\n"); |
---|
[7b7f4ba] | 205 | fprintf(fp, "\t${CC} ${DCFLAGS} -g -c -fPIC -DPIC $< -o $*.og\n"); |
---|
[58933c] | 206 | fprintf(fp, "\n"); |
---|
[cff7cec] | 207 | |
---|
[5922b4] | 208 | fprintf(fp, "%s.so: ${OBJS}\n", module->targetname); |
---|
[d47e6f] | 209 | fprintf(fp, "\t${CC} ${CFLAGS} -shared -Wl,-soname -Wl,%s.so.%d \\\n", |
---|
[5922b4] | 210 | module->targetname, module->major); |
---|
| 211 | fprintf(fp, "\t\t-o %s.so.%d.%d.%d ${OBJS}\n", module->targetname, |
---|
[d47e6f] | 212 | module->major, module->minor, module->level); |
---|
[5922b4] | 213 | fprintf(fp, "\trm -f %s.so\n", module->targetname); |
---|
| 214 | fprintf(fp, "\tln -s %s.so.%d.%d.%d %s.so\n", module->targetname, module->major, |
---|
| 215 | module->minor, module->level, module->targetname); |
---|
[d47e6f] | 216 | fprintf(fp, "\n"); |
---|
[58933c] | 217 | |
---|
[5922b4] | 218 | fprintf(fp, "%s_g.so: ${DOBJS}\n", module->targetname); |
---|
[58933c] | 219 | fprintf(fp, "\t${CC} ${DCFLAGS} -shared -Wl,-soname -Wl,%s_g.so.%d \\\n", |
---|
[5922b4] | 220 | module->targetname, module->major); |
---|
| 221 | fprintf(fp, "\t\t-o %s_g.so.%d.%d.%d ${DOBJS}\n", module->targetname, |
---|
[58933c] | 222 | module->major, module->minor, module->level); |
---|
[5922b4] | 223 | fprintf(fp, "\trm -f %s_g.so\n", module->targetname); |
---|
[cff7cec] | 224 | fprintf(fp, "\tln -s %s_g.so.%d.%d.%d %s_g.so\n", module->targetname, |
---|
[5922b4] | 225 | module->major, module->minor, module->level, module->targetname); |
---|
[58933c] | 226 | fprintf(fp, "\n"); |
---|
[d47e6f] | 227 | } |
---|
| 228 | |
---|
| 229 | /*========================================================================*/ |
---|
[21e48b] | 230 | #else |
---|
[d47e6f] | 231 | #if defined(HPUX_9) || defined(HPUX_10) |
---|
| 232 | void build_compile_section( |
---|
| 233 | FILE *fp, |
---|
| 234 | moddefv module |
---|
| 235 | ) |
---|
| 236 | { |
---|
[5922b4] | 237 | fprintf(fp, "all:\t%s.sl\n", module->targetname); |
---|
[d47e6f] | 238 | fprintf(fp, "\n"); |
---|
| 239 | fprintf(fp, "%%.o: %%.cc Makefile\n"); |
---|
| 240 | fprintf(fp, "\t${CC} ${CFLAGS} -c -fPIC -DPIC $< -o $*.o\n"); |
---|
| 241 | fprintf(fp, "\n"); |
---|
[5922b4] | 242 | fprintf(fp, "%s.sl: ${OBJS}\n", module->targetname); |
---|
| 243 | fprintf(fp, "\t${LD} -b -o %s.sl \\\n", module->targetname); |
---|
[d47e6f] | 244 | fprintf(fp, "\t\t${OBJS}\n"); |
---|
| 245 | } |
---|
| 246 | |
---|
[21e48b] | 247 | #else /* HPUX_9 or HPUX_10 */ |
---|
[d47e6f] | 248 | /*========================================================================*/ |
---|
| 249 | void build_compile_section( |
---|
| 250 | FILE *fp, |
---|
| 251 | moddefv module |
---|
| 252 | ) |
---|
| 253 | { |
---|
| 254 | fprintf(fp, "all:\t\n"); |
---|
| 255 | fprintf(fp, "\techo \"don't know how to build library\"\n"); |
---|
| 256 | } |
---|
[cff7cec] | 257 | #endif |
---|
| 258 | #endif |
---|
[fc04a1] | 259 | |
---|
[21e48b] | 260 | //# ifdef ix86_Win |
---|
| 261 | //void build_compile_section( |
---|
| 262 | // FILE *fp, |
---|
| 263 | // moddefv module |
---|
| 264 | // ) |
---|
| 265 | //{ |
---|
| 266 | // fprintf(fp, "all:\t%s.dll %s_g.dll \n", module->name, module->name); |
---|
| 267 | // fprintf(fp, "\n"); |
---|
| 268 | // fprintf(fp, "%%.o: %%.cc Makefile\n"); |
---|
| 269 | // fprintf(fp, "\t${CC} ${CFLAGS} -c $< -o $*.o\n"); |
---|
| 270 | // fprintf(fp, "\n"); |
---|
| 271 | // fprintf(fp, "%%.og: %%.cc Makefile\n"); |
---|
| 272 | // fprintf(fp, "\t${CC} ${DCFLAGS} -c $< -o $*.og\n"); |
---|
| 273 | // fprintf(fp, "\n"); |
---|
| 274 | // |
---|
| 275 | // fprintf(fp, "%s.dll: ${OBJS}\n", module->name); |
---|
| 276 | // fprintf(fp, "\t${CC} ${CFLAGS} -Wl,--out-implib,lib%s.import.a -shared \\\n", |
---|
| 277 | // module->name); |
---|
| 278 | // fprintf(fp, "\t\t-o %s.dll ${OBJS}\n", module->name); |
---|
| 279 | // fprintf(fp, "\n"); |
---|
| 280 | // |
---|
| 281 | // fprintf(fp, "%s_g.so: ${DOBJS}\n", module->name); |
---|
| 282 | // fprintf(fp, "\t${CC} ${DCFLAGS} -Wl,--out-implib,lib%s_g.import.a -shared \\\n", |
---|
| 283 | // module->name); |
---|
| 284 | // fprintf(fp, "\t\t-o %s_g.dll ${DOBJS}\n", module->name); |
---|
| 285 | // fprintf(fp, "\n"); |
---|
| 286 | // |
---|
| 287 | // fprintf(fp, "all:\t\n"); |
---|
| 288 | // fprintf(fp, "\techo \"don't know how to build library\"\n"); |
---|
| 289 | //} |
---|
| 290 | //# endif /* ix86_Win */ |
---|
[fc04a1] | 291 | |
---|