blob: 518b9453206aed679f50db16705419869fd18c7c [file] [log] [blame]
Björn Stenbergc6b3d382008-11-20 11:27:31 +00001# __________ __ ___.
2# Open \______ \ ____ ____ | | _\_ |__ _______ ___
3# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
4# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
5# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
6# \/ \/ \/ \/ \/
Björn Stenberga091d202008-11-25 19:54:23 +00007# $Id$
Björn Stenbergc6b3d382008-11-20 11:27:31 +00008#
9
10# preprocess - run preprocessor on a file and return the result as a string
11#
Björn Stenbergc6b3d382008-11-20 11:27:31 +000012# 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
17preprocess = $(shell $(CC) $(PPCFLAGS) $(2) -E -P -x c -include config.h $(1) | \
Sean Bartellcadb3622011-10-30 12:05:04 -040018 grep -v '^\#' | grep -v "^ *$$" | \
Björn Stenberg344ad682008-11-21 13:01:03 +000019 sed -e 's:^..*:$(dir $(1))&:')
Björn Stenbergc6b3d382008-11-20 11:27:31 +000020
Rafaël Carré27c509f2010-08-21 18:07:12 +000021preprocess2file = $(SILENT)$(CC) $(PPCFLAGS) $(3) -E -P -x c -include config.h $(1) | \
22 grep -v '^\#' | grep -v "^$$" > $(2)
Björn Stenbergc6b3d382008-11-20 11:27:31 +000023
Rafaël Carré27c509f2010-08-21 18:07:12 +000024asmdefs2file = $(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 Mahone668a7692009-07-13 00:40:35 +000026
Vencislav Atanasov7f9fc202019-07-28 19:44:23 +030027c2obj = $(addsuffix .o,$(basename $(call full_path_subst,$(ROOTDIR)/%,$(BUILDDIR)/%,$(1))))
Björn Stenbergc6b3d382008-11-20 11:27:31 +000028
Thomas Martitzf269aa02012-03-26 22:24:57 +020029a2lnk = $(patsubst lib%.a,-l%,$(notdir $(1)))
30
Thomas Martitz4b56ee02012-04-04 21:43:22 +020031# objcopy wrapper that keeps debug symbols in DEBUG builds
32# handles the $(1) == $(2) case too
33ifndef APP_TYPE
34objcopy = $(OC) $(if $(filter yes, $(USE_ELF)), -S -x, -O binary) $(1) $(2) # objcopy native
35else ifneq (,$(findstring sdl-sim,$(APP_TYPE)))
36objcopy = cp $(1) $(1).tmp;mv -f $(1).tmp $(2) # objcopy simulator
37else
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
43endif
44
Rafaël Carré27c509f2010-08-21 18:07:12 +000045# calculate dependencies for a list of source files $(2) and output them to $(1)
46mkdepfile = $(SILENT)perl $(TOOLSDIR)/multigcc.pl $(CC) $(PPCFLAGS) $(OTHER_INC) -MG -MM -include config.h -- $(2) | \
Teruaki Kawashimae3fc65c2010-01-17 13:03:10 +000047 sed -e "s: lang.h: lang/lang.h:" \
Andrew Mahone668a7692009-07-13 00:40:35 +000048 -e 's:_asmdefs.o:_asmdefs.h:' \
Andrew Mahone541072a2009-07-12 22:02:09 +000049 -e "s: max_language_size.h: lang/max_language_size.h:" | \
50 $(TOOLSDIR)/addtargetdir.pl $(ROOTDIR) $(BUILDDIR) \
Rafaël Carré27c509f2010-08-21 18:07:12 +000051 >> $(1)
Björn Stenbergc6b3d382008-11-20 11:27:31 +000052
53# function to create .bmp dependencies
Rafaël Carré27c509f2010-08-21 18:07:12 +000054bmpdepfile = $(SILENT) \
Björn Stenbergc6b3d382008-11-20 11:27:31 +000055 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 Peachy4c933a12018-12-25 10:33:35 -050058 hdr=`echo $$each | sed -e 's/.*\/\(.*\)\..*\.bmp/bitmaps\/\1\.h/'`; \
Björn Stenbergc6b3d382008-11-20 11:27:31 +000059 echo $$obj: $$src; \
60 echo $$src: $$each; \
Solomon Peachy4c933a12018-12-25 10:33:35 -050061 echo $(BUILDDIR)/$$hdr: $$src; \
Björn Stenbergc6b3d382008-11-20 11:27:31 +000062 done \
Rafaël Carré27c509f2010-08-21 18:07:12 +000063 >> $(1)
Björn Stenbergc6b3d382008-11-20 11:27:31 +000064
65ifndef V
66SILENT:=@
67else
68VERBOSEOPT:=-v
69endif
70PRINTS=$(SILENT)$(call info,$(1))
71
72# old 'make' versions don't have the built-in 'info' function
73info=old$(shell echo >&2 "Consider upgrading to GNU make 3.81+ for optimum build performance.")
74ifeq ($(call info),old)
75export info=echo "$$(1)";
76endif
77
Amaury Poulyb9596552017-05-12 19:50:56 +100078# 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))
91NO_MATCH=this_string_will_never_match_anything
92full_path_subst=$(patsubst $(NO_MATCH)/%,%, $(patsubst $(NO_MATCH)/$(1), $(2), $(addprefix $(NO_MATCH)/, $(3))))