source: git/modules/modgen/makefile.cc @ 0d3e24

fieker-DuValspielwiese
Last change on this file since 0d3e24 was cff7cec, checked in by Hans Schönemann <hannes@…>, 17 years ago
*hannes: install depends on all git-svn-id: file:///usr/local/Singular/svn/trunk@10308 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 8.9 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: makefile.cc,v 1.30 2007-09-17 09:35:19 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  fprintf(fp, "SINGULARROOT\t= ../..\n");
100#warning "PROBLEM: nice place for include file has to be found"
101  fprintf(fp, "CFLAGS\t= -DNDEBUG -DBUILD_MODULE -I. -I${SINGULARROOT}/kernel -I${SINGULARROOT}/Singular -I${SINGULARROOT}/%s/include\n",SINGUNAME);
102  fprintf(fp, "DCFLAGS\t= -DBUILD_MODULE -I. -I${SINGULARROOT}/kernel -I${SINGULARROOT}/Singular -I${SINGULARROOT}/%s/include\n",SINGUNAME);
103  fprintf(fp, "#LD\t=\n");
104  fprintf(fp, "\n");
105  fprintf(fp, "instdir          = %s\n", inst_dir );
106  fprintf(fp, "MKINSTALLDIRS\t\t= ${SINGULARROOT}/modules/mkinstalldirs\n");
107#warning "PROBLEM: do we also install install-sh when installing Singular?"
108  fprintf(fp, "INSTALL\t\t= ${SINGULARROOT}/Singular/install-sh -c\n");
109  fprintf(fp, "INSTALL_PROGRAM\t= ${INSTALL}\n");
110  fprintf(fp, "INSTALL_DATA\t= ${INSTALL} -m 644\n");
111}
112
113/*========================================================================*/
114void build_clean_section(
115  FILE *fp,
116  moddefv module
117  )
118{
119  fprintf(fp, "clean:\n");
120  fprintf(fp, "\trm -f *.o *.og *.lo *.so* *.sl *.la *~ core\n\n");
121
122  fprintf(fp, "distclean: clean\n");
123  fprintf(fp, "\trm -f %s.cc %s.h Makefile *.bin *.pl\n\n",
124               module->name, module->name);
125}
126
127/*========================================================================*/
128void build_install_section(
129  FILE *fp,
130  moddefv module
131  )
132{
133  fprintf(fp, "install bindist: all\n");
134  fprintf(fp, "\t${MKINSTALLDIRS} ${instdir}\n");
135  fprintf(fp, "\t${MKINSTALLDIRS} ${instdir}/MOD\n");
136  fprintf(fp, "\t${INSTALL_PROGRAM} %s.so ${instdir}/MOD/%s.so\n",
137          module->targetname, module->targetname);
138  fprintf(fp, "\t${INSTALL_PROGRAM} %s.bin ${instdir}/MOD/%s.bin\n",
139          module->targetname, module->targetname);
140  fprintf(fp, "install-bindist: all\n");
141  fprintf(fp, "\t${MKINSTALLDIRS} ${install_bindir}\n");
142  fprintf(fp, "\t${INSTALL_PROGRAM} %s.so ${install_bindir}/%s.so\n",
143          module->targetname, module->targetname);
144  fprintf(fp, "\t${INSTALL_PROGRAM} %s.bin ${install_bindir}/%s.bin\n",
145          module->targetname, module->targetname);
146}
147
148/*========================================================================*/
149static char *object_name(char *p)
150{
151  char *q = (char *)strrchr(p, '.');
152  if(q==NULL) return "";
153  *q = '\0';
154  char *r = (char *)malloc(strlen(p)+4);
155  sprintf(r, "%s.o", p);
156
157  *q = '.';
158  return(r);
159}
160
161/*========================================================================*/
162/*===  Machine depend Makefile creation                                ===*/
163/*========================================================================*/
164#if defined(ix86_Linux)
165#define HAVE_ELF_SYSTEM
166#endif
167
168#if defined(ix86_Linux_libc5)
169#define HAVE_ELF_SYSTEM
170#endif
171
172#if defined(ix86_freebsd)
173#define HAVE_ELF_SYSTEM
174#endif
175
176#if defined(x86_64_Linux)
177#define HAVE_ELF_SYSTEM
178#endif
179
180#if defined(IRIX_6)
181#define HAVE_ELF_SYSTEM
182#endif
183
184#if defined(sparc64_Linux)
185#define HAVE_ELF_SYSTEM
186#endif
187
188#if defined(IA64_Linux)
189#define HAVE_ELF_SYSTEM
190#endif
191
192#if defined(DecAlpha_Linux)
193#define HAVE_ELF_SYSTEM
194#endif
195
196#if defined(ppc_Linux)
197#define HAVE_ELF_SYSTEM
198#endif
199
200#if defined(HAVE_ELF_SYSTEM)
201void build_compile_section(
202  FILE *fp,
203  moddefv module
204  )
205{
206  fprintf(fp, "all:\t%s.so %s_g.so \n", module->targetname, module->targetname);
207  fprintf(fp, "\n");
208  fprintf(fp, "%%.o: %%.cc Makefile\n");
209  fprintf(fp, "\t${CC} ${CFLAGS} -c -fPIC -DPIC $< -o $*.o\n");
210  fprintf(fp, "\n");
211  fprintf(fp, "%%.og: %%.cc Makefile\n");
212  fprintf(fp, "\t${CC} ${DCFLAGS} -g -c -fPIC -DPIC $< -o $*.og\n");
213  fprintf(fp, "\n");
214
215  fprintf(fp, "%s.so: ${OBJS}\n", module->targetname);
216  fprintf(fp, "\t${CC} ${CFLAGS} -shared -Wl,-soname -Wl,%s.so.%d \\\n",
217          module->targetname, module->major);
218  fprintf(fp, "\t\t-o %s.so.%d.%d.%d ${OBJS}\n", module->targetname,
219          module->major, module->minor, module->level);
220  fprintf(fp, "\trm -f %s.so\n", module->targetname);
221  fprintf(fp, "\tln -s %s.so.%d.%d.%d %s.so\n", module->targetname, module->major,
222          module->minor, module->level, module->targetname);
223  fprintf(fp, "\n");
224
225  fprintf(fp, "%s_g.so: ${DOBJS}\n", module->targetname);
226  fprintf(fp, "\t${CC} ${DCFLAGS} -shared -Wl,-soname -Wl,%s_g.so.%d \\\n",
227          module->targetname, module->major);
228  fprintf(fp, "\t\t-o %s_g.so.%d.%d.%d ${DOBJS}\n", module->targetname,
229          module->major, module->minor, module->level);
230  fprintf(fp, "\trm -f %s_g.so\n", module->targetname);
231  fprintf(fp, "\tln -s %s_g.so.%d.%d.%d %s_g.so\n", module->targetname,
232          module->major, module->minor, module->level, module->targetname);
233  fprintf(fp, "\n");
234}
235
236/*========================================================================*/
237#else
238#if defined(HPUX_9) || defined(HPUX_10)
239void build_compile_section(
240  FILE *fp,
241  moddefv module
242  )
243{
244  fprintf(fp, "all:\t%s.sl\n", module->targetname);
245  fprintf(fp, "\n");
246  fprintf(fp, "%%.o: %%.cc Makefile\n");
247  fprintf(fp, "\t${CC} ${CFLAGS} -c -fPIC -DPIC $< -o $*.o\n");
248  fprintf(fp, "\n");
249  fprintf(fp, "%s.sl: ${OBJS}\n", module->targetname);
250  fprintf(fp, "\t${LD} -b -o %s.sl \\\n", module->targetname);
251  fprintf(fp, "\t\t${OBJS}\n");
252}
253
254#else /* HPUX_9  or HPUX_10 */
255/*========================================================================*/
256void build_compile_section(
257  FILE *fp,
258  moddefv module
259  )
260{
261  fprintf(fp, "all:\t\n");
262  fprintf(fp, "\techo \"don't know how to build library\"\n");
263}
264#endif
265#endif
266
267//#  ifdef ix86_Win
268//void build_compile_section(
269//  FILE *fp,
270//  moddefv module
271//  )
272//{
273//  fprintf(fp, "all:\t%s.dll %s_g.dll \n", module->name, module->name);
274//  fprintf(fp, "\n");
275//  fprintf(fp, "%%.o: %%.cc Makefile\n");
276//  fprintf(fp, "\t${CC} ${CFLAGS} -c $< -o $*.o\n");
277//  fprintf(fp, "\n");
278//  fprintf(fp, "%%.og: %%.cc Makefile\n");
279//  fprintf(fp, "\t${CC} ${DCFLAGS} -c $< -o $*.og\n");
280//  fprintf(fp, "\n");
281//
282//  fprintf(fp, "%s.dll: ${OBJS}\n", module->name);
283//  fprintf(fp, "\t${CC} ${CFLAGS} -Wl,--out-implib,lib%s.import.a -shared \\\n",
284//          module->name);
285//  fprintf(fp, "\t\t-o %s.dll ${OBJS}\n", module->name);
286//  fprintf(fp, "\n");
287//
288//  fprintf(fp, "%s_g.so: ${DOBJS}\n", module->name);
289//  fprintf(fp, "\t${CC} ${DCFLAGS} -Wl,--out-implib,lib%s_g.import.a -shared \\\n",
290//          module->name);
291//  fprintf(fp, "\t\t-o %s_g.dll ${DOBJS}\n", module->name);
292//  fprintf(fp, "\n");
293//
294//  fprintf(fp, "all:\t\n");
295//  fprintf(fp, "\techo \"don't know how to build library\"\n");
296//}
297//#  endif /* ix86_Win */
298
Note: See TracBrowser for help on using the repository browser.