blob: 0891599890d0d4a53e2c9b8e0a302abc4150ad18 [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
Nico Huber23b2b862022-08-23 18:07:54 +020024override CFLAGS += -I$(SHAREDSRCDIR)/include
Stefan Taunerf268d8b2017-10-26 18:45:00 +020025
Thomas Heijligen3976b7e2021-10-20 15:55:35 +020026# Auto determine HOST_OS and TARGET_OS if they are not set as argument
Miklós Mártona75a2ed2018-01-30 20:25:00 +010027HOST_OS ?= $(shell uname)
Thomas Heijligen3976b7e2021-10-20 15:55:35 +020028TARGET_OS := $(call c_macro_test, ../../Makefile.d/os_test.h)
29
Miklós Mártona75a2ed2018-01-30 20:25:00 +010030ifeq ($(findstring MINGW, $(HOST_OS)), MINGW)
31# Explicitly set CC = gcc on MinGW, otherwise: "cc: command not found".
32CC = gcc
Miklós Mártona75a2ed2018-01-30 20:25:00 +010033endif
34
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +000035ifeq ($(TARGET_OS), DOS)
Stefan Taunerf268d8b2017-10-26 18:45:00 +020036EXEC_SUFFIX := .exe
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +000037# DJGPP has odd uint*_t definitions which cause lots of format string warnings.
Nico Huber8b1b3142023-01-08 13:46:05 +010038FLASHROM_CFLAGS += -Wno-format
39endif
40
41ifeq ($(TARGET_OS), MinGW)
42EXEC_SUFFIX := .exe
43# Some functions provided by Microsoft do not work as described in C99 specifications. This macro fixes that
Thomas Heijligen3976b7e2021-10-20 15:55:35 +020044# for MinGW. See http://sourceforge.net/p/mingw-w64/wiki2/printf%20and%20scanf%20family/
Nico Huber8b1b3142023-01-08 13:46:05 +010045FLASHROM_CFLAGS += -D__USE_MINGW_ANSI_STDIO=1
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +000046endif
Stefan Taunerf268d8b2017-10-26 18:45:00 +020047
Carl-Daniel Hailfingerb7bce8a2012-08-14 21:36:11 +000048ifeq ($(WARNERROR), yes)
49CFLAGS += -Werror
50endif
51
52
Carl-Daniel Hailfingera8da2242012-08-15 23:06:32 +000053FLASHROM_CFLAGS += -MMD -MP -MF $(DEPPATH)/$(@F).d
Carl-Daniel Hailfingerb7bce8a2012-08-14 21:36:11 +000054# enables functions that populate the descriptor structs from plain binary dumps
Nico Huberad186312016-05-02 15:15:29 +020055FLASHROM_CFLAGS += -D ICH_DESCRIPTORS_FROM_DUMP_ONLY
Carl-Daniel Hailfingera8da2242012-08-15 23:06:32 +000056FLASHROM_CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +000057
Stefan Taunerb3850962011-12-24 00:00:32 +000058OBJ = $(OBJATH)/$(SRC:%.c=%.o)
59
60SHAREDOBJ = $(OBJATH)/$(notdir $(SHAREDSRC:%.c=%.o))
61
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +000062all:$(PROGRAM)$(EXEC_SUFFIX)
Stefan Taunerb3850962011-12-24 00:00:32 +000063
64$(OBJ): $(OBJATH)/%.o : %.c
Carl-Daniel Hailfingera8da2242012-08-15 23:06:32 +000065 $(CC) $(CFLAGS) $(CPPFLAGS) $(FLASHROM_CFLAGS) -o $@ -c $<
Stefan Taunerb3850962011-12-24 00:00:32 +000066
67# this enables us to share source files without simultaneously sharing .o files
68# with flashrom, which would lead to unexpected results (w/o running make clean)
69$(SHAREDOBJ): $(OBJATH)/%.o : $(SHAREDSRCDIR)/%.c
Carl-Daniel Hailfingera8da2242012-08-15 23:06:32 +000070 $(CC) $(CFLAGS) $(CPPFLAGS) $(FLASHROM_CFLAGS) -o $@ -c $<
Stefan Taunerb3850962011-12-24 00:00:32 +000071
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +000072$(PROGRAM)$(EXEC_SUFFIX): $(OBJ) $(SHAREDOBJ)
Carl-Daniel Hailfingera8da2242012-08-15 23:06:32 +000073 $(CC) $(LDFLAGS) -o $(PROGRAM)$(EXEC_SUFFIX) $(OBJ) $(SHAREDOBJ)
Stefan Taunerb3850962011-12-24 00:00:32 +000074
Thomas Heijligen3976b7e2021-10-20 15:55:35 +020075# We don't use EXEC_SUFFIX here because we want to clean everything.
Stefan Taunerb3850962011-12-24 00:00:32 +000076clean:
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +000077 rm -f $(PROGRAM) $(PROGRAM).exe
Stefan Taunerb3850962011-12-24 00:00:32 +000078 rm -rf $(DEPPATH) $(OBJATH)
79
80# Include the dependency files.
81-include $(shell mkdir -p $(DEPPATH) $(OBJATH) 2>/dev/null) $(wildcard $(DEPPATH)/*)
82
83.PHONY: all clean