Sol Boucher | 0e53931 | 2015-03-05 15:38:03 -0800 | [diff] [blame] | 1 | obj ?= . |
Peter Stuge | 1d862de | 2009-04-14 00:08:34 +0000 | [diff] [blame] | 2 | |
Alexandru Gagniuc | 4a7b115 | 2014-01-27 17:17:29 -0600 | [diff] [blame] | 3 | HOSTCC ?= $(CC) |
Sol Boucher | 0e53931 | 2015-03-05 15:38:03 -0800 | [diff] [blame] | 4 | |
Stefan Tauner | d0398f1 | 2015-04-26 21:41:41 +0200 | [diff] [blame] | 5 | CFLAGS += -g3 |
Sol Boucher | 0e53931 | 2015-03-05 15:38:03 -0800 | [diff] [blame] | 6 | CFLAGS += -std=c99 -Werror -Wall -Wextra |
| 7 | CFLAGS += -Wcast-qual -Wmissing-prototypes -Wredundant-decls -Wshadow |
| 8 | CFLAGS += -Wstrict-prototypes -Wwrite-strings |
Sol Boucher | 69b88bf | 2015-02-26 11:47:19 -0800 | [diff] [blame] | 9 | CPPFLAGS += -D_DEFAULT_SOURCE # memccpy() from string.h |
Sol Boucher | 0e53931 | 2015-03-05 15:38:03 -0800 | [diff] [blame] | 10 | CPPFLAGS += -D_POSIX_C_SOURCE=200809L # strdup() from string.h |
Sol Boucher | 69b88bf | 2015-02-26 11:47:19 -0800 | [diff] [blame] | 11 | CPPFLAGS += -Iflashmap |
Paul Menzel | 6548ae9 | 2015-05-03 09:35:32 +0200 | [diff] [blame] | 12 | LDFLAGS += -g3 |
Stefan Reinauer | 3a5c277 | 2009-05-26 12:22:10 +0000 | [diff] [blame] | 13 | |
Aaron Durbin | 4fde5a6 | 2014-03-07 15:11:53 -0600 | [diff] [blame] | 14 | CBFSTOOL_BINARY:=$(obj)/cbfstool |
Sol Boucher | 0e53931 | 2015-03-05 15:38:03 -0800 | [diff] [blame] | 15 | CBFSTOOL_COMMON:=common.o cbfs_image.o compress.o fit.o |
Aaron Durbin | 4fde5a6 | 2014-03-07 15:11:53 -0600 | [diff] [blame] | 16 | CBFSTOOL_COMMON+=elfheaders.o cbfs-mkstage.o cbfs-mkpayload.o xdr.o |
Sol Boucher | e3260a0 | 2015-03-25 13:40:08 -0700 | [diff] [blame] | 17 | CBFSTOOL_COMMON+=partitioned_file.o linux_trampoline.o cbfs-payload-linux.o |
Aaron Durbin | 4be1674 | 2015-09-15 17:00:23 -0500 | [diff] [blame] | 18 | CBFSTOOL_COMMON+=rmodule.o |
Stefan Reinauer | 2e200cd | 2012-10-30 14:02:45 -0700 | [diff] [blame] | 19 | # LZMA |
Aaron Durbin | 4fde5a6 | 2014-03-07 15:11:53 -0600 | [diff] [blame] | 20 | CBFSTOOL_COMMON+=lzma/lzma.o |
| 21 | CBFSTOOL_COMMON+=lzma/C/LzFind.o lzma/C/LzmaDec.o lzma/C/LzmaEnc.o |
Sol Boucher | e3260a0 | 2015-03-25 13:40:08 -0700 | [diff] [blame] | 22 | # FMAP |
| 23 | CBFSTOOL_COMMON+=flashmap/fmap.o |
| 24 | CBFSTOOL_COMMON+=flashmap/kv_pair.o flashmap/valstr.o |
Peter Stuge | 1d862de | 2009-04-14 00:08:34 +0000 | [diff] [blame] | 25 | |
Aaron Durbin | 4fde5a6 | 2014-03-07 15:11:53 -0600 | [diff] [blame] | 26 | CBFSTOOL_COMMON:=$(addprefix $(obj)/,$(CBFSTOOL_COMMON)) |
Peter Stuge | 1d862de | 2009-04-14 00:08:34 +0000 | [diff] [blame] | 27 | |
Sol Boucher | 69b88bf | 2015-02-26 11:47:19 -0800 | [diff] [blame] | 28 | FMAPTOOL_BINARY:=$(obj)/fmaptool |
Sol Boucher | 023e829 | 2015-03-18 10:13:48 -0700 | [diff] [blame] | 29 | FMAPTOOL_COMMON:=cbfs_sections.o fmap_from_fmd.o |
| 30 | FMAPTOOL_COMMON+=fmd.o fmd_parser.o fmd_scanner.o |
Sol Boucher | 69b88bf | 2015-02-26 11:47:19 -0800 | [diff] [blame] | 31 | # FMAP |
| 32 | FMAPTOOL_COMMON+=flashmap/fmap.o |
| 33 | FMAPTOOL_COMMON+=flashmap/kv_pair.o flashmap/valstr.o |
| 34 | |
| 35 | FMAPTOOL_COMMON:=$(addprefix $(obj)/,$(FMAPTOOL_COMMON)) |
Aaron Durbin | 4fde5a6 | 2014-03-07 15:11:53 -0600 | [diff] [blame] | 36 | |
| 37 | RMODTOOL_BINARY:=$(obj)/rmodtool |
Sol Boucher | 0e53931 | 2015-03-05 15:38:03 -0800 | [diff] [blame] | 38 | RMODTOOL_COMMON:=rmodule.o common.o elfheaders.o xdr.o |
Aaron Durbin | 4fde5a6 | 2014-03-07 15:11:53 -0600 | [diff] [blame] | 39 | |
| 40 | RMODTOOL_COMMON:=$(addprefix $(obj)/,$(RMODTOOL_COMMON)) |
| 41 | |
Sol Boucher | 69b88bf | 2015-02-26 11:47:19 -0800 | [diff] [blame] | 42 | FMAPTESTS_BINARY:=$(obj)/flashmap_tests |
| 43 | FMAPTESTS_COMMON:=flashmap/fmap.o flashmap/valstr.o flashmap/kv_pair.o |
| 44 | |
| 45 | FMAPTESTS_COMMON:=$(addprefix $(obj)/,$(FMAPTESTS_COMMON)) |
| 46 | |
| 47 | GENERATED:=fmd_parser.c fmd_parser.h fmd_scanner.c fmd_scanner.h |
| 48 | |
Sol Boucher | 0e53931 | 2015-03-05 15:38:03 -0800 | [diff] [blame] | 49 | .PHONY: all |
Sol Boucher | 69b88bf | 2015-02-26 11:47:19 -0800 | [diff] [blame] | 50 | all: .dependencies $(CBFSTOOL_BINARY) $(FMAPTOOL_BINARY) $(RMODTOOL_BINARY) |
Stefan Reinauer | 746d174 | 2012-08-15 16:02:52 -0700 | [diff] [blame] | 51 | |
Sol Boucher | 0e53931 | 2015-03-05 15:38:03 -0800 | [diff] [blame] | 52 | $(obj)/%: $(obj)/%.o |
| 53 | mkdir -p $(dir $@) |
Paul Menzel | 6548ae9 | 2015-05-03 09:35:32 +0200 | [diff] [blame] | 54 | $(HOSTCC) $(LDFLAGS) -o $@ $^ $(LDLIBS) |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 55 | $(obj)/%.o: %.c |
Sol Boucher | 0e53931 | 2015-03-05 15:38:03 -0800 | [diff] [blame] | 56 | mkdir -p $(dir $@) |
| 57 | $(HOSTCC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< |
Patrick Georgi | 8d6e24c | 2015-05-19 16:41:21 +0200 | [diff] [blame] | 58 | |
| 59 | fmd_scanner.h: fmd_scanner.c |
| 60 | fmd_scanner.c: fmd_scanner.l |
Sol Boucher | 69b88bf | 2015-02-26 11:47:19 -0800 | [diff] [blame] | 61 | $(LEX) $(LFLAGS) -t --header-file=$*.h $< >$*.c |
Patrick Georgi | 8d6e24c | 2015-05-19 16:41:21 +0200 | [diff] [blame] | 62 | |
| 63 | fmd_parser.h: fmd_parser.c |
| 64 | fmd_parser.c: fmd_parser.y |
Sol Boucher | 69b88bf | 2015-02-26 11:47:19 -0800 | [diff] [blame] | 65 | $(YACC) $(YFLAGS) -d $< |
| 66 | mv -f y.tab.c $*.c |
| 67 | mv -f y.tab.h $*.h |
Peter Stuge | 1d862de | 2009-04-14 00:08:34 +0000 | [diff] [blame] | 68 | |
Sol Boucher | 0e53931 | 2015-03-05 15:38:03 -0800 | [diff] [blame] | 69 | .PHONY: clean |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 70 | clean: |
Sol Boucher | 0e53931 | 2015-03-05 15:38:03 -0800 | [diff] [blame] | 71 | $(RM) $(CBFSTOOL_COMMON) $(CBFSTOOL_BINARY).o $(CBFSTOOL_BINARY) |
Sol Boucher | 69b88bf | 2015-02-26 11:47:19 -0800 | [diff] [blame] | 72 | $(RM) $(FMAPTOOL_COMMON) $(FMAPTOOL_BINARY).o $(FMAPTOOL_BINARY) |
Sol Boucher | 0e53931 | 2015-03-05 15:38:03 -0800 | [diff] [blame] | 73 | $(RM) $(RMODTOOL_COMMON) $(RMODTOOL_BINARY).o $(RMODTOOL_BINARY) |
Sol Boucher | 69b88bf | 2015-02-26 11:47:19 -0800 | [diff] [blame] | 74 | $(RM) $(FMAPTESTS_COMMON) $(FMAPTESTS_BINARY).o $(FMAPTESTS_BINARY) |
Sol Boucher | 0e53931 | 2015-03-05 15:38:03 -0800 | [diff] [blame] | 75 | .PHONY: distclean |
| 76 | distclean: clean |
| 77 | $(RM) .dependencies |
Sol Boucher | 69b88bf | 2015-02-26 11:47:19 -0800 | [diff] [blame] | 78 | .PHONY: maintainer-clean |
| 79 | maintainer-clean: distclean |
| 80 | $(RM) $(GENERATED) |
Peter Stuge | 1d862de | 2009-04-14 00:08:34 +0000 | [diff] [blame] | 81 | |
Sol Boucher | 69b88bf | 2015-02-26 11:47:19 -0800 | [diff] [blame] | 82 | tags: $(GENERATED) |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 83 | ctags *.[ch] |
Peter Stuge | 1d862de | 2009-04-14 00:08:34 +0000 | [diff] [blame] | 84 | |
Sol Boucher | 69b88bf | 2015-02-26 11:47:19 -0800 | [diff] [blame] | 85 | .dependencies: $(GENERATED) |
Sol Boucher | 0e53931 | 2015-03-05 15:38:03 -0800 | [diff] [blame] | 86 | @$(HOSTCC) $(CPPFLAGS) $(CFLAGS) -MM -MG *.c > $@ |
Sol Boucher | 69b88bf | 2015-02-26 11:47:19 -0800 | [diff] [blame] | 87 | @$(HOSTCC) $(CPPFLAGS) $(CFLAGS) -MM flashmap/*.c >> $@ |
Sol Boucher | 0e53931 | 2015-03-05 15:38:03 -0800 | [diff] [blame] | 88 | @$(HOSTCC) $(CPPFLAGS) $(CFLAGS) -MM lzma/*.c >> $@ |
| 89 | @$(HOSTCC) $(CPPFLAGS) $(CFLAGS) -MM lzma/C/*.c >> $@ |
| 90 | @sed -i 's|.*:.*|$$(obj)/&|' $@ |
Aaron Durbin | 4fde5a6 | 2014-03-07 15:11:53 -0600 | [diff] [blame] | 91 | |
Sol Boucher | 0e53931 | 2015-03-05 15:38:03 -0800 | [diff] [blame] | 92 | $(CBFSTOOL_BINARY): $(CBFSTOOL_COMMON) |
Sol Boucher | 69b88bf | 2015-02-26 11:47:19 -0800 | [diff] [blame] | 93 | $(FMAPTOOL_BINARY): $(FMAPTOOL_COMMON) |
Sol Boucher | 0e53931 | 2015-03-05 15:38:03 -0800 | [diff] [blame] | 94 | $(RMODTOOL_BINARY): $(RMODTOOL_COMMON) |
Stefan Reinauer | 746d174 | 2012-08-15 16:02:52 -0700 | [diff] [blame] | 95 | |
Sol Boucher | 69b88bf | 2015-02-26 11:47:19 -0800 | [diff] [blame] | 96 | # This target must be built manually |
| 97 | $(FMAPTESTS_BINARY): $(FMAPTESTS_COMMON) |
| 98 | |
| 99 | # Yacc source is superset of header |
| 100 | $(obj)/fmd_parser.o: CFLAGS += -Wno-redundant-decls |
Kyösti Mälkki | c877149 | 2015-05-09 08:06:02 +0300 | [diff] [blame] | 101 | # Lex generates unneeded functions and declarations |
| 102 | $(obj)/fmd_scanner.o: CFLAGS += -Wno-redundant-decls |
Sol Boucher | 69b88bf | 2015-02-26 11:47:19 -0800 | [diff] [blame] | 103 | $(obj)/fmd_scanner.o: CFLAGS += -Wno-unused-function |
Sol Boucher | 0e53931 | 2015-03-05 15:38:03 -0800 | [diff] [blame] | 104 | # Tolerate lzma sdk warnings |
| 105 | $(obj)/lzma/C/LzmaEnc.o: CFLAGS += -Wno-sign-compare -Wno-cast-qual |
Stefan Reinauer | 746d174 | 2012-08-15 16:02:52 -0700 | [diff] [blame] | 106 | |
| 107 | -include .dependencies |