scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

rules.mk (4569B)


      1 # Define the target all as default
      2 all:
      3 
      4 # Define default configuration variables
      5 PREFIX = /usr/local
      6 LIBPREFIX = $(PREFIX)
      7 LIBPROFILE = scc
      8 CONF = amd64-linux
      9 TOOL = unix
     10 HOST = posix
     11 ROFF = gnu
     12 
     13 # Define helper macros for project directories
     14 DOCDIR    = $(PROJECTDIR)/doc
     15 INCDIR    = $(PROJECTDIR)/include
     16 BINDIR    = $(PROJECTDIR)/bin
     17 SRCDIR    = $(PROJECTDIR)/src
     18 SCRIPTDIR = $(PROJECTDIR)/scripts
     19 LIBDIR    = $(PROJECTDIR)/lib
     20 LIBEXEC   = $(PROJECTDIR)/libexec
     21 BUILDDIR  = $(PROJECTDIR)/scripts/build
     22 CRTDIR    = $(PROJECTDIR)/lib/scc
     23 LIBCDIR   = $(CRTDIR)/$(ARCH)-$(SYS)
     24 MKDEP     = $(SCRIPTDIR)/mkdep
     25 SRCDIR    = $(PROJECTDIR)/src
     26 CMDDIR    = $(SRCDIR)/cmd
     27 
     28 # library dependences helpers
     29 LIBMACH = $(LIBDIR)/scc/libmach.a
     30 LIBSCC  = $(LIBDIR)/scc/libscc.a
     31 
     32 # Include configuration definitions
     33 include $(BUILDDIR)/conf/$(CONF).mk
     34 include $(BUILDDIR)/tool/$(TOOL).mk
     35 include $(BUILDDIR)/host/$(HOST).mk
     36 
     37 # Locations for -I or -L in compiler, assembler or linker
     38 CPPINCLUDES = -I$(INCDIR)/scc
     39 ASINCLUDES= -I$(INCDIR)/scc
     40 LDINCLUDES= -L$(LIBDIR)/scc
     41 
     42 # C standard for the target compiler
     43 STD = c99
     44 
     45 # Definition of command line for cc, as, ld and emu
     46 PROJ_CPPFLAGS =\
     47 	$(CPPINCLUDES)\
     48 	$(HOST_CPPFLAGS)\
     49 	$(MORE_CPPFLAGS)
     50 
     51 PROJ_CFLAGS =\
     52 	$(MORE_CFLAGS)\
     53 	$(HOST_CFLAGS)\
     54 	$(SYS_CFLAGS)\
     55 	$(TOOL_CFLAGS)\
     56 	$(CFLAGS)
     57 
     58 PROJ_LDFLAGS =\
     59 	$(MORE_LDFLAGS)\
     60 	$(HOST_LDFLAGS)\
     61 	$(SYS_LDFLAGS)\
     62 	$(TOOL_LDFLAGS)\
     63 	$(LDINCLUDES)\
     64 	$(LDFLAGS)
     65 
     66 PROJ_ASFLAGS =\
     67 	$(MORE_ASFLAGS)\
     68 	$(HOST_ASFLAGS)\
     69 	$(SYS_ASFLAGS)\
     70 	$(TOOL_ASFLAGS)\
     71 	$(ASINCLUDES)\
     72 	$(ASFLAGS)
     73 
     74 PROJ_ARFLAGS =\
     75 	$(MORE_ARFLAGS)\
     76 	$(HOST_ARFLAGS)\
     77 	$(SYS_ARFLAGS)\
     78 	$(TOOL_ARFLAGS)\
     79 	$(ARFLAGS)
     80 
     81 PROJ_RLFLAGS =\
     82 	$(MORE_RLFLAGS)\
     83 	$(HOST_RLFLAGS)\
     84 	$(SYS_RLFLAGS)\
     85 	$(TOOL_RLFLAGS)\
     86 	$(RLFLAGS)
     87 
     88 PROJ_LDLIBS =\
     89 	$(MORE_LDLIBS)\
     90 	$(HOST_LDLIBS)\
     91 	$(SYS_LDLIBS)\
     92 	$(TOOL_LDLIBS)\
     93 	$(LIBS)
     94 
     95 # Definition of tools
     96 CC = $(CROSS_COMPILE)$(COMP)
     97 AS = $(CROSS_COMPILE)$(ASM)
     98 LD = $(CROSS_COMPILE)$(LINKER)
     99 OC = $(CROSS_COMPILE)$(OBJCOPY)
    100 OD = $(CROSS_COMPILE)$(OBJDUMP)
    101 RL = $(CROSS_COMPILE)$(RANLIB)
    102 AR = $(CROSS_COMPILE)$(ARCHIVE)
    103 CPP = $(CROSS_COMPILE)$(PRECOMP)
    104 GS = gs
    105 
    106 # helper macro to run over all the directories
    107 FORALL = +@set -e ;\
    108 	for i in $(DIRS); \
    109 	do \
    110 		cd $$i; \
    111 		$(MAKE) $@; \
    112 		cd -; \
    113 	done
    114 
    115 $(DIRS) DUMMY : FORCE
    116 	+@cd $@ && $(MAKE)
    117 
    118 # Generic rules
    119 .SUFFIXES:
    120 .SUFFIXES: .c .map .dump .elf .bin\
    121 	   .i .a .o .s .S .ko .ld .tmpl\
    122 	   .pdf .ps .eps .puml\
    123 	   .ms .1 .2 .3 .4 .5 .6 .7\
    124 
    125 .c:
    126 	$(CC) $(PROJ_CPPFLAGS) $(PROJ_CFLAGS) -o $@ $<
    127 
    128 .s.o:
    129 	$(AS) $(PROJ_ASFLAGS) $< -o $@
    130 
    131 .s.ko:
    132 	$(AS) $(PROJ_ASFLAGS) $< -o $@
    133 
    134 .c.o:
    135 	$(CC) $(PROJ_CPPFLAGS) $(PROJ_CFLAGS) -o $@ -c $<
    136 
    137 .c.s:
    138 	$(CC) $(PROJ_CPPFLAGS) $(PROJ_CFLAGS) -S -o $@ $<
    139 
    140 .c.i:
    141 	$(CPP) $(PROJ_CPPFLAGS) -o $@ $<
    142 
    143 .elf.bin:
    144 	$(OC) -O binary $< $@
    145 
    146 .o.dump:
    147 	trap "rm -f $$$$.eps" EXIT QUIT INT TERM;\
    148 	$(OD) -D $< > $$$$.dump && mv $$$$.dump $@
    149 
    150 .elf.map:
    151 	trap "rm -f $$$$.eps" EXIT QUIT INT TERM;\
    152 	$(LD) -Map=$@ $< -o /dev/null
    153 
    154 .puml.eps:
    155 	trap "rm -f $$$$.eps" EXIT QUIT INT TERM;\
    156 	plantuml -p -teps < $< > $$$$.eps && mv $$$$.eps $@
    157 
    158 .ms.ps:
    159 	trap "rm -f $$$$.ps" EXIT QUIT INT TERM;\
    160 	$(SOELIM) $< | $(GRAP) | $(PIC) | $(EQN) | $(TBL) |\
    161 	$(TROFF) -ms | $(DPOST) > $$$$.ps &&\
    162 	mv $$$$.ps $@
    163 .1.ps:
    164 	trap "rm -f $$$$.ps" EXIT QUIT INT TERM;\
    165 	$(TBL) $< | $(TROFF) -man | $(DPOST) > $$$$.ps && mv $$$$.ps $@
    166 
    167 .2.ps:
    168 	trap "rm -f $$$$.ps" EXIT QUIT INT TERM;\
    169 	$(TBL) $< | $(TROFF) -man | $(DPOST) > $$$$.ps && mv $$$$.ps $@
    170 
    171 .3.ps:
    172 	trap "rm -f $$$$.ps" EXIT QUIT INT TERM;\
    173 	$(TBL) $< | $(TROFF) -man | $(DPOST) > $$$$.ps && mv $$$$.ps $@
    174 
    175 .4.ps:
    176 	trap "rm -f $$$$.ps" EXIT QUIT INT TERM;\
    177 	$(TBL) $< | $(TROFF) -man | $(DPOST) > $$$$.ps && mv $$$$.ps $@
    178 
    179 .5.ps:
    180 	trap "rm -f $$$$.ps" EXIT QUIT INT TERM;\
    181 	$(TBL) $< | $(TROFF) -man | $(DPOST) > $$$$.ps && mv $$$$.ps $@
    182 
    183 .6.ps:
    184 	trap "rm -f $$$$.ps" EXIT QUIT INT TERM;\
    185 	$(TBL) $< | $(TROFF) -man | $(DPOST) > $$$$.ps && mv $$$$.ps $@
    186 
    187 .7.ps:
    188 	trap "rm -f $$$$.ps" EXIT QUIT INT TERM;\
    189 	$(TBL) $< | $(TROFF) -man | $(DPOST) > $$$$.ps && mv $$$$.ps $@
    190 
    191 .ps.pdf:
    192 	$(GS) -P- -dSAFER -q -P- -dNOPAUSE -dBATCH -sDEVICE=pdfwrite \
    193 	    -ssdout=%stderr "-sOutputFile=$@" -P- -dSAFER "$<"
    194 
    195 .eps.pdf:
    196 	$(GS) -P- -dSAFER -q -P- -dNOPAUSE -dBATCH -sDEVICE=pdfwrite \
    197 	    -ssdout=%stderr "-sOutputFile=$@" -P- -dSAFER "$<"
    198 FORCE:
    199 
    200 clean: clean-files clean-dirs
    201 
    202 clean-dirs:
    203 	+@set -e; \
    204 	for i in $(DIRS); \
    205 	do \
    206 		cd $$i; \
    207 		$(MAKE) clean; \
    208 		cd -; \
    209 	done
    210 
    211 clean-files:
    212 	rm -f *.i *.d *.o *.a *.elf $(TARGET)
    213 
    214 dep: inc-dep
    215 	$(FORALL)
    216 
    217 inc-dep: FORCE
    218 	test -n "$(NODEP)" || $(MKDEP)