source: git/dyn_modules/modgen/makefile.cc @ 6ce030f

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