Per-source CFLAGS

From: David Schultz (dschultz_at_OCF.Berkeley.EDU)
Date: 06/22/03

  • Next message: Bruce Evans: "Re: Per-source CFLAGS"
    Date: Sat, 21 Jun 2003 17:51:24 -0700
    To: arch@FreeBSD.ORG
    
    

    The following patch adds support for per-file CFLAGS, which gets
    appended to the command line after the global CFLAGS. I would
    like to commit this in a few days. Do people want a similar
    feature for LDFLAGS? If we do add it to LDFLAGS, I will have to
    rework the following patch to use ${CFLAGS_${.TARGET}} instead of
    ${CFLAGS_${.IMPSRC}}, for consistency. The present version only
    works on C sources.

    I intend to use this feature for gdtoa, which is technically part
    of libc, but also on a vendor branch and intended to stay that
    way. The problem being addressed is that gcc at higher warning
    levels has some inane warnings that the vendor and I consider
    wrong, and yet people want to be able to compile libc cleanly at
    these warning levels. As an example, gcc complains that the
    expression 'a << b - c' must have parentheses because obviously
    nobody remembers C's precedence rules. So here's just one
    potential use of the new feature:

    Index: lib/libc/gdtoa/Makefile.inc
    ===================================================================
    RCS file: /cvs/src/lib/libc/gdtoa/Makefile.inc,v
    retrieving revision 1.3
    diff -u -r1.3 Makefile.inc
    --- lib/libc/gdtoa/Makefile.inc 5 Apr 2003 22:10:13 -0000 1.3
    +++ lib/libc/gdtoa/Makefile.inc 2 May 2003 09:31:15 -0000
    @@ -16,6 +16,7 @@
     .for src in ${GDTOASRCS}
     MISRCS+=gdtoa_${src}
     CLEANFILES+=gdtoa_${src}
    +CFLAGS_gdtoa_${src}+=-w
     gdtoa_${src}:
             ln -sf ${.CURDIR}/../../contrib/gdtoa/${src} ${.TARGET}
     .endfor

    The patch I would actually like reviewed is this one:

    Index: share/mk/bsd.lib.mk
    ===================================================================
    RCS file: /cvs/src/share/mk/bsd.lib.mk,v
    retrieving revision 1.140
    diff -u -r1.140 bsd.lib.mk
    --- share/mk/bsd.lib.mk 10 Jun 2003 04:47:49 -0000 1.140
    +++ share/mk/bsd.lib.mk 21 Jun 2003 08:39:35 -0000
    @@ -53,17 +53,18 @@
                 touch ${.TARGET}
     
     .c.o:
    - ${CC} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
    + ${CC} ${CFLAGS} ${CFLAGS_${.IMPSRC}} -c ${.IMPSRC} -o ${.TARGET}
             @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET}
             @mv ${.TARGET}.tmp ${.TARGET}
     
     .c.po:
    - ${CC} -pg ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
    + ${CC} -pg ${CFLAGS} ${CFLAGS_${.IMPSRC}} -c ${.IMPSRC} -o ${.TARGET}
             @${LD} -o ${.TARGET}.tmp -X -r ${.TARGET}
             @mv ${.TARGET}.tmp ${.TARGET}
     
     .c.So:
    - ${CC} ${PICFLAG} -DPIC ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
    + ${CC} ${PICFLAG} -DPIC ${CFLAGS} ${CFLAGS_${.IMPSRC}} \
    + -c ${.IMPSRC} -o ${.TARGET}
             @${LD} ${LDFLAGS} -o ${.TARGET}.tmp -x -r ${.TARGET}
             @mv ${.TARGET}.tmp ${.TARGET}
     
    @@ -113,36 +114,38 @@
             @mv ${.TARGET}.tmp ${.TARGET}
     
     .s.o .asm.o:
    - ${CC} -x assembler-with-cpp ${CFLAGS} ${AINC} -c \
    + ${CC} -x assembler-with-cpp ${CFLAGS} ${CFLAGS_${.IMPSRC}} ${AINC} -c \
                 ${.IMPSRC} -o ${.TARGET}
             @${LD} ${LDFLAGS} -o ${.TARGET}.tmp -x -r ${.TARGET}
             @mv ${.TARGET}.tmp ${.TARGET}
     
     .s.po .asm.po:
    - ${CC} -x assembler-with-cpp -DPROF ${CFLAGS} ${AINC} -c \
    - ${.IMPSRC} -o ${.TARGET}
    + ${CC} -x assembler-with-cpp -DPROF ${CFLAGS} ${CFLAGS_${.IMPSRC}} \
    + ${AINC} -c ${.IMPSRC} -o ${.TARGET}
             @${LD} ${LDFLAGS} -o ${.TARGET}.tmp -X -r ${.TARGET}
             @mv ${.TARGET}.tmp ${.TARGET}
     
     .s.So .asm.So:
             ${CC} -x assembler-with-cpp ${PICFLAG} -DPIC ${CFLAGS} \
    - ${AINC} -c ${.IMPSRC} -o ${.TARGET}
    + ${CFLAGS_${.IMPSRC}} ${AINC} -c ${.IMPSRC} -o ${.TARGET}
             @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET}
             @mv ${.TARGET}.tmp ${.TARGET}
     
     .S.o:
    - ${CC} ${CFLAGS} ${AINC} -c ${.IMPSRC} -o ${.TARGET}
    + ${CC} ${CFLAGS} ${CFLAGS_${.IMPSRC}} ${AINC} \
    + -c ${.IMPSRC} -o ${.TARGET}
             @${LD} ${LDFLAGS} -o ${.TARGET}.tmp -x -r ${.TARGET}
             @mv ${.TARGET}.tmp ${.TARGET}
     
     .S.po:
    - ${CC} -DPROF ${CFLAGS} ${AINC} -c ${.IMPSRC} -o ${.TARGET}
    + ${CC} -DPROF ${CFLAGS} ${CFLAGS_${.IMPSRC}} ${AINC} \
    + -c ${.IMPSRC} -o ${.TARGET}
             @${LD} ${LDFLAGS} -o ${.TARGET}.tmp -X -r ${.TARGET}
             @mv ${.TARGET}.tmp ${.TARGET}
     
     .S.So:
    - ${CC} ${PICFLAG} -DPIC ${CFLAGS} ${AINC} -c ${.IMPSRC} \
    - -o ${.TARGET}
    + ${CC} ${PICFLAG} -DPIC ${CFLAGS} ${CFLAGS_${.IMPSRC}} ${AINC} \
    + -c ${.IMPSRC} -o ${.TARGET}
             @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET}
             @mv ${.TARGET}.tmp ${.TARGET}
     
    Index: share/mk/sys.mk
    ===================================================================
    RCS file: /cvs/src/share/mk/sys.mk,v
    retrieving revision 1.67
    diff -u -r1.67 sys.mk
    --- share/mk/sys.mk 1 Jun 2003 22:13:45 -0000 1.67
    +++ share/mk/sys.mk 21 Jun 2003 08:56:15 -0000
    @@ -117,7 +117,8 @@
     
     # SINGLE SUFFIX RULES
     .c:
    - ${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${.IMPSRC}
    + ${CC} ${CFLAGS} ${CFLAGS_${.IMPSRC}} ${LDFLAGS} \
    + -o ${.TARGET} ${.IMPSRC}
     
     .f:
             ${FC} ${FFLAGS} ${LDFLAGS} -o ${.TARGET} ${.IMPSRC}
    @@ -129,20 +130,20 @@
     # DOUBLE SUFFIX RULES
     
     .c.o:
    - ${CC} ${CFLAGS} -c ${.IMPSRC}
    + ${CC} ${CFLAGS} ${CFLAGS_${.IMPSRC}} -c ${.IMPSRC}
     
     .f.o:
             ${FC} ${FFLAGS} -c ${.IMPSRC}
     
     .y.o:
             ${YACC} ${YFLAGS} ${.IMPSRC}
    - ${CC} ${CFLAGS} -c y.tab.c
    + ${CC} ${CFLAGS} ${CFLAGS_${.IMPSRC}} -c y.tab.c
             rm -f y.tab.c
             mv y.tab.o ${.TARGET}
     
     .l.o:
             ${LEX} ${LFLAGS} ${.IMPSRC}
    - ${CC} ${CFLAGS} -c lex.yy.c
    + ${CC} ${CFLAGS} ${CFLAGS_${.IMPSRC}} -c lex.yy.c
             rm -f lex.yy.c
             mv lex.yy.o ${.TARGET}
     
    @@ -155,7 +156,7 @@
             mv lex.yy.c ${.TARGET}
     
     .c.a:
    - ${CC} ${CFLAGS} -c ${.IMPSRC}
    + ${CC} ${CFLAGS} ${CFLAGS_${.IMPSRC}} -c ${.IMPSRC}
             ${AR} ${ARFLAGS} ${.TARGET} ${.PREFIX}.o
             rm -f ${.PREFIX}.o
     
    @@ -181,10 +182,11 @@
                 touch ${.TARGET}
     
     .c:
    - ${CC} ${CFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
    + ${CC} ${CFLAGS} ${CFLAGS_${.IMPSRC}} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} \
    + -o ${.TARGET}
     
     .c.o:
    - ${CC} ${CFLAGS} -c ${.IMPSRC}
    + ${CC} ${CFLAGS} ${CFLAGS_${.IMPSRC}} -c ${.IMPSRC}
     
     .cc .cpp .cxx .C:
             ${CXX} ${CXXFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
    @@ -206,7 +208,7 @@
             ${FC} ${RFLAGS} ${EFLAGS} ${FFLAGS} -c ${.IMPSRC}
     
     .S.o:
    - ${CC} ${CFLAGS} -c ${.IMPSRC}
    + ${CC} ${CFLAGS} ${CFLAGS_${.IMPSRC}} -c ${.IMPSRC}
     
     .s.o .asm.o:
             ${AS} ${AFLAGS} -o ${.TARGET} ${.IMPSRC}
    @@ -214,12 +216,12 @@
     # XXX not -j safe
     .y.o:
             ${YACC} ${YFLAGS} ${.IMPSRC}
    - ${CC} ${CFLAGS} -c y.tab.c -o ${.TARGET}
    + ${CC} ${CFLAGS} ${CFLAGS_${.IMPSRC}} -c y.tab.c -o ${.TARGET}
             rm -f y.tab.c
     
     .l.o:
             ${LEX} -t ${LFLAGS} ${.IMPSRC} > ${.PREFIX}.tmp.c
    - ${CC} ${CFLAGS} -c ${.PREFIX}.tmp.c -o ${.TARGET}
    + ${CC} ${CFLAGS} ${CFLAGS_${.IMPSRC}} -c ${.PREFIX}.tmp.c -o ${.TARGET}
             rm -f ${.PREFIX}.tmp.c
     
     # XXX not -j safe
    @@ -231,7 +233,8 @@
             ${LEX} -t ${LFLAGS} ${.IMPSRC} > ${.TARGET}
     
     .s.out .c.out .o.out:
    - ${CC} ${CFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
    + ${CC} ${CFLAGS} ${CFLAGS_${.IMPSRC}} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} \
    + -o ${.TARGET}
     
     .f.out .F.out .r.out .e.out:
             ${FC} ${EFLAGS} ${RFLAGS} ${FFLAGS} ${LDFLAGS} ${.IMPSRC} \
    @@ -241,12 +244,14 @@
     # XXX not -j safe
     .y.out:
             ${YACC} ${YFLAGS} ${.IMPSRC}
    - ${CC} ${CFLAGS} ${LDFLAGS} y.tab.c ${LDLIBS} -ly -o ${.TARGET}
    + ${CC} ${CFLAGS} ${CFLAGS_${.IMPSRC}} ${LDFLAGS} y.tab.c ${LDLIBS} \
    + -ly -o ${.TARGET}
             rm -f y.tab.c
     
     .l.out:
             ${LEX} -t ${LFLAGS} ${.IMPSRC} > ${.PREFIX}.tmp.c
    - ${CC} ${CFLAGS} ${LDFLAGS} ${.PREFIX}.tmp.c ${LDLIBS} -ll -o ${.TARGET}
    + ${CC} ${CFLAGS} ${CFLAGS_${.IMPSRC}} ${LDFLAGS} ${.PREFIX}.tmp.c \
    + ${LDLIBS} -ll -o ${.TARGET}
             rm -f ${.PREFIX}.tmp.c
     
     .endif
    _______________________________________________
    freebsd-arch@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-arch
    To unsubscribe, send any mail to "freebsd-arch-unsubscribe@freebsd.org"


  • Next message: Bruce Evans: "Re: Per-source CFLAGS"