scc

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

rules.mk (4287B)


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