Björn Stenberg | c6b3d38 | 2008-11-20 11:27:31 +0000 | [diff] [blame] | 1 | # __________ __ ___. |
| 2 | # Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 3 | # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 4 | # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 5 | # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 6 | # \/ \/ \/ \/ \/ |
Björn Stenberg | a091d20 | 2008-11-25 19:54:23 +0000 | [diff] [blame] | 7 | # $Id$ |
Björn Stenberg | c6b3d38 | 2008-11-20 11:27:31 +0000 | [diff] [blame] | 8 | # |
| 9 | |
| 10 | # preprocess - run preprocessor on a file and return the result as a string |
| 11 | # |
Björn Stenberg | c6b3d38 | 2008-11-20 11:27:31 +0000 | [diff] [blame] | 12 | # The weird grep -v thing in here is due to Apple's stupidities and is needed |
| 13 | # to make this do right when used on Mac OS X. |
| 14 | # |
| 15 | # The sed line is to prepend the directory to all source files |
| 16 | |
| 17 | preprocess = $(shell $(CC) $(PPCFLAGS) $(2) -E -P -x c -include config.h $(1) | \ |
Sean Bartell | cadb362 | 2011-10-30 12:05:04 -0400 | [diff] [blame] | 18 | grep -v '^\#' | grep -v "^ *$$" | \ |
Björn Stenberg | 344ad68 | 2008-11-21 13:01:03 +0000 | [diff] [blame] | 19 | sed -e 's:^..*:$(dir $(1))&:') |
Björn Stenberg | c6b3d38 | 2008-11-20 11:27:31 +0000 | [diff] [blame] | 20 | |
Rafaël Carré | 27c509f | 2010-08-21 18:07:12 +0000 | [diff] [blame] | 21 | preprocess2file = $(SILENT)$(CC) $(PPCFLAGS) $(3) -E -P -x c -include config.h $(1) | \ |
| 22 | grep -v '^\#' | grep -v "^$$" > $(2) |
Björn Stenberg | c6b3d38 | 2008-11-20 11:27:31 +0000 | [diff] [blame] | 23 | |
Rafaël Carré | 27c509f | 2010-08-21 18:07:12 +0000 | [diff] [blame] | 24 | asmdefs2file = $(SILENT)$(CC) $(PPCFLAGS) $(3) -S -x c -o - -include config.h $(1) | \ |
| 25 | perl -ne 'if(/^_?AD_(\w+):$$/){$$var=$$1}else{/^\W\.(?:word|long)\W(.*)$$/ && $$var && print "\#define $$var $$1\n";$$var=0}' > $(2) |
Andrew Mahone | 668a769 | 2009-07-13 00:40:35 +0000 | [diff] [blame] | 26 | |
Vencislav Atanasov | 7f9fc20 | 2019-07-28 19:44:23 +0300 | [diff] [blame^] | 27 | c2obj = $(addsuffix .o,$(basename $(call full_path_subst,$(ROOTDIR)/%,$(BUILDDIR)/%,$(1)))) |
Björn Stenberg | c6b3d38 | 2008-11-20 11:27:31 +0000 | [diff] [blame] | 28 | |
Thomas Martitz | f269aa0 | 2012-03-26 22:24:57 +0200 | [diff] [blame] | 29 | a2lnk = $(patsubst lib%.a,-l%,$(notdir $(1))) |
| 30 | |
Thomas Martitz | 4b56ee0 | 2012-04-04 21:43:22 +0200 | [diff] [blame] | 31 | # objcopy wrapper that keeps debug symbols in DEBUG builds |
| 32 | # handles the $(1) == $(2) case too |
| 33 | ifndef APP_TYPE |
| 34 | objcopy = $(OC) $(if $(filter yes, $(USE_ELF)), -S -x, -O binary) $(1) $(2) # objcopy native |
| 35 | else ifneq (,$(findstring sdl-sim,$(APP_TYPE))) |
| 36 | objcopy = cp $(1) $(1).tmp;mv -f $(1).tmp $(2) # objcopy simulator |
| 37 | else |
| 38 | ifdef DEBUG |
| 39 | objcopy = cp $(1) $(1).tmp;mv -f $(1).tmp $(2) # objcopy hosted (DEBUG) |
| 40 | else |
| 41 | objcopy = $(OC) -S -x $(1) $(2) # objcopy hosted (!DEBUG) |
| 42 | endif |
| 43 | endif |
| 44 | |
Rafaël Carré | 27c509f | 2010-08-21 18:07:12 +0000 | [diff] [blame] | 45 | # calculate dependencies for a list of source files $(2) and output them to $(1) |
| 46 | mkdepfile = $(SILENT)perl $(TOOLSDIR)/multigcc.pl $(CC) $(PPCFLAGS) $(OTHER_INC) -MG -MM -include config.h -- $(2) | \ |
Teruaki Kawashima | e3fc65c | 2010-01-17 13:03:10 +0000 | [diff] [blame] | 47 | sed -e "s: lang.h: lang/lang.h:" \ |
Andrew Mahone | 668a769 | 2009-07-13 00:40:35 +0000 | [diff] [blame] | 48 | -e 's:_asmdefs.o:_asmdefs.h:' \ |
Andrew Mahone | 541072a | 2009-07-12 22:02:09 +0000 | [diff] [blame] | 49 | -e "s: max_language_size.h: lang/max_language_size.h:" | \ |
| 50 | $(TOOLSDIR)/addtargetdir.pl $(ROOTDIR) $(BUILDDIR) \ |
Rafaël Carré | 27c509f | 2010-08-21 18:07:12 +0000 | [diff] [blame] | 51 | >> $(1) |
Björn Stenberg | c6b3d38 | 2008-11-20 11:27:31 +0000 | [diff] [blame] | 52 | |
| 53 | # function to create .bmp dependencies |
Rafaël Carré | 27c509f | 2010-08-21 18:07:12 +0000 | [diff] [blame] | 54 | bmpdepfile = $(SILENT) \ |
Björn Stenberg | c6b3d38 | 2008-11-20 11:27:31 +0000 | [diff] [blame] | 55 | for each in $(2); do \ |
| 56 | obj=`echo $$each | sed -e 's/\.bmp/.o/' -e 's:$(ROOTDIR):$(BUILDDIR):'`; \ |
| 57 | src=`echo $$each | sed -e 's/\.bmp/.c/' -e 's:$(ROOTDIR):$(BUILDDIR):'`; \ |
Solomon Peachy | 4c933a1 | 2018-12-25 10:33:35 -0500 | [diff] [blame] | 58 | hdr=`echo $$each | sed -e 's/.*\/\(.*\)\..*\.bmp/bitmaps\/\1\.h/'`; \ |
Björn Stenberg | c6b3d38 | 2008-11-20 11:27:31 +0000 | [diff] [blame] | 59 | echo $$obj: $$src; \ |
| 60 | echo $$src: $$each; \ |
Solomon Peachy | 4c933a1 | 2018-12-25 10:33:35 -0500 | [diff] [blame] | 61 | echo $(BUILDDIR)/$$hdr: $$src; \ |
Björn Stenberg | c6b3d38 | 2008-11-20 11:27:31 +0000 | [diff] [blame] | 62 | done \ |
Rafaël Carré | 27c509f | 2010-08-21 18:07:12 +0000 | [diff] [blame] | 63 | >> $(1) |
Björn Stenberg | c6b3d38 | 2008-11-20 11:27:31 +0000 | [diff] [blame] | 64 | |
| 65 | ifndef V |
| 66 | SILENT:=@ |
| 67 | else |
| 68 | VERBOSEOPT:=-v |
| 69 | endif |
| 70 | PRINTS=$(SILENT)$(call info,$(1)) |
| 71 | |
| 72 | # old 'make' versions don't have the built-in 'info' function |
| 73 | info=old$(shell echo >&2 "Consider upgrading to GNU make 3.81+ for optimum build performance.") |
| 74 | ifeq ($(call info),old) |
| 75 | export info=echo "$$(1)"; |
| 76 | endif |
| 77 | |
Amaury Pouly | b959655 | 2017-05-12 19:50:56 +1000 | [diff] [blame] | 78 | # path substituion can be surprisingly tricky, indeed the following almost |
| 79 | # always work but not quite: |
| 80 | # BMPOBJ = $(BMP:$(ROOTDIR)/%.bmp=$(BUILDDIR)/%.o) |
| 81 | # indeed if |
| 82 | # ROOTDIR=/rockbox |
| 83 | # BUILDDIR=/rockbox/build-bla |
| 84 | # then: |
| 85 | # /rockbox/apps/bitmaps/rockboxlogo-bla.bmp -> /rockbox/apps/bitmaps/rockbox/build-blalogo.o |
| 86 | # this function ensure that this type of problems does not occur |
| 87 | # |
| 88 | # usage: $(call full_path_subst,patterm,replacement,text) |
| 89 | # |
| 90 | # example: $(call full_path_subst,$(ROOTDIR)/%.bmp,$(BUILDDIR)/%.o,$(BMP)) |
| 91 | NO_MATCH=this_string_will_never_match_anything |
| 92 | full_path_subst=$(patsubst $(NO_MATCH)/%,%, $(patsubst $(NO_MATCH)/$(1), $(2), $(addprefix $(NO_MATCH)/, $(3)))) |