esp-idf-bootloader: when binding for esp, skip posix.c
[apeos.git] / program.mk
blobde2c13085355cfecd0c01be0e3141772a587860e
1 # Copyright 2018 apeos contributors
3 # apeos partial GNU makefile, build binary program from C sources
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # variables that have to be set before evaulating this program:
20 # BIN - name of the resulting binary program
21 # SRCS - whitespace separated list of source filenames in /src/,
22 # without /src/ prefix.
24 TOP_DIR := $(shell pwd)
25 #$(warning TOP_DIR=$(TOP_DIR))
26 BUILD_DIR_BASE := $(TOP_DIR)/build
27 #$(warning BUILD_DIR_BASE=$(BUILD_DIR_BASE))
28 BUILD_PREFIX := $(BUILD_DIR_BASE)/$(BIN)-
29 #$(warning BUILD_PREFIX=$(BUILD_PREFIX))
30 SRC_DIR := $(TOP_DIR)/src
32 BIN_PATH := $(BUILD_DIR_BASE)/$(BIN)
34 # by default, create the resulting binary file
35 .PHONY: default
36 default: $(BIN_PATH)
37 @file $(BIN_PATH)
39 #$(warning SRC_DIR=$(SRC_DIR))
40 SRCS_PREFIXED := $(addprefix $(SRC_DIR)/,$(SRCS))
41 #$(warning SRCS_PREFIXED="$(SRCS_PREFIXED)")
42 OBJS := $(addprefix $(BUILD_PREFIX),$(patsubst %.c,%.o,$(SRCS)))
43 #$(warning OBJS="$(OBJS)")
45 BUILT_FILES := $(OBJS) $(BIN)
47 $(BUILT_FILES): program.mk
49 CPPFLAGS := -I include
51 CFLAGS := -pipe
52 LDFLAGS :=
54 ifeq ($(CFG),debug)
55 CFLAGS += -O0
56 CFLAGS += -g
57 LDFLAGS += -g
58 endif
59 ifeq ($(CFG),size)
60 CFLAGS := -Os
61 endif
63 CFLAGS += -static
64 LDFLAGS += -static
66 # gcc
67 CC := $(GCC_PREFIX)gcc
68 LD := $(GCC_PREFIX)gcc
70 ifneq ($(V),1)
71 CC := @$(CC)
72 LD := @$(LD)
73 endif
75 $(BUILD_DIR_BASE):
76 @mkdir -v $@
78 $(BUILT_FILES): $(BUILD_DIR_BASE)
80 $(BUILD_PREFIX)%.o: $(SRC_DIR)/%.c
81 @echo [CC] $(shell basename $<)
82 $(CC) -c $< $(CPPFLAGS) $(CFLAGS) -o $@
84 $(BIN_PATH): $(OBJS)
85 @echo [LD] $(BIN)
86 $(LD) $(OBJS) $(LDFLAGS) -o $@
88 .PHONY: clean
89 clean:
90 @rm -vf $(BUILT_FILES)