scc

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

rules.mk (4379B)


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