2010-02-06 6 views
0

다음 Makefile에 대한 조언이 필요합니다. 그것은 잘 작동하지만 지나치게 중복되고 C 프로젝트를 돕기 위해 할 수있는 대부분의 마법을 이용하지 않습니다.이 Makefile을 더 좋게/더 쉽게/덜 불필요하게 만들 수 있습니까?

그 목적은 작은 ANSI C 라이브러리를 테스트하는 것입니다. 이식성이 중요합니다.

.PHONY : test 

OPTIMIZE = -g 
INCLUDE = -I. 
CC  = gcc 
WARNINGS = -Wall -ansi -pedantic -Wno-long-long -Wextra -Wdeclaration-after-statement -Wendif-labels -Wconversion 
CFLAGS = $(WARNINGS) $(OPTIMIZE) $(INCLUDE) 
COMPILE = $(CC) $(CFLAGS) 
LINK  = $(COMPILE) 

all : time64.o bin/check_max 

bin/check_max : time64.o time64_config.h bin/check_max.c 
    $(LINK) time64.o bin/check_max.c -o [email protected] 

time64.o : time64_config.h time64.h time64.c Makefile 

t/bench : t/bench.c time64.o 
    $(LINK) time64.o t/bench.c -o [email protected] 

bench : t/bench 
    time t/bench 

t/localtime_test : t/localtime_test.c time64.o 
    $(LINK) time64.o t/localtime_test.c -o [email protected] 

t/gmtime_test : t/gmtime_test.c time64.o 
    $(LINK) time64.o t/gmtime_test.c -o [email protected] 

t/year_limit.t : t/tap.c t/year_limit.t.c time64.o 
    $(LINK) time64.o t/year_limit.t.c -o [email protected] 

t/negative.t : t/tap.c t/negative.t.c time64.o 
    $(LINK) time64.o t/negative.t.c -o [email protected] 

t/overflow.t : t/tap.c t/overflow.t.c time64.o 
    $(LINK) time64.o t/overflow.t.c -o [email protected] 

t/timegm.t : t/tap.c t/timegm.t.c time64.o 
    $(LINK) time64.o t/timegm.t.c -o [email protected] 

t/safe_year.t : t/tap.c t/safe_year.t.c time64.c 
    $(LINK) t/safe_year.t.c -o [email protected] 

t/gmtime64.t : t/tap.c t/gmtime64.t.c time64.o 
    $(LINK) time64.o t/gmtime64.t.c -o [email protected] 

t/mktime64.t : t/tap.c t/mktime64.t.c time64.o 
    $(LINK) time64.o t/mktime64.t.c -o [email protected] 

t/asctime64.t : t/tap.c t/asctime64.t.c time64.o 
    $(LINK) time64.o t/asctime64.t.c -o [email protected] 

t/ctime64.t : t/tap.c t/ctime64.t.c time64.o 
    $(LINK) time64.o t/ctime64.t.c -o [email protected] 

t/seconds_between_years.t : t/tap.c t/seconds_between_years.t.c time64.c 
    $(LINK) t/seconds_between_years.t.c -o [email protected] 

test : tap_tests localtime_tests 

localtime_tests: t/localtime_test t/gmtime_test 
    @which bzdiff > /dev/null || (echo 'You need bzdiff to run these tests'; exit 1) 
    @which less > /dev/null || (echo 'You need less to run these tests'; exit 1) 
    @echo "On failure, these tests will produce a diff between the failed and expected results. If they pass they'll be quiet." 
    TZ=Canada/Eastern t/gmtime_test | bzip2 -9 > t/gmtime_test.out.bz2 
    bzdiff -u t/gmtime_test.out.bz2 t/gmtime.out.bz2 | less -F 
    TZ=Canada/Eastern t/localtime_test | bzip2 -9 > t/eastern_test.out.bz2 
    bzdiff -u t/eastern_test.out.bz2 t/eastern.out.bz2 | less -F 
    TZ=Australia/West t/localtime_test | bzip2 -9 > t/oz_test.out.bz2 
    bzdiff -u t/oz_test.out.bz2 t/oztime.out.bz2 | less -F 

tap_tests: t/year_limit.t t/negative.t t/overflow.t t/timegm.t t/safe_year.t t/gmtime64.t t/asctime64.t t/ctime64.t 
    @which prove > /dev/null || (echo 'You need prove (from the Test::Harness perl module) to run these tests'; exit 1) 
    @prove --exec '' t/*.t 

clean: 
    -rm  t/*.t   \ 
     t/localtime_test \ 
     t/gmtime_test  \ 
     t/*_test.out.bz2 \ 
     t/bench   \ 
     *.o 

You can see it in situ here.

답변

3

암시 적 규칙을 사용하고 자동으로 알 수있는 것을 다시 선언하지 마십시오. 또한 상단의 변수가 단순화되었지만, 더 선호되는 변수도 있습니다 (기본값은 단순히 기본값을 재설정 함). 이것은 다소 덜 휴대 가능하지만 크게는 아닙니다. IMHO. 그것은 또한 어떤면에서 더 휴대 가능합니다. 'gcc'가 기본 컴파일러가 아닌 시스템에서.

localtime_tests와 tap_tests를 쉘 스크립트로 만들고 (하지만 그 기능을 변경하지 않음), 논리를 다른 위치로 옮기고 매일 메이크 파일을 읽을 수있게 만드는 주요 기능입니다. 이동성의 손실이 허용되는 경우

 
CFLAGS = -g -Wall -ansi -pedantic -Wno-long-long -Wextra \ 
-Wdeclaration-after-statement -Wendif-labels -Wconversion 

all : bin/check_max 

bin/check_max : time64.o time64_config.h 
time64.o : time64_config.h time64.h Makefile 

bench : t/bench 
    time t/bench 

t/bench : t/bench.c time64.o 
t/localtime_test : time64.o 
t/gmtime_test : time64.o 

t/year_limit.t: t/tap.c time64.o 
t/negative.t : t/tap.c time64.o 
t/overflow.t : t/tap.c time64.o 
t/timegm.t : t/tap.c time64.o 
t/safe_year.t : t/tap.c time64.c 
t/gmtime64.t : t/tap.c time64.o 
t/mktime64.t : t/tap.c time64.o 
t/asctime64.t : t/tap.c time64.o 
t/ctime64.t : t/tap.c time64.o 
t/seconds_between_years.t: t/tap.c time64.c 

test : tap_tests localtime_tests 
tap_tests: t/year_limit.t t/negative.t t/overflow.t t/timegm.t t/safe_year.t \ 
t/gmtime64.t t/asctime64.t t/ctime64.t 
    ./tap_tests 
localtime_tests: t/localtime_test t/gmtime_test 
    ./localtime_tests 
.PHONY : test tap_tests localtime_tests 

clean: 
    -rm t/*.t t/localtime_test t/gmtime_test t/*_test.out.bz2 t/bench 
    -rm *.o 
.PHONY : clean 

당신은 simplifymore에 GNUmake 특정 기능을 사용할 수 있습니다.

+0

고마워요! 나는 또한 테스트 코드에서보기 흉한 약간의 비트들을 정리해야한다는 충고를 대부분 취했다. 생산을위한 최적화 플래그를 변경하려고하지만 경고 플래그 만 남겨두기 때문에 CFLAGS를 조각에 남겼습니다. 나중에 localtime_tests를 Perl 스크립트로 정규화 할 것입니다. – Schwern

관련 문제