scc

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

rules.mk (4299B)


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