scc

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

rules.mk (4482B)


      1 # Define the target all as default
      2 all:
      3 
      4 PREFIX = /usr/local
      5 LIBPREFIX = $(PREFIX)
      6 LIBPROFILE = scc
      7 CONF = amd64-linux
      8 TOOL = unix
      9 HOST = posix
     10 ROFF = gnu
     11 include $(PROJECTDIR)/config.mk
     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)/bits
     39 ASINCLUDES  = -I$(INCDIR)/bits
     40 LDINCLUDES  = -L$(LIBDIR)/scc
     41 
     42 # Definition of command line for cc, as, ld and emu
     43 PROJ_CPPFLAGS =\
     44 	$(CPPINCLUDES)\
     45 	$(HOST_CPPFLAGS)\
     46 	$(MORE_CPPFLAGS)
     47 
     48 PROJ_CFLAGS =\
     49 	$(PROJ_CPPFLAGS)\
     50 	$(MORE_CFLAGS)\
     51 	$(HOST_CFLAGS)\
     52 	$(SYS_CFLAGS)\
     53 	$(TOOL_CFLAGS)\
     54 	$(CFLAGS)
     55 
     56 PROJ_LDFLAGS =\
     57 	$(MORE_LDFLAGS)\
     58 	$(HOST_LDFLAGS)\
     59 	$(SYS_LDFLAGS)\
     60 	$(TOOL_LDFLAGS)\
     61 	$(LDINCLUDES)\
     62 	$(LDFLAGS)
     63 
     64 PROJ_ASFLAGS =\
     65 	$(MORE_ASFLAGS)\
     66 	$(HOST_ASFLAGS)\
     67 	$(SYS_ASFLAGS)\
     68 	$(TOOL_ASFLAGS)\
     69 	$(ASINCLUDES)\
     70 	$(ASFLAGS)
     71 
     72 PROJ_ARFLAGS =\
     73 	$(MORE_ARFLAGS)\
     74 	$(HOST_ARFLAGS)\
     75 	$(SYS_ARFLAGS)\
     76 	$(TOOL_ARFLAGS)\
     77 	$(ARFLAGS)
     78 
     79 PROJ_RLFLAGS =\
     80 	$(MORE_RLFLAGS)\
     81 	$(HOST_RLFLAGS)\
     82 	$(SYS_RLFLAGS)\
     83 	$(TOOL_RLFLAGS)\
     84 	$(RLFLAGS)
     85 
     86 PROJ_LDLIBS =\
     87 	$(MORE_LDLIBS)\
     88 	$(HOST_LDLIBS)\
     89 	$(SYS_LDLIBS)\
     90 	$(TOOL_LDLIBS)\
     91 	$(LIBS)
     92 
     93 # Definition of tools
     94 CC = $(CROSS_COMPILE)$(COMP)
     95 AS = $(CROSS_COMPILE)$(ASM)
     96 LD = $(CROSS_COMPILE)$(LINKER)
     97 OC = $(CROSS_COMPILE)$(OBJCOPY)
     98 OD = $(CROSS_COMPILE)$(OBJDUMP)
     99 RL = $(CROSS_COMPILE)$(RANLIB)
    100 AR = $(CROSS_COMPILE)$(ARCHIVE)
    101 CPP = $(CROSS_COMPILE)$(PRECOMP)
    102 GS = gs
    103 
    104 $(DIRS) DUMMY : FORCE
    105 	+@cd $@ && $(MAKE)
    106 
    107 # Generic rules
    108 .SUFFIXES:
    109 .SUFFIXES: .c .map .dump .elf .bin\
    110 	   .i .a .o .s .S .ko .ld .tmpl\
    111 	   .pdf .ps .eps .puml\
    112 	   .ms .1 .2 .3 .4 .5 .6 .7\
    113 
    114 .c:
    115 	$(CC) $(PROJ_CFLAGS) $(PROJ_LDFLAGS) -o $@ $< $(PROJ_LDLIBS)
    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_CPPFLAGS) -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 *.elf $(TARGET)
    202 
    203 dep: inc-dep
    204 	@set -e; \
    205 	for i in $(DIRS); \
    206 	do \
    207 		test $$i = tests && continue;\
    208 		cd $$i; \
    209 		$(MAKE) $@; \
    210 		cd -; \
    211 	done
    212 
    213 inc-dep: FORCE
    214 	test -n "$(NODEP)" || $(MKDEP)