[PATCH] fix cc_ge and cc_le

Cristian Ionescu-Idbohrn cristian.ionescu-idbohrn at axis.com
Mon Mar 13 20:04:03 UTC 2006


On Mon, 13 Mar 2006, Cristian Ionescu-Idbohrn wrote:

> on my Debian sid box, and it didn't fail me once.

--- the test Makefile
#!/usr/bin/make -f

#CC	= i386-uclibc-linux-gcc
#CC	= gcc-2.95
#CC	= gcc-3.3
#CC	= gcc-3.4
CC	= gcc-4.0

# Get the CC MAJOR/MINOR version
# gcc centric. Perhaps fiddle with findstring gcc,$(CC) for the rest
CC_MAJOR:=$(shell printf "%02d" \
	$(shell echo __GNUC__ | $(CC) -E -xc - | tail -n 1))
CC_MINOR:=$(shell printf "%02d" \
	$(shell echo __GNUC_MINOR__ | $(CC) -E -xc - | tail -n 1))

# Note: spaces are significant here!

# Check if CC version is equal to given MAJOR,MINOR. Returns empty if false.
define cc_eq
$(shell [ `expr $(CC_MAJOR) \* 100 \+ $(CC_MINOR)` -eq \
	  `expr $(1) \* 100 \+ $(2)` ] && echo y)
endef

# Check if CC version is greater or equal than given MAJOR,MINOR
define cc_ge
$(shell [ `expr $(CC_MAJOR) \* 100 \+ $(CC_MINOR)` -ge \
	  `expr $(1) \* 100 \+ $(2)` ] && echo y)
endef

# Check if CC version is less or equal than given MAJOR,MINOR
define cc_le
$(shell [ `expr $(CC_MAJOR) \* 100 \+ $(CC_MINOR)` -le \
	  `expr $(1) \* 100 \+ $(2)` ] && echo y)
endef

CC_EQ_33 =$(if $(call cc_eq,3,3), $(shell echo "cc_eq 3.3 match"))
CC_GE_33 =$(if $(call cc_ge,3,3), $(shell echo "cc_ge 3.3 match"))
CC_LE_33 =$(if $(call cc_le,3,3), $(shell echo "cc_le 3.3 match"))

all:
	@echo CC=$(shell $(CC) -dumpversion)
	@echo CC_MAJOR=$(CC_MAJOR), CC_MINOR=$(CC_MINOR)
	@echo CC_EQ_33=$(CC_EQ_33)
	@echo CC_EQ_33=$(CC_GE_33)
	@echo CC_EQ_33=$(CC_LE_33)
---

And the test result:

# make -f Makefile.gcc-check # CC = i386-uclibc-linux-gcc
CC=3.3.6
CC_MAJOR=03, CC_MINOR=03
CC_EQ_33= cc_eq 3.3 match
CC_EQ_33= cc_ge 3.3 match
CC_EQ_33= cc_le 3.3 match

# make -f Makefile.gcc-check # CC = gcc-2.95
CC=2.95.4
CC_MAJOR=02, CC_MINOR=95
CC_EQ_33=
CC_EQ_33=
CC_EQ_33= cc_le 3.3 match

# make -f Makefile.gcc-check # CC = gcc-3.3
CC=3.3.6
CC_MAJOR=03, CC_MINOR=03
CC_EQ_33= cc_eq 3.3 match
CC_EQ_33= cc_ge 3.3 match
CC_EQ_33= cc_le 3.3 match

# make -f Makefile.gcc-check # CC = gcc-3.4
CC=3.4.6
CC_MAJOR=03, CC_MINOR=04
CC_EQ_33=
CC_EQ_33= cc_ge 3.3 match
CC_EQ_33=

# make -f Makefile.gcc-check # CC = gcc-4.0
CC=4.0.3
CC_MAJOR=04, CC_MINOR=00
CC_EQ_33=
CC_EQ_33= cc_ge 3.3 match
CC_EQ_33=

Same result when $SHELL is /bin/bash or /bin/dash.


Cheers,
Cristian



More information about the busybox mailing list