Changeset 1574


Ignore:
Timestamp:
Aug 14, 2012 11:36:11 PM (9 months ago)
Author:
hailfinger
Message:

Allow the user to specify CFLAGS without breaking the build

GNU make has a very interesting quirk: If you set a variable on the
command line, any changes to that variable in the Makefile are ignored
unless marked with the "override" keyword.

Use CFLAGS only for optimization and warning options, and use CPPFLAGS
for the dependency and other preprocessor related options.
That way packagers can specify their own CFLAGS without breaking the
build.

As a side benefit, the ich_descriptors_tool Makefile now behaves exactly
the same whether called standalone or as part of the main Makefile.

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@…>
Acked-by: Stefan Tauner <stefan.tauner@…>

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Makefile

    r1567 r1574  
    2727# make CC=i586-pc-msdosdjgpp-gcc 
    2828# You may have to specify STRIP/AR/RANLIB as well. 
     29# 
     30# Note for anyone editing this Makefile: gnumake will happily ignore any 
     31# changes in this Makefile to variables set on the command line. 
    2932CC      ?= gcc 
    3033STRIP   ?= strip 
     
    8487CPPFLAGS += -I../libgetopt 
    8588# DJGPP has odd uint*_t definitions which cause lots of format string warnings. 
    86 CPPFLAGS += -Wno-format 
     89CFLAGS += -Wno-format 
    8790# FIXME Check if we can achieve the same effect with -L../libgetopt -lgetopt 
    8891LIBS += ../libgetopt/libgetopt.a 
     
    120123EXEC_SUFFIX := .exe 
    121124# MinGW doesn't have the ffs() function, but we can use gcc's __builtin_ffs(). 
    122 CFLAGS += -Dffs=__builtin_ffs 
     125CPPFLAGS += -Dffs=__builtin_ffs 
    123126# libusb-win32/libftdi stuff is usually installed in /usr/local. 
    124127CPPFLAGS += -I/usr/local/include 
  • trunk/util/ich_descriptors_tool/Makefile

    r1567 r1574  
    1 CC ?= gcc 
     1# 
     2# This file is part of the flashrom project. 
     3# 
     4# This Makefile works standalone, but it is usually called from the main 
     5# Makefile in the flashrom directory. 
    26 
    37PROGRAM=ich_descriptors_tool 
     
    711SHAREDSRC = ich_descriptors.c 
    812SHAREDSRCDIR = ../.. 
     13# If your compiler spits out excessive warnings, run make WARNERROR=no 
     14# You shouldn't have to change this flag. 
     15WARNERROR ?= yes 
    916 
    1017SRC = $(wildcard *.c) 
    1118 
    12 CFLAGS += -Wall 
    13 CFLAGS += -MMD -MP -MF $(DEPPATH)/$(@F).d 
    14 # enables functions that populate the descriptor structs from plain binary dumps 
    15 CFLAGS += -D ICH_DESCRIPTORS_FROM_DUMP 
    16 CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) 
     19CC ?= gcc 
    1720 
     21# If the user has specified custom CFLAGS, all CFLAGS settings below will be 
     22# completely ignored by gnumake. 
     23CFLAGS ?= -Os -Wall -Wshadow 
    1824ifeq ($(TARGET_OS), DOS) 
    1925# DJGPP has odd uint*_t definitions which cause lots of format string warnings. 
    2026CFLAGS += -Wno-format 
    2127endif 
     28ifeq ($(WARNERROR), yes) 
     29CFLAGS += -Werror 
     30endif 
     31 
     32 
     33CPPFLAGS += -MMD -MP -MF $(DEPPATH)/$(@F).d 
     34# enables functions that populate the descriptor structs from plain binary dumps 
     35CPPFLAGS += -D ICH_DESCRIPTORS_FROM_DUMP 
     36CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) 
    2237 
    2338OBJ = $(OBJATH)/$(SRC:%.c=%.o) 
     
    2843 
    2944$(OBJ): $(OBJATH)/%.o : %.c 
    30         $(CC) $(CFLAGS) -o $@ -c $< 
     45        $(CC) $(CFLAGS) $(CPPFLAGS) -o $@ -c $< 
    3146 
    3247# this enables us to share source files without simultaneously sharing .o files 
    3348# with flashrom, which would lead to unexpected results (w/o running make clean) 
    3449$(SHAREDOBJ): $(OBJATH)/%.o : $(SHAREDSRCDIR)/%.c 
    35         $(CC) $(CFLAGS) -o $@ -c $< 
     50        $(CC) $(CFLAGS) $(CPPFLAGS) -o $@ -c $< 
    3651 
    3752$(PROGRAM)$(EXEC_SUFFIX): $(OBJ) $(SHAREDOBJ) 
Note: See TracChangeset for help on using the changeset viewer.