source: git/modules/modgen/makefile.cc @ 21e48b

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