-
Notifications
You must be signed in to change notification settings - Fork 273
/
configure.c
1947 lines (1733 loc) · 52 KB
/
configure.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* configure.c - core analysis suite
*
* Copyright (C) 1999, 2000, 2001, 2002 Mission Critical Linux, Inc.
* Copyright (C) 2002-2013 David Anderson
* Copyright (C) 2002-2013 Red Hat, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
/*
* define, clear and undef dynamically update the top-level Makefile:
*
* -b define: TARGET, GDB, GDB_FILES, GDB_OFILES, GDB_PATCH_FILES,
* TARGET_CFLAGS, LDFLAGS, GDB_CONF_FLAGS and GPL_FILES
* create: build_data.c
*
* -d define: TARGET, GDB, GDB_FILES, GDB_OFILES, GDB_PATCH_FILES,
* TARGET_CFLAGS, LDFLAGS, GDB_CONF_FLAGS and PROGRAM (for daemon)
* create: build_data.c
*
* -u clear: TARGET, GDB, GDB_FILES, GDB_OFILES, VERSION, GDB_PATCH_FILES,
* TARGET_CFLAGS, LDFLAGS, GDB_CONF_FLAGS and GPL_FILES
* undef: WARNING_ERROR, WARNING_OPTIONS
*
* -r define: GDB_FILES, VERSION, GDB_PATCH_FILES GPL_FILES
*
* -w define: WARNING_OPTIONS
* undef: WARNING_ERROR
*
* -W define: WARNING_ERROR, WARNING_OPTIONS
*
* -n undef: WARNING_ERROR, WARNING_OPTIONS
*
* -g define: GDB
*
* -p Create or remove .rh_rpm_package file
*
* -q Don't print configuration
*
* -s Create crash.spec file
*
* -x Add extra libraries/flags to build
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include <ctype.h>
struct supported_gdb_version;
void build_configure(struct supported_gdb_version *);
void release_configure(char *, struct supported_gdb_version *);
void make_rh_rpm_package(char *, int);
void unconfigure(void);
void set_warnings(int);
void show_configuration(void);
void target_rebuild_instructions(struct supported_gdb_version *, char *);
void arch_mismatch(struct supported_gdb_version *);
void get_current_configuration(struct supported_gdb_version *);
void makefile_setup(FILE **, FILE **);
void makefile_create(FILE **, FILE **);
char *strip_linefeeds(char *);
char *upper_case(char *, char *);
char *lower_case(char *, char *);
char *shift_string_left(char *, int);
char *shift_string_right(char *, int);
char *strip_beginning_whitespace(char *);
char *strip_ending_whitespace(char *);
char *strip_linefeeds(char *);
int file_exists(char *);
int count_chars(char *, char);
void make_build_data(char *);
void gdb_configure(struct supported_gdb_version *);
int parse_line(char *, char **);
struct supported_gdb_version *setup_gdb_defaults(void);
struct supported_gdb_version *store_gdb_defaults(struct supported_gdb_version *);
void make_spec_file(struct supported_gdb_version *);
void set_initial_target(struct supported_gdb_version *);
char *target_to_name(int);
int name_to_target(char *);
char *get_extra_flags(char *, char *);
void add_extra_lib(char *);
#define TRUE 1
#define FALSE 0
#undef X86
#undef ALPHA
#undef PPC
#undef IA64
#undef S390
#undef S390X
#undef PPC64
#undef X86_64
#undef ARM
#undef ARM64
#undef MIPS
#undef SPARC64
#undef MIPS64
#undef RISCV64
#undef LOONGARCH64
#define UNKNOWN 0
#define X86 1
#define ALPHA 2
#define PPC 3
#define IA64 4
#define S390 5
#define S390X 6
#define PPC64 7
#define X86_64 8
#define ARM 9
#define ARM64 10
#define MIPS 11
#define SPARC64 12
#define MIPS64 13
#define RISCV64 14
#define LOONGARCH64 15
#define TARGET_X86 "TARGET=X86"
#define TARGET_ALPHA "TARGET=ALPHA"
#define TARGET_PPC "TARGET=PPC"
#define TARGET_IA64 "TARGET=IA64"
#define TARGET_S390 "TARGET=S390"
#define TARGET_S390X "TARGET=S390X"
#define TARGET_PPC64 "TARGET=PPC64"
#define TARGET_X86_64 "TARGET=X86_64"
#define TARGET_ARM "TARGET=ARM"
#define TARGET_ARM64 "TARGET=ARM64"
#define TARGET_MIPS "TARGET=MIPS"
#define TARGET_MIPS64 "TARGET=MIPS64"
#define TARGET_SPARC64 "TARGET=SPARC64"
#define TARGET_RISCV64 "TARGET=RISCV64"
#define TARGET_LOONGARCH64 "TARGET=LOONGARCH64"
#define TARGET_CFLAGS_X86 "TARGET_CFLAGS=-D_FILE_OFFSET_BITS=64"
#define TARGET_CFLAGS_ALPHA "TARGET_CFLAGS="
#define TARGET_CFLAGS_PPC "TARGET_CFLAGS=-D_FILE_OFFSET_BITS=64"
#define TARGET_CFLAGS_IA64 "TARGET_CFLAGS="
#define TARGET_CFLAGS_S390 "TARGET_CFLAGS=-D_FILE_OFFSET_BITS=64"
#define TARGET_CFLAGS_S390X "TARGET_CFLAGS="
#define TARGET_CFLAGS_PPC64 "TARGET_CFLAGS=-m64"
#define TARGET_CFLAGS_X86_64 "TARGET_CFLAGS="
#define TARGET_CFLAGS_ARM "TARGET_CFLAGS=-D_FILE_OFFSET_BITS=64"
#define TARGET_CFLAGS_ARM_ON_X86 "TARGET_CFLAGS=-D_FILE_OFFSET_BITS=64"
#define TARGET_CFLAGS_ARM_ON_X86_64 "TARGET_CFLAGS=-m32 -D_FILE_OFFSET_BITS=64"
#define TARGET_CFLAGS_X86_ON_X86_64 "TARGET_CFLAGS=-m32 -D_FILE_OFFSET_BITS=64"
#define TARGET_CFLAGS_PPC_ON_PPC64 "TARGET_CFLAGS=-m32 -D_FILE_OFFSET_BITS=64 -fPIC"
#define TARGET_CFLAGS_ARM64 "TARGET_CFLAGS="
#define TARGET_CFLAGS_ARM64_ON_X86_64 "TARGET_CFLAGS="
#define TARGET_CFLAGS_PPC64_ON_X86_64 "TARGET_CFLAGS="
#define TARGET_CFLAGS_MIPS "TARGET_CFLAGS=-D_FILE_OFFSET_BITS=64"
#define TARGET_CFLAGS_MIPS_ON_X86 "TARGET_CFLAGS=-D_FILE_OFFSET_BITS=64"
#define TARGET_CFLAGS_MIPS_ON_X86_64 "TARGET_CFLAGS=-m32 -D_FILE_OFFSET_BITS=64"
#define TARGET_CFLAGS_MIPS64 "TARGET_CFLAGS="
#define TARGET_CFLAGS_SPARC64 "TARGET_CFLAGS="
#define TARGET_CFLAGS_RISCV64 "TARGET_CFLAGS="
#define TARGET_CFLAGS_RISCV64_ON_X86_64 "TARGET_CFLAGS="
#define TARGET_CFLAGS_LOONGARCH64 "TARGET_CFLAGS="
#define TARGET_CFLAGS_LOONGARCH64_ON_X86_64 "TARGET_CFLAGS="
#define GDB_TARGET_DEFAULT "GDB_CONF_FLAGS="
#define GDB_TARGET_ARM_ON_X86 "GDB_CONF_FLAGS=--target=arm-elf-linux"
#define GDB_TARGET_ARM_ON_X86_64 "GDB_CONF_FLAGS=--target=arm-elf-linux CFLAGS=-m32 CXXFLAGS=-m32"
#define GDB_TARGET_X86_ON_X86_64 "GDB_CONF_FLAGS=--target=i686-pc-linux-gnu CFLAGS=-m32 CXXFLAGS=-m32"
#define GDB_TARGET_PPC_ON_PPC64 "GDB_CONF_FLAGS=--target=ppc-elf-linux CFLAGS=-m32 CXXFLAGS=-m32"
#define GDB_TARGET_ARM64_ON_X86_64 "GDB_CONF_FLAGS=--target=aarch64-elf-linux" /* TBD */
#define GDB_TARGET_PPC64_ON_X86_64 "GDB_CONF_FLAGS=--target=powerpc64le-unknown-linux-gnu"
#define GDB_TARGET_MIPS_ON_X86 "GDB_CONF_FLAGS=--target=mipsel-elf-linux"
#define GDB_TARGET_MIPS_ON_X86_64 "GDB_CONF_FLAGS=--target=mipsel-elf-linux CFLAGS=-m32 CXXFLAGS=-m32"
#define GDB_TARGET_RISCV64_ON_X86_64 "GDB_CONF_FLAGS=--target=riscv64-unknown-linux-gnu"
#define GDB_TARGET_LOONGARCH64_ON_X86_64 "GDB_CONF_FLAGS=--target=loongarch64-unknown-linux-gnu"
/*
* The original plan was to allow the use of a particular version
* of gdb for a given architecture. But for practical purposes,
* it's a one-size-fits-all scheme, and they all use the default
* unless overridden.
*/
#define GDB_5_3 (0)
#define GDB_6_0 (1)
#define GDB_6_1 (2)
#define GDB_7_0 (3)
#define GDB_7_3_1 (4)
#define GDB_7_6 (5)
#define GDB_10_2 (6)
#define SUPPORTED_GDB_VERSIONS (GDB_10_2 + 1)
int default_gdb = GDB_10_2;
struct supported_gdb_version {
char *GDB;
char *GDB_VERSION_IN;
char *GDB_FILES;
char *GDB_OFILES;
char *GDB_PATCH_FILES;
char *GDB_FLAGS;
char *GPL;
} supported_gdb_versions[SUPPORTED_GDB_VERSIONS] = {
{
"GDB=gdb-5.3post-0.20021129.36rh",
"Red Hat Linux (5.3post-0.20021129.36rh)",
"GDB_FILES=${GDB_5.3post-0.20021129.36rh_FILES}",
"GDB_OFILES=${GDB_5.3post-0.20021129.36rh_OFILES}",
"GDB_PATCH_FILES=",
"GDB_FLAGS=-DGDB_5_3",
"GPLv2"
},
{
"GDB=gdb-6.0",
"6.0",
"GDB_FILES=${GDB_6.0_FILES}",
"GDB_OFILES=${GDB_6.0_OFILES}",
"GDB_PATCH_FILES=",
"GDB_FLAGS=-DGDB_6_0",
"GPLv2"
},
{
"GDB=gdb-6.1",
"6.1",
"GDB_FILES=${GDB_6.1_FILES}",
"GDB_OFILES=${GDB_6.1_OFILES}",
"GDB_PATCH_FILES=gdb-6.1.patch",
"GDB_FLAGS=-DGDB_6_1",
"GPLv2"
},
{
"GDB=gdb-7.0",
"7.0",
"GDB_FILES=${GDB_7.0_FILES}",
"GDB_OFILES=${GDB_7.0_OFILES}",
"GDB_PATCH_FILES=gdb-7.0.patch",
"GDB_FLAGS=-DGDB_7_0",
"GPLv3"
},
{
"GDB=gdb-7.3.1",
"7.3.1",
"GDB_FILES=${GDB_7.3.1_FILES}",
"GDB_OFILES=${GDB_7.3.1_OFILES}",
"GDB_PATCH_FILES=gdb-7.3.1.patch",
"GDB_FLAGS=-DGDB_7_3_1",
"GPLv3"
},
{
"GDB=gdb-7.6",
"7.6",
"GDB_FILES=${GDB_7.6_FILES}",
"GDB_OFILES=${GDB_7.6_OFILES}",
"GDB_PATCH_FILES=gdb-7.6.patch gdb-7.6-ppc64le-support.patch gdb-7.6-proc_service.h.patch",
"GDB_FLAGS=-DGDB_7_6",
"GPLv3"
},
{
"GDB=gdb-10.2",
"10.2",
"GDB_FILES=${GDB_10.2_FILES}",
"GDB_OFILES=${GDB_10.2_OFILES}",
"GDB_PATCH_FILES=gdb-10.2.patch",
"GDB_FLAGS=-DGDB_10_2",
"GPLv3"
},
};
#define DAEMON 0x1
#define QUIET 0x2
#define MAXSTRLEN 256
#define MIN(a,b) (((a)<(b))?(a):(b))
struct target_data {
int target;
int host;
int initial_gdb_target;
int flags;
char program[MAXSTRLEN];
char gdb_version[MAXSTRLEN];
char release[MAXSTRLEN];
struct stat statbuf;
const char *target_as_param;
} target_data = { 0 };
int
main(int argc, char **argv)
{
int c;
struct supported_gdb_version *sp;
sp = setup_gdb_defaults();
while ((c = getopt(argc, argv, "gsqnWwubdr:p:P:t:x:")) > 0) {
switch (c) {
case 'q':
target_data.flags |= QUIET;
break;
case 'u':
unconfigure();
break;
case 'd':
target_data.flags |= DAEMON;
case 'b':
build_configure(sp);
break;
case 'r':
release_configure(optarg, sp);
break;
case 'p':
make_rh_rpm_package(optarg, 0);
break;
case 'P':
make_rh_rpm_package(optarg, 1);
break;
case 'W':
case 'w':
case 'n':
set_warnings(c);
break;
case 's':
make_spec_file(sp);
break;
case 'g':
gdb_configure(sp);
break;
case 't':
target_data.target_as_param = optarg;
break;
case 'x':
add_extra_lib(optarg);
break;
}
}
exit(0);
}
void
target_rebuild_instructions(struct supported_gdb_version *sp, char *target)
{
fprintf(stderr,
"\nIn order to build a crash binary for the %s architecture:\n",
target);
fprintf(stderr, " 1. remove the %s subdirectory\n",
&sp->GDB[strlen("GDB=")]);
fprintf(stderr, " 2. perform a \"make clean\"\n");
fprintf(stderr, " 3. retry the build\n\n");
}
void
arch_mismatch(struct supported_gdb_version *sp)
{
fprintf(stderr,
"\nThe initial build in this source tree was for the %s architecture.\n",
target_to_name(target_data.initial_gdb_target));
target_rebuild_instructions(sp, target_to_name(target_data.target));
exit(1);
}
void
get_current_configuration(struct supported_gdb_version *sp)
{
FILE *fp;
static char buf[512];
char *p;
#ifdef __alpha__
target_data.target = ALPHA;
#endif
#ifdef __i386__
target_data.target = X86;
#endif
#ifdef __powerpc__
target_data.target = PPC;
#endif
#ifdef __ia64__
target_data.target = IA64;
#endif
#ifdef __s390__
target_data.target = S390;
#endif
#ifdef __s390x__
target_data.target = S390X;
#endif
#ifdef __powerpc64__
target_data.target = PPC64;
#endif
#ifdef __x86_64__
target_data.target = X86_64;
#endif
#ifdef __arm__
target_data.target = ARM;
#endif
#ifdef __aarch64__
target_data.target = ARM64;
#endif
#ifdef __mips__
#ifndef __mips64
target_data.target = MIPS;
#else
target_data.target = MIPS64;
#endif
#endif
#ifdef __sparc_v9__
target_data.target = SPARC64;
#endif
#if defined(__riscv) && (__riscv_xlen == 64)
target_data.target = RISCV64;
#endif
#ifdef __loongarch64
target_data.target = LOONGARCH64;
#endif
set_initial_target(sp);
/*
* Override target if specified on command line.
*/
target_data.host = target_data.target;
if (target_data.target_as_param) {
if ((target_data.target == X86 || target_data.target == X86_64) &&
(name_to_target((char *)target_data.target_as_param) == ARM)) {
/*
* Debugging of ARM core files supported on X86, and on
* X86_64 when built as a 32-bit executable.
*/
target_data.target = ARM;
} else if ((target_data.target == X86 || target_data.target == X86_64) &&
(name_to_target((char *)target_data.target_as_param) == MIPS)) {
/*
* Debugging of MIPS little-endian core files
* supported on X86, and on X86_64 when built as a
* 32-bit executable.
*/
target_data.target = MIPS;
} else if ((target_data.target == X86_64) &&
(name_to_target((char *)target_data.target_as_param) == X86)) {
/*
* Build an X86 crash binary on an X86_64 host.
*/
target_data.target = X86;
} else if ((target_data.target == X86_64) &&
(name_to_target((char *)target_data.target_as_param) == ARM64)) {
/*
* Build an ARM64 crash binary on an X86_64 host.
*/
target_data.target = ARM64;
} else if ((target_data.target == X86_64) &&
(name_to_target((char *)target_data.target_as_param) == PPC64)) {
/*
* Build a PPC64 little-endian crash binary on an X86_64 host.
*/
target_data.target = PPC64;
} else if ((target_data.target == PPC64) &&
(name_to_target((char *)target_data.target_as_param) == PPC)) {
/*
* Build an PPC crash binary on an PPC64 host.
*/
target_data.target = PPC;
} else if (name_to_target((char *)target_data.target_as_param) ==
target_data.host) {
if ((target_data.initial_gdb_target != UNKNOWN) &&
(target_data.host != target_data.initial_gdb_target))
arch_mismatch(sp);
} else if ((target_data.target == X86_64) &&
(name_to_target((char *)target_data.target_as_param) == RISCV64)) {
/*
* Build an RISCV64 crash binary on an X86_64 host.
*/
target_data.target = RISCV64;
} else if ((target_data.target == X86_64) &&
(name_to_target((char *)target_data.target_as_param) == LOONGARCH64)) {
/*
* Build an LOONGARCH64 crash binary on an X86_64 host.
*/
target_data.target = LOONGARCH64;
} else {
fprintf(stderr,
"\ntarget=%s is not supported on the %s host architecture\n\n",
target_data.target_as_param,
target_to_name(target_data.host));
exit(1);
}
}
/*
* Impose implied (sticky) target if an initial build has been
* done in the source tree.
*/
if (target_data.initial_gdb_target &&
(target_data.target != target_data.initial_gdb_target)) {
if ((target_data.initial_gdb_target == ARM) &&
(target_data.target != ARM)) {
if ((target_data.target == X86) ||
(target_data.target == X86_64))
target_data.target = ARM;
else
arch_mismatch(sp);
}
if ((target_data.target == ARM) &&
(target_data.initial_gdb_target != ARM))
arch_mismatch(sp);
if ((target_data.initial_gdb_target == MIPS) &&
(target_data.target != MIPS)) {
if ((target_data.target == X86) ||
(target_data.target == X86_64))
target_data.target = MIPS;
else
arch_mismatch(sp);
}
if ((target_data.initial_gdb_target == MIPS64) &&
(target_data.target != MIPS64))
arch_mismatch(sp);
if ((target_data.initial_gdb_target == LOONGARCH64) &&
(target_data.target != LOONGARCH64)) {
if (target_data.target == X86_64)
target_data.target = LOONGARCH64;
else
arch_mismatch(sp);
}
if ((target_data.initial_gdb_target == RISCV64) &&
(target_data.target != RISCV64)) {
if (target_data.target == X86_64)
target_data.target = RISCV64;
else
arch_mismatch(sp);
}
if ((target_data.initial_gdb_target == X86) &&
(target_data.target != X86)) {
if (target_data.target == X86_64)
target_data.target = X86;
else
arch_mismatch(sp);
}
if ((target_data.target == X86) &&
(target_data.initial_gdb_target != X86))
arch_mismatch(sp);
if ((target_data.initial_gdb_target == ARM64) &&
(target_data.target != ARM64)) {
if (target_data.target == X86_64)
target_data.target = ARM64;
else
arch_mismatch(sp);
}
if ((target_data.target == ARM64) &&
(target_data.initial_gdb_target != ARM64))
arch_mismatch(sp);
if ((target_data.initial_gdb_target == PPC64) &&
(target_data.target != PPC64)) {
if (target_data.target == X86_64)
target_data.target = PPC64;
else
arch_mismatch(sp);
}
if ((target_data.target == PPC64) &&
(target_data.initial_gdb_target != PPC64))
arch_mismatch(sp);
if ((target_data.initial_gdb_target == PPC) &&
(target_data.target != PPC)) {
if (target_data.target == PPC64)
target_data.target = PPC;
else
arch_mismatch(sp);
}
if ((target_data.target == PPC) &&
(target_data.initial_gdb_target != PPC))
arch_mismatch(sp);
if ((target_data.target == SPARC64) &&
(target_data.initial_gdb_target != SPARC64))
arch_mismatch(sp);
}
if ((fp = fopen("Makefile", "r")) == NULL) {
perror("Makefile");
goto get_release;
}
while (fgets(buf, 512, fp)) {
if (strncmp(buf, "PROGRAM=", strlen("PROGRAM=")) == 0) {
p = strstr(buf, "=") + 1;
strip_linefeeds(p);
upper_case(p, target_data.program);
if (target_data.flags & DAEMON)
strcat(target_data.program, "D");
continue;
}
}
fclose(fp);
get_release:
target_data.release[0] = '\0';
if (file_exists(".rh_rpm_package")) {
if ((fp = fopen(".rh_rpm_package", "r")) == NULL) {
perror(".rh_rpm_package");
} else {
if (fgets(buf, 512, fp)) {
strip_linefeeds(buf);
if (strlen(buf)) {
buf[MAXSTRLEN-1] = '\0';
strcpy(target_data.release, buf);
} else
fprintf(stderr,
"WARNING: .rh_rpm_package file is empty!\n");
} else
fprintf(stderr,
"WARNING: .rh_rpm_package file is empty!\n");
fclose(fp);
if (strlen(target_data.release))
return;
}
} else
fprintf(stderr,
"WARNING: .rh_rpm_package file does not exist!\n");
if ((fp = fopen("defs.h", "r")) == NULL) {
perror("defs.h");
return;
}
while (fgets(buf, 512, fp)) {
if (strncmp(buf, "#define BASELEVEL_REVISION",
strlen("#define BASELEVEL_REVISION")) == 0) {
p = strstr(buf, "\"") + 1;
strip_linefeeds(p);
p[strlen(p)-1] = '\0';
strcpy(target_data.release, p);
break;
}
}
fclose(fp);
}
void
show_configuration(void)
{
int i;
if (target_data.flags & QUIET)
return;
switch (target_data.target)
{
case X86:
printf("TARGET: X86\n");
break;
case ALPHA:
printf("TARGET: ALPHA\n");
break;
case PPC:
printf("TARGET: PPC\n");
break;
case IA64:
printf("TARGET: IA64\n");
break;
case S390:
printf("TARGET: S390\n");
break;
case S390X:
printf("TARGET: S390X\n");
break;
case PPC64:
printf("TARGET: PPC64\n");
break;
case X86_64:
printf("TARGET: X86_64\n");
break;
case ARM:
printf("TARGET: ARM\n");
break;
case ARM64:
printf("TARGET: ARM64\n");
break;
case MIPS:
printf("TARGET: MIPS\n");
break;
case MIPS64:
printf("TARGET: MIPS64\n");
break;
case SPARC64:
printf("TARGET: SPARC64\n");
break;
case RISCV64:
printf("TARGET: RISCV64\n");
break;
case LOONGARCH64:
printf("TARGET: LOONGARCH64\n");
break;
}
if (strlen(target_data.program)) {
for (i = 0; i < (strlen("TARGET")-strlen(target_data.program));
i++)
printf(" ");
printf("%s: ", target_data.program);
if (strlen(target_data.release))
printf("%s\n", target_data.release);
else
printf("???\n");
}
if (strlen(target_data.gdb_version))
printf(" GDB: %s\n\n", &target_data.gdb_version[4]);
}
void
build_configure(struct supported_gdb_version *sp)
{
FILE *fp1, *fp2;
char buf[512];
char *target;
char *target_CFLAGS;
char *gdb_conf_flags;
char *ldflags;
char *cflags;
get_current_configuration(sp);
target = target_CFLAGS = NULL;
gdb_conf_flags = GDB_TARGET_DEFAULT;
switch (target_data.target)
{
case X86:
target = TARGET_X86;
if (target_data.host == X86_64) {
target_CFLAGS = TARGET_CFLAGS_X86_ON_X86_64;
gdb_conf_flags = GDB_TARGET_X86_ON_X86_64;
} else
target_CFLAGS = TARGET_CFLAGS_X86;
break;
case ALPHA:
target = TARGET_ALPHA;
target_CFLAGS = TARGET_CFLAGS_ALPHA;
break;
case PPC:
target = TARGET_PPC;
if (target_data.host == PPC64) {
target_CFLAGS = TARGET_CFLAGS_PPC_ON_PPC64;
gdb_conf_flags = GDB_TARGET_PPC_ON_PPC64;
} else
target_CFLAGS = TARGET_CFLAGS_PPC;
break;
case IA64:
target = TARGET_IA64;
target_CFLAGS = TARGET_CFLAGS_IA64;
break;
case S390:
target = TARGET_S390;
target_CFLAGS = TARGET_CFLAGS_S390;
break;
case S390X:
target = TARGET_S390X;
target_CFLAGS = TARGET_CFLAGS_S390X;
break;
case PPC64:
target = TARGET_PPC64;
if (target_data.host == X86_64) {
target_CFLAGS = TARGET_CFLAGS_PPC64_ON_X86_64;
gdb_conf_flags = GDB_TARGET_PPC64_ON_X86_64;
} else
target_CFLAGS = TARGET_CFLAGS_PPC64;
break;
case X86_64:
target = TARGET_X86_64;
target_CFLAGS = TARGET_CFLAGS_X86_64;
break;
case ARM:
target = TARGET_ARM;
if (target_data.host == X86) {
target_CFLAGS = TARGET_CFLAGS_ARM_ON_X86;
gdb_conf_flags = GDB_TARGET_ARM_ON_X86;
} else if (target_data.host == X86_64) {
target_CFLAGS = TARGET_CFLAGS_ARM_ON_X86_64;
gdb_conf_flags = GDB_TARGET_ARM_ON_X86_64;
} else
target_CFLAGS = TARGET_CFLAGS_ARM;
break;
case ARM64:
target = TARGET_ARM64;
if (target_data.host == X86_64) {
target_CFLAGS = TARGET_CFLAGS_ARM64_ON_X86_64;
gdb_conf_flags = GDB_TARGET_ARM64_ON_X86_64;
} else
target_CFLAGS = TARGET_CFLAGS_ARM64;
break;
case MIPS:
target = TARGET_MIPS;
if (target_data.host == X86) {
target_CFLAGS = TARGET_CFLAGS_MIPS_ON_X86;
gdb_conf_flags = GDB_TARGET_MIPS_ON_X86;
} else if (target_data.host == X86_64) {
target_CFLAGS = TARGET_CFLAGS_MIPS_ON_X86_64;
gdb_conf_flags = GDB_TARGET_MIPS_ON_X86_64;
} else
target_CFLAGS = TARGET_CFLAGS_MIPS;
break;
case MIPS64:
target = TARGET_MIPS64;
target_CFLAGS = TARGET_CFLAGS_MIPS64;
break;
case SPARC64:
target = TARGET_SPARC64;
target_CFLAGS = TARGET_CFLAGS_SPARC64;
break;
case RISCV64:
target = TARGET_RISCV64;
if (target_data.host == X86_64) {
target_CFLAGS = TARGET_CFLAGS_RISCV64_ON_X86_64;
gdb_conf_flags = GDB_TARGET_RISCV64_ON_X86_64;
} else
target_CFLAGS = TARGET_CFLAGS_RISCV64;
break;
case LOONGARCH64:
target = TARGET_LOONGARCH64;
if (target_data.host == X86_64) {
target_CFLAGS = TARGET_CFLAGS_LOONGARCH64_ON_X86_64;
gdb_conf_flags = GDB_TARGET_LOONGARCH64_ON_X86_64;
} else
target_CFLAGS = TARGET_CFLAGS_LOONGARCH64;
break;
}
ldflags = get_extra_flags("LDFLAGS.extra", NULL);
cflags = get_extra_flags("CFLAGS.extra", NULL);
gdb_conf_flags = get_extra_flags("GDBFLAGS.extra", gdb_conf_flags);
makefile_setup(&fp1, &fp2);
while (fgets(buf, 512, fp1)) {
if (strncmp(buf, "TARGET=", strlen("TARGET=")) == 0)
fprintf(fp2, "%s\n", target);
else if (strncmp(buf, "TARGET_CFLAGS=",
strlen("TARGET_CFLAGS=")) == 0)
fprintf(fp2, "%s%s%s\n", target_CFLAGS,
cflags ? " " : "", cflags ? cflags : "");
else if (strncmp(buf, "GDB_CONF_FLAGS=",
strlen("GDB_CONF_FLAGS=")) == 0)
fprintf(fp2, "%s\n", gdb_conf_flags);
else if (strncmp(buf, "GDB_FILES=",strlen("GDB_FILES=")) == 0)
fprintf(fp2, "%s\n", sp->GDB_FILES);
else if (strncmp(buf, "GDB_OFILES=",strlen("GDB_OFILES=")) == 0)
fprintf(fp2, "%s\n", sp->GDB_OFILES);
else if (strncmp(buf, "GDB_PATCH_FILES=",strlen("GDB_PATCH_FILES=")) == 0)
fprintf(fp2, "%s\n", sp->GDB_PATCH_FILES);
else if (strncmp(buf, "GDB_FLAGS=",strlen("GDB_FLAGS=")) == 0)
fprintf(fp2, "%s\n", sp->GDB_FLAGS);
else if (strncmp(buf, "GPL_FILES=", strlen("GPL_FILES=")) == 0)
fprintf(fp2, "GPL_FILES=%s\n", strcmp(sp->GPL, "GPLv2") == 0 ?
"COPYING" : "COPYING3");
else if (strncmp(buf, "GDB=", strlen("GDB=")) == 0) {
fprintf(fp2, "%s\n", sp->GDB);
sprintf(target_data.gdb_version, "%s", &sp->GDB[4]);
} else if (strncmp(buf, "LDFLAGS=", strlen("LDFLAGS=")) == 0) {
fprintf(fp2, "LDFLAGS=%s\n", ldflags ? ldflags : "");
} else
fprintf(fp2, "%s", buf);
}
makefile_create(&fp1, &fp2);
show_configuration();
make_build_data(&target[strlen("TARGET=")]);
}
void
release_configure(char *gdb_version, struct supported_gdb_version *sp)
{
FILE *fp1, *fp2;
int found;
char buf[512];
char gdb_files[MAXSTRLEN];
get_current_configuration(sp);
sprintf(buf, "%s/gdb", gdb_version);
if (!file_exists(buf)) {
fprintf(stderr, "make release: no such directory: %s\n", buf);
exit(1);
}
sprintf(gdb_files, "GDB_%s_FILES",
&gdb_version[strlen("gdb-")]);
makefile_setup(&fp1, &fp2);
found = 0;
while (fgets(buf, 512, fp1)) {
if (strncmp(buf, gdb_files, strlen(gdb_files)) == 0)
found++;
if (strncmp(buf, "GDB_FILES=", strlen("GDB_FILES=")) == 0)
fprintf(fp2, "GDB_FILES=${%s}\n", gdb_files);
else if (strncmp(buf, "VERSION=", strlen("VERSION=")) == 0)
fprintf(fp2, "VERSION=%s\n",
target_data.release);
else if (strncmp(buf, "GDB_PATCH_FILES=", strlen("GDB_PATCH_FILES=")) == 0)
fprintf(fp2, "%s\n", sp->GDB_PATCH_FILES);
else if (strncmp(buf, "GPL_FILES=", strlen("GPL_FILES=")) == 0)
fprintf(fp2, "GPL_FILES=%s\n", strcmp(sp->GPL, "GPLv2") == 0 ?
"COPYING" : "COPYING3");
else
fprintf(fp2, "%s", buf);
}
if (!found) {
fprintf(stderr, "make release: cannot find %s\n", gdb_files);
exit(1);
}
makefile_create(&fp1, &fp2);
}
/*
* Create an .rh_rpm_package file if the passed-in variable is set.
*/
void
make_rh_rpm_package(char *package, int release)
{
char *p, *cur;
FILE *fp;
char buf[256];
if ((strcmp(package, "remove") == 0)) {
if (file_exists(".rh_rpm_package")) {
if (unlink(".rh_rpm_package")) {
perror("unlink");
fprintf(stderr,
"cannot remove .rh_rpm_package\n");
exit(1);
}
}
return;
}
if (!(p = strstr(package, "=")))
return;
if (!strlen(++p))
return;
if (release) {
if (!(fp = popen("./crash -v", "r"))) {
fprintf(stderr, "cannot execute \"crash -v\"\n");
exit(1);
}
cur = NULL;
while (fgets(buf, 256, fp)) {
if (strncmp(buf, "crash ", 6) == 0) {
cur = &buf[6];
break;
}
}
pclose(fp);
if (!cur) {
fprintf(stderr, "cannot get version from \"crash -v\"\n");
exit(1);
}
strip_linefeeds(cur);
if (strcmp(cur, p) != 0) {
fprintf(stderr, "./crash version: %s\n", cur);
fprintf(stderr, "release version: %s\n", p);
exit(1);
}
}
if ((fp = fopen(".rh_rpm_package", "w")) == NULL) {
perror("fopen");
fprintf(stderr, "cannot open .rh_rpm_package\n");
exit(1);
}
fprintf(fp, "%s\n", strip_linefeeds(p));