Compile makefile files for static and dynamic libraries

Source: Internet
Author: User

write a MAKEFILE file for compiling static and dynamic libraries. Modify the static values in makefile to compile static or dynamic libraries. The complete Program and makefile files are listed in here .

Makefile

Static = 0

Libpath = lib
Cflags =-wall
Ldflags =-I $ (libpath)-L $ (libpath)-lfunc

Ifeq ($ (static), 1)
Lib = $ (libpath)/libfunc.
Else
Lib = $ (libpath)/libfunc. So
Cflags + =-FPIC
Endif

Target = Main
Src = Main. c
Libsrc = libinc. c libdec. c
Libobj = $ (addprefix $ (libpath)/, $ (addsuffix. O, $ (basename $ (libsrc ))))

ALL: $ (LIB) $ (target)

Target: $ (target)

Lib: $ (LIB)

$ (Libpath)/%. O: %. c
$ (CC) $ (cflags)-o $ @-C $ <

Ifeq ($ (static), 1)
$ (LIB): $ (libobj)
$ (AR)-RCS $ ^
Else
$ (LIB): $ (libobj)
$ (CC)-shared-o $ @ $ ^
Endif

$ (Target): $ (SRC)
$ (CC) $ (cflags)-o $ @ $ ^ $ (ldflags)

Clean:
Rm-F $ (target) $ (LIB) $ (libobj)

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.