source: git/dyn_modules/modgen/makefile.cc @ d44ced

spielwiese
Last change on this file since d44ced was d44ced, checked in by Hans Schoenemann <hannes@…>, 13 years ago
generic ELF handling git-svn-id: file:///usr/local/Singular/svn/trunk@13672 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 8.3 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id$ */
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 <regex.h>
16
17#include "modgen.h"
18#include "typmap.h"
19#include "pathnames.h"
20
21extern char* inst_dir;
22
23extern void mod_create_makefile(moddefv module);
24extern void build_head_section(FILE *fp, moddefv module);
25extern void build_clean_section(FILE *fp, moddefv module);
26extern void build_install_section(FILE *fp, moddefv module);
27extern void build_compile_section(FILE *fp, moddefv module);
28
29extern int do_create_srcdir;
30
31static char *object_name(char *p);
32/*========================================================================*/
33/*
34  run mod_create_makefile();
35
36 */
37/*========================================================================*/
38
39
40/*========================================================================*/
41void mod_create_makefile(moddefv module)
42{
43  FILE *fp;
44
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  }
51  if(do_create_srcdir) mkdir(module->name, 0755);
52  fp = fopen(build_filename(module, "Makefile", 0), "w");
53  cfilesv cf = module->files;
54  int i;
55
56  if(trace)printf("Creating Makefile  ...");fflush(stdout);
57  write_header(fp, module->name, "#");
58  build_head_section(fp, module);
59  fprintf(fp, "SRCS\t= %s.cc", module->name);
60
61  for(i=0; i<module->filecnt; i++)
62    fprintf(fp, " %s", cf[i].filename);
63
64  fprintf(fp, "\nOBJS\t= %s.o", module->name);
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);
68  for(i=0; i<module->filecnt; i++)
69    fprintf(fp, " %s", object_name(cf[i].filename));
70
71  fprintf(fp, "\n\n");
72  build_compile_section(fp, module);
73  build_clean_section(fp, module);
74  build_install_section(fp, module);
75
76  fprintf(fp, "\n");
77  fprintf(fp, "\n");
78
79  fclose(fp);
80  if(trace)printf("  done.\n");
81}
82
83/*========================================================================*/
84void 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");
91  fprintf(fp, "SINGULARROOT\t= ../..\n");
92  fprintf(fp, "SINGUNAME\t= %s\n",SINGUNAME);
93#warning "PROBLEM: nice place for include file has to be found"
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");
96  fprintf(fp, "#LD\t=\n");
97  fprintf(fp, "\n");
98  fprintf(fp, "instdir          = %s\n", inst_dir );
99  fprintf(fp, "MKINSTALLDIRS\t\t= ${SINGULARROOT}/dyn_modules/mkinstalldirs\n");
100#warning "PROBLEM: do we also install install-sh when installing Singular?"
101  fprintf(fp, "INSTALL\t\t= ${SINGULARROOT}/Singular/install-sh -c\n");
102  fprintf(fp, "INSTALL_PROGRAM\t= ${INSTALL}\n");
103  fprintf(fp, "INSTALL_DATA\t= ${INSTALL} -m 644\n");
104}
105
106/*========================================================================*/
107void build_clean_section(
108  FILE *fp,
109  moddefv module
110  )
111{
112  fprintf(fp, "clean:\n");
113  fprintf(fp, "\trm -f *.o *.og *.lo *.so* *.sl *.la *~ core\n\n");
114
115  fprintf(fp, "distclean: clean\n");
116  fprintf(fp, "\trm -f %s.cc %s.h Makefile *.bin *.pl\n\n",
117               module->name, module->name);
118}
119
120/*========================================================================*/
121void build_install_section(
122  FILE *fp,
123  moddefv module
124  )
125{
126  fprintf(fp, "install bindist: all\n");
127  fprintf(fp, "\t${MKINSTALLDIRS} ${instdir}\n");
128  fprintf(fp, "\t${MKINSTALLDIRS} ${instdir}/MOD\n");
129  fprintf(fp, "\t${INSTALL_PROGRAM} %s.so ${instdir}/MOD/%s.so\n",
130          module->targetname, module->targetname);
131  fprintf(fp, "\t${INSTALL_PROGRAM} %s.bin ${instdir}/MOD/%s.bin\n",
132          module->targetname, module->targetname);
133  fprintf(fp, "install-bindist: all\n");
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);
139}
140
141/*========================================================================*/
142static 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);
149
150  *q = '.';
151  return(r);
152}
153
154/*========================================================================*/
155/*===  Machine depend Makefile creation                                ===*/
156/*========================================================================*/
157// relying on gcc to define __ELF__, check with cpp -dM /dev/null
158#if defined(__ELF__)
159#define HAVE_ELF_SYSTEM
160#endif
161
162#if defined(HAVE_ELF_SYSTEM)
163void build_compile_section(
164  FILE *fp,
165  moddefv module
166  )
167{
168  fprintf(fp, "all:\t%s.so %s_g.so \n", module->targetname, module->targetname);
169  fprintf(fp, "\n");
170  fprintf(fp, "%%.o: %%.cc Makefile\n");
171  fprintf(fp, "\t${CC} ${CFLAGS} -c -fPIC -DPIC $< -o $*.o\n");
172  fprintf(fp, "\n");
173  fprintf(fp, "%%.og: %%.cc Makefile\n");
174  fprintf(fp, "\t${CC} ${DCFLAGS} -g -c -fPIC -DPIC $< -o $*.og\n");
175  fprintf(fp, "\n");
176
177  fprintf(fp, "%s.so: ${OBJS}\n", module->targetname);
178  fprintf(fp, "\t${CC} ${CFLAGS} -shared -Wl,-soname -Wl,%s.so.%d \\\n",
179          module->targetname, module->major);
180  fprintf(fp, "\t\t-o %s.so.%d.%d.%d ${OBJS}\n", module->targetname,
181          module->major, module->minor, module->level);
182  fprintf(fp, "\trm -f %s.so\n", module->targetname);
183  fprintf(fp, "\tln -s %s.so.%d.%d.%d %s.so\n", module->targetname, module->major,
184          module->minor, module->level, module->targetname);
185  fprintf(fp, "\n");
186
187  fprintf(fp, "%s_g.so: ${DOBJS}\n", module->targetname);
188  fprintf(fp, "\t${CC} ${DCFLAGS} -shared -Wl,-soname -Wl,%s_g.so.%d \\\n",
189          module->targetname, module->major);
190  fprintf(fp, "\t\t-o %s_g.so.%d.%d.%d ${DOBJS}\n", module->targetname,
191          module->major, module->minor, module->level);
192  fprintf(fp, "\trm -f %s_g.so\n", module->targetname);
193  fprintf(fp, "\tln -s %s_g.so.%d.%d.%d %s_g.so\n", module->targetname,
194          module->major, module->minor, module->level, module->targetname);
195  fprintf(fp, "\n");
196}
197
198/*========================================================================*/
199#else
200#if defined(HPUX_9) || defined(HPUX_10)
201void build_compile_section(
202  FILE *fp,
203  moddefv module
204  )
205{
206  fprintf(fp, "all:\t%s.sl\n", 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, "%s.sl: ${OBJS}\n", module->targetname);
212  fprintf(fp, "\t${LD} -b -o %s.sl \\\n", module->targetname);
213  fprintf(fp, "\t\t${OBJS}\n");
214}
215
216#else /* HPUX_9  or HPUX_10 */
217/*========================================================================*/
218void build_compile_section(
219  FILE *fp,
220  moddefv module
221  )
222{
223  fprintf(fp, "all:\t\n");
224  fprintf(fp, "\techo \"don't know how to build library\"\n");
225}
226#endif
227#endif
228
229//#  ifdef ix86_Win
230//void build_compile_section(
231//  FILE *fp,
232//  moddefv module
233//  )
234//{
235//  fprintf(fp, "all:\t%s.dll %s_g.dll \n", module->name, module->name);
236//  fprintf(fp, "\n");
237//  fprintf(fp, "%%.o: %%.cc Makefile\n");
238//  fprintf(fp, "\t${CC} ${CFLAGS} -c $< -o $*.o\n");
239//  fprintf(fp, "\n");
240//  fprintf(fp, "%%.og: %%.cc Makefile\n");
241//  fprintf(fp, "\t${CC} ${DCFLAGS} -c $< -o $*.og\n");
242//  fprintf(fp, "\n");
243//
244//  fprintf(fp, "%s.dll: ${OBJS}\n", module->name);
245//  fprintf(fp, "\t${CC} ${CFLAGS} -Wl,--out-implib,lib%s.import.a -shared \\\n",
246//          module->name);
247//  fprintf(fp, "\t\t-o %s.dll ${OBJS}\n", module->name);
248//  fprintf(fp, "\n");
249//
250//  fprintf(fp, "%s_g.so: ${DOBJS}\n", module->name);
251//  fprintf(fp, "\t${CC} ${DCFLAGS} -Wl,--out-implib,lib%s_g.import.a -shared \\\n",
252//          module->name);
253//  fprintf(fp, "\t\t-o %s_g.dll ${DOBJS}\n", module->name);
254//  fprintf(fp, "\n");
255//
256//  fprintf(fp, "all:\t\n");
257//  fprintf(fp, "\techo \"don't know how to build library\"\n");
258//}
259//#  endif /* ix86_Win */
260
Note: See TracBrowser for help on using the repository browser.