blob: ea80dc633a05f844ea6cbb11c4282ef5a299115b [file] [log] [blame]
Carl-Daniel Hailfingerb7bce8a2012-08-14 21:36:11 +00001#
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.
Stefan Taunerb3850962011-12-24 00:00:32 +00006
Thomas Heijligen1e76dc82021-09-28 15:22:34 +02007include ../../Makefile.include
8
Stefan Taunerb3850962011-12-24 00:00:32 +00009PROGRAM=ich_descriptors_tool
10EXTRAINCDIRS = ../../ .
11DEPPATH = .dep
12OBJATH = .obj
13SHAREDSRC = ich_descriptors.c
14SHAREDSRCDIR = ../..
Carl-Daniel Hailfingerb7bce8a2012-08-14 21:36:11 +000015# If your compiler spits out excessive warnings, run make WARNERROR=no
16# You shouldn't have to change this flag.
17WARNERROR ?= yes
Stefan Taunerb3850962011-12-24 00:00:32 +000018
19SRC = $(wildcard *.c)
20
Carl-Daniel Hailfingerb7bce8a2012-08-14 21:36:11 +000021# If the user has specified custom CFLAGS, all CFLAGS settings below will be
22# completely ignored by gnumake.
23CFLAGS ?= -Os -Wall -Wshadow
Stefan Taunerf268d8b2017-10-26 18:45:00 +020024
Thomas Heijligen3976b7e2021-10-20 15:55:35 +020025# Auto determine HOST_OS and TARGET_OS if they are not set as argument
Miklós Mártona75a2ed2018-01-30 20:25:00 +010026HOST_OS ?= $(shell uname)
Thomas Heijligen3976b7e2021-10-20 15:55:35 +020027TARGET_OS := $(call c_macro_test, ../../Makefile.d/os_test.h)
28
Miklós Mártona75a2ed2018-01-30 20:25:00 +010029ifeq ($(findstring MINGW, $(HOST_OS)), MINGW)
30# Explicitly set CC = gcc on MinGW, otherwise: "cc: command not found".
31CC = gcc
Miklós Mártona75a2ed2018-01-30 20:25:00 +010032endif
33
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +000034ifeq ($(TARGET_OS), DOS)
Stefan Taunerf268d8b2017-10-26 18:45:00 +020035EXEC_SUFFIX := .exe
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +000036# DJGPP has odd uint*_t definitions which cause lots of format string warnings.
Nico Huber8b1b3142023-01-08 13:46:05 +010037FLASHROM_CFLAGS += -Wno-format
38endif
39
40ifeq ($(TARGET_OS), MinGW)
41EXEC_SUFFIX := .exe
42# Some functions provided by Microsoft do not work as described in C99 specifications. This macro fixes that
Thomas Heijligen3976b7e2021-10-20 15:55:35 +020043# for MinGW. See http://sourceforge.net/p/mingw-w64/wiki2/printf%20and%20scanf%20family/
Nico Huber8b1b3142023-01-08 13:46:05 +010044FLASHROM_CFLAGS += -D__USE_MINGW_ANSI_STDIO=1
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +000045endif
Stefan Taunerf268d8b2017-10-26 18:45:00 +020046
Carl-Daniel Hailfingerb7bce8a2012-08-14 21:36:11 +000047ifeq ($(WARNERROR), yes)
48CFLAGS += -Werror
49endif
50
51
Carl-Daniel Hailfingera8da2242012-08-15 23:06:32 +000052FLASHROM_CFLAGS += -MMD -MP -MF $(DEPPATH)/$(@F).d
Carl-Daniel Hailfingerb7bce8a2012-08-14 21:36:11 +000053# enables functions that populate the descriptor structs from plain binary dumps
Nico Huberad186312016-05-02 15:15:29 +020054FLASHROM_CFLAGS += -D ICH_DESCRIPTORS_FROM_DUMP_ONLY
Carl-Daniel Hailfingera8da2242012-08-15 23:06:32 +000055FLASHROM_CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +000056
Stefan Taunerb3850962011-12-24 00:00:32 +000057OBJ = $(OBJATH)/$(SRC:%.c=%.o)
58
59SHAREDOBJ = $(OBJATH)/$(notdir $(SHAREDSRC:%.c=%.o))
60
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +000061all:$(PROGRAM)$(EXEC_SUFFIX)
Stefan Taunerb3850962011-12-24 00:00:32 +000062
63$(OBJ): $(OBJATH)/%.o : %.c
Carl-Daniel Hailfingera8da2242012-08-15 23:06:32 +000064 $(CC) $(CFLAGS) $(CPPFLAGS) $(FLASHROM_CFLAGS) -o $@ -c $<
Stefan Taunerb3850962011-12-24 00:00:32 +000065
66# this enables us to share source files without simultaneously sharing .o files
67# with flashrom, which would lead to unexpected results (w/o running make clean)
68$(SHAREDOBJ): $(OBJATH)/%.o : $(SHAREDSRCDIR)/%.c
Carl-Daniel Hailfingera8da2242012-08-15 23:06:32 +000069 $(CC) $(CFLAGS) $(CPPFLAGS) $(FLASHROM_CFLAGS) -o $@ -c $<
Stefan Taunerb3850962011-12-24 00:00:32 +000070
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +000071$(PROGRAM)$(EXEC_SUFFIX): $(OBJ) $(SHAREDOBJ)
Carl-Daniel Hailfingera8da2242012-08-15 23:06:32 +000072 $(CC) $(LDFLAGS) -o $(PROGRAM)$(EXEC_SUFFIX) $(OBJ) $(SHAREDOBJ)
Stefan Taunerb3850962011-12-24 00:00:32 +000073
Thomas Heijligen3976b7e2021-10-20 15:55:35 +020074# We don't use EXEC_SUFFIX here because we want to clean everything.
Stefan Taunerb3850962011-12-24 00:00:32 +000075clean:
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +000076 rm -f $(PROGRAM) $(PROGRAM).exe
Stefan Taunerb3850962011-12-24 00:00:32 +000077 rm -rf $(DEPPATH) $(OBJATH)
78
79# Include the dependency files.
80-include $(shell mkdir -p $(DEPPATH) $(OBJATH) 2>/dev/null) $(wildcard $(DEPPATH)/*)
81
82.PHONY: all clean