To build sed-4.1.5 on non-GCC compilers, the following small patches are required: --- lib/regex_internal.h +++ lib/regex_internal.h @@ -41,6 +41,10 @@ #endif /* HAVE_WCTYPE_H || _LIBC */ #if defined HAVE_STDBOOL_H || defined _LIBC # include <stdbool.h> +#elif defined HAVE__BOOL +# define bool _Bool +# define false 0 +# define true 1 #endif /* HAVE_STDBOOL_H || _LIBC */ #if defined _LIBC # include <bits/libc-lock.h> @@ -410,7 +414,10 @@ static unsigned int re_string_context_at #define re_string_skip_bytes(pstr,idx) ((pstr)->cur_idx += (idx)) #define re_string_set_index(pstr,idx) ((pstr)->cur_idx = (idx)) -#include <alloca.h> +#if defined(__sun) || defined(__sgi) || defined HAVE_ALLOCA_H +# include <alloca.h> +#endif +#include <stdlib.h> #ifndef _LIBC # if HAVE_ALLOCA (NB: This replaces sed-4.1.5-alloca.patch) --- lib/regcomp.c +++ lib/regcomp.c @@ -558,7 +558,17 @@ weak_alias (__regerror, regerror) static const bitset_t utf8_sb_map = { /* Set the first 128 bits. */ - [0 ... 0x80 / BITSET_WORD_BITS - 1] = BITSET_WORD_MAX +#if BITSET_WORD_MAX == 0xffffffffULL + [0] = BITSET_WORD_MAX, + [1] = BITSET_WORD_MAX, + [2] = BITSET_WORD_MAX, + [3] = BITSET_WORD_MAX +#elif BITSET_WORD_MAX == 0xffffffffffffffffULL + [0] = BITSET_WORD_MAX, + [1] = BITSET_WORD_MAX +#else +#error "Unknown value for BITSET_WORD_MAX" +#endif }; #endif --- lib/regexec.c +++ lib/regexec.c @@ -2894,7 +2894,7 @@ check_arrival (re_match_context_t *mctx, sizeof (re_dfastate_t *) * (path->alloc - old_alloc)); } - str_idx = path->next_idx ?: top_str; + str_idx = path->next_idx ? path->next_idx : top_str; /* Temporary modify MCTX. */ backup_state_log = mctx->state_log;
(In reply to comment #0) > -#include <alloca.h> > +#if defined(__sun) || defined(__sgi) || defined HAVE_ALLOCA_H > +# include <alloca.h> > +#endif > +#include <stdlib.h> > (NB: This replaces sed-4.1.5-alloca.patch) That patch adds the HAVE_ALLOCA_H guard. Why isn't that sufficient for IRIX? This patch looks quite wrong to me, especially since this works fine on Solaris, so no need to add the sun define in there. I think on IRIX we should fix the configure check, if broken. These are c99-isms that I have no problems with to patch if this helps MIPSpro. > --- lib/regcomp.c > +++ lib/regcomp.c > @@ -558,7 +558,17 @@ weak_alias (__regerror, regerror) > static const bitset_t utf8_sb_map = > { > /* Set the first 128 bits. */ > - [0 ... 0x80 / BITSET_WORD_BITS - 1] = BITSET_WORD_MAX > +#if BITSET_WORD_MAX == 0xffffffffULL > + [0] = BITSET_WORD_MAX, > + [1] = BITSET_WORD_MAX, > + [2] = BITSET_WORD_MAX, > + [3] = BITSET_WORD_MAX > +#elif BITSET_WORD_MAX == 0xffffffffffffffffULL > + [0] = BITSET_WORD_MAX, > + [1] = BITSET_WORD_MAX > +#else > +#error "Unknown value for BITSET_WORD_MAX" > +#endif > }; > #endif > > > --- lib/regexec.c > +++ lib/regexec.c > @@ -2894,7 +2894,7 @@ check_arrival (re_match_context_t *mctx, > sizeof (re_dfastate_t *) * (path->alloc - old_alloc)); > } > > - str_idx = path->next_idx ?: top_str; > + str_idx = path->next_idx ? path->next_idx : top_str; > > /* Temporary modify MCTX. */ > backup_state_log = mctx->state_log; >
Yes - you're right. I've just tried building sed-4.1.5-r1 with the above patches but omitting the changes to the guard around <alloca.h> and it's fine. (Incidentally, sed's lib/getopt.c looks as if it should include <string.h> because the compiler warns about implicitly declaration for a number of str* functions - but this doesn't cause a build failure.) The other (non-fatal, and potentially spurious) build warnings are: Making all in sed make[2]: Entering directory `/usr/opt/portage/var/tmp/portage/sys-apps/sed-4.1.5-r1/work/sed-4.1.5/sed' source='sed.c' object='sed.o' libtool=no \ DEPDIR=.deps depmode=sgi /bin/sh ../config/depcomp \ cc -DHAVE_CONFIG_H -I. -I. -I.. -I../lib -I../intl -I.. -I../lib -I../intl -DLOCALEDIR=\"/opt/portage/usr/share/locale\" -I/opt/portage/usr/include -c99 -O2 -n32 -mips4 -r14000 -float_const -use_readonly_const -TARG:isa=mips4:platform=ip35:processor=r14000 -TENV:zeroinit_in_bss=ON -OPT:fast_io=ON:Olimit=8192:reorg_common=ON:swp=ON -LNO:auto_dist=ON:fusion_peeling_limit=8:gather_scatter=2 -woff 1174,1183,1185,1552,3968,3970 -c sed.c source='compile.c' object='compile.o' libtool=no \ DEPDIR=.deps depmode=sgi /bin/sh ../config/depcomp \ cc -DHAVE_CONFIG_H -I. -I. -I.. -I../lib -I../intl -I.. -I../lib -I../intl -DLOCALEDIR=\"/opt/portage/usr/share/locale\" -I/opt/portage/usr/include -c99 -O2 -n32 -mips4 -r14000 -float_const -use_readonly_const -TARG:isa=mips4:platform=ip35:processor=r14000 -TENV:zeroinit_in_bss=ON -OPT:fast_io=ON:Olimit=8192:reorg_common=ON:swp=ON -LNO:auto_dist=ON:fusion_peeling_limit=8:gather_scatter=2 -woff 1174,1183,1185,1552,3968,3970 -c compile.c cc-1515 cc: WARNING File = compile.c, Line = 414 A value of type "char *" cannot be assigned to an entity of type "struct output *". p = OB_MALLOC(&obs, 1, struct output); ^ cc-1140 cc: WARNING File = compile.c, Line = 718 A value of type "char *" cannot be used to initialize an entity of type "struct sed_label *". struct sed_label *ret = OB_MALLOC(&obs, 1, struct sed_label); ^ cc-1140 cc: WARNING File = compile.c, Line = 755 A value of type "char *" cannot be used to initialize an entity of type "struct replacement *". struct replacement *r = OB_MALLOC(&obs, 1, struct replacement); ^ cc-1515 cc: WARNING File = compile.c, Line = 1257 A value of type "char *" cannot be assigned to an entity of type "struct subst *". cur_cmd->x.cmd_subst = OB_MALLOC(&obs, 1, struct subst); ^ cc-1515 cc: WARNING File = compile.c, Line = 1362 A value of type "char *" cannot be assigned to an entity of type "unsigned char *". cur_cmd->x.translate = translate; ^ source='fmt.c' object='fmt.o' libtool=no \ DEPDIR=.deps depmode=sgi /bin/sh ../config/depcomp \ cc -DHAVE_CONFIG_H -I. -I. -I.. -I../lib -I../intl -I.. -I../lib -I../intl -DLOCALEDIR=\"/opt/portage/usr/share/locale\" -I/opt/portage/usr/include -c99 -O2 -n32 -mips4 -r14000 -float_const -use_readonly_const -TARG:isa=mips4:platform=ip35:processor=r14000 -TENV:zeroinit_in_bss=ON -OPT:fast_io=ON:Olimit=8192:reorg_common=ON:swp=ON -LNO:auto_dist=ON:fusion_peeling_limit=8:gather_scatter=2 -woff 1174,1183,1185,1552,3968,3970 -c fmt.c cc-1047 cc: WARNING File = /usr/include/internal/limits_core.h, Line = 218 Macro "RE_DUP_MAX" (declared at line 270 of "../lib/regex.h") has an incompatible redefinition. #define RE_DUP_MAX 255 ^ There are several similar additional warnings when building the test-suite - but the good news is that all 75 tests are passed regardless. Can these changes be merged?
ok, let's try to get things going here. sed has a patch sed-4.1.5-regex-nobool.patch which looks like it has the same effect as your regex_internal.h patch. Can you attach your lib/regcomp.c and lib/regexec.c "less c99" patches? Bugzilla doesn't retain tabs...
Created attachment 148118 [details, diff] Patch to lib/regexec.c & lib/regcomp.c Patches to allow compilation under non-GNU compilers.
With those patches, there are many errors from building getopt.c because it needs to '#include <strings.h>', a warning from utils.c that 'getline' is undefined (needs an 'extern' prototype?), the warnings about from compile.c (should OB_MALLOC be declared to be of type (void *)?), and finally the complain about the redefinition of RE_DUP_MAX (which I guess should be guarded in case its already set). The good news is that in spite of these warnings, sed compiles successfully, and scores 75/75 in its test-suite :)
Patch added, thanks!