1 // Copyright (C) 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /* Copyright (C) 2011 IBM Corporation and Others. All Rights Reserved */
4
5 /**
6 Input:
7 -o makeconv makeconv.o ucnvstat.o ../../lib/libicuuc48.so -qOPTION='*DUPPROC *DUPVAR*'
8
9 CRTPGM PGM(SRLICU/MAKECONV) MODULE(SRLICU/MAKECONV SRLICU/UCNVSTAT SRLICU/GENMBCS SRLICU/GENCNVEX) BNDSRVPGM(SRLICU/LIBICUUC48 SRLICU/LIBICUTU48 SRLICU/LIBICUIN48) OPTION(*DUPPROC *DUPVAR) REPLACE(*YES)
10
11 Handles .o ( modules ), .so ( srvpgm ), .a ( bnddir ).
12
13 TODO:
14
15 - cleanup
16 - much better error handling
17 - factor common code
18 - instead of caring about .o vs .so vs .a, just read the link - if it ends in .srvpgm then treat it as a service program, etc.
19
20 */
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <errno.h>
26
27 #ifndef TEST_MODE
28 #define TEST_MODE 0
29 #endif
30
31
32 #if !TEST_MODE
33 #include <qp0z1170.h>
34 #else
Qp0zSystem(const char * cmd)35 static int Qp0zSystem(const char *cmd) {
36 printf("CL: %s\n", cmd);
37 return 0;
38 }
39 #endif
40
runcmd(const char * cmd)41 static int runcmd(const char *cmd) {
42 int rc;
43 printf("%s\n", cmd);
44 rc = Qp0zSystem(cmd);
45 if(rc==0) {
46 printf("..ok\n");
47 return 0;
48 } else if(rc<0){
49 printf("..Qp0zSystem failed.\n");
50 return 1;
51 } else {
52 printf("..System call failed.\n");
53 return 1;
54 }
55 }
56
main(int argc,const char * argv[])57 int main(int argc, const char *argv[]) {
58 int i;
59
60 char buf[8048];
61 char opt[4100];
62 char objs[4024];
63 char libs[4024];
64 char bnddirs[4024];
65 const char *prog="";
66 const char *progshort=prog;
67 const char *outputdir=getenv("OUTPUTDIR");
68
69 printf("# OUTPUTDIR=%s ",outputdir);
70 for(i=0;i<argc;i++) {
71 printf("%s ", argv[i]);
72 }
73 printf("\n");
74
75 buf[0]=0;
76 opt[0]=0;
77 objs[0]=0;
78 libs[0]=0;
79 bnddirs[0]=0;
80
81 for(i=1;i<argc;i++) {
82 if(argv[i][0]=='-') {
83 switch(argv[i][1]) {
84 case 'O':
85 printf(".. ignoring optimization: %s\n", argv[i]);
86 break;
87 case 'g':
88 printf(".. ignoring debugging: %s\n", argv[i]);
89 break;
90 case 'l':
91 printf(".. ignoring lib: %s\n", argv[i]);
92 break;
93 case 'v':
94 printf(".. already verbose\n");
95 break;
96 case 'o':
97 i++;
98 prog=argv[i];
99 progshort=strrchr(prog,'/');
100 if(!progshort) {
101 progshort=prog;
102 } else {
103 progshort++; /* / */
104 }
105 break;
106 case 'q':
107 if(!strncmp(argv[i]+2,"OPTION=",7)) {
108 strcat(opt,argv[i]+9);
109 } else {
110 printf("Unknown -q option: %s\n", argv[i]);
111 return 1;
112 }
113 break;
114 default:
115 printf("Unknown option: %s\n", argv[i]);
116 return 1;
117 }
118 } else {
119 int n = strlen(argv[i]);
120 if(argv[i][n-1]=='o' &&
121 argv[i][n-2]=='.') {
122 const char *b = argv[i];
123 char linkbuf[200];
124 char outbuf[100];
125 int nlen = n-2;
126
127 if(nlen >= 10) {
128 nlen = 10;
129 }
130
131 if(readlink(b,linkbuf,200)>0) {
132 /* printf("linkbuf %s for %s\n", linkbuf, b); */
133 /* /qsys.lib/srlicu.lib/currtest.module */
134 char *mend = strrchr(linkbuf,'.');
135 if(mend) {
136 *mend=0;
137 mend = strrchr(linkbuf,'/');
138 if(mend) {
139 mend++;
140 strcpy(outbuf,mend);
141 b=outbuf;
142 nlen=strlen(b);
143 }
144 }
145 } else {
146 /* perror("readlink");
147 puts(b); */
148 }
149
150 strcat(objs,outputdir);
151 strcat(objs,"/");
152 strncat(objs,b,nlen);
153 strcat(objs, " ");
154 } else if(argv[i][n-1]=='a' &&
155 argv[i][n-2]=='.') {
156 const char *b = argv[i];
157 char linkbuf[200];
158 char outbuf[100];
159 int nlen = n-2;
160
161 if(nlen >= 10) {
162 nlen = 10;
163 }
164
165 if(readlink(b,linkbuf,200)>0) {
166 /* printf("linkbuf %s for %s\n", linkbuf, b); */
167 /* /qsys.lib/srlicu.lib/currtest.srvpgm */
168 char *mend = strrchr(linkbuf,'.');
169 if(mend) {
170 *mend=0;
171 mend = strrchr(linkbuf,'/');
172 if(mend) {
173 mend++;
174 strcpy(outbuf,mend);
175 b=outbuf;
176 nlen=strlen(b);
177 }
178 }
179 } else {
180 /* perror("readlink");
181 puts(b); */
182 }
183
184 strcat(bnddirs,outputdir);
185 strcat(bnddirs,"/");
186 strncat(bnddirs,b,nlen);
187 strcat(bnddirs, " ");
188 } else if(argv[i][n-1]=='o' &&
189 argv[i][n-2]=='s' &&
190 argv[i][n-3]=='.') {
191 const char *p = strrchr(argv[i],'/');
192 if(!p) {
193 printf("Can't find trailing slash in %s\n", argv[i]);
194 return 1;
195 }
196 strcat(libs,outputdir);
197 strcat(libs,"/");
198 strncat(libs,p+1,strlen(p)-4);
199 strcat(libs," ");
200 } else {
201 printf("Unknown input file: %s\n", argv[i]);
202 return 1;
203 }
204 }
205 }
206
207 if(prog[0]==0) {
208 printf("no program (-o) option specified.\n");
209 return 1;
210 }
211
212 sprintf(buf,"CRTPGM PGM(%s/%s) MODULE(%s) BNDSRVPGM(%s) BNDDIR(%s) OPTION(%s) REPLACE(*YES)",
213 outputdir,progshort,
214
215 objs,
216
217 libs,
218
219 bnddirs,
220
221 opt);
222
223
224 if(runcmd(buf)) {
225 return 1;
226 }
227
228 /* -- OK */
229 {
230 char path1[1000];
231 sprintf(path1,"/qsys.lib/%s.lib/%s.pgm",
232 outputdir,
233 progshort);
234 printf("# ln -s %s %s\n", path1, prog);
235 if((!TEST_MODE) && symlink(path1,prog)) {
236 perror("symlink");
237 if(errno!=EEXIST) { /* ignored */
238 return 1;
239 }
240 }
241 }
242 return 0;
243 }
244
245
246
247
248
249
250
251
252