Coder Social home page Coder Social logo

More Noob Friendly Intro about ycm-generator HOT 1 CLOSED

rdnetto avatar rdnetto commented on July 29, 2024
More Noob Friendly Intro

from ycm-generator.

Comments (1)

rdnetto avatar rdnetto commented on July 29, 2024

Ok, so there's two separate things here I'd like to talk about:

The first is that the core idea is not that you should write makefiles, etc. with YCM-Gen in mind - it's that you should just write good, portable makefiles and YCM-Gen will just work. Actually, all portable means for us is that you haven't hardcoded the path to the compiler. That is, you should be using $(CC) and $(CXX) instead of the name of the compiler.

The second is that the large projects aren't there as examples of how a build system should be written. They're there to demonstrate that YCM-Gen works with 'real' projects, with all their painful complexity and ugly hacks.


That being said, it probably is worthwhile to include an example, so here's the Makefile from a simple C program I wrote a little while ago as reference, which I consider to be fairly concise:

CFLAGS=-g -std=gnu99 -Wall -Wno-parentheses

all: main.o base_station.o sensor_node.o
    $(CC) $(CFLAGS) $^ -o simulate_wsn

clean:
    rm -rf *.o simulate_wsn

main.c, base_station.c, etc. are the source files. (Header files do not need to be included.) Because their respective object files are dependencies of all, make will generate implicit targets for them of the form:

$(CC) $(CFLAGS) foo.c -o foo.o

We then have a single explicitly defined rule for the all target, which links those object files together to generate the binary. ($^ contains all the dependencies of the current target. i.e. the object file names). The clean target is needed as YCM-Gen uses it to erase any state left behind, but you'll normally want to include that anyway out of convenience.

It's worth noting that you can ignore pretty much all of what I said, because only two things really matter:

  • there should be all and clean targets
  • all invocations of the C compiler use $(CC) instead of gcc, etc. (Use $(CXX) for C++.)

Now, if for some reason you need to use a specific / non-default compiler for a given project, you can define the CC variable (in a similar fashion to the CFLAGS variable), but you will then need to pass --make-flags=-e to YCM-Gen so that it will be overridden.

Let me know if I've left anything out. :)

from ycm-generator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.