diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2009-11-24 15:39:58 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2009-11-24 15:39:58 -0800 |
commit | 1034ea7e8532da25cceb292469e8d90b6041ffab (patch) | |
tree | 5752b9e5b776450499b75e9afe0ccc550a9564a9 | |
parent | c9589217a057869582aa6a5ec1dbd048a525455e (diff) | |
download | txr-1034ea7e8532da25cceb292469e8d90b6041ffab.tar.gz txr-1034ea7e8532da25cceb292469e8d90b6041ffab.tar.bz2 txr-1034ea7e8532da25cceb292469e8d90b6041ffab.zip |
Auto-detect what specifiers to use for inline functions.
Allow compiler command to be set independently of full path
for easier compiler switching.
-rw-r--r-- | ChangeLog | 20 | ||||
-rw-r--r-- | Makefile | 6 | ||||
-rwxr-xr-x | configure | 68 | ||||
-rw-r--r-- | lib.h | 18 |
4 files changed, 90 insertions, 22 deletions
@@ -1,5 +1,25 @@ 2009-11-24 Kaz Kylheku <kkylheku@gmail.com> + Auto-detect what specifiers to use for inline functions. + Allow compiler command to be set independently of full path + for easier compiler switching. + + * Makefile (conftest.o): Target removed. What this rule does + is already an implicit rule; and nowhere else in the Makefile + are there rules for .c -> .o. + (conftest2): New target, for two-translation-unit config test program. + (INLINE_FLAGS): Removed. + + * configure (ccname, inline): New variables. + (inline_flags): Variable removed. INLINE_FLAGS not generated + any more in config.make. Added test for what inline specifiers to use, + which is turned into #define INLINE ... in the config.h header. + + * lib.h: (tag, is_ptr, is_num, is_chr, is_lit, type, auto_str, + static_str, litptr): Changed from inline to INLINE. + +2009-11-24 Kaz Kylheku <kkylheku@gmail.com> + Changes to make the code portable to C++ compilers, which can be taken advantage of for better diagnostics. @@ -29,7 +29,7 @@ -include config.make CFLAGS := -I. -I$(top_srcdir) $(LANG_FLAGS) $(DIAG_FLAGS) \ - $(OPT_FLAGS) $(INLINE_FLAGS) $(DBG_FLAGS) $(PLATFORM_FLAGS) + $(OPT_FLAGS) $(DBG_FLAGS) $(PLATFORM_FLAGS) CFLAGS := $(filter-out $(REMOVE_FLAGS),$(CFLAGS)) OBJS := txr.o lex.yy.o y.tab.o match.o lib.o regex.o gc.o unwind.o stream.o @@ -110,8 +110,8 @@ config.make config.h: conftest: conftest.c $(CC) $(CFLAGS) -o $@ $^ -conftest.o: conftest.c - $(CC) $(CFLAGS) -c -o $@ $^ +conftest2: conftest1.c conftest2.c + $(CC) $(CFLAGS) -o $@ $^ conftest.syms: conftest.o $(NM) -t o -P $^ > $@ @@ -103,18 +103,19 @@ datadir=${datadir-'$(prefix)/share/txr'} mandir=${mandir-'$(prefix)/share/man'} cross=${cross-} compiler_prefix=${compiler_prefix-} -cc=${cc-'$(cross)$(compiler_prefix)gcc'} -intptr= +ccname=${ccname-gcc} +cc=${cc-'$(cross)$(compiler_prefix)$(ccname)'} +intptr=${intptr-} tool_prefix=${tool_prefix-} lex=${lex-'$(cross)$(tool_prefix)flex'} lexlib=${lexlib--lfl} yacc=${yacc-'$(cross)$(tool_prefix)yacc'} nm=${nm-'$(cross)$(tool_prefix)nm'} opt_flags=${opt_flags--O2} -lang_flags=${lang_flags--ansi -std=c89 -D_POSIX_C_SOURCE=2} +lang_flags=${lang_flags--ansi -D_POSIX_C_SOURCE=2} diag_flags=${diag_flags--Wall} debug_flags=${debug_flags--g} -inline_flags=${inline_flags--Dinline=\"static __inline\"} +inline=${inline-} platform_flags=${platform_flags-} remove_flags=${remove_flags-} lex_dbg_flags=${lex_dbg_flags-} @@ -206,6 +207,11 @@ compiler_prefix [$compiler_prefix] "bin/mips-linux-" then the compiler command, unless otherwise specified, will be "/cross/toolchain/bin/mips-linux-gcc". +ccname [$ccname] + + Specifies just the name of the compiler front-end program, without the path. + The following variable, cc, specifies the full name. + cc [$cc] Specifies the name of the toolchain front-end driver command to use for @@ -218,6 +224,15 @@ intptr [$intptr] value can be converted to it. If this is blank, the configure script will try to auto detect it. +inline [$inline] + + Specifies the syntax for defining an inline function, in such + a way that the function definition can be included into multiple + translation units without clashes. + + If blank, an attempt is made to auto-detect this which + falls back on "static". + tool_prefix [$tool_prefix] Specifies a prefix to be added to tool commands other than the @@ -260,11 +275,6 @@ debug_flags [$debug_flags] Specifies flags for requesting that debugging information be retained in the compile and link. -inline_flags [$inline_flags] - - Specifies flag for defining a macro that expands to a suitable - compiler-specific inline specifier. - platform_flags [$platform_flags] Specify additional compiler flags for anything else, such as CPU tuning, @@ -458,6 +468,9 @@ mandir := $mandir # cross compiler toolchain root directory cross := $cross +# compiler name +ccname = $ccname + # prefix for compiler command compiler_prefix := $compiler_prefix @@ -474,7 +487,6 @@ OPT_FLAGS := $opt_flags LANG_FLAGS := $lang_flags DIAG_FLAGS := $diag_flags DBG_FLAGS := $debug_flags -INLINE_FLAGS := $inline_flags PLATFORM_FLAGS := $platform_flags REMOVE_FLAGS := $remove_flags LEX_DBG_FLAGS := $lex_dbg_flags @@ -598,10 +610,46 @@ intptr_max_expr="((((($intptr) 1 << $((sizeof_ptr * 8 - 2))) - 1) << 1) + 1)" printf "#define INT_PTR_MAX %s\n" "$intptr_max_expr" >> config.h printf "#define INT_PTR_MIN (-INT_PTR_MAX)\n" >> config.h +printf "Checking how to declare inline functions ... " + +if [ -z "$inline" ] ; then + for inline in \ + "inline" "static inline" "extern inline" \ + "__inline__" "static __inline__" "extern __inline__" \ + "static" + do + cat > conftest1.c <<! +$inline int func(void) +{ + return 0; +} + +int main(void) +{ + return func(); +} +! + cat > conftest2.c <<! +$inline int func(void) +{ + return 0; +} +! + if ! make conftest2 > conftest.err 2>&1 ; then + continue + fi + break + done +fi + +printf '"%s"\n' "$inline" +printf "#define INLINE $inline\n" >> config.h + # # Clean up # rm -f conftest conftest.c conftest.o conftest.err conftest.syms +rm -f conftest1.o conftest2.o conftest2 # # Save configuration in config.log @@ -163,28 +163,28 @@ union obj { struct cobj co; }; -inline cnum tag(val obj) { return ((cnum) obj) & TAG_MASK; } -inline int is_ptr(val obj) { return obj && tag(obj) == TAG_PTR; } -inline int is_num(val obj) { return tag(obj) == TAG_NUM; } -inline int is_chr(val obj) { return tag(obj) == TAG_CHR; } -inline int is_lit(val obj) { return tag(obj) == TAG_LIT; } +INLINE cnum tag(val obj) { return ((cnum) obj) & TAG_MASK; } +INLINE int is_ptr(val obj) { return obj && tag(obj) == TAG_PTR; } +INLINE int is_num(val obj) { return tag(obj) == TAG_NUM; } +INLINE int is_chr(val obj) { return tag(obj) == TAG_CHR; } +INLINE int is_lit(val obj) { return tag(obj) == TAG_LIT; } -inline type_t type(val obj) +INLINE type_t type(val obj) { return tag(obj) ? (type_t) tag(obj) : obj->t.type; } -inline val auto_str(const wchar_t *str) +INLINE val auto_str(const wchar_t *str) { return (val) ((cnum) (str) | TAG_LIT); } -inline val static_str(const wchar_t *str) +INLINE val static_str(const wchar_t *str) { return (val) ((cnum) (str) | TAG_LIT); } -inline wchar_t *litptr(val obj) +INLINE wchar_t *litptr(val obj) { return (wchar_t *) ((cnum) obj & ~TAG_MASK); } |