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
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
67 CC
:= $(GCC_PREFIX
)gcc
68 LD
:= $(GCC_PREFIX
)gcc
78 $(BUILT_FILES
): |
$(BUILD_DIR_BASE
)
80 $(BUILD_PREFIX
)%.o
: $(SRC_DIR
)/%.c
81 @echo
[CC
] $(shell basename $<)
82 $(CC
) -c
$< $(CPPFLAGS
) $(CFLAGS
) -o
$@
86 $(LD
) $(OBJS
) $(LDFLAGS
) -o
$@
90 @
rm -vf
$(BUILT_FILES
)